@astrofoundry/pi-astro 0.36.0 → 0.36.1

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.
@@ -24,6 +24,7 @@ import {
24
24
  majorChange,
25
25
  messageComponents,
26
26
  notesFor,
27
+ packageCasks,
27
28
  npmGlobalVersion,
28
29
  parseToolsButton,
29
30
  parseVerdict,
@@ -105,6 +106,34 @@ const COLLECTED: Collected = {
105
106
  warnings: [],
106
107
  };
107
108
 
109
+ describe("casks whose installer needs a password", () => {
110
+ const info = {
111
+ formulae: [],
112
+ casks: [
113
+ { token: "temurin@17", artifacts: [{ uninstall: [] }, { pkg: ["OpenJDK17U.pkg"] }] },
114
+ { token: "google-chrome", artifacts: [{ app: ["Google Chrome.app"] }, { zap: [] }] },
115
+ ],
116
+ };
117
+ const outdated = {
118
+ formulae: [],
119
+ casks: [
120
+ { name: "google-chrome", installed_versions: ["155.0"], current_version: "156.0" },
121
+ { name: "temurin@17", installed_versions: ["17.0.20,8"], current_version: "17.0.20.1,1" },
122
+ ],
123
+ };
124
+
125
+ it("finds package installers and gives their lines no button", () => {
126
+ expect([...packageCasks(info)]).toEqual(["temurin@17"]);
127
+ const lines = buildLines({ ...COLLECTED, brewInfo: info, brewOutdated: outdated, installer: {}, piInstalled: null, piLatest: null, piAstroInstalled: null, piAstroLatest: null });
128
+ const temurin = lines.find((l) => l.key === "cask:temurin@17");
129
+ const chrome = lines.find((l) => l.key === "cask:google-chrome");
130
+ expect(temurin?.manual).toContain("brew upgrade --cask temurin@17");
131
+ expect(chrome?.manual).toBeUndefined();
132
+ expect(lineText(temurin as ToolLine)).toContain("asks for your password");
133
+ expect(brewHasOutdated(outdated)).toBe(false);
134
+ });
135
+ });
136
+
108
137
  describe("versions", () => {
109
138
  it("compares dotted versions with revisions and build numbers", () => {
110
139
  expect(compareLoose("10.48", "10.47_1")).toBeGreaterThan(0);
@@ -252,7 +281,6 @@ describe("report layout", () => {
252
281
  const pages = layoutMessages(report);
253
282
  expect(pages.length).toBe(2);
254
283
  expect(pages[0].head).toBe(true);
255
- expect(pages[pages.length - 1].tail).toBe(true);
256
284
  expect(pages[pages.length - 1].all).toBe(true);
257
285
  expect(pages.flatMap((p) => p.keys)).toEqual(many.map((l) => l.key));
258
286
  for (const p of pages) expect(countComponents(messageComponents(report, p))).toBeLessThanOrEqual(40);
@@ -263,7 +291,7 @@ describe("report layout", () => {
263
291
  it("says everything is up to date without buttons", () => {
264
292
  const report = sampleReport([], false);
265
293
  const pages = layoutMessages(report);
266
- expect(pages).toEqual([{ keys: [], head: true, all: false, tail: false }]);
294
+ expect(pages).toEqual([{ keys: [], head: true, all: false }]);
267
295
  expect(messageComponents(report, pages[0])).toEqual([{ type: 10, content: "**Cortex Tools Report:** everything is up to date (checked 06:00 CEST)." }]);
268
296
  });
269
297
 
@@ -370,7 +398,7 @@ describe("state files", () => {
370
398
 
371
399
  it("keeps the posted report for button checks", () => {
372
400
  expect(readPostedReport()).toBeNull();
373
- const report = { ...sampleReport(buildLines(COLLECTED)), messages: [{ id: "1", keys: ["pi"], head: true, all: false, tail: false }] };
401
+ const report = { ...sampleReport(buildLines(COLLECTED)), messages: [{ id: "1", keys: ["pi"], head: true, all: false }] };
374
402
  writePostedReport(report);
375
403
  expect(readPostedReport()).toEqual(report);
376
404
  });
@@ -48,6 +48,8 @@ export interface ToolLine {
48
48
  state: LineState;
49
49
  /** Why the last update failed, or what it ended at. */
50
50
  detail?: string;
51
+ /** The update needs the owner's password (a cask whose installer is a macOS package), so the line has no button. */
52
+ manual?: string;
51
53
  }
52
54
 
53
55
  /** One posted message of a report and what it shows, so a click can redraw exactly that message. */
@@ -56,7 +58,6 @@ export interface PostedMessage {
56
58
  keys: string[];
57
59
  head: boolean;
58
60
  all: boolean;
59
- tail: boolean;
60
61
  }
61
62
 
62
63
  export interface ToolsReport {
@@ -154,6 +155,20 @@ export function onRequestFormulae(info: unknown): Map<string, string> {
154
155
  return out;
155
156
  }
156
157
 
158
+ /**
159
+ * Casks that install a macOS package: `brew upgrade` runs that installer through sudo,
160
+ * which asks for the owner's password, so the bridge cannot run it.
161
+ */
162
+ export function packageCasks(info: unknown): Set<string> {
163
+ const out = new Set<string>();
164
+ const casks = (info as { casks?: { token?: unknown; artifacts?: unknown }[] } | null)?.casks;
165
+ for (const c of Array.isArray(casks) ? casks : []) {
166
+ if (typeof c.token !== "string" || !Array.isArray(c.artifacts)) continue;
167
+ if (c.artifacts.some((a) => typeof a === "object" && a !== null && "pkg" in a)) out.add(c.token);
168
+ }
169
+ return out;
170
+ }
171
+
157
172
  function outdatedEntries(json: unknown, kind: "formulae" | "casks"): { name: string; installed: string; latest: string; pinned: boolean }[] {
158
173
  const list = (json as Record<string, OutdatedEntry[] | undefined> | null)?.[kind];
159
174
  const out: { name: string; installed: string; latest: string; pinned: boolean }[] = [];
@@ -228,16 +243,19 @@ export function buildLines(c: Collected): ToolLine[] {
228
243
  lines.push(line(`brew:${full}`, f.name, f.installed, f.latest, { kind: "brew", name: full }));
229
244
  }
230
245
  const casks = outdatedEntries(c.brewOutdated, "casks");
246
+ const packages = packageCasks(c.brewInfo);
231
247
  for (const k of casks.sort((a, b) => a.name.localeCompare(b.name))) {
232
248
  if (k.pinned) continue;
233
- lines.push(line(`cask:${k.name}`, k.name, k.installed, k.latest, { kind: "cask", token: k.name }));
249
+ const l = line(`cask:${k.name}`, k.name, k.installed, k.latest, { kind: "cask", token: k.name });
250
+ if (packages.has(k.name)) l.manual = `its installer asks for your password; on Cortex: brew upgrade --cask ${k.name}`;
251
+ lines.push(l);
234
252
  }
235
253
  return lines;
236
254
  }
237
255
 
238
- /** True when Homebrew lists anything outdated, dependencies and pinned packages aside. */
256
+ /** True when Homebrew lists an outdated formula, dependencies included and pinned ones aside; casks have their own lines. */
239
257
  export function brewHasOutdated(brewOutdated: unknown): boolean {
240
- return [...outdatedEntries(brewOutdated, "formulae"), ...outdatedEntries(brewOutdated, "casks")].some((e) => !e.pinned);
258
+ return outdatedEntries(brewOutdated, "formulae").some((e) => !e.pinned);
241
259
  }
242
260
 
243
261
  /** The newest Node release marked LTS that has a macOS arm64 tarball, from nodejs.org's `index.json`. */
@@ -561,7 +579,8 @@ export function updateCommand(action: UpdateAction, version: string): Command {
561
579
  }
562
580
  }
563
581
 
564
- export const BREW_ALL: Command = { file: BREW, args: ["upgrade"] };
582
+ /** Formulae only: a cask whose installer needs a password would fail the whole run. */
583
+ export const BREW_ALL: Command = { file: BREW, args: ["upgrade", "--formula"] };
565
584
 
566
585
  /** Pi has an exact previous version on npm to go back to; the installer restores its own, and Homebrew cannot downgrade. */
567
586
  export function rollbackCommand(action: UpdateAction, previous: string): Command | null {
@@ -652,13 +671,15 @@ export function lineText(l: ToolLine): string {
652
671
  const head = `**${escapeDiscord(l.label)}** ${escapeDiscord(l.installed)} → ${escapeDiscord(l.latest)}${l.major ? " · major version" : ""}`;
653
672
  const notes = l.review ? `\n-# ${l.review.verdict ? `${VERDICT_MARK[l.review.verdict]}: ` : "notes: "}${escapeDiscord(l.review.reason)}` : "";
654
673
  const detail = l.detail ? `\n-# ${escapeDiscord(l.detail)}` : "";
655
- return `${head}${notes}${detail}`.slice(0, 1000);
674
+ const manual = l.manual ? `\n-# ${escapeDiscord(l.manual)}` : "";
675
+ return `${head}${notes}${detail}${manual}`.slice(0, 1000);
656
676
  }
657
677
 
658
678
  function lineSection(l: ToolLine): MessageComponent {
659
679
  const id = updateId(l);
660
- const accessory: MessageComponent =
661
- id.length <= CUSTOM_ID_MAX && KEY.test(l.key) && VERSION.test(l.latest)
680
+ const accessory: MessageComponent = l.manual
681
+ ? { type: 2, style: SECONDARY, label: "By hand", custom_id: `tools:none:${l.key}`.slice(0, CUSTOM_ID_MAX), disabled: true }
682
+ : id.length <= CUSTOM_ID_MAX && KEY.test(l.key) && VERSION.test(l.latest)
662
683
  ? stateButton(l.state, id, "Update")
663
684
  : { type: 2, style: SECONDARY, label: "Update by hand", custom_id: `tools:none:${l.key}`.slice(0, CUSTOM_ID_MAX), disabled: true };
664
685
  return { type: 9, components: [{ type: 10, content: lineText(l) }], accessory };
@@ -666,7 +687,7 @@ function lineSection(l: ToolLine): MessageComponent {
666
687
 
667
688
  function allSection(report: ToolsReport): MessageComponent {
668
689
  const detail = report.brewAllDetail ? `\n-# ${escapeDiscord(report.brewAllDetail)}` : "";
669
- return { type: 9, components: [{ type: 10, content: `**Homebrew**: upgrade every outdated package, dependencies included${detail}` }], accessory: stateButton(report.brewAll, allId(report.date), "Upgrade everything") };
690
+ return { type: 9, components: [{ type: 10, content: `**Homebrew**: upgrade every outdated formula, dependencies included${detail}` }], accessory: stateButton(report.brewAll, allId(report.date), "Upgrade everything") };
670
691
  }
671
692
 
672
693
  function clock(iso: string, timeZone: string): string {
@@ -683,7 +704,6 @@ function headText(report: ToolsReport): MessageComponent {
683
704
  return { type: 10, content: `${head}${warnings}` };
684
705
  }
685
706
 
686
- const TAIL: MessageComponent = { type: 10, content: "-# Nothing changes until an owner presses a button. A restart waits until nothing runs on that service." };
687
707
  const MESSAGE_COMPONENTS = 40;
688
708
 
689
709
  /** The components of one posted message, redrawn from the report's current state. */
@@ -695,30 +715,27 @@ export function messageComponents(report: ToolsReport, m: Omit<PostedMessage, "i
695
715
  if (l) out.push(lineSection(l));
696
716
  }
697
717
  if (m.all) out.push(allSection(report));
698
- if (m.tail) out.push(TAIL);
699
718
  return out;
700
719
  }
701
720
 
702
- /** Splits the report into messages of at most 40 components each: header first, footer last. */
721
+ /** Splits the report into messages of at most 40 components each, header first. */
703
722
  export function layoutMessages(report: ToolsReport): Omit<PostedMessage, "id">[] {
704
- const hasButtons = report.lines.length > 0 || report.brewOutdated;
705
- type Item = { kind: "head" } | { kind: "line"; key: string } | { kind: "all" } | { kind: "tail" };
706
- const items: Item[] = [{ kind: "head" }, ...report.lines.map((l) => ({ kind: "line" as const, key: l.key })), ...(report.brewOutdated ? [{ kind: "all" as const }] : []), ...(hasButtons ? [{ kind: "tail" as const }] : [])];
723
+ type Item = { kind: "head" } | { kind: "line"; key: string } | { kind: "all" };
724
+ const items: Item[] = [{ kind: "head" }, ...report.lines.map((l) => ({ kind: "line" as const, key: l.key })), ...(report.brewOutdated ? [{ kind: "all" as const }] : [])];
707
725
  const pages: Omit<PostedMessage, "id">[] = [];
708
- let page: Omit<PostedMessage, "id"> = { keys: [], head: false, all: false, tail: false };
726
+ let page: Omit<PostedMessage, "id"> = { keys: [], head: false, all: false };
709
727
  let used = 0;
710
728
  const size = (item: Item) => (item.kind === "line" || item.kind === "all" ? 3 : 1);
711
729
  for (const item of items) {
712
730
  if (used + size(item) > MESSAGE_COMPONENTS) {
713
731
  pages.push(page);
714
- page = { keys: [], head: false, all: false, tail: false };
732
+ page = { keys: [], head: false, all: false };
715
733
  used = 0;
716
734
  }
717
735
  used += size(item);
718
736
  if (item.kind === "head") page.head = true;
719
737
  else if (item.kind === "line") page.keys.push(item.key);
720
- else if (item.kind === "all") page.all = true;
721
- else page.tail = true;
738
+ else page.all = true;
722
739
  }
723
740
  pages.push(page);
724
741
  return pages;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/pi-astro",
3
- "version": "0.36.0",
3
+ "version": "0.36.1",
4
4
  "description": "Personal pi customizations (extensions, subagents, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"