@bridgebrew/shell 0.0.8 → 0.0.10

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>
@@ -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";
@@ -29,8 +29,13 @@ export function createOverlayHold(
29
29
  let count = 0;
30
30
  /** A joined Bridge's page shows under the home page (the app's state). */
31
31
  let shown = false;
32
- /** The app was told the home page is in front. */
32
+ /** The shell raised the home page and has not lowered it: what it must lower. An overlay another raised (an older
33
+ * rail's own count) is never the shell's. */
33
34
  let sent = false;
35
+ /** The app's overlay as it last said (`state.overlay`): raised while `sent` is not, it is another's. */
36
+ let raised = false;
37
+ /** Disposed: no hold raises the home page any more. */
38
+ let disposed = false;
34
39
  /** The last overlay request: a hold while it runs waits for it. */
35
40
  let request: Promise<void> = Promise.resolve();
36
41
  /** The app's state came through `onState`: the first `state()` read, answering later, is stale. */
@@ -43,8 +48,12 @@ export function createOverlayHold(
43
48
  const app = desktop();
44
49
 
45
50
  const send = (open: boolean, focus = false): Promise<void> => {
46
- if (!app || (open === sent && !focus)) return request;
47
- sent = open;
51
+ if (!app) return request;
52
+ // Already raised by another (an older rail's own count): theirs, the shell neither takes it over nor lowers it on
53
+ // release; a modal hold still asks for the focus.
54
+ const theirs = open && raised && !sent;
55
+ if ((open === sent || theirs) && !focus) return request;
56
+ if (!theirs) sent = open;
48
57
  request = app.overlay(open, ...(focus ? [{ focus: true }] : [])).then(
49
58
  () => undefined,
50
59
  // Refused (the app is closing, an older app): the popup opens anyway, the next hold asks again.
@@ -56,10 +65,13 @@ export function createOverlayHold(
56
65
  };
57
66
  const follow = (state: DesktopState) => {
58
67
  shown = state.shown !== null && state.shown !== undefined;
59
- // The app's overlay, set by someone else: what was sent is no longer true.
60
- if (typeof state.overlay === 'boolean') sent = state.overlay;
68
+ // The app's overlay, set off by someone else: what the shell raised is down. Set on by someone else, it is still
69
+ // theirs: the shell does not take it over (nor lower it on dispose).
70
+ if (state.overlay !== undefined) raised = state.overlay;
71
+ if (state.overlay === false) sent = false;
61
72
  // A remote page shown while a popup is open: the home page comes in front now; none any more: nothing to cover.
62
- void send(shown && count > 0);
73
+ // Holding nothing, the overlay is not the shell's: another raised it (an older rail's own count), it lowers it.
74
+ if (count > 0) void send(shown);
63
75
  };
64
76
  const stop = app?.onState((state) => {
65
77
  followed = true;
@@ -97,9 +109,10 @@ export function createOverlayHold(
97
109
  const releaseId = id === undefined ? undefined : held.hold(id);
98
110
  // The desktop app focuses the home page over its remote view (`focus`, ignored by an older app); the page too.
99
111
  if (modal) window.focus();
100
- const raise = () => (shown ? send(true, modal).then(frame) : Promise.resolve());
101
- const ready = !app ? Promise.resolve() : bounded(followed || settled ? raise() : watching.then(raise));
102
112
  let released = false;
113
+ // Released (or the shell disposed) before the app's first state answered: nothing to raise any more.
114
+ const raise = () => (shown && !released && !disposed ? send(true, modal).then(frame) : Promise.resolve());
115
+ const ready = !app ? Promise.resolve() : bounded(followed || settled ? raise() : watching.then(raise));
103
116
  const release = () => {
104
117
  if (released) return;
105
118
  released = true;
@@ -116,6 +129,7 @@ export function createOverlayHold(
116
129
  /** The shell is disposed: stop following the app, drop every hold, give the window back. */
117
130
  dispose() {
118
131
  stop?.();
132
+ disposed = true;
119
133
  clearTimeout(lowering);
120
134
  count = 0;
121
135
  held.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/shell",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
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.20261125.1"
106
+ "bridge": ">=0.0.2-nightly.20261130.1"
107
107
  }
108
108
  }