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
10 changes: 10 additions & 0 deletions .changeset/reinstall-standalone-homebrew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"sessionpipe": patch
---

Recognize official standalone (`install.sh`) and Homebrew launchers in `sessionpipe doctor` and `sessionpipe reinstall`:

- Read standalone (`~/.local/bin/sessionpipe`) and Homebrew (`/opt/homebrew/bin/sessionpipe`) launchers safely on `PATH` (bounded plain-file check, never executed) instead of treating them as unknown files blocking npm.
- Keep healthy standalone and Homebrew installs untouched during `sessionpipe reinstall` while removing leftover global npm copies and dangling links (including when npm is not installed or a newer release is out, with an update note).
- Report deleted or broken standalone and Homebrew installs with their native repair commands (`curl -fsSL https://sessionpipe.org/install.sh | sh` or `brew reinstall <formula>`) rather than suggesting `mv` and `npx`.
- Note leftover npm copies in `install.sh` when replacing an existing npm global symlink.
112 changes: 76 additions & 36 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1564,17 +1564,33 @@ async function checkup(deep: boolean): Promise<{ report: Record<string, unknown>
const around = process.platform === "win32" ? null : copies({ npmPrefix: npmrcPrefix(), service: look });
// An npx cache entry nothing uses is a cache, not a second copy (plan.ts `idle`).
const installs = (around?.copies ?? []).filter((c) => c.slot && !idle(c));
const typedManaged = around?.copies.find((c) => c.dir === around.typed && c.managed !== null) ?? null;
const managedBroken = !!typedManaged?.wrong;
const managedFormula =
typedManaged?.managed === "homebrew"
? (homebrewFormula(path.join(typedManaged.dir, "dist")) ?? "sessionpipe")
: null;
const dangling = around?.dangling ?? [];
const collide = installs.length > 1 || dangling.length > 0 || installs.some((c) => c.wrong);
const collide =
installs.length > 1 ||
dangling.length > 0 ||
installs.some((c) => c.wrong) ||
(!!typedManaged && (installs.length > 0 || managedBroken));
// What typing `sessionpipe` starts, where that is known to be no installed copy a shell
// finds: a finding with nothing to type, said as `reinstall` says it, so the two never
// disagree about which computer is all good.
const astray = around ? typing(around, shown) : null;
report.copies = installs.map((c) => ({ dir: c.dir, version: c.version, whole: !c.wrong, uses: c.uses }));
const named = (c: (typeof installs)[number], where: string): string =>
`${c.aside ? "a leftover" : c.version} in ${where}`;
// What is typed is not a copy npm installed (a checkout, Volta's copy): nothing to fix,
// and said as what is so. It counts for nothing in the verdict.
const listed = [...(typedManaged ? [typedManaged] : []), ...installs];
report.copies = listed.map((c) => ({ dir: c.dir, version: c.version, whole: !c.wrong, uses: c.uses }));
const named = (c: (typeof listed)[number], where: string): string =>
`${c.aside ? "a leftover" : (c.version ?? "broken")} in ${where}`;
const describeCopy = (c: (typeof listed)[number]): string =>
`${named(c, c.where)} (${[
...(c.managed ? [c.managed === "standalone" ? "standalone" : "Homebrew"] : []),
c.wrong ?? usedBy(c),
].join("; ")})`;
// What is typed is not a copy npm installed (a standalone/Homebrew install, a checkout,
// Volta's copy): nothing to fix by itself, and said as what is so.
const own = around ? typedAs(around, shown) : null;
// But not where what is typed is a folder in npm's own place that is no whole install
// (an install that was cut off): `sessionpipe` may not run at all there, and the repair
Expand All @@ -1592,13 +1608,10 @@ async function checkup(deep: boolean): Promise<{ report: Record<string, unknown>
label: "copies",
value: [
...(collide
? [
...installs.map((c) => `${named(c, c.where)} (${c.wrong ?? usedBy(c)})`),
...dangling.map((f) => `${shown(f)}, a link to one that is gone`),
]
? [...listed.map(describeCopy), ...dangling.map((f) => `${shown(f)}, a link to one that is gone`)]
: []),
...(astray ? [astray] : []),
...(own ? [own.slice(0, -1)] : []),
...(own && !typedManaged ? [own.slice(0, -1)] : []),
].join("; "),
});
// Nothing to type for it, and still not all good: it is said among what is to fix.
Expand All @@ -1610,15 +1623,25 @@ async function checkup(deep: boolean): Promise<{ report: Record<string, unknown>
if (collide)
warnings.push(
`${
installs.length > 1
? `${installs.length} copies of sessionpipe are on this computer (${installs.map((c) => named(c, c.dir)).join("; ")})`
: `the copy of sessionpipe on this computer is not whole (${[
...installs.filter((c) => c.wrong).map((c) => `${named(c, c.dir)}: ${c.wrong}`),
...dangling.map((f) => `${f} is a link to one that is gone`),
].join("; ")})`
}; \`sessionpipe reinstall\` leaves one clean copy`,
listed.length > 1
? `${listed.length} copies of sessionpipe are on this computer (${listed.map((c) => named(c, c.dir)).join("; ")})`
: managedBroken && typedManaged
? `the ${typedManaged.managed === "standalone" ? "standalone" : "Homebrew"} copy of sessionpipe on this computer is not whole (${named(typedManaged, typedManaged.dir)}: ${typedManaged.wrong})`
: typedManaged
? `a leftover link to a sessionpipe copy that is gone is on this computer (${dangling.map((f) => `${f} is a link to one that is gone`).join("; ")})`
: `the copy of sessionpipe on this computer is not whole (${[
...installs.filter((c) => c.wrong).map((c) => `${named(c, c.dir)}: ${c.wrong}`),
...dangling.map((f) => `${f} is a link to one that is gone`),
].join("; ")})`
}; ${
managedBroken && typedManaged
? typedManaged.managed === "standalone"
? "re-run the standalone installer to repair it"
: `\`brew reinstall ${managedFormula}\` repairs it`
: "`sessionpipe reinstall` leaves one clean copy"
}`,
);
const blocked = !!own && !cut && (collide || two);
const blocked = !!own && !cut && !typedManaged && (collide || two);
if (down || apart.length || collide || two || cut)
todo.push({
order: 1,
Expand All @@ -1628,9 +1651,15 @@ async function checkup(deep: boolean): Promise<{ report: Record<string, unknown>
down ? "The background service isn't running, so no message reaches this computer. " : ""
}${two ? "A daemon someone started by hand holds the socket the background service needs. " : ""}${
collide
? installs.length > 1
? `${installs.length} copies of sessionpipe are on this computer, and one is enough. `
: "The copy of sessionpipe on this computer is not whole. "
? managedBroken && typedManaged
? `The ${typedManaged.managed === "standalone" ? "standalone" : "Homebrew"} copy of sessionpipe on this computer is not whole. `
: typedManaged
? installs.length > 0
? `${installs.length === 1 ? "A leftover npm copy" : `${installs.length} leftover npm copies`} of sessionpipe ${installs.length === 1 ? "is" : "are"} on this computer beside your ${typedManaged.managed === "standalone" ? "standalone" : "Homebrew"} install. `
: "A link to a sessionpipe copy that is gone is left on this computer. "
: installs.length > 1
? `${installs.length} copies of sessionpipe are on this computer, and one is enough. `
: "The copy of sessionpipe on this computer is not whole. "
: apart.length
? `This command is sessionpipe ${VERSION}, and ${apart.join(", and ")}. `
: ""
Expand All @@ -1641,15 +1670,21 @@ async function checkup(deep: boolean): Promise<{ report: Record<string, unknown>
? "What you type is not a copy npm installed, so `sessionpipe reinstall` leaves it alone and can't put this right from here."
: "One command puts it right:"
}`,
// Where what is typed is not whole, `sessionpipe` may not run: the repair goes through npx.
// Where what is typed is not whole, `sessionpipe` may not run: the repair goes through npx
// (or the standalone installer / Homebrew for managed installs).
...(blocked
? {}
: {
run: cut
? "npx -y sessionpipe@latest reinstall"
: collide || two
? "sessionpipe reinstall"
: "sessionpipe update",
run:
managedBroken && typedManaged
? typedManaged.managed === "standalone"
? "curl -fsSL https://sessionpipe.org/install.sh | sh"
: `brew reinstall ${managedFormula}`
: cut
? "npx -y sessionpipe@latest reinstall"
: collide || two
? "sessionpipe reinstall"
: "sessionpipe update",
}),
});
const w = report.hook_wall_ms as { p50: number; p95: number; n: number } | null;
Expand Down Expand Up @@ -2680,8 +2715,8 @@ async function reinstall(): Promise<void> {
if (a !== "" && a !== "y" && a !== "yes") return out(" Nothing was changed.");
say("");
}
const home = (p.home as NonNullable<typeof p.home>).prefix;
const slot = slotIn(home);
const home = p.home?.prefix ?? null;
const slot = home ? slotIn(home) : (p.managed as NonNullable<typeof p.managed>).dir;
const dist = path.join(slot, "dist");
const sock = socketPath(state);
// The copy in the home is never removed, by whatever name it is asked for.
Expand Down Expand Up @@ -2769,13 +2804,18 @@ async function reinstall(): Promise<void> {
}
};
const files = [served?.file, ...facts.hookFiles].filter((x): x is string => !!x);
const launcher = home ? null : (now.onPath.find((e) => e.dir !== null && same(e.dir, slot))?.file ?? null);
return {
// The copy in the home runs, through the link npm made for it: a shell can start
// the file that link leads to (node, asked next, reads one of any mode).
runs:
leads(path.join(home, "bin", "sessionpipe"), slot) && startable(path.join(dist, "cli.js"))
? versionRun(path.join(dist, "cli.js"))
: null,
// The copy in the home runs, through the link npm made for it (or through the
// standalone/Homebrew launcher): a shell can start the file that link/launcher
// leads to (node, asked next, reads one of any mode).
runs: (
home
? leads(path.join(home, "bin", "sessionpipe"), slot) && startable(path.join(dist, "cli.js"))
: launcher !== null && startable(launcher) && existsSync(path.join(dist, "cli.js"))
)
? versionRun(path.join(dist, "cli.js"))
: null,
typed: now.typed !== null && same(now.typed, slot),
onPath: now.onPath.map((e) => e.file),
named: files.flatMap((file) => removed.filter((r) => text(file).includes(r)).map((r) => ({ file, path: r }))),
Expand Down
Loading
Loading