@bridgebrew/bridge-settings 0.0.0-stage → 0.0.2

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bridgebrew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,45 @@
1
+ // System (research-016 C1): settings for all of Bridge, as a section of the Admin workspace's sidebar: four root
2
+ // screens side by side, Status (the first: the plugin's view), Health (./health.tsx, research-047), Logs (./logs.tsx,
3
+ // bridge#222: every log file, and their rotation and retention), Network, Plugin install
4
+ // (./plugin-install.tsx, research-062, experimental), Appearance and Providers (./providers.tsx).
5
+ // Bridge's own plugins (`_host`: its storage, harness, shell, window manager…) and their settings are on the Plugins
6
+ // screen, which in Admin lists them under System above Admin's own (research-027 P10). Installed in Admin only, which
7
+ // Bridge never removes (C5); when Admin cannot run, the safe-mode page `/_bridge/` does the repairs these screens do.
8
+ import * as React from 'react';
9
+ import type { Context } from 'cordis';
10
+ import type {} from '@bridge/ui-renderer/client';
11
+ import { SystemAppearance, SystemNetwork, SystemStatus } from './system.tsx';
12
+ import { SystemProviders } from './providers.tsx';
13
+ import { SystemHealth } from './health.tsx';
14
+ import { SystemLogs } from './logs.tsx';
15
+ import { SystemPluginInstall } from './plugin-install.tsx';
16
+
17
+ export const name = 'bridge-settings';
18
+ export const inject = ['slots', 'workspace', 'nodes', 'shell', 'hostStatus', 'screen'];
19
+
20
+ function Screen({
21
+ ctx,
22
+ screen,
23
+ item,
24
+ others,
25
+ }: {
26
+ ctx: Context;
27
+ screen: string;
28
+ item?: string | undefined;
29
+ /** The other windows of this screen on the desk (Bridge's research-018 slice 6c): Health's episode windows. */
30
+ others?: readonly { item?: string; kind?: string }[] | undefined;
31
+ }) {
32
+ if (screen === 'health') return <SystemHealth ctx={ctx} item={item} others={others} />;
33
+ if (screen === 'logs') return <SystemLogs ctx={ctx} item={item} />;
34
+ if (screen === 'network') return <SystemNetwork ctx={ctx} />;
35
+ if (screen === 'plugin-install') return <SystemPluginInstall ctx={ctx} />;
36
+ if (screen === 'appearance') return <SystemAppearance ctx={ctx} />;
37
+ if (screen === 'providers' || screen === 'harnesses') return <SystemProviders ctx={ctx} />;
38
+ return <SystemStatus ctx={ctx} />;
39
+ }
40
+
41
+ export function apply(ctx: Context) {
42
+ ctx.slots.register({ name: 'screen', key: name }, ({ screen, item, others }) => (
43
+ <Screen ctx={ctx} screen={screen} item={item} others={others} />
44
+ ));
45
+ }
@@ -0,0 +1,159 @@
1
+ // Health's model (research-047): `health.log`'s episodes as the host folds them (`/_bridge/logs/health`), kept by
2
+ // `episodeId` in the page as snapshots arrive, newest first.
3
+ import { formatDate } from '@bridge/ui';
4
+
5
+ /** An episode's snapshot as the host writes it (`HealthLine`, `packages/host/src/logs.ts`). */
6
+ export interface Episode {
7
+ time: string;
8
+ episodeId: string;
9
+ cause: string;
10
+ /** The plugin by key; none for a workspace's own episode (`workspace_failed`). */
11
+ plugin?: string;
12
+ workspace: string;
13
+ severity: 'error' | 'warning';
14
+ recovery: 'automatic' | 'user' | 'unknown';
15
+ message: string;
16
+ pluginId?: string;
17
+ /** A field of the plugin's settings to open, one of its settings actions to run (`confirm`: asked first), or the
18
+ * workspace to restart (`retry`, its label: Restart workspace here). */
19
+ fix?:
20
+ | { setting: string }
21
+ | { action: string; label: string; confirm?: string }
22
+ | { retry: string };
23
+ count: number;
24
+ firstSeen: string;
25
+ lastSeen: string;
26
+ resolvedAt?: string;
27
+ }
28
+
29
+ export type HealthState = 'open' | 'resolved' | 'all';
30
+
31
+ /** `known` with `snapshots` folded in: an episode keeps its latest snapshot (by `time`), whichever came first. */
32
+ export function fold(known: ReadonlyMap<string, Episode>, snapshots: readonly Episode[]) {
33
+ const next = new Map(known);
34
+ for (const snapshot of snapshots) {
35
+ const before = next.get(snapshot.episodeId);
36
+ if (!before || before.time <= snapshot.time) next.set(snapshot.episodeId, snapshot);
37
+ }
38
+ return next;
39
+ }
40
+
41
+ /** What the list shows: open only (`open`), resolved only (`resolved`) or every one, of `workspace` when given, newest snapshot first. */
42
+ export const shown = (
43
+ episodes: ReadonlyMap<string, Episode>,
44
+ state: HealthState,
45
+ workspace?: string,
46
+ ) =>
47
+ [...episodes.values()]
48
+ .filter((each) => state === 'all' || (state === 'open') === (each.resolvedAt === undefined))
49
+ .filter((each) => workspace === undefined || each.workspace === workspace)
50
+ .sort((a, b) => (a.time < b.time ? 1 : a.time > b.time ? -1 : 0));
51
+
52
+ /** The query of `/_bridge/logs/health` and its events. */
53
+ export const healthQuery = (
54
+ state: HealthState,
55
+ workspace?: string,
56
+ before?: number,
57
+ episode?: string,
58
+ ) =>
59
+ new URLSearchParams({
60
+ state,
61
+ ...(workspace !== undefined && { workspace }),
62
+ ...(episode !== undefined && { episode }),
63
+ ...(before !== undefined && { before: String(before) }),
64
+ }).toString();
65
+
66
+ /** The navigation item of the Plugins screen that opens the episode's plugin on its Logs tab, up to a minute past its
67
+ * last sighting (`<root>/<plugin id>/logs/<ISO time>`, plugin-manager's `logsOpening`); none without a plugin. */
68
+ export const logsItem = (episode: Episode) =>
69
+ episode.pluginId === undefined
70
+ ? undefined
71
+ : `${episode.workspace}/${episode.pluginId}/logs/${logsUntil(episode)}`;
72
+ /** A minute past the episode's last sighting: where its logs stop. */
73
+ export const logsUntil = ({ lastSeen }: Episode) =>
74
+ new Date(Date.parse(lastSeen) + 60_000).toISOString();
75
+
76
+ /** A time as the list shows it: `21 Oct 14:03`, in the page's time zone. */
77
+ export const when = (time: string) =>
78
+ formatDate(time, {
79
+ day: 'numeric',
80
+ month: 'short',
81
+ hour: '2-digit',
82
+ minute: '2-digit',
83
+ });
84
+
85
+ /** How long an episode lasted, or has lasted while open (`now`): `45 s`, `12 min`, `3 h`, `2 d`. */
86
+ export const duration = ({ firstSeen, resolvedAt }: Episode, now = Date.now()) => {
87
+ const seconds = Math.max(
88
+ 0,
89
+ ((resolvedAt ? Date.parse(resolvedAt) : now) - Date.parse(firstSeen)) / 1000,
90
+ );
91
+ if (seconds < 60) return `${Math.round(seconds)} s`;
92
+ if (seconds < 3600) return `${Math.round(seconds / 60)} min`;
93
+ if (seconds < 86_400) return `${Math.round(seconds / 3600)} h`;
94
+ return `${Math.round(seconds / 86_400)} d`;
95
+ };
96
+
97
+ /** The problems the host records by itself (not a plugin's attention): their message is a raw diagnostic. */
98
+ const systemCauses: Record<
99
+ string,
100
+ { label: string; summary: (plugin: string, workspace: string) => string }
101
+ > = {
102
+ plugin_failed: { label: 'Failed to start', summary: (plugin) => `${plugin} failed to start` },
103
+ plugin_unresolved: {
104
+ label: 'Missing a service',
105
+ summary: (plugin) => `${plugin} is missing a service`,
106
+ },
107
+ reload_failed: { label: 'Reload failed', summary: (plugin) => `${plugin} could not reload` },
108
+ browser_error: { label: 'Browser error', summary: (plugin) => `${plugin} failed in the browser` },
109
+ workspace_failed: { label: 'Workspace failed', summary: (_, workspace) => `${workspace} failed` },
110
+ service_waiting: { label: 'Waiting for a service', summary: () => '' },
111
+ health_trimmed: { label: 'History trimmed', summary: () => '' },
112
+ };
113
+
114
+ /** An episode's title and, for a problem the host recorded, the raw diagnostic under it (`workspace`: its title). */
115
+ export function summaryOf(
116
+ episode: Episode,
117
+ workspace: string,
118
+ ): { title: string; diagnostic?: string } {
119
+ const summary = systemCauses[episode.cause]?.summary(episode.plugin ?? '', workspace);
120
+ if (!summary) return { title: episode.message };
121
+ // The host's message often starts with what the title already says ("sessions could not reload: …"): not twice.
122
+ const repeated = episode.message.toLowerCase().startsWith(`${summary.toLowerCase()}: `);
123
+ return {
124
+ title: summary,
125
+ diagnostic: repeated ? episode.message.slice(summary.length + 2) : episode.message,
126
+ };
127
+ }
128
+
129
+ /** A cause's name for people: the host's own in words, a plugin's code made readable (`no_connection` → No connection). */
130
+ export const causeLabel = (cause: string) =>
131
+ systemCauses[cause]?.label ??
132
+ cause.replaceAll('_', ' ').replace(/^./, (first) => first.toUpperCase());
133
+
134
+ /** What gets an open problem with no fix of its own out: its plugin reloaded, the page reloaded (a browser error), or
135
+ * its workspace restarted; none for one its plugin owns (its attention says what to do). */
136
+ export function repairOf(
137
+ episode: Episode,
138
+ ): 'reload-plugin' | 'reload-page' | 'restart' | undefined {
139
+ if (episode.resolvedAt !== undefined) return undefined;
140
+ if (episode.fix) return 'retry' in episode.fix ? 'restart' : undefined;
141
+ if (episode.cause === 'browser_error') return 'reload-page';
142
+ if (episode.cause === 'workspace_failed') return 'restart';
143
+ if (
144
+ ['plugin_failed', 'plugin_unresolved', 'reload_failed'].includes(episode.cause) &&
145
+ episode.pluginId
146
+ )
147
+ return 'reload-plugin';
148
+ return undefined;
149
+ }
150
+
151
+ /** How long ago, as Linear's lists say it: `now`, `5m`, `3h`, `2d`, then the date (`21 Oct`). */
152
+ export const ago = (time: string, now = Date.now()) => {
153
+ const seconds = Math.max(0, (now - Date.parse(time)) / 1000);
154
+ if (seconds < 60) return 'now';
155
+ if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;
156
+ if (seconds < 86_400) return `${Math.floor(seconds / 3600)}h`;
157
+ if (seconds < 7 * 86_400) return `${Math.floor(seconds / 86_400)}d`;
158
+ return formatDate(time, { day: 'numeric', month: 'short' });
159
+ };