@bridgebrew/shell 0.0.1 → 0.0.4

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.
@@ -56,6 +56,7 @@ import {
56
56
  CommandHostProvider,
57
57
  ToastStack,
58
58
  TooltipProvider,
59
+ Tip,
59
60
  DEFAULT_ICON_SET,
60
61
  DEFAULT_KIT,
61
62
  clampSidebarWidth,
@@ -196,6 +197,7 @@ type RenderScreen = (
196
197
  next: Record<string, string> | undefined,
197
198
  options?: { push?: boolean },
198
199
  ) => void;
200
+ setActions?: (list: readonly ScreenAction[]) => void;
199
201
  },
200
202
  opts: { entryKey: string; fallback: React.ReactNode },
201
203
  ) => React.ReactNode;
@@ -213,14 +215,25 @@ type Parts = {
213
215
  };
214
216
  bar: { 'data-slot': 'shell-window-bar' };
215
217
  crumbs: React.ReactNode;
218
+ actions?: React.ReactNode;
216
219
  body: React.ReactNode;
217
220
  };
221
+ /** ./shell.d.ts `ScreenAction`: a button a desktop screen gives its window's bar. */
222
+ type ScreenAction = {
223
+ id: string;
224
+ label: string;
225
+ icon: string;
226
+ onSelect: () => void;
227
+ pressed?: boolean;
228
+ disabled?: boolean;
229
+ };
218
230
  type Options = {
219
231
  focused: boolean;
220
232
  active?: boolean;
221
233
  choices?: boolean;
222
234
  others?: Others;
223
235
  frame?: (parts: Parts) => React.ReactNode;
236
+ drawsActions?: boolean;
224
237
  };
