@join-pantheon/cli 0.33.11-rc.1 → 0.33.11

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.
@@ -14,7 +14,7 @@ export const PANTHEON_HOME_ENTRIES = [
14
14
  { name: "worker-cursor.json", what: "where the worker last read", identity: true },
15
15
  { name: "profile.json", what: "your profile", identity: true },
16
16
  { name: "worker-policy.json", what: "the worker's wake policy", identity: true },
17
- { name: "setup-changes.log", what: "the history of changes to your setup", identity: true },
17
+ { name: "setup-changes.log", what: "the history of changes to your setup" },
18
18
  { name: "setup-pending.json", what: "changes to your setup waiting for your yes" },
19
19
  { name: "run-control.json", what: "requests you took over from your agent, or stopped" },
20
20
  { name: "worker-declined.json", what: "requests your worker will not take, and why" },
@@ -48,6 +48,7 @@ export const PANTHEON_HOME_ENTRIES = [
48
48
  { name: "lfs-hooks", what: "the LFS-only hooks folder woken runs' git uses", dir: true },
49
49
  { name: "runtime", what: "Pantheon's own Node", dir: true, kept: "managed" },
50
50
  { name: "install.log", what: "the installer's log", kept: "managed" },
51
+ { name: ".uninstalling", what: "the mark that an uninstall is still removing Pantheon's own Node", kept: "managed" },
51
52
  { name: "data", what: "the relay's ledger", dir: true, kept: "it is your team's history and may be its only copy; delete it yourself once no relay runs from it" },
52
53
  { name: /^(\.DS_Store|Thumbs\.db|desktop\.ini)$/i, sample: ".DS_Store", what: "the file browser's folder cache" },
53
54
  ];
package/dist/uninstall.js CHANGED
@@ -143,36 +143,46 @@ export function managedInstall(home, os = platform(), env = process.env, fs = re
143
143
  const log = os === "win32" ? p.join(root, "install.log") : p.join(root, "logs", "install.log");
144
144
  return { os, root, runtime, binDir, launcher, log, present: fs.exists(runtime) || fs.exists(launcher) };
145
145
  }
146
- export function finishAfterExit(paths, pids = [process.pid], ifEmpty = null) {
147
- const inner = cleanupScript(paths, pids, ifEmpty);
146
+ export function finishAfterExit(paths, pids = [process.pid], ifEmpty = null, emptyFirst = []) {
147
+ const inner = cleanupScript(paths, pids, ifEmpty, emptyFirst);
148
148
  if (!inner)
149
149
  return false;
150
+ const mark = ifEmpty ? win32.join(ifEmpty, UNINSTALL_MARK) : null;
150
151
  const ps = `${process.env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
151
152
  try {
152
- const r = spawnSync(ps, ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", cleanupLauncher(ps, inner)], {
153
- windowsHide: true, stdio: "ignore", timeout: 30_000,
153
+ const r = spawnSync(ps, ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", cleanupLauncher(ps, inner, mark)], {
154
+ windowsHide: true, stdio: ["ignore", "pipe", "ignore"], encoding: "utf8", timeout: 30_000,
154
155
  });
155
- return r.status === 0;
156
+ return /^\d+$/.test(String(r.stdout ?? "").trim());
156
157
  }
157
158
  catch {
158
159
  return false;
159
160
  }
160
161
  }
161
- export function cleanupLauncher(ps, inner) {
162
+ export const UNINSTALL_MARK = ".uninstalling";
163
+ export function cleanupLauncher(ps, inner, mark = null) {
162
164
  const enc = Buffer.from(inner, "utf16le").toString("base64");
163
- return `Start-Process -FilePath '${ps.replace(/'/g, "''")}' -WindowStyle Hidden -ArgumentList '-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-EncodedCommand','${enc}'`;
165
+ const start = `$p = Start-Process -PassThru -FilePath '${ps.replace(/'/g, "''")}' -WindowStyle Hidden -ArgumentList '-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-EncodedCommand','${enc}'`;
166
+ const write = mark && !/[\r\n]/.test(mark)
167
+ ? `; try { [IO.File]::WriteAllText('${mark.replace(/'/g, "''")}', [string]$p.Id + ' ' + $p.StartTime.ToUniversalTime().Ticks + "\`r\`npantheon uninstall is removing Pantheon's own Node from here; this file goes when it is done.\`r\`n") } catch { }`
168
+ : "";
169
+ return `${start}${write}; $p.Id`;
164
170
  }
