@join-pantheon/cli 0.33.10 → 0.33.11-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -136,15 +136,20 @@ if ($NoticeScript -and (Test-Path -LiteralPath $NoticeScript)) {
136
136
  # never XML (src/notice-windows.ts QueuedNotice, version 2); each is checked
137
137
  # here, and the XML is built here, with the same escaping as Node's toastXml,
138
138
  # so a file someone else drops into the queue cannot inject markup. Every link
139
- # must be one of the four pantheon:// forms (src/uri-handler.ts parseUri), and
139
+ # must be one of the pantheon:// forms (src/uri-handler.ts parseUri), and
140
140
  # the app ids the two the notifier uses. Anything else is dropped and logged.
141
141
  $PT.linkForms = @{
142
142
  board = @{ required = @(); optional = @() }
143
143
  done = @{ required = @('decision', 'k'); optional = @('act', 'space') }
144
144
  explain = @{ required = @('decision', 'k'); optional = @('act', 'space') }
145
145
  details = @{ required = @('act', 'k'); optional = @('decision', 'space') }
146
+ # 0.33.10: Approve / Keep as is on a setup change; Take over / Stop on a run the worker started.
147
+ change = @{ required = @('id', 'answer', 'k'); optional = @() }
148
+ work = @{ required = @('ref', 'do', 'k'); optional = @('space') }
149
+ changes = @{ required = @(); optional = @() }
146
150
  }
147
- $PT.linkValues = @{ decision = '^o_[a-z0-9]{6,48}$'; act = '^a_[A-Za-z0-9]{6,48}$'; space = '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$'; k = '^[0-9a-f]{32}$' }
151
+ $PT.linkValues = @{ decision = '^o_[a-z0-9]{6,48}$'; act = '^a_[A-Za-z0-9]{6,48}$'; space = '^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$'; k = '^[0-9a-f]{32}$'
152
+ id = '^c_[0-9a-f]{8}$'; answer = '^(approve|keep)$'; ref = '^(cont%3A)?a_[A-Za-z0-9]{6,48}$'; do = '^(stop|takeover)$' }
148
153
  # Pantheon's own app id (uri-handler.ts PANTHEON_AUMID) and Windows PowerShell's (notice-windows.ts POWERSHELL_AUMID).
149
154
  $PT.aumids = @('JoinPantheon.Pantheon', '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe')
150
155
  # A queued file that cannot be taken (read and deleted) is tried for this long, then skipped while it is there unchanged.
@@ -152,7 +157,7 @@ $PT.stuck = @{}
152
157
  $PT.stuckSeconds = 5
153
158
  $PT.skippedFile = Join-Path $PT.hostDir 'notices.skipped'
154
159
 
155
- # One link: pantheon://board, or done/explain/details with each parameter once,
160
+ # One link: pantheon://board, or done/explain/details/change/work with each parameter once,
156
161
  # every value in the form Pantheon writes it. Strict, as the handler is.
157
162
  function global:Test-PantheonLink($uri) {
158
163
  if ($uri -isnot [string] -or -not $uri -or $uri.Length -gt 400) { return $false }
@@ -284,8 +289,11 @@ function global:Read-QueuedNotice([string]$json, [datetime]$now) {
284
289
  $text = [string]$balloon.text; if ($text.Length -gt 255) { $text = $text.Substring(0, 255) }
285
290
  if (-not $title) { $title = 'Pantheon' }
286
291
  if (-not $text) { $text = 'Open Pantheon' }
292
+ # How long until it leaves the Action Center (minutes), when it says: optional, a small whole number.
293
+ $expires = 0
294
+ if ($null -ne $q.expires) { if ([string]$q.expires -cnotmatch '^\d{1,4}$' -or [int][string]$q.expires -gt 1440) { return $null }; $expires = [int][string]$q.expires }
287
295
  return @{
288
- stale = $false; about = $about; xml = $xml; tag = [string]$q.tag
296
+ stale = $false; about = $about; xml = $xml; tag = [string]$q.tag; expires = $expires
289
297
  aumids = @($q.aumids | ForEach-Object { [string]$_ }); title = $title; text = $text
290
298
  }
291
299
  } catch { return $null }
@@ -428,6 +436,10 @@ function global:Read-Status([string]$json) {
428
436
  # The board's cards: lane "now", or a row from an older CLI without lanes that is not a wait (menubar.swift effectiveLane).
429
437
  if ($lane -eq 'now' -or (@('now', 'handling', 'waiting', 'older') -notcontains $lane -and $kind -ne 'waiting')) { $need++ }
430
438
  }
439
+ # A setup change waiting for the person (it is one of the items above, a card: counted there).
440
+ $changes = @(Read-PendingChanges $j.pending_changes)
441
+ # Work the worker has under "Your agents are handling" (0.33.10): Take over / Stop.
442
+ $handling = @(Read-Handling $j.items)
431
443
  return @{
432
444
  loaded = $true; reachable = $true
433
445
  configured = [bool]$j.configured; relayOk = [bool]$j.relay_ok
@@ -437,6 +449,9 @@ function global:Read-Status([string]$json) {
437
449
  # Why this computer cannot take requests, with the fix (signed out, no agent CLI): the heading, the icon and a menu line say it.
438
450
  agentProblem = $(if ($j.agent_problem -is [string]) { $p = ([string]$j.agent_problem) -replace '[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]', ''; if ($p.Length -gt 200) { $p.Substring(0, 199) + $PT.ellipsis } else { $p } } else { '' })
439
451
  agentProblemLead = $(if ($j.agent_problem_lead) { [string]$j.agent_problem_lead } else { "Unattended work can't run" })
452
+ # Changes to this person's setup waiting for them (0.33.10): each with the two signed links its menu items run.
453
+ changes = $changes
454
+ handling = $handling
440
455
  # Teams gone for this computer (deleted, or this person removed): a line each, and the id `pantheon leave <id> --yes` takes.
441
456
  # tray-status leaves them out of relay_ok, so one gone team never marks the whole machine unreachable.
442
457
  gone = @(@($j.gone_spaces) | Where-Object { $null -ne $_ -and $_.space -is [string] -and $_.line -is [string] -and $_.space } | ForEach-Object {
@@ -446,6 +461,34 @@ function global:Read-Status([string]$json) {
446
461
  }
447
462
  }
448
463
 
464
+ # A request under "Your agents are handling", as the menu shows it: its title and
465
+ # the two signed links (Take over, Stop) that pass Test-PantheonLink. Others are left out.
466
+ function global:Read-Handling($items) {
467
+ $out = @()
468
+ foreach ($i in @($items)) {
469
+ if ($null -eq $i -or [string]$i.lane -ne 'handling' -or $null -eq $i.run) { continue }
470
+ if (-not (Test-PantheonLink $i.run.takeover) -or -not (Test-PantheonLink $i.run.stop)) { continue }
471
+ $title = ([string]$i.title) -replace '[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]', ''
472
+ if ($title.Length -gt 60) { $title = $title.Substring(0, 59) + $PT.ellipsis }
473
+ $out += @{ title = $title; takeover = [string]$i.run.takeover; stop = [string]$i.run.stop }
474
+ }
475
+ return $out
476
+ }
477
+
478
+ # A waiting change, as the menu shows it: a short plain label. It is answered in
479
+ # a console (pantheon changes review), where the whole of what it does is shown
480
+ # before anything is approved -- never from a menu line that can show only its name.
481
+ function global:Read-PendingChanges($list) {
482
+ $out = @()
483
+ foreach ($c in @($list)) {
484
+ if ($null -eq $c -or $c.label -isnot [string] -or [string]$c.id -cnotmatch '^c_[0-9a-f]{8}$') { continue }
485
+ $label = ([string]$c.label) -replace '[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]', ''
486
+ if ($label.Length -gt 80) { $label = $label.Substring(0, 79) + $PT.ellipsis }
487
+ $out += @{ label = $label }
488
+ }
489
+ return $out
490
+ }
491
+
449
492
  function global:Get-Summary {
450
493
  $s = $PT.state
451
494
  if (-not $s.loaded) { return 'Checking status' + $PT.ellipsis }
@@ -645,7 +688,7 @@ function global:Exit-Tray {
645
688
  function global:Show-QueuedNotices {
646
689
  foreach ($n in (Get-QueuedNotices (Get-Date))) {
647
690
  if ($n.stale) { Write-PantheonAlertLog ('tray: dropped ' + $n.about + ' (queued more than ten minutes ago)'); continue }
648
- $r = Show-PantheonToast $n.xml $n.tag $n.aumids
691
+ $r = Show-PantheonToast $n.xml $n.tag $n.aumids $null ([int]$n.expires)
649
692
  if ($r.code -eq 0) { Write-PantheonAlertLog ('tray: shown ' + $n.about + ' (' + ($r.said -join ' | ') + ')'); continue }
650
693
  try {
651
694
  $PT.tray.ShowBalloonTip(15000, $n.title, $n.text, [System.Windows.Forms.ToolTipIcon]::Info)
@@ -722,7 +765,27 @@ function global:Build-Menu {
722
765
  # Not greyed out: a click opens status, which says it in full with the fix.
723
766
  # The heading already says it cannot run (when nothing else needs you): the row says why, and the fix.
724
767
  if ($s.agentProblem) { Add-MenuItem $(if ($s.need -eq 0) { $s.agentProblem } else { $s.agentProblemLead + ': ' + $s.agentProblem }) { Open-PantheonConsole 'Pantheon status' 'status' } $true }
768
+ # A change to this person's setup asked by an agent waits for their yes: answered here, as on the alert.
769
+ if (@($s.changes).Count) {
770
+ [void]$menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator))
771
+ foreach ($c in @($s.changes)) { if ($null -ne $c) { Add-MenuItem ('Setup change waiting: ' + $c.label) $null $true $false } }
772
+ Add-MenuItem ' Review' { Open-PantheonConsole 'Pantheon changes' 'changes review' }
773
+ }
774
+ # What the worker is on for teammates: the person can take it back, or stop it.
775
+ if (@($s.handling).Count) {
776
+ [void]$menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator))
777
+ Add-MenuItem 'Your agents are handling' $null $true $false
778
+ foreach ($h in @($s.handling)) {
779
+ if ($null -eq $h) { continue }
780
+ Add-MenuItem (' ' + $h.title) $null $false $false
781
+ $take = $h.takeover; $stop = $h.stop
782
+ Add-MenuItem ' Take over' ({ Invoke-Hidden @('handle-uri', $take) 'take over a request' }.GetNewClosure())
783
+ Add-MenuItem ' Stop' ({ Invoke-Hidden @('handle-uri', $stop) 'stop a request' }.GetNewClosure())
784
+ }
785
+ }
725
786
  $gone = @($s.gone)
787
+ # The gone teams are their own block: a separator, so they never read as part of the work above.
788
+ if ($gone.Count) { [void]$menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator)) }
726
789
  foreach ($g in ($gone | Select-Object -First $PT.goneShown)) { Add-GoneItem ($g.line + ' ' + $PT.dot + ' Remove from this computer') $g.space $g.line }
727
790
  if ($gone.Count -gt $PT.goneShown) { Add-MenuItem ('and ' + ($gone.Count - $PT.goneShown) + ' more gone ' + $PT.dash + ' Open board') { Open-Board } }
728
791
  [void]$menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator))
@@ -242,6 +242,42 @@ function Install-Pantheon {
242
242
  return , $out
243
243
  }
244
244
 
245
+ # A pantheon uninstall run from this root removes its runtime and launcher a
246
+ # moment after it exits, by a hidden PowerShell that marks the root with
247
+ # .uninstalling ("<its id> <its start time, UTC ticks>") until it is done
248
+ # (uninstall.ts finishAfterExit). An install made meanwhile would be deleted
249
+ # under it. Live: that very process still runs (its id AND start time, so an
250
+ # id Windows gave to another program is not it) and the mark is younger than
251
+ # $MaxAge. A mark without an id is judged by its age alone.
252
+ function Test-PantheonUninstallLive([string]$Mark, [TimeSpan]$MaxAge) {
253
+ try { $item = Get-Item -LiteralPath $Mark -Force -ErrorAction Stop } catch { return $false }
254
+ if (([DateTime]::UtcNow - $item.LastWriteTimeUtc) -gt $MaxAge) { return $false }
255
+ $first = ''
256
+ try { $first = [string]@(Get-Content -LiteralPath $Mark -TotalCount 1 -ErrorAction Stop)[0] } catch { $first = '' }
257
+ if ($first -notmatch '^\s*(\d+)\s+(\d+)\s*$') { return $true }
258
+ $id = [int]$Matches[1]; $ticks = [long]$Matches[2]
259
+ $p = Get-Process -Id $id -ErrorAction SilentlyContinue
260
+ if (-not $p) { return $false }
261
+ try { $start = $p.StartTime.ToUniversalTime().Ticks } catch { return $true }
262
+ return [Math]::Abs($start - $ticks) -le [TimeSpan]::TicksPerSecond
263
+ }
264
+
265
+ # Waits, at most $Seconds, while such a cleanup runs. 'none': no mark; 'done':
266
+ # it finished; 'running': still going; 'stale': a mark nothing will ever remove
267
+ # (a restart or logoff mid-cleanup, a security tool that stopped it).
268
+ function Wait-PantheonUninstall([string]$Root, [int]$Seconds, [scriptblock]$OnWait, [scriptblock]$Sleep = { Start-Sleep -Milliseconds 500 }, [TimeSpan]$MaxAge = [TimeSpan]::FromMinutes(3)) {
269
+ $mark = Join-Path $Root '.uninstalling'
270
+ if (-not (Test-Path -LiteralPath $mark)) { return 'none' }
271
+ if (Test-PantheonUninstallLive $mark $MaxAge) {
272
+ if ($OnWait) { & $OnWait }
273
+ $until = [DateTime]::UtcNow.AddSeconds($Seconds)
274
+ while ((Test-Path -LiteralPath $mark) -and (Test-PantheonUninstallLive $mark $MaxAge) -and [DateTime]::UtcNow -lt $until) { & $Sleep }
275
+ }
276
+ if (-not (Test-Path -LiteralPath $mark)) { return 'done' }
277
+ if (Test-PantheonUninstallLive $mark $MaxAge) { return 'running' }
278
+ return 'stale'
279
+ }
280
+
245
281
  # A full path in the \\?\ form, which Windows takes past 260 characters.
246
282
  function ConvertTo-PantheonLongPath([string]$Path) {
247
283
  if ($Path.StartsWith('\\?\')) { return $Path }
@@ -782,6 +818,25 @@ function Install-Pantheon {
782
818
  $pantheonHomeDir = if ($env:PANTHEON_HOME) { $env:PANTHEON_HOME } else { Join-Path ([Environment]::GetFolderPath('UserProfile')) '.pantheon' }
783
819
  $hostDir = Join-Path $pantheonHomeDir 'host'
784
820
 
821
+ # ---- an uninstall still removing what was here ------------------------
822
+ $State.step = 'waiting for the last uninstall to finish'
823
+ $q = { param($p) "'" + $p.Replace("'", "''") + "'" }
824
+ $uninstallMark = Join-Path $root '.uninstalling'
825
+ $pending = Wait-PantheonUninstall $root 60 { Say "The last pantheon uninstall is still removing Pantheon from $root; waiting for it to finish (up to a minute)..." }
826
+ if ($pending -eq 'running') {
827
+ Fail "the last pantheon uninstall has not finished removing Pantheon from $root, and installing now would be deleted under it. Close your agent windows (one may still be running Pantheon) and run this again in a minute."
828
+ }
829
+ if ($pending -eq 'stale') {
830
+ # Its cleanup stopped part way: what it was removing goes now, as it would have.
831
+ $State.step = 'finishing an uninstall that stopped part way'
832
+ Say "An earlier pantheon uninstall stopped before it finished removing Pantheon from $root; finishing that first."
833
+ if (Test-Path -LiteralPath $runtime) {
834
+ $why = Remove-PantheonTree $runtime
835
+ if ($why) { Fail "an earlier pantheon uninstall left Pantheon's old files in $runtime, and they cannot be removed ($why). Close your agent windows (one may still be running Pantheon), then run this again; or remove them in PowerShell first: Remove-Item -Recurse -Force $(& $q $runtime)" }
836
+ }
837
+ Remove-Item -LiteralPath $launcher, $uninstallMark -Force -ErrorAction SilentlyContinue
838
+ }
839
+
785
840
  $State.step = "creating $root"
786
841
  try { New-Item -ItemType Directory -Force -Path $runtime, $binDir | Out-Null }
787
842
  catch { Fail "could not create $runtime ($($_.Exception.Message)). Check that the folder is yours and the disk has space, then run this again." }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@join-pantheon/cli",
3
- "version": "0.33.10",
3
+ "version": "0.33.11-rc.2",
4
4
  "description": "Let your coding agent collaborate directly with your teammates' agents — ask, agree an interface, and deliver, without a human relaying messages.",
5
5
  "type": "module",
6
6
  "bin": {