225
238
  type StageOwner = {
226
239
  renderWindow: (id: string, view: View, options: Options) => React.ReactNode;
@@ -232,7 +245,7 @@ type StageOwner = {
232
245
  * before windows (main's `shell-top-bar`): a line on its left against the sidebar, a 44px top bar holding the
233
246
  * breadcrumb over a line, the screen under it scrolling alone; no corner, no shadow (./window.css adds the line between
234
247
  * the rail and the sidebar). */
235
- export const flatFrame = ({ window, bar, crumbs, body }: Parts) => (
248
+ export const flatFrame = ({ window, bar, crumbs, actions, body }: Parts) => (
236
249
  <div
237
250
  {...window}
238
251
  data-flat=""
@@ -240,6 +253,7 @@ export const flatFrame = ({ window, bar, crumbs, body }: Parts) => (
240
253
  >
241
254
  <header {...bar} className="flex h-11 shrink-0 items-center gap-4 border-b border-border px-4">
242
255
  {crumbs}
256
+ {actions && <div className="-mr-2 ml-auto flex shrink-0">{actions}</div>}
243
257
  </header>
244
258
  {body}
245
259
  </div>
@@ -466,11 +480,14 @@ export function ShellWindow({
466
480
  choices,
467
481
  others,
468
482
  frame,
483
+ drawsActions = false,
469
484
  mobile,
470
485
  }: {
471
486
  shell: Shell;
472
487
  renderSlot: RenderScreen;
473
488
  mobile?: boolean | undefined;
489
+ /** `frame` draws `Parts.actions`: only then does its screen get `setActions`. */
490
+ drawsActions?: boolean | undefined;
474
491
  id: string;
475
492
  view: View;
476
493
  focused: boolean;
@@ -498,6 +515,15 @@ export function ShellWindow({
498
515
  shell.setScreenState(id, next, options),
499
516
  [shell, id],
500
517
  );
518
+ // The buttons its screen gives the bar (`setActions`), kept with the view that gave them: another screen or node in
519
+ // this window shows none of the previous one's.
520
+ const viewKey = JSON.stringify([node, screen?.plugin, screen?.id]);
521
+ const [given, setGiven] = React.useState<{ key: string; list: readonly ScreenAction[] }>();
522
+ const setActions = React.useCallback(
523
+ (list: readonly ScreenAction[]) => setGiven({ key: viewKey, list }),
524
+ [viewKey],
525
+ );
526
+ const actions = given?.key === viewKey && given.list.length > 0 ? given.list : undefined;
501
527
  const stateProps = { ...(screenState && { screenState }), setScreenState };
502
528
  // Research-069: the view's scope, one per view generation (a node change remounts the view): its editors register
503
529
  // there; the state the shell shows (a notice in its place) is told once rendered.
@@ -657,6 +683,8 @@ export function ShellWindow({
657
683
  ...at,
658
684
  ...(others && { others }),
659
685
  ...stateProps,
686
+ // Only where its frame draws them: a screen without it draws its own (a manager that does not, an older one).
687
+ ...(drawsActions && { setActions }),
660
688
  };
661
689
  // Research-069: shown, the slot has no entry for it (failed, missing, or not loaded yet): the view says so.
662
690
  const fallback = (
@@ -748,6 +776,24 @@ export function ShellWindow({
748
776
  />
749
777
  </FollowProvider>
750
778
  ),
779
+ actions: actions && (
780
+ <div data-slot="shell-window-actions" className="flex items-center gap-1">
781
+ {actions.map((each) => (
782
+ <Tip key={each.id} label={each.label}>
783
+ <Button
784
+ variant="ghost"
785
+ size="icon-sm"
786
+ aria-label={each.label}
787
+ {...(each.pressed !== undefined && { 'aria-pressed': each.pressed })}
788
+ disabled={each.disabled}
789
+ onClick={each.onSelect}
790
+ >
791
+ <Icon name={each.icon} size={16} />
792
+ </Button>
793
+ </Tip>
794
+ ))}
795
+ </div>
796
+ ),
751
797
  body: (
752
798
  <div data-slot="shell-window-body" className="flex min-h-0 flex-1 flex-col overflow-y-auto">
753
799
  {/* One parent whether archived or not: only a node change remounts the view. */}
@@ -811,7 +857,11 @@ function Main({
811
857
  });
812
858
  }, [failed, toast, chooser]);
813
859
  const renderWindow = React.useCallback(
814
- (id: string, view: View, { focused, active, choices, others, frame }: Options) => (
860
+ (
861
+ id: string,
862
+ view: View,
863
+ { focused, active, choices, others, frame, drawsActions }: Options,
864
+ ) => (
815
865
  <ShellWindow
816
866
  key={id}
817
867
  shell={shell}
@@ -823,25 +873,31 @@ function Main({
823
873
  choices={choices}
824
874
  others={others}
825
875
  frame={frame ?? flatFrame}
876
+ drawsActions={frame === undefined || drawsActions === true}
826
877
  mobile={mobile}
827
878
  />
828
879
  ),
829
880
  [shell, renderSlot, mobile],
830
881
  );
831
882
  const view = viewOf(state);
883
+ // Workspace plugins' dialogs (research-034): each portals its own modal over the page, on a phone too.
884
+ const dialogs = renderSlot('dialogs', {});
832
885
  // On a phone: no window manager, the one view full screen under the phone's header (./mobile.tsx).
833
886
  if (mobile)
834
- return renderWindow('main', view, {
835
- focused: false,
836
- active: true,
837
- frame: mobileFrame(shell, view),
838
- });
887
+ return (
888
+ <>
889
+ {renderWindow('main', view, {
890
+ focused: false,
891
+ active: true,
892
+ frame: mobileFrame(shell, view),
893
+ })}
894
+ {dialogs}
895
+ </>
896
+ );
839
897
  // The shell's one window, flat in the stage: the window the user works in.
840
898
  const one = renderWindow('main', view, { focused: false, active: true });
841
899
  // Set aside, none chosen, or none installed (re-read on each change: the shell notifies when `stage` changes).
842
900
  const plugin = stagePlugin();
843
- // Workspace plugins' dialogs (research-034): each portals its own modal over the page.
844
- const dialogs = renderSlot('dialogs', {});
845
901
  if (failed || plugin === undefined)
846
902
  return (
847
903
  <>
@@ -55,10 +55,11 @@ export const fixLabels: Record<Fix['action'], string> = {
55
55
  'reload-all': 'Reload all',
56
56
  setting: 'Open the setting',
57
57
  'plugin-action': 'Run',
58
+ contract: 'Fix',
58
59
  };
59
60
  /** A fix's button label: a plugin's action names its own; a setting with no field opens the plugin's settings page. */
60
61
  export const fixLabel = (fix: Fix) =>
61
- fix.action === 'plugin-action' || fix.action === 'retry'
62
+ fix.action === 'plugin-action' || fix.action === 'retry' || fix.action === 'contract'
62
63
  ? fix.label
63
64
  : fix.action === 'setting' && fix.setting === ''
64
65
  ? 'Open its settings'
@@ -66,7 +67,9 @@ export const fixLabel = (fix: Fix) =>
66
67
 
67
68
  /** The host route a fix's button runs (the Plugins section's, `bridge restart` / `bridge reload`'s); Reload page then
68
69
  * reloads the page. Reload all is not one route: the targets are walked in turn. */
69
- const fixUrl = (fix: Exclude<Fix, { action: 'reload-all' | 'setting' | 'plugin-action' }>) =>
70
+ const fixUrl = (
71
+ fix: Exclude<Fix, { action: 'reload-all' | 'setting' | 'plugin-action' | 'contract' }>,
72
+ ) =>
70
73
  fix.action === 'restart-bridge'
71
74
  ? '/_bridge/restart'
72
75
  : `/_bridge/workspaces/${encodeURIComponent(fix.slug)}/${
@@ -80,10 +83,10 @@ const fixUrl = (fix: Exclude<Fix, { action: 'reload-all' | 'setting' | 'plugin-a
80
83
  export function runFix(fix: Fix, title: string, toast: (input: ToastInput) => string) {
81
84
  // Open the setting is the page's own navigation (`Notifications`), no request.
82
85
  if (fix.action === 'setting') return;
83
- if (fix.action === 'plugin-action') {
86
+ if (fix.action === 'plugin-action' || fix.action === 'contract') {
84
87
  // Through `ActionConfirm` when it is mounted (its question first), else at once.
85
88
  if (actions.size) for (const listener of actions) listener(fix);
86
- else void runPluginAction(fix, toast);
89
+ else void (fix.action === 'contract' ? runContractFix(fix, toast) : runPluginAction(fix, toast));
87
90
  return;
88
91
  }
89
92
  const label = fixLabels[fix.action];
@@ -147,42 +150,141 @@ export function runFix(fix: Fix, title: string, toast: (input: ToastInput) => st
147
150
  }
148
151
 
149
152
  type PluginActionFix = Extract<Fix, { action: 'plugin-action' }>;
150
- /** The mounted `ActionConfirm`s, `runFix`'s way to a plugin's action (one, the shell's). */
151
- const actions = new Set<(fix: PluginActionFix) => void>();
153
+ type ContractFix = Extract<Fix, { action: 'contract' }>;
154
+ /** The mounted `ActionConfirm`s, `runFix`'s way to a plugin's action or a contract fix (one, the shell's). */
155
+ const actions = new Set<(fix: PluginActionFix | ContractFix) => void>();
156
+ /** A step of a contract fix in people's words. */
157
+ const stepText = (step: ContractFix['steps'][number]) =>
158
+ step.action === 'install'
159
+ ? `Install a plugin providing ${step.contract}`
160
+ : `${step.action[0]!.toUpperCase()}${step.action.slice(1)} ${step.plugin}`;
161
+ /** What a contract fix's request answered: done, refused (its words), or a change that would leave other readers in
162
+ * error, announced (`contract_break`, bridgebrew/bridge#598): made only once `accept` names them. */
163
+ type FixAnswer =
164
+ | { done: true }
165
+ | { done: false; message: string; hint?: string; accept?: string[] };
166
+ /** Runs a contract fix as one change (`plugin/batch` behind the host's `…/plugins/<id>/fix`), with `accept` the readers
167
+ * an announcement named; a refusal toasted unless it is an announcement, which is handed back. */
168
+ async function postContractFix(fix: ContractFix, accept?: string[]): Promise<FixAnswer> {
169
+ const steps = fix.steps
170
+ .map((step) => `${step.action}:${step.action === 'install' ? step.contract : step.plugin}`)
171
+ .join(',');
172
+ try {
173
+ const res = await fetch(
174
+ `/_bridge/workspaces/${encodeURIComponent(fix.slug)}/plugins/${encodeURIComponent(fix.plugin)}/fix?steps=${encodeURIComponent(steps)}${accept ? `&accept=${accept.map(encodeURIComponent).join(',')}` : ''}`,
175
+ { method: 'POST' },
176
+ );
177
+ if (res.ok) return { done: true };
178
+ const body: unknown = await res.json().catch(() => undefined);
179
+ const { message, hint } = refusalOf(body, res.status);
180
+ const error = isRecord(body) && isRecord(body.error) ? body.error : {};
181
+ const readers = Array.isArray(error.accept)
182
+ ? error.accept.filter((each): each is string => typeof each === 'string')
183
+ : undefined;
184
+ return {
185
+ done: false,
186
+ message,
187
+ ...(hint !== undefined && { hint }),
188
+ ...(error.code === 'contract_break' && readers?.length && { accept: readers }),
189
+ };
190
+ } catch (cause) {
191
+ return { done: false, message: cause instanceof Error ? cause.message : String(cause) };
192
+ }
193
+ }
194
+ /** A contract fix without its dialog: run at once, an announcement left unconfirmed (its words toasted). */
195
+ async function runContractFix(
196
+ fix: ContractFix,
197
+ toast: (input: ToastInput) => string,
198
+ accept?: string[],
199
+ ): Promise<FixAnswer> {
200
+ toast({ variant: 'info', title: `${fix.label}…` });
201
+ const answer = await postContractFix(fix, accept);
202
+ if (!answer.done && answer.accept === undefined) {
203
+ const text = [answer.message, answer.hint].filter(Boolean).join(' ');
204
+ toast(
205
+ toastOf({
206
+ variant: 'error',
207
+ title: `${fix.label} failed`,
208
+ description: text,
209
+ copy: copyOf(`${fix.label} failed`, text),
210
+ }),
211
+ );
212
+ }
213
+ return answer;
214
+ }
152
215
 
153
216
  /** A plugin's settings action run from a toast, a card or Health (`runFix`): its `confirm` asked first in a dialog
154
217
  * (Take over: the other Bridge stops writing), the buttons on the right; one without `confirm` runs at once. */
155
218
  export function ActionConfirm() {
156
219
  const { toast } = useToast();
157
- const [pending, setPending] = React.useState<PluginActionFix | undefined>(undefined);
220
+ /** The question shown: a settings action's `confirm`, a contract fix's steps, or what a fix would leave in error. */
221
+ const [pending, setPending] = React.useState<
222
+ | { fix: PluginActionFix }
223
+ | { fix: ContractFix; announced?: { message: string; hint?: string; accept: string[] } }
224
+ | undefined
225
+ >(undefined);
158
226
  React.useEffect(() => {
159
- const listener = (fix: PluginActionFix) => {
160
- if (fix.confirm === undefined) void runPluginAction(fix, toast);
161
- else setPending(fix);
227
+ const listener = (fix: PluginActionFix | ContractFix) => {
228
+ if (fix.action === 'plugin-action' && fix.confirm === undefined) void runPluginAction(fix, toast);
229
+ else setPending({ fix } as typeof pending);
162
230
  };
163
231
  actions.add(listener);
164
232
  return () => void actions.delete(listener);
165
233
  }, [toast]);
234
+ const confirm = async () => {
235
+ if (!pending) return;
236
+ setPending(undefined);
237
+ if (pending.fix.action === 'plugin-action') return void runPluginAction(pending.fix, toast);
238
+ const announced = 'announced' in pending ? pending.announced : undefined;
239
+ const answer = await runContractFix(pending.fix, toast, announced?.accept);
240
+ // Readers it would leave in error (bridgebrew/bridge#598): said, then made for exactly them once confirmed.
241
+ if (!answer.done && answer.accept !== undefined)
242
+ setPending({
243
+ fix: pending.fix,
244
+ announced: {
245
+ message: answer.message,
246
+ ...(answer.hint !== undefined && { hint: answer.hint }),
247
+ accept: answer.accept,
248
+ },
249
+ });
250
+ };
251
+ const fix = pending?.fix;
252
+ const announced = pending && 'announced' in pending ? pending.announced : undefined;
166
253
  return (
167
254
  <Dialog open={pending !== undefined} onOpenChange={(open) => !open && setPending(undefined)}>
168
255
  <DialogContent>
169
256
  <DialogHeader>
170
- <DialogTitle>{pending?.label}</DialogTitle>
257
+ <DialogTitle>{fix?.label}</DialogTitle>
171
258
  </DialogHeader>
172
259
  <DialogBody className="pb-4">
173
- <DialogDescription>{pending?.confirm}</DialogDescription>
260
+ {fix?.action === 'contract' ? (
261
+ announced ? (
262
+ <>
263
+ <DialogDescription>{announced.message}.</DialogDescription>
264
+ {announced.hint && <p className="m-0 mt-2 text-xs text-secondary">{announced.hint}</p>}
265
+ </>
266
+ ) : (
267
+ <>
268
+ <DialogDescription>
269
+ Bridge makes these changes as one, then restarts the workspace:
270
+ </DialogDescription>
271
+ <ol data-fix-steps className="m-0 mt-2 pl-5 text-sm">
272
+ {fix.steps.map((step) => (
273
+ <li key={stepText(step)}>{stepText(step)}</li>
274
+ ))}
275
+ </ol>
276
+ </>
277
+ )
278
+ ) : (
279
+ <DialogDescription>{fix?.confirm}</DialogDescription>
280
+ )}
174
281
  </DialogBody>
175
282
  <DialogFooter className="justify-end gap-2">
176
283
  <Button variant="outline" onClick={() => setPending(undefined)}>
177
284
  Cancel
178
285
  </Button>
179
- <Button
180
- onClick={() => {
181
- if (pending) void runPluginAction(pending, toast);
182
- setPending(undefined);
183
- }}
184
- >
185
- {pending?.label}
286
+ <Button variant="primary" onClick={() => void confirm()}>
287
+ {announced ? 'Continue' : fix?.label}
186
288
  </Button>
187
289
  </DialogFooter>
188
290
  </DialogContent>
@@ -409,6 +511,16 @@ function ErrorCard({
409
511
  {fixLabel(item.fix)}
410
512
  </Button>
411
513
  )}
514
+ {item.more?.map((fix) => (
515
+ <Button
516
+ key={fixLabel(fix)}
517
+ size="sm"
518
+ variant="outline"
519
+ onClick={(event) => onFix(fix, item.title, event)}
520
+ >
521
+ {fixLabel(fix)}
522
+ </Button>
523
+ ))}
412
524
  <CopyButton text={copy} />
413
525
  </div>
414
526
  {hasLogs && (
@@ -41,6 +41,7 @@
41
41
 
42
42
  import type { HostStatusEvent } from './shell.d.ts';
43
43
  import type { Attention } from '@bridge/kernel/status';
44
+ import type { FixStep } from '@bridge/kernel/contracts';
44
45
  import { pageSlot } from './page-slot.ts';
45
46
 
46
47
  export type { HostStatusEvent };
@@ -55,6 +56,9 @@ export type Fix =
55
56
  /** Restarts workspace `slug`, which tries its composition again (an attention's `retry`, research-087 §7.7); `label`,
56
57
  * its button. */
57
58
  | { action: 'retry'; slug: string; label: string }
59
+ /** A way out of plugin `plugin`'s contracts that do not agree (bridgebrew/bridge#598, `PluginView.fixes`): its `steps`
60
+ * run as one change (`plugin/batch`), shown first; `label`, its button. */
61
+ | { action: 'contract'; slug: string; plugin: string; steps: FixStep[]; label: string }
58
62
  /** Opens plugin `plugin`'s settings in workspace `slug`, on field `setting`. */
59
63
  | { action: 'setting'; slug: string; plugin: string; setting: string }
60
64
  /** Runs plugin `plugin`'s settings action `id` (an `x-bridge-action` entry's) in workspace `slug`; `label`, its button. */
@@ -87,6 +91,42 @@ export const attentionFix = (
87
91
  label: fix.label,
88
92
  ...(fix.confirm !== undefined && { confirm: fix.confirm }),
89
93
  };
94
+ const capital = (word: string) => `${word[0]!.toUpperCase()}${word.slice(1)}`;
95
+ /** A plugin's contract fixes (`PluginView.fixes`, bridgebrew/bridge#598) as buttons, named by their steps as the status
96
+ * page names them (`Enable contacts, then Remove organizations`). A fix that installs a plugin is not one click (which
97
+ * plugin is the person's choice): left out. */
98
+ export const contractFixes = (
99
+ { id, fixes }: Pick<PluginView, 'id' | 'fixes'>,
100
+ slug: string,
101
+ ): Extract<Fix, { action: 'contract' }>[] =>
102
+ (fixes ?? []).flatMap((steps) =>
103
+ steps.some((step) => step.action === 'install')
104
+ ? []
105
+ : [
106
+ {
107
+ action: 'contract' as const,
108
+ slug,
109
+ plugin: id,
110
+ steps,
111
+ label: steps
112
+ .map((step) => (step.action === 'install' ? '' : `${capital(step.action)} ${step.plugin}`))
113
+ .join(', then '),
114
+ },
115
+ ],
116
+ );
117
+ /** A toast's one button among `fixes`: never a removal (one click would take a plugin away); the Errors modal offers
118
+ * them all. */
119
+ const toastFix = (fixes: Extract<Fix, { action: 'contract' }>[]) =>
120
+ fixes.find(({ steps }) => !steps.some((step) => step.action === 'remove'));
121
+ /** What a plugin's contracts say (`PluginView.contracts`), as one text, and a provider to install when that is a way
122
+ * out (which plugin is the person's choice: no button); none when they agree. */
123
+ const contractsText = ({ contracts, fixes }: Pick<PluginView, 'contracts' | 'fixes'>) => {
124
+ if (!contracts?.length) return undefined;
125
+ const install = fixes
126
+ ?.flat()
127
+ .flatMap((step) => (step.action === 'install' ? [step.contract] : []));
128
+ return `${contracts.join('; ')}.${install?.length ? ` Install a plugin providing ${install.join(', ')}.` : ''}`;
129
+ };
90
130
  export type Notice = {
91
131
  variant: 'error' | 'warning' | 'info' | 'success';
92
132
  title: string;
@@ -318,7 +358,19 @@ const shownOf = ({
318
358
  reloadError,
319
359
  blockedBy,
320
360
  attention,
321
- }: PluginView) => [state, error, unresolved, browserError, reloadError, blockedBy, attention];
361
+ contracts,
362
+ fixes,
363
+ }: PluginView) => [
364
+ state,
365
+ error,
366
+ unresolved,
367
+ browserError,
368
+ reloadError,
369
+ blockedBy,
370
+ attention,
371
+ contracts,
372
+ fixes,
373
+ ];
322
374
  /** `a`; `a and b`; `a, b and c`: every name. */
323
375
  const listNames = (names: string[]) =>
324
376
  names.length <= 1 ? (names[0] ?? '') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
@@ -357,22 +409,28 @@ function noticesOf(
357
409
  });
358
410
  } else if (state === 'failed') {
359
411
  if ((reloadError === undefined ? undefined : withoutGeneration(reloadError)) !== error) {
360
- const description = withHint(plugin, slug, error, true);
412
+ // A reader whose contracts do not agree (bridgebrew/bridge#598): what they say, and their first fix.
413
+ const contract = toastFix(contractFixes(plugin, slug));
414
+ const description = contractsText(plugin) ?? withHint(plugin, slug, error, true);
361
415
  notices.push({
362
416
  variant: 'error',
363
417
  title: failed,
364
418
  description,
365
- ...fixOf(plugin, slug, error),
419
+ ...(contract ? { fix: contract } : fixOf(plugin, slug, error)),
366
420
  copy: copyOf(failed, description),
367
421
  details,
368
422
  });
369
423
  }
370
424
  } else if (state === 'unresolved') {
371
- const description = unresolved?.length ? `Unresolved: ${unresolved.join(', ')}` : undefined;
425
+ // Waiting for a provider (bridgebrew/bridge#598): what its contracts say, and their first fix.
426
+ const contract = toastFix(contractFixes(plugin, slug));
427
+ const description =
428
+ contractsText(plugin) ?? (unresolved?.length ? `Unresolved: ${unresolved.join(', ')}` : undefined);
372
429
  notices.push({
373
430
  variant: 'warning',
374
431
  title: failed,
375
432
  ...(description !== undefined && { description }),
433
+ ...(contract && { fix: contract }),
376
434
  copy: copyOf(failed, description),
377
435
  details,
378
436
  });
@@ -1106,6 +1164,8 @@ export type ReportItem = {
1106
1164
  /** Every other status field set, as the modal's definition list. */
1107
1165
  details: { label: string; value: string }[];
1108
1166
  fix?: Fix;
1167
+ /** Its other ways out, after `fix` (a reader's contract fixes, bridgebrew/bridge#598). */
1168
+ more?: Fix[];
1109
1169
  };
1110
1170
 
1111
1171
  /** The status fields of `view` (and a workspace's reason) an item does not already show as its `text`; a field equal to
@@ -1201,10 +1261,13 @@ export function report(given: SnapshotData['workspaces']): ReportItem[] {
1201
1261
  const { key, slug, view } = entry;
1202
1262
  if (!pluginFails(view) || view.blockedBy?.length || inCause.has(key)) continue;
1203
1263
  const reload = view.reloadError;
1264
+ const contract = contractFixes(view, slug);
1204
1265
  const text =
1205
1266
  reload !== undefined
1206
1267
  ? reload
1207
- : view.state === 'unresolved'
1268
+ : contractsText(view) !== undefined
1269
+ ? contractsText(view)!
1270
+ : view.state === 'unresolved'
1208
1271
  ? `Unresolved: ${view.unresolved?.join(', ') ?? ''}`
1209
1272
  : view.state === 'failed'
1210
1273
  ? (view.error ?? `${view.id} failed`)
@@ -1213,7 +1276,8 @@ export function report(given: SnapshotData['workspaces']): ReportItem[] {
1213
1276
  const title = `${view.id} ${reloading ? 'failed to reload' : 'failed'} in ${titleOf(slug)}`;
1214
1277
  const cause = reloading ? reload : view.state === 'failed' ? view.error : view.browserError;
1215
1278
  const hint = view.state === 'unresolved' ? undefined : sentenceOf(view, slug, cause, true);
1216
- const { fix } = fixOf(view, slug, cause);
1279
+ const fix = reloading ? fixOf(view, slug, cause).fix : (contract[0] ?? fixOf(view, slug, cause).fix);
1280
+ const more = !reloading && contract[0] ? contract.slice(1) : [];
1217
1281
  items.push({
1218
1282
  key,
1219
1283
  kind: 'plugin',
@@ -1226,6 +1290,7 @@ export function report(given: SnapshotData['workspaces']): ReportItem[] {
1226
1290
  .map((each) => ({ slug: each.slug, id: each.view.id })),
1227
1291
  details: detailsOf(view, text),
1228
1292
  ...(fix !== undefined && { fix }),
1293
+ ...(more.length > 0 && { more }),
1229
1294
  });
1230
1295
  }
1231
1296
  for (const workspace of workspaces) {
@@ -206,22 +206,40 @@ export interface WindowParts {
206
206
  };
207
207
  bar: { 'data-slot': 'shell-window-bar' };
208
208
  crumbs: ReactNode;
209
+ /** The buttons its screen gave (`screen`'s `setActions`), drawn by the shell (`shell-window-actions`): the manager
210
+ * places them in its bar at the right of `crumbs`, before its own controls, and says so (`WindowOptions.drawsActions`).
211
+ * Absent while the screen gives none. */
212
+ actions?: ReactNode;
209
213
  body: ReactNode;
210
214
  }
211
215
 
216
+ /** A button a desktop screen gives its window's bar (`screen`'s `setActions`): an icon button the shell draws, `label`
217
+ * its name and tooltip, `pressed` its `aria-pressed` when it toggles something (a panel shown). */
218
+ export interface ScreenAction {
219
+ id: string;
220
+ label: string;
221
+ icon: string;
222
+ onSelect: () => void;
223
+ pressed?: boolean;
224
+ disabled?: boolean;
225
+ }
226
+
212
227
  /** `renderWindow`'s options: `focused` marks the window focused among several (`data-focused`, where the manager draws
213
228
  * its ring); `active`: it is the window the user works in (the focused one, ring or not: alone, it has none), its
214
229
  * screen gets `focused: true`, the others `false`; absent (a manager that does not say), the screen's `focused` is
215
230
  * absent too. `choices`: an empty window (a node alone) offers the node's views as buttons under "Choose a view in the
216
231
  * sidebar". `others` (research-018 slice 6c): the other windows of its desk (shown or minimized) showing its screen on
217
232
  * its node, each with its item and the kind its screen's `windows` rules give, passed on to its screen as `others`.
218
- * `frame`: draws the window around its parts (`WindowParts`); absent, the shell's flat frame, as without a manager. */
233
+ * `frame`: draws the window around its parts (`WindowParts`); absent, the shell's flat frame, as without a manager.
234
+ * `drawsActions`: `frame` draws `WindowParts.actions`; only then does its screen get `setActions` (the flat frame
235
+ * always draws them), so a screen falls back to its own buttons under a manager that does not. */
219
236
  export interface WindowOptions {
220
237
  focused: boolean;
221
238
  active?: boolean;
222
239
  choices?: boolean;
223
240
  others?: readonly { item?: string; kind?: string }[];
224
241
  frame?: (parts: WindowParts) => ReactNode;
242
+ drawsActions?: boolean;
225
243
  }
226
244
 
227
245
  /** A window shortcut (research-018 C5): `keys`, one or several, each modifiers then a `KeyboardEvent.code` (or a single
@@ -859,7 +877,12 @@ declare module '@bridge/ui-slots' {
859
877
  * node, each with its item and the kind its screen's `windows` rules give it: a list may leave its own card pane
860
878
  * while card windows are open, and send a click to them (`reuse`); absent, a manager (or a Bridge) that does not say.
861
879
  * `screenState`, `setScreenState` (research-090): its window's own state and its setter, as `workspace.d.ts`'s
862
- * `screen` says; absent from an older Bridge. */
880
+ * `screen` says; absent from an older Bridge. `setActions`: the buttons the screen wants in its window's bar
881
+ * (`ScreenAction`), at the right of the breadcrumb, before the window's own controls (the shell's top bar without a
882
+ * window manager); call it from an effect, and with `[]` when the screen unmounts. Kept per window and per view:
883
+ * another screen or node there shows none of them. Given only where they are drawn: absent, an older shell, a
884
+ * window manager that does not draw them (`WindowOptions.drawsActions`), a phone, or a utility screen; the
885
+ * screen then draws its own. */
863
886
  screen: {
864
887
  kind: 'keyed';
865
888
  scope: 'root';
@@ -875,6 +898,7 @@ declare module '@bridge/ui-slots' {
875
898
  next: Record<string, string> | undefined,
876
899
  options?: { push?: boolean },
877
900
  ) => void;
901
+ setActions?: (actions: readonly ScreenAction[]) => void;
878
902
  };
879
903
  };
880
904
  /** Declared by `shell`'s `main` entry (research-020 C): a screen's phone variant, filled under its plugin key as
@@ -886,7 +910,7 @@ declare module '@bridge/ui-slots' {
886
910
  /** `setActions` (research-020, iOS 26's layout): the buttons the screen wants the shell to draw, in glass:
887
911
  * `top`, the capsule at the top right; `primary`, the round button at the bottom right beside the bar of
888
912
  * screens. Call it from an effect, and with `[]` when the screen unmounts. Absent: an older shell. */
889
- owner: SlotMap['screen']['owner'] & {
913
+ owner: Omit<SlotMap['screen']['owner'], 'setActions'> & {
890
914
  setActions?: (
891
915
  actions: readonly {
892
916
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridgebrew/shell",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
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": [
@@ -72,7 +72,24 @@
72
72
  "placement": "host",
73
73
  "implements": [
74
74
  "shell"
75
- ]
75
+ ],
76
+ "contracts": {
77
+ "provides": {
78
+ "shell": {
79
+ "version": "1.0"
80
+ }
81
+ },
82
+ "uses": {
83
+ "plugin-manager": {
84
+ "version": "1.0",
85
+ "optional": true
86
+ },
87
+ "bridge-settings": {
88
+ "version": "1.0",
89
+ "optional": true
90
+ }
91
+ }
92
+ }
76
93
  },
77
94
  "peerDependencies": {
78
95
  "@bridge/kernel": ">=0.0.1",
@@ -86,6 +103,6 @@
86
103
  "typecheck": "bridge plugin check ."
87
104
  },
88
105
  "engines": {
89
- "bridge": ">=0.0.1-nightly.20261117.1"
106
+ "bridge": ">=0.0.1-nightly.20261120.1"
90
107
  }
91
108
  }