165
- export function cleanupScript(paths, pids, ifEmpty = null) {
166
- if (!paths.length || paths.some((x) => /[\r\n]/.test(x)) || (ifEmpty && /[\r\n]/.test(ifEmpty)))
171
+ export function cleanupScript(paths, pids, ifEmpty = null, emptyFirst = []) {
172
+ if (!paths.length || [...paths, ...emptyFirst, ifEmpty ?? ""].some((x) => /[\r\n]/.test(x)))
167
173
  return null;
168
174
  const ids = pids.filter((n) => Number.isInteger(n) && n > 0);
175
+ const q = (x) => `'${x.replace(/'/g, "''")}'`;
176
+ const ifEmptyDir = (d) => `$d = ${q(d)}; if ((Test-Path -LiteralPath $d) -and -not (Get-ChildItem -LiteralPath $d -Force)) { Remove-Item -LiteralPath $d -Force }`;
169
177
  const steps = [
170
178
  ids.length ? `Wait-Process -Id ${ids.join(",")} -Timeout 60 -ErrorAction SilentlyContinue` : "",
171
179
  "Start-Sleep -Milliseconds 500",
172
- `Remove-Item -LiteralPath ${paths.map((x) => `'${x.replace(/'/g, "''")}'`).join(",")} -Recurse -Force`,
173
- ifEmpty ? `$d = '${ifEmpty.replace(/'/g, "''")}'; if ((Test-Path -LiteralPath $d) -and -not (Get-ChildItem -LiteralPath $d -Force)) { Remove-Item -LiteralPath $d -Force }` : "",
180
+ `Remove-Item -LiteralPath ${paths.map(q).join(",")} -Recurse -Force`,
181
+ ...emptyFirst.map(ifEmptyDir),
174
182
  ].filter(Boolean).join("; ");
175
- return `& { ${steps} } *> (Join-Path $env:TEMP 'pantheon-uninstall.log')`;
183
+ const last = ifEmpty ? `Remove-Item -LiteralPath ${q(win32.join(ifEmpty, UNINSTALL_MARK))} -Force -ErrorAction SilentlyContinue; ${ifEmptyDir(ifEmpty)}` : "";
184
+ return `$o = $null; try { $o = & { ${steps} } *>&1 } finally { ${last} }; ` +
185
+ `try { $t = $env:TEMP; if (-not $t) { $t = [IO.Path]::GetTempPath() }; @("pantheon uninstall, cleanup after exit, $(Get-Date -Format o)") + @($o) | Out-File -LiteralPath (Join-Path $t 'pantheon-uninstall.log') -ErrorAction Stop } catch { }`;
176
186
  }
177
187
  export function removeManagedInstall(o) {
178
188
  const fs = o.fs ?? realUninstallFs;
@@ -251,7 +261,7 @@ export function removeManagedInstall(o) {
251
261
  }
252
262
  const lockedHere = m.os === "win32" && !!o.running && o.running.root.toLowerCase() === m.root.toLowerCase();
253
263
  if (lockedHere) {
254
- const finish = o.finishLater ? o.finishLater([m.runtime, m.binDir, m.log], m.root) : finishAfterExit([m.runtime, m.binDir, m.log], undefined, m.root);
264
+ const finish = o.finishLater ? o.finishLater([m.runtime, m.launcher, m.log], m.root, [m.binDir]) : finishAfterExit([m.runtime, m.launcher, m.log], undefined, m.root, [m.binDir]);
255
265
  const byHand = `Remove-Item -Recurse -Force ${[m.runtime, m.binDir].map((x) => `'${x.replace(/'/g, "''")}'`).join(", ")}`;
256
266
  left.push(finish
257
267
  ? `${m.runtime} — Windows keeps Pantheon's node.exe locked while this command runs, so it is removed a few seconds after this command exits. If it is still there afterwards, an agent window has it open: close them, then in PowerShell: ${byHand}`
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "format": 1,
3
- "built_at": "2026-10-14T06:07:49.511Z",
3
+ "built_at": "2026-10-14T11:53:40.645Z",
4
4
  "swiftc": "Apple Swift version 6.3.3 (swiftlang-6.3.3.1.3 clang-2100.1.1.101)",
5
5
  "helpers": {
6
6
  "pantheon-tray": {
@@ -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.11-rc.1",
3
+ "version": "0.33.11",
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": {