@bridgebrew/shell 0.0.7 → 0.0.9

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.
@@ -4,7 +4,8 @@
4
4
  // is; `shell.reviewRequest` opens it on a chosen one, and the persistent Review button on the first. Later (Escape, the
5
5
  // close button) keeps a request waiting and never reopens it on its own until the page reloads; Approve and Reject POST
6
6
  // the host route and move to the next one, or close. At 0:00 a request expired: fetched again. An installation approved
7
- // while sessions work stays listed, approved, until its restart applies.
7
+ // while work runs stays listed, approved, until its restart applies. A reload or a restart waits for the plugins holding
8
+ // work (bridge#722): Bridge never forces on its own; a person chooses Force now, or Wait (it keeps waiting).
8
9
  import * as React from 'react';
9
10
  import {
10
11
  Button,
@@ -19,6 +20,7 @@ import {
19
20
  DialogTitle,
20
21
  Icon,
21
22
  ensureOk,
23
+ isRecord,
22
24
  readJson,
23
25
  } from '@bridge/ui';
24
26
  import type { Context } from 'cordis';
@@ -26,21 +28,23 @@ import type { Review, Shell } from './shell-state.ts';
26
28
 
27
29
  /** A request as `GET /_bridge/workspaces/<slug>/requests` gives it (research-031 M3/M4): a node request, with
28
30
  * `kind: 'install'` the installation waiting for its restart, or with `kind: 'reload'` a plugin reload waiting for
29
- * the running sessions (`state` from the host's install coordinator or reload gate). */
31
+ * the running work (`state` from the host's install coordinator or reload gate). */
30
32
  export type Pending = {
31
33
  id: string;
32
34
  kind?: 'install' | 'reload';
33
- /** A `reload` that is Bridge's own restart, waiting for this workspace's sessions. */
35
+ /** A `reload` that is Bridge's own restart, waiting for this workspace's running work. */
34
36
  bridge?: boolean;
35
- /** A `reload` that is an update of a plugin (another version), waiting for the sessions (bridge#434). */
37
+ /** A `reload` that is an update of a plugin (another version), waiting for running work (bridge#434). */
36
38
  update?: boolean;
37
39
  state?: 'waiting' | 'ready' | 'approved' | 'applying';
38
40
  create?: { title: string; folder?: string };
39
41
  /** The full path of the folder it installs or creates the project from, shown apart from the explanation. */
40
42
  folder?: string;
41
43
  created: string;
42
- /** A reload waiting for the sessions has no decision deadline: it waits as long as they run. */
44
+ /** A reload waiting for running work has no decision deadline: it waits as long as the work runs. */
43
45
  expires?: string;
46
+ /** The plugins holding its work that did not answer in time (bridge#722), by name: it opens by itself. */
47
+ notResponding?: string[];
44
48
  explanation: string[];
45
49
  };
46
50
 
@@ -49,10 +53,35 @@ export type Pending = {
49
53
  export const settled = (request: Pending) =>
50
54
  request.state === 'approved' || request.state === 'applying';
51
55
 
52
- /** The request the modal opens on by itself: the first neither settled nor dismissed with Later. */
53
- /** A reload waiting for the sessions never opens by itself: it runs once they finish, the toast offers Reload now. */
56
+ /** What Later or Wait dismisses: a request, and apart from it the same request once a holder of its work does not
57
+ * respond, so a wait closed while the work ran still opens by itself then. */
58
+ export const dismissal = (request: Pending) =>
59
+ request.notResponding?.length ? `${request.id} not responding` : request.id;
60
+
61
+ /** The request the modal opens on by itself: the first neither settled nor dismissed with Later. A reload waiting for
62
+ * running work opens by itself only when a holder does not respond: otherwise it runs once the work finished, the
63
+ * toast offers Force now. */
54
64
  export const nextToOpen = (list: Pending[], dismissed: ReadonlySet<string>) =>
55
- list.find((each) => !settled(each) && each.kind !== 'reload' && !dismissed.has(each.id));
65
+ list.find(
66
+ (each) =>
67
+ !settled(each) &&
68
+ (each.kind !== 'reload' || !!each.notResponding?.length) &&
69
+ !dismissed.has(dismissal(each)),
70
+ );
71
+
72
+ /** The requests a `GET …/requests` answer lists: the host's own (trusted), but `notResponding`, which opens the modal
73
+ * by itself and is shown, checked to be names. */
74
+ const requestsOf = (body: unknown): Pending[] =>
75
+ isRecord(body) && Array.isArray(body.requests)
76
+ ? body.requests.filter(isRecord).map((each) => {
77
+ const { notResponding, ...rest } = each;
78
+ const request = rest as Omit<Pending, 'notResponding'>;
79
+ return Array.isArray(notResponding) &&
80
+ notResponding.every((name) => typeof name === 'string')
81
+ ? { ...request, notResponding }
82
+ : request;
83
+ })
84
+ : [];
56
85
 
57
86
  /** `m:ss`, the approval modal's countdown. */
58
87
  const clock = (seconds: number) =>
@@ -61,14 +90,16 @@ const clock = (seconds: number) =>
61
90
  /** What the modal says a request is, above its explanation. */
62
91
  const describe = (request: Pending) =>
63
92
  request.kind === 'reload'
64
- ? request.bridge
65
- ? "Bridge's restart waiting for the sessions"
66
- : request.update
67
- ? 'Update waiting for the sessions'
68
- : 'Reload waiting for the sessions'
93
+ ? request.notResponding?.length
94
+ ? `${request.bridge ? "Bridge's restart" : request.update ? 'Update' : 'Reload'} waiting: ${request.notResponding.join(', ')} not responding`
95
+ : request.bridge
96
+ ? "Bridge's restart waiting for running work"
97
+ : request.update
98
+ ? 'Update waiting for running work'
99
+ : 'Reload waiting for running work'
69
100
  : request.kind === 'install'
70
101
  ? request.state === 'approved'
71
- ? 'Approved: the installation waits for the sessions'
102
+ ? 'Approved: the installation waits for running work'
72
103
  : request.state === 'applying'
73
104
  ? 'Installing and restarting the workspace'
74
105
  : 'A plugin installation waits for your approval'
@@ -102,6 +133,7 @@ export function Approvals({
102
133
  /** The request whose 0:00 was handled, so it is fetched again only once. */
103
134
  const expired = React.useRef<string | undefined>(undefined);
104
135
  const approve = React.useRef<HTMLButtonElement>(null);
136
+ const wait = React.useRef<HTMLButtonElement>(null);
105
137
 
106
138
  /** Reads the current workspace's requests and shows the one asked (`wantId`, even a dismissed or settled one), else
107
139
  * keeps the one shown while it is listed, else opens the next by itself (`open`); closes when none is left. */
@@ -116,7 +148,7 @@ export function Approvals({
116
148
  const res = await fetch(`/_bridge/workspaces/${encodeURIComponent(slug)}/requests`, {
117
149
  cache: 'no-store',
118
150
  });
119
- const next = ((await readJson(res)) as { requests?: Pending[] }).requests ?? [];
151
+ const next = requestsOf(await readJson(res));
120
152
  if (run !== latest.current) return;
121
153
  setList(next);
122
154
  setError('');
@@ -222,9 +254,9 @@ export function Approvals({
222
254
  }
223
255
  };
224
256
  /** Later (Escape, the close button): closes the modal, the request stays waiting, and this page does not open it
225
- * again on its own until a reload. */
257
+ * again on its own until a reload (`dismissal`). */
226
258
  const later = () => {
227
- if (shown) dismissed.current.add(shown.id);
259
+ if (shown) dismissed.current.add(dismissal(shown));
228
260
  setShownId(undefined);
229
261
  };
230
262
  const waiting = list.filter((each) => !settled(each)).length;
@@ -246,7 +278,7 @@ export function Approvals({
246
278
  ? waiting === waitingReloads
247
279
  ? describe(list.find((each) => !settled(each))!)
248
280
  : `${waiting} approval${waiting === 1 ? '' : 's'} waiting`
249
- : 'Approved: waiting for the sessions'}
281
+ : 'Approved: waiting for running work'}
250
282
  </span>
251
283
  <Button size="sm" variant="outline" onClick={() => void sync(list[0]?.id)}>
252
284
  Review
@@ -259,7 +291,11 @@ export function Approvals({
259
291
  open={shown !== undefined}
260
292
  onOpenChange={(open) => !open && later()}
261
293
  >
262
- <DialogContent className="w-[520px]" initialFocus={approve}>
294
+ {/* A reload's wait focuses Wait: Enter, typed into the page as it opens by itself, never cuts work. */}
295
+ <DialogContent
296
+ className="w-[520px]"
297
+ initialFocus={shown?.kind === 'reload' ? wait : approve}
298
+ >
263
299
  <DialogHeader>
264
300
  <DialogTitle>Approval needed</DialogTitle>
265
301
  <DialogClose
@@ -269,7 +305,8 @@ export function Approvals({
269
305
  </DialogClose>
270
306
  </DialogHeader>
271
307
  {shown && (
272
- <DialogBody className="flex flex-col gap-3 pb-3">
308
+ // A long explanation scrolls in the body: the buttons below stay in view.
309
+ <DialogBody className="flex min-h-0 flex-col gap-3 overflow-y-auto pb-3">
273
310
  <DialogDescription>
274
311
  {describe(shown)}
275
312
  {list.length > 1 && ` · ${index + 1} of ${list.length}`}
@@ -335,8 +372,8 @@ export function Approvals({
335
372
  </DialogBody>
336
373
  )}
337
374
  <DialogFooter className="justify-end gap-2">
338
- <Button variant="ghost" disabled={busy} onClick={later}>
339
- Later
375
+ <Button ref={wait} variant="ghost" disabled={busy} onClick={later}>
376
+ {shown?.kind === 'reload' ? 'Wait' : 'Later'}
340
377
  </Button>
341
378
  <Button
342
379
  variant="ghost"
@@ -357,13 +394,7 @@ export function Approvals({
357
394
  disabled={busy || (shown !== undefined && settled(shown))}
358
395
  onClick={() => void decide('approve')}
359
396
  >
360
- {shown?.kind === 'reload'
361
- ? shown.bridge
362
- ? 'Restart now'
363
- : shown.update
364
- ? 'Update now'
365
- : 'Reload now'
366
- : 'Approve'}
397
+ {shown?.kind === 'reload' ? 'Force now' : 'Approve'}
367
398
  </Button>
368
399
  </DialogFooter>
369
400
  </DialogContent>
@@ -1326,7 +1326,7 @@ function Frame({
1326
1326
  app: boolean;
1327
1327
  errors: ErrorsSignal;
1328
1328
  renderSlot: (
1329
- key: 'rail' | 'sidebar' | 'main' | 'overlay' | 'controls' | 'more',
1329
+ key: 'rail' | 'sidebar' | 'main' | 'overlay' | 'controls' | 'more-header',
1330
1330
  props: object,
1331
1331
  options?: { only?: string },
1332
1332
  ) => React.ReactNode;
@@ -2076,7 +2076,7 @@ export function apply(ctx: Context) {
2076
2076
  sidebar: { ...slot, ...open },
2077
2077
  main: slot,
2078
2078
  overlay: { kind: 'list', scope: 'root' },
2079
- more: { kind: 'list', scope: 'root' },
2079
+ 'more-header': { kind: 'list', scope: 'root' },
2080
2080
  controls: { kind: 'list', scope: 'root', ...open },
2081
2081
  },
2082
2082
  },
@@ -1038,8 +1038,8 @@ export function MobileFrame({
1038
1038
  renderSlot,
1039
1039
  }: {
1040
1040
  shell: Shell;
1041
- /** The frame's slots: `main`, the drawer's `more` rows, and `overlay` (its entries opted in on a phone only). */
1042
- renderSlot: (key: 'main' | 'more' | 'overlay', props: object, options?: { only?: string }) => React.ReactNode;
1041
+ /** The frame's slots: `main`, the drawer's `more-header` buttons, and `overlay` (its entries opted in on a phone only). */
1042
+ renderSlot: (key: 'main' | 'more-header' | 'overlay', props: object, options?: { only?: string }) => React.ReactNode;
1043
1043
  }) {
1044
1044
  const open = React.useSyncExternalStore(drawer.subscribe, drawer.get);
1045
1045
  const overlays = React.useSyncExternalStore(phoneOverlays.subscribe, phoneOverlays.get);
@@ -1157,6 +1157,10 @@ function PageRow({ icon, title, onSelect }: { icon: string; title: string; onSel
1157
1157
  /** A page of the `pages` menu: a node's (its views, then its child nodes), or a row's (it, then the rows under it). */
1158
1158
  type Page = { node: string } | { entry: Entry };
1159
1159
 
1160
+ /** A button of More's header (`more-header`): its look without its ink, the icon's size, and the drawer's close. */
1161
+ type MoreHeader = { className: string; iconSize: number; close: (then?: () => void) => void };
1162
+ const headerButton = 'mobile-press relative flex size-11 shrink-0 items-center justify-center rounded-full active:bg-hover';
1163
+
1160
1164
  /** The drawer's content: with `pages`, a page (a node's views, then its child nodes; a view's rows under it), each
1161
1165
  * row with rows under it opening its own page in the drawer, Back going up one; with `tree`, the node's views as a
1162
1166
  * tree and a row opening the tree's page. The workspaces. It opens on the node shown. */
@@ -1167,7 +1171,7 @@ function Menu({
1167
1171
  }: {
1168
1172
  shell: Shell;
1169
1173
  style: MenuStyle;
1170
- renderSlot: (key: 'more', props: { style: MenuStyle; close: (then?: () => void) => void }) => React.ReactNode;
1174
+ renderSlot: (key: 'more-header', props: MoreHeader) => React.ReactNode;
1171
1175
  }) {
1172
1176
  const state = React.useSyncExternalStore(shell.subscribe, shell.get);
1173
1177
  useSidebarItems();
@@ -1208,8 +1212,7 @@ function Menu({
1208
1212
  };
1209
1213
  const back = style === 'pages' && above !== undefined;
1210
1214
  const kids = 'node' in page ? childrenOf(nodes, page.node, shown) : [];
1211
- const iconButton =
1212
- 'mobile-press flex size-11 shrink-0 items-center justify-center rounded-full text-secondary active:bg-hover';
1215
+ const iconButton = `${headerButton} text-secondary`;
1213
1216
  return (
1214
1217
  <div
1215
1218
  data-mobile=""
@@ -1240,6 +1243,13 @@ function Menu({
1240
1243
  ) : (
1241
1244
  <DialogTitle className="min-w-0 flex-1 truncate text-[22px]">{titleOf(page)}</DialogTitle>
1242
1245
  )}
1246
+ {/* Buttons plugins add (`more-header`, research-128 §7), before More's own: drawn as them (`className`, the
1247
+ icon's size, ink left to the plugin), and `close`, which closes the drawer and runs `then` after. */}
1248
+ {renderSlot('more-header', {
1249
+ className: headerButton,
1250
+ iconSize: 22,
1251
+ close: (then?: () => void) => drawer.close(then),
1252
+ })}
1243
1253
  <button
1244
1254
  type="button"
1245
1255
  aria-label="Phone settings"
@@ -1306,9 +1316,6 @@ function Menu({
1306
1316
  push={(next) => push({ entry: next })}
1307
1317
  />
1308
1318
  )}
1309
- {/* Rows plugins add (`more`, research-128 §7), after More's own: the menu's style, so a row is drawn as its
1310
- neighbours, and `close`, which closes the drawer and runs `then` after (as a row of the menu does). */}
1311
- {!back && renderSlot('more', { style, close: (then?: () => void) => drawer.close(then) })}
1312
1319
  {style === 'pages' && kids.length > 0 && (
1313
1320
  <nav aria-label="Nodes" className="flex flex-col px-2 pb-2">
1314
1321
  <h2 className="m-0 px-2 pt-3 pb-1 text-xs font-medium tracking-wide text-secondary uppercase">
@@ -49,7 +49,7 @@ export type { HostStatusEvent };
49
49
  * reload the root and its reload-failed dependents (`targets`, one per workspace). */
50
50
  export type Fix =
51
51
  | { action: 'restart'; slug: string; plugin?: string }
52
- /** Restarts Bridge itself once every session is idle (the notice of its own code changed). */
52
+ /** Restarts Bridge itself once no work is running (the notice of its own code changed). */
53
53
  | { action: 'restart-bridge' }
54
54
  | { action: 'reload' | 'reload-page'; slug: string; plugin: string }
55
55
  | { action: 'reload-all'; targets: { slug: string; plugins: string[] }[] }
@@ -154,9 +154,9 @@ export const codeNotice = (code: CodeChange, waiting: string[] = []): Notice | u
154
154
  // Under way: the restart screen (./restart-screen.tsx) tells it.
155
155
  if (code.restarting === 'now') return undefined;
156
156
  if (code.restarting === 'waiting') {
157
- const title = 'Bridge restarts once every session is idle';
157
+ const title = 'Bridge restarts once no work is running';
158
158
  const description =
159
- 'Sessions are still working. Each workspace waiting for its sessions lists it in its requests: Restart now, or Cancel restart.';
159
+ 'Work is still running. Each workspace waiting for it lists it in its requests: Force now, or Cancel restart.';
160
160
  return { variant: 'warning', title, description, copy: copyOf(title, description) };
161
161
  }
162
162
  const title = "Bridge's code changed; restart required";
@@ -896,13 +896,14 @@ declare module '@bridge/ui-slots' {
896
896
  /** Over the whole frame, after it: `_host` plugins add floating layers (each its own `id`), fixed-positioned. On a
897
897
  * phone, only the entries that opted in (`shell.overlayOnPhone(id)`) are drawn, outside the frame. */
898
898
  overlay: { kind: 'list'; scope: 'root' };
899
- /** Declared by `shell` (research-128 §7): rows a plugin adds to the phone's More, after its own, each its own `id`.
900
- * `style`: the menu's (`tree`: a SidebarTreeItem row, as its views; `pages`: a 48px row with a 20px icon), so a row
901
- * is drawn as its neighbours; `close(then)`: closes the drawer, then runs `then` (open a page from it). */
902
- more: {
899
+ /** Declared by `shell` (research-128 §7): buttons a plugin adds to the header of the phone's More, before its own,
900
+ * each its own `id`. `className`: the look of More's header buttons without their ink (44px round, pressed state),
901
+ * `iconSize` its icons' (22px), so a button is drawn as its neighbours; `close(then)`: closes the drawer, then runs
902
+ * `then` (open a window from it). */
903
+ 'more-header': {
903
904
  kind: 'list';
904
905
  scope: 'root';
905
- owner: { style: 'tree' | 'pages'; close: (then?: () => void) => void };
906
+ owner: { className: string; iconSize: number; close: (then?: () => void) => void };
906
907
  };
907
908
  /** Declared by `shell`: with its theme controls, wherever they stand (under the sidebar, under the rail while it is
908
909
  * hidden, in the narrow column of the desktop app's pages), first; each entry its own `id`, a 28px button (the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/shell",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "license": "MIT",
5
5
  "description": "The page around everything: the rail, the sidebar column, the stage beside it and the theme controls.",
6
6
  "keywords": [
@@ -103,6 +103,6 @@
103
103
  "typecheck": "bridge plugin check ."
104
104
  },
105
105
  "engines": {
106
- "bridge": ">=0.0.1-nightly.20261124.1"
106
+ "bridge": ">=0.0.2-nightly.20261129.1"
107
107
  }
108
108
  }