dmontgomery40 commited on
Commit
bdfada7
·
verified ·
1 Parent(s): b019fd5

Sync from GitHub via hub-sync

Browse files
dashboard/src/components/charts/theme.ts CHANGED
@@ -30,6 +30,8 @@ export const OBS = {
30
  fail: '#ff6b6b',
31
  notInForce: '#94a3b4',
32
  flag: '#f0b429',
 
 
33
  surface: '#151b23',
34
  inset: '#090d12',
35
  edge: '#2c3642',
 
30
  fail: '#ff6b6b',
31
  notInForce: '#94a3b4',
32
  flag: '#f0b429',
33
+ commitFill: '#1f7a45',
34
+ rollbackFill: '#9c2b2b',
35
  surface: '#151b23',
36
  inset: '#090d12',
37
  edge: '#2c3642',
dashboard/src/observatory/LayerMap.tsx ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { OBS } from '../components/charts/theme';
3
+ import { num } from './format';
4
+ import { Label } from './parts';
5
+ import { logScale, rampColor, RAMP_CSS } from './scale';
6
+ import type { Trajectory, TrajectorySession } from './types';
7
+
8
+ /** Width of an element in CSS pixels, so charts draw 1 unit = 1 px and text never scales. */
9
+ export function useWidth<T extends HTMLElement>(): [React.RefObject<T>, number] {
10
+ const ref = useRef<T>(null);
11
+ const [w, setW] = useState(0);
12
+ useEffect(() => {
13
+ const el = ref.current;
14
+ if (!el) return;
15
+ const measure = () => setW(Math.floor(el.getBoundingClientRect().width));
16
+ measure();
17
+ if (typeof ResizeObserver === 'undefined') return;
18
+ const ro = new ResizeObserver(measure);
19
+ ro.observe(el);
20
+ return () => ro.disconnect();
21
+ }, []);
22
+ return [ref, w];
23
+ }
24
+
25
+ export type TensorPick = 'all' | 0 | 1 | 2 | 3;
26
+
27
+ /** [layer][chunk] magnitudes for one tensor, or all four combined in quadrature. Null stays null. */
28
+ export function layerGrid(session: TrajectorySession, layers: number, pick: TensorPick): (number | null)[][] {
29
+ return Array.from({ length: layers }, (_, l) =>
30
+ session.chunks.map((c) => {
31
+ const v = c.per_layer;
32
+ if (!v) return null;
33
+ if (pick === 'all') {
34
+ const parts = [0, 1, 2, 3].map((k) => v[l * 4 + k]);
35
+ if (parts.some((x) => x === null || x === undefined)) return null;
36
+ return Math.sqrt(parts.reduce((a: number, x) => a + (x as number) ** 2, 0));
37
+ }
38
+ const x = v[l * 4 + pick];
39
+ return x === undefined ? null : x;
40
+ })
41
+ );
42
+ }
43
+
44
+ function turnOf(session: TrajectorySession, chunk: number): number | null {
45
+ const t = session.turns.find((tr) => chunk >= tr.tx[0] && chunk < tr.tx[1]);
46
+ return t ? t.i : null;
47
+ }
48
+
49
+ const LABEL_W = 64;
50
+ const ROW_FLAG = 13;
51
+ const ROW_DECISION = 13;
52
+
53
+ export function LayerMap({ trajectory, session: sessionId }: { trajectory: Trajectory; session: string }) {
54
+ const session = trajectory.sessions.find((s) => s.session_id === sessionId) ?? trajectory.sessions[0];
55
+ const layers = trajectory.per_layer.layers;
56
+ const tensors = trajectory.per_layer.tensors;
57
+ const [pick, setPick] = useState<TensorPick>('all');
58
+ const [view, setView] = useState<'flat' | 'terrain'>('flat');
59
+ const [tilt, setTilt] = useState(0.5);
60
+ const [hover, setHover] = useState<{ chunk: number; layer: number } | null>(null);
61
+ const [ref, width] = useWidth<HTMLDivElement>();
62
+ const grid = useMemo(() => layerGrid(session, layers, pick), [session, layers, pick]);
63
+ const scale = useMemo(() => logScale(grid.flat()), [grid]);
64
+ const n = session.chunks.length;
65
+ const plotW = Math.max(120, width - LABEL_W);
66
+ const cw = plotW / n;
67
+ const ch = 9;
68
+ const mapH = layers * ch;
69
+ const cell = hover ? session.chunks[hover.chunk] : null;
70
+ const turn = hover ? turnOf(session, hover.chunk) : null;
71
+ const turnText = turn !== null ? session.turns[turn] : null;
72
+
73
+ const onMove = (e: React.MouseEvent<SVGSVGElement>) => {
74
+ const r = e.currentTarget.getBoundingClientRect();
75
+ const x = e.clientX - r.left - LABEL_W;
76
+ const y = e.clientY - r.top - ROW_FLAG - ROW_DECISION - 6;
77
+ const chunk = Math.floor(x / cw);
78
+ const layer = layers - 1 - Math.floor(y / ch);
79
+ setHover(chunk >= 0 && chunk < n && layer >= 0 && layer < layers ? { chunk, layer } : null);
80
+ };
81
+
82
+ const turnStarts = session.turns.map((t) => t.tx[0]).filter((x) => x > 0 && x < n);
83
+
84
+ return (
85
+ <div className="space-y-3">
86
+ <div className="flex flex-wrap items-center gap-3">
87
+ <div role="group" aria-label="Tensor" className="flex flex-wrap gap-1">
88
+ {(['all', 0, 1, 2, 3] as TensorPick[]).map((p) => (
89
+ <button
90
+ key={String(p)}
91
+ type="button"
92
+ aria-pressed={pick === p}
93
+ onClick={() => setPick(p)}
94
+ className={`rounded border px-2 py-0.5 font-mono text-xs font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${
95
+ pick === p ? 'border-accent bg-accent-soft text-accent' : 'border-edge-strong bg-surface-overlay text-ink-secondary hover:text-ink-primary'
96
+ }`}
97
+ >
98
+ {p === 'all' ? 'W1 b1 W2 b2 combined' : tensors[p]}
99
+ </button>
100
+ ))}
101
+ </div>
102
+ <div role="group" aria-label="View" className="ml-auto flex rounded border border-edge-strong bg-surface-overlay p-0.5">
103
+ {(['flat', 'terrain'] as const).map((v) => (
104
+ <button
105
+ key={v}
106
+ type="button"
107
+ aria-pressed={view === v}
108
+ onClick={() => setView(v)}
109
+ className={`rounded px-2.5 py-0.5 text-xs font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${view === v ? 'bg-accent-soft text-accent' : 'text-ink-secondary hover:text-ink-primary'}`}
110
+ >
111
+ {v === 'flat' ? 'Map' : 'Terrain'}
112
+ </button>
113
+ ))}
114
+ </div>
115
+ </div>
116
+ <div ref={ref} className="min-w-0">
117
+ {width > 0 && view === 'flat' ? (
118
+ <svg
119
+ width={width}
120
+ height={ROW_FLAG + ROW_DECISION + 6 + mapH + 22}
121
+ onMouseMove={onMove}
122
+ onMouseLeave={() => setHover(null)}
123
+ role="img"
124
+ aria-label={`Proposed fast-weight change per layer and chunk, ${session.session_id} session, ${layers} layers by ${n} chunks, log color scale from ${num(scale.lo)} to ${num(scale.hi)}`}
125
+ shapeRendering="crispEdges"
126
+ >
127
+ <text x={LABEL_W - 6} y={ROW_FLAG - 3} textAnchor="end" fontSize={11} fill={OBS.inkMuted}>flag</text>
128
+ <text x={LABEL_W - 6} y={ROW_FLAG + ROW_DECISION - 3} textAnchor="end" fontSize={11} fill={OBS.inkMuted}>kept</text>
129
+ {session.chunks.map((c, i) => (
130
+ <g key={i}>
131
+ {c.flags.length ? <rect x={LABEL_W + i * cw} width={Math.max(1, cw - 0.5)} y={2} height={ROW_FLAG - 5} fill={OBS.flag} /> : null}
132
+ <rect x={LABEL_W + i * cw} y={ROW_FLAG + 2} width={Math.max(1, cw - 0.5)} height={ROW_DECISION - 5} fill={c.applied === 'rollback' ? OBS.rollbackFill : c.applied === 'commit' ? OBS.commitFill : OBS.notInForce} />
133
+ </g>
134
+ ))}
135
+ <g transform={`translate(0 ${ROW_FLAG + ROW_DECISION + 6})`}>
136
+ {grid.map((row, l) =>
137
+ row.map((v, i) => {
138
+ const t = scale.t(v);
139
+ return <rect key={`${l}-${i}`} x={LABEL_W + i * cw} y={(layers - 1 - l) * ch} width={Math.max(1, cw)} height={ch} fill={t === null ? OBS.inset : rampColor(t)} />;
140
+ })
141
+ )}
142
+ {turnStarts.map((x) => (
143
+ <line key={x} x1={LABEL_W + x * cw} x2={LABEL_W + x * cw} y1={0} y2={mapH} stroke={OBS.surface} strokeWidth={1} />
144
+ ))}
145
+ {hover ? <rect x={LABEL_W + hover.chunk * cw} y={(layers - 1 - hover.layer) * ch} width={Math.max(2, cw)} height={ch} fill="none" stroke={OBS.ink} strokeWidth={1.5} /> : null}
146
+ {[0, Math.floor(layers / 2), layers - 1].map((l) => (
147
+ <text key={l} x={LABEL_W - 6} y={(layers - 1 - l) * ch + ch - 1} textAnchor="end" fontSize={11} fill={OBS.inkMuted}>
148
+ layer {l}
149
+ </text>
150
+ ))}
151
+ <text x={LABEL_W} y={mapH + 15} fontSize={11} fill={OBS.inkMuted}>chunk 0</text>
152
+ <text x={LABEL_W + plotW} y={mapH + 15} textAnchor="end" fontSize={11} fill={OBS.inkMuted}>chunk {n - 1}</text>
153
+ <text x={LABEL_W + plotW / 2} y={mapH + 15} textAnchor="middle" fontSize={11} fill={OBS.inkMuted}>
154
+ {session.turns.length} turns, separated by thin gaps
155
+ </text>
156
+ </g>
157
+ </svg>
158
+ ) : null}
159
+ {width > 0 && view === 'terrain' ? <Terrain grid={grid} scale={scale} width={width} tilt={tilt} /> : null}
160
+ </div>
161
+ <div className="flex flex-wrap items-center gap-x-5 gap-y-2 text-xs text-ink-secondary">
162
+ <span className="flex items-center gap-2">
163
+ <span className="font-mono">{num(scale.lo)}</span>
164
+ <span className="inline-block h-2.5 w-28 rounded-sm" style={{ background: RAMP_CSS }} />
165
+ <span className="font-mono">{num(scale.hi)}</span>
166
+ <span className="text-ink-muted">proposed change norm, log scale</span>
167
+ </span>
168
+ {view === 'flat' ? (
169
+ <>
170
+ <span className="flex items-center gap-1.5"><span className="inline-block h-2.5 w-2.5 rounded-sm" style={{ background: OBS.flag }} /> intervention flagged</span>
171
+ <span className="flex items-center gap-1.5"><span className="inline-block h-2.5 w-2.5 rounded-sm" style={{ background: OBS.commitFill }} /> committed</span>
172
+ <span className="flex items-center gap-1.5"><span className="inline-block h-2.5 w-2.5 rounded-sm" style={{ background: OBS.rollbackFill }} /> rolled back</span>
173
+ </>
174
+ ) : (
175
+ <span className="text-ink-muted">height and color: the same log scale; layer 0 in front</span>
176
+ )}
177
+ {view === 'terrain' ? (
178
+ <label className="ml-auto flex items-center gap-2">
179
+ tilt
180
+ <input type="range" min={0.15} max={0.9} step={0.05} value={tilt} onChange={(e) => setTilt(Number(e.target.value))} aria-label="Terrain tilt" />
181
+ </label>
182
+ ) : null}
183
+ </div>
184
+ {view === 'flat' ? (
185
+ <div className="min-h-[3.25rem] rounded border border-edge bg-surface-inset px-3 py-2 text-sm" aria-live="polite">
186
+ {hover && cell ? (
187
+ <>
188
+ <div className="font-mono text-ink-primary">
189
+ turn {turn !== null ? turn + 1 : 'n/a'} · chunk {cell.i} ({cell.source} tokens) · layer {hover.layer} · {pick === 'all' ? 'combined' : tensors[pick]} {num(grid[hover.layer][hover.chunk])}
190
+ <span className="text-ink-secondary"> · chunk total {num(cell.proposed)} proposed, {num(cell.accepted)} kept · surprise {num(cell.surprise_mean)} · loss {num(cell.chunk_loss)}</span>
191
+ </div>
192
+ <div className="truncate text-ink-secondary">
193
+ {cell.flags.length ? <span className="text-status-scale">{cell.flags.join(', ')} · </span> : null}
194
+ {turnText ? `“${turnText.prompt}”` : ''}
195
+ </div>
196
+ </>
197
+ ) : (
198
+ <span className="text-ink-muted">Point at a cell to read its layer, chunk, turn and signals.</span>
199
+ )}
200
+ </div>
201
+ ) : null}
202
+ </div>
203
+ );
204
+ }
205
+
206
+ /** Secondary view: each layer as a ridge, stacked in depth. Labels stay upright; heights use the same log scale. */
207
+ function Terrain({ grid, scale, width, tilt }: { grid: (number | null)[][]; scale: ReturnType<typeof logScale>; width: number; tilt: number }) {
208
+ const layers = grid.length;
209
+ const n = grid[0]?.length ?? 0;
210
+ const gap = 4 + tilt * 10;
211
+ const skew = tilt * 3;
212
+ const amp = 46;
213
+ const plotW = width - LABEL_W - skew * layers;
214
+ const height = amp + gap * layers + 30;
215
+ const ridges = [];
216
+ for (let l = layers - 1; l >= 0; l--) {
217
+ const x0 = LABEL_W + l * skew;
218
+ const y0 = amp + (layers - 1 - l) * gap;
219
+ const pts = grid[l].map((v, i) => `${(x0 + (i / Math.max(1, n - 1)) * plotW).toFixed(1)},${(y0 - (scale.t(v) ?? 0) * amp).toFixed(1)}`);
220
+ const d = `M${x0},${y0} L${pts.join(' L')} L${x0 + plotW},${y0} Z`;
221
+ ridges.push(<path key={l} d={d} fill={OBS.surface} stroke={rampColor(0.35 + 0.65 * (l / Math.max(1, layers - 1)))} strokeWidth={1.25} strokeLinejoin="round" />);
222
+ }
223
+ return (
224
+ <svg width={width} height={height} role="img" aria-label={`Terrain: ${layers} layers as ridges over ${n} chunks, heights on the log scale`}>
225
+ {ridges}
226
+ {[0, Math.floor(layers / 2), layers - 1].map((l) => (
227
+ <text key={l} x={LABEL_W - 6} y={amp + (layers - 1 - l) * gap + 4} textAnchor="end" fontSize={11} fill={OBS.inkMuted}>
228
+ layer {l}
229
+ </text>
230
+ ))}
231
+ <text x={LABEL_W} y={height - 6} fontSize={11} fill={OBS.inkMuted}>chunk 0</text>
232
+ <text x={LABEL_W + plotW} y={height - 6} textAnchor="end" fontSize={11} fill={OBS.inkMuted}>chunk {n - 1}</text>
233
+ </svg>
234
+ );
235
+ }
236
+
237
+ export function SessionPicker({ trajectory, value, onChange }: { trajectory: Trajectory; value: string; onChange: (v: string) => void }) {
238
+ return (
239
+ <div className="flex flex-col gap-1">
240
+ <Label>Session</Label>
241
+ <div role="group" aria-label="Session" className="flex gap-1">
242
+ {trajectory.sessions.map((s) => (
243
+ <button
244
+ key={s.session_id}
245
+ type="button"
246
+ aria-pressed={value === s.session_id}
247
+ onClick={() => onChange(s.session_id)}
248
+ className={`rounded border px-2.5 py-1 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${
249
+ value === s.session_id ? 'border-accent bg-accent-soft text-accent' : 'border-edge-strong bg-surface-overlay text-ink-secondary hover:text-ink-primary'
250
+ }`}
251
+ >
252
+ {s.session_id === 'teach' ? 'Teaching' : s.session_id === 'rolled' ? 'Rolled back' : s.session_id}
253
+ </button>
254
+ ))}
255
+ </div>
256
+ </div>
257
+ );
258
+ }
dashboard/src/observatory/ObservatoryScreen.tsx CHANGED
@@ -5,10 +5,11 @@ import { AnatomyView } from './AnatomyView';
5
  import { loadIndex } from './data';
6
  import { RunsView } from './RunsView';
7
  import type { ObservatoryIndex } from './types';
 
8
 
9
- export const VIEWS = ['runs', 'anatomy'] as const;
10
  export type View = (typeof VIEWS)[number];
11
- const VIEW_LABEL: Record<View, string> = { runs: 'Runs', anatomy: 'Anatomy of a sleep' };
12
 
13
  export interface Route {
14
  view: View;
@@ -95,6 +96,8 @@ export function ObservatoryScreen() {
95
  </div>
96
  {route.view === 'anatomy' ? (
97
  <AnatomyView index={index} runId={runId} arm={route.arm} onSelect={(run, arm) => go({ run, arm })} />
 
 
98
  ) : (
99
  <RunsView index={index} runId={runId} arm={route.arm} onSelect={(run, arm) => go({ run, arm })} />
100
  )}
 
5
  import { loadIndex } from './data';
6
  import { RunsView } from './RunsView';
7
  import type { ObservatoryIndex } from './types';
8
+ import { WeightsView } from './WeightsView';
9
 
10
+ export const VIEWS = ['runs', 'anatomy', 'weights'] as const;
11
  export type View = (typeof VIEWS)[number];
12
+ const VIEW_LABEL: Record<View, string> = { runs: 'Runs', anatomy: 'Anatomy of a sleep', weights: 'Weights and changes' };
13
 
14
  export interface Route {
15
  view: View;
 
96
  </div>
97
  {route.view === 'anatomy' ? (
98
  <AnatomyView index={index} runId={runId} arm={route.arm} onSelect={(run, arm) => go({ run, arm })} />
99
+ ) : route.view === 'weights' ? (
100
+ <WeightsView index={index} runId={runId} arm={route.arm} onSelect={(run, arm) => go({ run, arm })} />
101
  ) : (
102
  <RunsView index={index} runId={runId} arm={route.arm} onSelect={(run, arm) => go({ run, arm })} />
103
  )}
dashboard/src/observatory/WeightsView.test.tsx ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @vitest-environment jsdom
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
4
+ import { clearObservatoryCache } from './data';
5
+ import { layerGrid } from './LayerMap';
6
+ import { ObservatoryScreen } from './ObservatoryScreen';
7
+ import { logScale } from './scale';
8
+ import { exportFetch, readExport } from './testData';
9
+ import type { Trajectory } from './types';
10
+
11
+ beforeEach(() => {
12
+ clearObservatoryCache();
13
+ vi.stubGlobal('fetch', vi.fn(exportFetch));
14
+ });
15
+ afterEach(() => {
16
+ cleanup();
17
+ vi.unstubAllGlobals();
18
+ });
19
+
20
+ describe('weights and changes', () => {
21
+ it('combines the four tensors of a layer in quadrature and keeps missing values missing', () => {
22
+ const t = readExport<Trajectory>('sessions/final_step250_seed0_exclude.json');
23
+ const teach = t.sessions[0];
24
+ const grid = layerGrid(teach, 24, 'all');
25
+ expect(grid.length).toBe(24);
26
+ expect(grid[0].length).toBe(165);
27
+ const v = teach.chunks[0].per_layer!;
28
+ expect(grid[0][0]).toBeCloseTo(Math.hypot(v[0]!, v[1]!, v[2]!, v[3]!), 6);
29
+ expect(layerGrid(teach, 24, 2)[5][10]).toBe(teach.chunks[10].per_layer![5 * 4 + 2]);
30
+ const missing = layerGrid({ ...teach, chunks: [{ ...teach.chunks[0], per_layer: null }] }, 24, 'all');
31
+ expect(missing[3][0]).toBeNull();
32
+ });
33
+
34
+ it('maps magnitudes on a log scale clipped to the central range', () => {
35
+ const s = logScale([null, 0, 0.001, 0.01, 0.1, 1, 10]);
36
+ expect(s.t(null)).toBeNull();
37
+ expect(s.t(0)).toBeNull(); // zero has no log position: drawn as "no value", not as the minimum
38
+ expect(s.t(s.lo)).toBe(0);
39
+ expect(s.t(s.hi)).toBe(1);
40
+ expect(s.t(1000)).toBe(1);
41
+ });
42
+
43
+ it('lists every consolidation attempt across runs and marks checks that were not in force', async () => {
44
+ window.history.replaceState(null, '', '/#sleep/weights');
45
+ render(<ObservatoryScreen />);
46
+ fireEvent.click(await screen.findByRole('button', { name: 'Across runs' }));
47
+ const table = (await screen.findByText('Every consolidation attempt')).closest('section')!;
48
+ const rows = within(table).getAllByRole('row').slice(1);
49
+ expect(rows.length).toBe(27);
50
+ expect(within(table).getAllByText('pulled back').length).toBe(4);
51
+ expect(within(table).getAllByText('not in force').length).toBeGreaterThan(5);
52
+ });
53
+
54
+ it('shows the per-layer map of the teaching session and the anchor’s W0 change', async () => {
55
+ window.history.replaceState(null, '', '/#sleep/weights/final_step250_seed0_exclude/anchor');
56
+ render(<ObservatoryScreen />);
57
+ expect(await screen.findByText('W0 change per tensor, child against parent')).toBeTruthy();
58
+ expect(screen.getByText('Anchor interpolates W0 directly; there are no gradient steps.')).toBeTruthy();
59
+ expect(await screen.findByRole('button', { name: 'Terrain' })).toBeTruthy();
60
+ });
61
+ });
dashboard/src/observatory/WeightsView.tsx ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useMemo, useState } from 'react';
2
+ import { Panel } from '../components/panels/Panel';
3
+ import { OBS } from '../components/charts/theme';
4
+ import { loadRun, loadTrajectory } from './data';
5
+ import { ARM_LABEL, isSleep, num, pct, ratio, signed } from './format';
6
+ import { LayerMap, SessionPicker, useWidth } from './LayerMap';
7
+ import { Label, OutcomeGlyph, useAsync } from './parts';
8
+ import { defaultRunId } from './RunsView';
9
+ import { logScale, rampColor, RAMP_CSS } from './scale';
10
+ import { Sparkline } from './Sparkline';
11
+ import type { DreamKept, GradientNorms, ObservatoryIndex, PerTensor, Run, SleepArm, Trajectory } from './types';
12
+
13
+ interface Props {
14
+ index: ObservatoryIndex;
15
+ runId: string | null;
16
+ arm: string | null;
17
+ onSelect: (run: string | null, arm: string | null) => void;
18
+ }
19
+
20
+ /** 4 tensors × N layers, colored on a log scale (shared when several grids are compared). */
21
+ export function PerTensorGrid({ data, scale, title }: { data: PerTensor; scale: ReturnType<typeof logScale>; title?: string }) {
22
+ const layers = data.values.length;
23
+ return (
24
+ <figure className="min-w-0">
25
+ {title ? <figcaption className="mb-1 font-mono text-xs text-ink-secondary">{title}</figcaption> : null}
26
+ <div className="grid grid-cols-[2rem_minmax(0,1fr)] items-center gap-x-2 gap-y-0.5">
27
+ {data.tensors.map((t, k) => (
28
+ <div key={t} className="contents">
29
+ <span className="text-right font-mono text-xs text-ink-muted">{t}</span>
30
+ <div className="grid gap-px" style={{ gridTemplateColumns: `repeat(${layers}, minmax(0, 1fr))` }}>
31
+ {data.values.map((row, l) => {
32
+ const v = row[k];
33
+ const tt = scale.t(v);
34
+ return <div key={l} className="h-4 rounded-[1px]" title={`layer ${l} ${t}: ${num(v, 4)}`} style={{ background: tt === null ? OBS.inset : rampColor(tt) }} />;
35
+ })}
36
+ </div>
37
+ </div>
38
+ ))}
39
+ <span />
40
+ <div className="flex justify-between font-mono text-micro text-ink-muted">
41
+ <span>layer 0</span>
42
+ <span>layer {layers - 1}</span>
43
+ </div>
44
+ </div>
45
+ </figure>
46
+ );
47
+ }
48
+
49
+ function ScaleLegend({ scale, label }: { scale: ReturnType<typeof logScale>; label: string }) {
50
+ return (
51
+ <div className="flex flex-wrap items-center gap-2 text-xs text-ink-secondary">
52
+ <span className="font-mono">{num(scale.lo, 4)}</span>
53
+ <span className="inline-block h-2.5 w-28 rounded-sm" style={{ background: RAMP_CSS }} />
54
+ <span className="font-mono">{num(scale.hi, 4)}</span>
55
+ <span className="text-ink-muted">{label}, log scale</span>
56
+ </div>
57
+ );
58
+ }
59
+
60
+ function GradGrid({ g }: { g: GradientNorms }) {
61
+ const scale = logScale(g.per_layer.flat());
62
+ const layers = g.per_layer.length;
63
+ return (
64
+ <div className="space-y-2">
65
+ <Sparkline values={g.total} label="gradient norm, total (before clipping)" />
66
+ <div className="grid gap-px" style={{ gridTemplateRows: `repeat(${layers}, 6px)`, gridTemplateColumns: `repeat(${g.steps.length}, minmax(0, 1fr))`, gridAutoFlow: 'column' }}>
67
+ {g.steps.map((_, s) =>
68
+ Array.from({ length: layers }, (_, i) => {
69
+ const l = layers - 1 - i;
70
+ const tt = scale.t(g.per_layer[l][s]);
71
+ return <div key={`${s}-${l}`} title={`step ${g.steps[s]} layer ${l}: ${num(g.per_layer[l][s], 4)}`} style={{ background: tt === null ? OBS.inset : rampColor(tt) }} />;
72
+ })
73
+ )}
74
+ </div>
75
+ <ScaleLegend scale={scale} label="per-layer gradient norm; rows are layers, top is the last layer" />
76
+ </div>
77
+ );
78
+ }
79
+
80
+ function DreamGains({ dream, index }: { dream: DreamKept; index: number }) {
81
+ const [ref, width] = useWidth<HTMLDivElement>();
82
+ const gains = dream.token_gain ?? [];
83
+ const max = Math.max(1e-6, ...gains.map((v) => Math.abs(v ?? 0)));
84
+ const h = 64;
85
+ const bw = gains.length ? width / gains.length : 0;
86
+ return (
87
+ <figure className="min-w-0">
88
+ <figcaption className="flex flex-wrap items-baseline justify-between gap-2 text-xs text-ink-secondary">
89
+ <span>
90
+ Dream {index + 1}: gain per reply token, teacher minus reset student
91
+ </span>
92
+ <span className="font-mono text-ink-muted">
93
+ mean {signed(dream.gain, 2)} nats/token · {gains.length} tokens
94
+ </span>
95
+ </figcaption>
96
+ <div ref={ref} className="mt-1">
97
+ {width > 0 && gains.length ? (
98
+ <svg width={width} height={h} role="img" aria-label={`Per-token gains for dream ${index + 1}: ${gains.length} tokens, largest magnitude ${num(max, 2)}`} shapeRendering="crispEdges">
99
+ <line x1={0} x2={width} y1={h / 2} y2={h / 2} stroke={OBS.edgeStrong} />
100
+ {gains.map((v, i) => {
101
+ const val = v ?? 0;
102
+ const bh = (Math.abs(val) / max) * (h / 2 - 2);
103
+ return <rect key={i} x={i * bw + 0.5} width={Math.max(1, bw - 1)} y={val >= 0 ? h / 2 - bh : h / 2} height={Math.max(val === 0 ? 0 : 1, bh)} fill={val >= 0 ? OBS.line : OBS.lineMuted} />;
104
+ })}
105
+ </svg>
106
+ ) : null}
107
+ </div>
108
+ <p className="mt-1 line-clamp-2 text-sm text-ink-primary">“{dream.text}”</p>
109
+ </figure>
110
+ );
111
+ }
112
+
113
+ function WithinOneSleep({ index, runId, arm, onSelect }: Props) {
114
+ const runs = index.runs.filter((r) => r.arms.some((a) => a.status !== null)).slice().reverse();
115
+ const id = runId && runs.some((r) => r.id === runId) ? runId : defaultRunId(index);
116
+ const entry = index.runs.find((r) => r.id === id);
117
+ const { data } = useAsync<{ run: Run; trajectory: Trajectory | null }>(
118
+ id ? async () => ({ run: await loadRun(id), trajectory: entry?.session_trajectory ? await loadTrajectory(id) : null }) : null,
119
+ [id]
120
+ );
121
+ const [session, setSession] = useState('teach');
122
+ const arms = (data?.run.arms.filter(isSleep) ?? []) as SleepArm[];
123
+ const chosen = arms.find((a) => a.arm === arm) ?? arms.find((a) => a.lineage.outcome === 'pulled back') ?? arms[0] ?? null;
124
+ const w0 = chosen?.w0_relative_update ?? chosen?.anchor_relative_update ?? null;
125
+ const w0Scale = useMemo(() => logScale(w0?.values.flat() ?? []), [w0]);
126
+
127
+ return (
128
+ <div className="space-y-4">
129
+ <div className="flex flex-wrap items-end gap-3 rounded-lg border border-edge bg-surface-raised px-4 py-3">
130
+ <label className="flex min-w-0 flex-col gap-1">
131
+ <Label>Run</Label>
132
+ <select
133
+ aria-label="Run"
134
+ value={id ?? ''}
135
+ onChange={(e) => onSelect(e.target.value, null)}
136
+ className="max-w-[22rem] rounded border border-edge-strong bg-surface-overlay px-2.5 py-1.5 font-mono text-sm text-ink-primary focus:border-accent focus:outline-none"
137
+ >
138
+ {runs.map((r) => (
139
+ <option key={r.id} value={r.id}>
140
+ {r.id}
141
+ </option>
142
+ ))}
143
+ </select>
144
+ </label>
145
+ {data?.trajectory ? <SessionPicker trajectory={data.trajectory} value={session} onChange={setSession} /> : null}
146
+ </div>
147
+
148
+ <Panel title="During the conversation" subtitle="proposed fast-weight change per layer, for every 16-token chunk of the session Sleep read">
149
+ {data?.trajectory ? (
150
+ <LayerMap trajectory={data.trajectory} session={session} />
151
+ ) : (
152
+ <p className="text-sm text-ink-muted">{data ? 'Session log not archived for this run.' : 'Loading…'}</p>
153
+ )}
154
+ </Panel>
155
+
156
+ <Panel title="During sleep" subtitle="what one consolidation arm did to the model">
157
+ <div role="group" aria-label="Arm" className="mb-4 flex flex-wrap gap-1">
158
+ {arms.map((a) => (
159
+ <button
160
+ key={a.arm}
161
+ type="button"
162
+ aria-pressed={chosen?.arm === a.arm}
163
+ onClick={() => onSelect(id, a.arm)}
164
+ className={`inline-flex items-center gap-1.5 rounded border px-2.5 py-1 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${
165
+ chosen?.arm === a.arm ? 'border-accent bg-accent-soft text-accent' : 'border-edge-strong bg-surface-overlay text-ink-secondary hover:text-ink-primary'
166
+ }`}
167
+ >
168
+ <OutcomeGlyph outcome={a.lineage.outcome === 'pulled back' ? 'pulled back' : 'committed'} size={12} />
169
+ {ARM_LABEL[a.arm]}
170
+ </button>
171
+ ))}
172
+ </div>
173
+ {chosen ? (
174
+ <div className="grid gap-6 xl:grid-cols-2">
175
+ <div className="space-y-2">
176
+ <Label>Training loss</Label>
177
+ {chosen.losses ? (
178
+ <Sparkline values={chosen.losses} label={chosen.loss_terms ?? 'loss'} />
179
+ ) : (
180
+ <p className="text-sm text-ink-secondary">{chosen.method === 'anchor' ? 'Anchor interpolates W0 directly; there are no gradient steps.' : 'Not recorded.'}</p>
181
+ )}
182
+ </div>
183
+ <div className="space-y-2">
184
+ <Label>Gradient norms by layer</Label>
185
+ {chosen.gradient_norms ? <GradGrid g={chosen.gradient_norms} /> : <p className="text-sm text-ink-secondary">{chosen.method === 'anchor' ? 'No gradient steps.' : 'Not recorded for this run.'}</p>}
186
+ </div>
187
+ <div className="space-y-2">
188
+ <Label>W0 change per tensor, child against parent</Label>
189
+ {w0 ? (
190
+ <>
191
+ <PerTensorGrid data={w0} scale={w0Scale} />
192
+ <ScaleLegend scale={w0Scale} label="‖ΔW0‖ / ‖W0‖" />
193
+ {w0.total != null ? <p className="font-mono text-xs text-ink-secondary">all tensors {num(w0.total, 4)}</p> : null}
194
+ </>
195
+ ) : (
196
+ <p className="text-sm text-ink-secondary">Not recorded for this run.</p>
197
+ )}
198
+ </div>
199
+ <div className="space-y-3">
200
+ <Label>Dreams kept for training</Label>
201
+ {chosen.dreams?.kept.length ? chosen.dreams.kept.slice(0, 3).map((d, i) => <DreamGains key={i} dream={d} index={i} />) : <p className="text-sm text-ink-secondary">{chosen.method === 'dream' ? 'No dream was kept.' : 'Not a Dream arm.'}</p>}
202
+ </div>
203
+ </div>
204
+ ) : null}
205
+ </Panel>
206
+ </div>
207
+ );
208
+ }
209
+
210
+ interface Row {
211
+ run: Run;
212
+ arm: SleepArm;
213
+ }
214
+
215
+ function Dot({ value, lo, hi, limit, tone }: { value: number | null; lo: number; hi: number; limit?: number | null; tone: string }) {
216
+ const x = (v: number) => `${((Math.min(hi, Math.max(lo, v)) - lo) / (hi - lo)) * 100}%`;
217
+ return (
218
+ <div className="relative h-5">
219
+ <div className="absolute inset-x-0 top-1/2 h-px bg-edge" />
220
+ {lo < 0 && hi > 0 ? <div className="absolute top-0.5 bottom-0.5 w-px bg-edge-strong" style={{ left: x(0) }} /> : null}
221
+ {limit != null ? <div className="absolute top-0 bottom-0 border-l-2 border-dashed border-ink-muted" style={{ left: x(limit) }} /> : null}
222
+ {value !== null ? <div className="absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2" style={{ left: x(value), background: tone, borderColor: OBS.surface }} /> : null}
223
+ </div>
224
+ );
225
+ }
226
+
227
+ function AcrossRuns({ index, onPick }: { index: ObservatoryIndex; onPick: (run: string, arm: string) => void }) {
228
+ const { data: runs } = useAsync(() => Promise.all(index.runs.map((r) => loadRun(r.id))), [index]);
229
+ const rows: Row[] = (runs ?? []).flatMap((run) => run.arms.filter(isSleep).map((arm) => ({ run, arm })));
230
+ const anchors = rows.filter((r) => r.arm.anchor_relative_update || r.arm.w0_relative_update);
231
+ const anchorScale = useMemo(() => logScale(anchors.flatMap((r) => (r.arm.w0_relative_update ?? r.arm.anchor_relative_update)!.values.flat())), [anchors]);
232
+ if (!runs) return <p className="text-sm text-ink-secondary">Loading runs…</p>;
233
+ const dNll = (a: SleepArm) => (a.heldout_nll.before?.mean != null && a.heldout_nll.after?.mean != null ? a.heldout_nll.after.mean - a.heldout_nll.before.mean : null);
234
+ return (
235
+ <div className="space-y-4">
236
+ <Panel title="Every consolidation attempt" subtitle="held-out loss and reply collapse after sleep, with the gate’s outcome">
237
+ <div className="overflow-x-auto">
238
+ <table className="w-full min-w-[760px] border-collapse text-sm">
239
+ <thead>
240
+ <tr className="border-b border-edge text-left text-label font-semibold uppercase tracking-wide text-ink-muted">
241
+ <th scope="col" className="px-2 py-1.5">Run · arm</th>
242
+ <th scope="col" className="w-[26%] px-2 py-1.5">Held-out NLL change</th>
243
+ <th scope="col" className="w-[26%] px-2 py-1.5">Same-reply share</th>
244
+ <th scope="col" className="px-2 py-1.5 text-right">Taught recalled</th>
245
+ <th scope="col" className="px-2 py-1.5">Outcome</th>
246
+ </tr>
247
+ </thead>
248
+ <tbody>
249
+ {rows.map(({ run, arm }) => {
250
+ const d = dNll(arm);
251
+ const shareCheck = arm.gate?.checks.find((c) => c.name === 'reply_cluster_share');
252
+ const share = shareCheck?.value ?? arm.recall.totals_after?.max_cluster_share ?? null;
253
+ const out = arm.lineage.outcome;
254
+ const shareTone = shareCheck && shareCheck.in_force ? (shareCheck.passed ? OBS.pass : OBS.fail) : OBS.notInForce;
255
+ const taught = arm.recall.after.by_group?.taught;
256
+ const nllLimit = arm.gate?.checks.find((c) => c.name === 'heldout_nll_mean_rise')?.limit ?? null;
257
+ return (
258
+ <tr key={`${run.id}-${arm.arm}`} className="cursor-pointer border-b border-edge hover:bg-surface-overlay" onClick={() => onPick(run.id, arm.arm)}>
259
+ <td className="px-2 py-1.5">
260
+ <button type="button" onClick={() => onPick(run.id, arm.arm)} className="text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-accent">
261
+ <span className="block font-mono text-xs text-ink-primary">{run.id}</span>
262
+ <span className="text-xs text-ink-secondary">{ARM_LABEL[arm.arm]}</span>
263
+ </button>
264
+ </td>
265
+ <td className="px-2 py-1.5">
266
+ <div className="grid grid-cols-[1fr_4.5rem] items-center gap-2">
267
+ <Dot value={d} lo={-0.5} hi={0.1} limit={nllLimit !== null && nllLimit <= 0.1 ? nllLimit : null} tone={OBS.line} />
268
+ <span className="text-right font-mono text-xs text-ink-primary">{signed(d)}</span>
269
+ </div>
270
+ </td>
271
+ <td className="px-2 py-1.5">
272
+ <div className="grid grid-cols-[1fr_6rem] items-center gap-2">
273
+ <Dot value={share} lo={0} hi={1} limit={0.25} tone={shareTone} />
274
+ <span className="text-right font-mono text-xs text-ink-primary">
275
+ {pct(share)}
276
+ {shareCheck && !shareCheck.in_force ? <span className="block text-micro font-normal text-ink-muted">not in force</span> : null}
277
+ </span>
278
+ </div>
279
+ </td>
280
+ <td className="px-2 py-1.5 text-right font-mono text-ink-primary">{taught ? ratio(taught) : arm.recall.totals_after ? `${arm.recall.totals_after.recalled}/${arm.recall.totals_after.n_probes} all` : 'n/a'}</td>
281
+ <td className="px-2 py-1.5">
282
+ <span className={`inline-flex items-center gap-1.5 whitespace-nowrap text-xs font-semibold ${out === 'committed' ? 'text-status-commit' : 'text-status-rollback'}`}>
283
+ <OutcomeGlyph outcome={out === 'committed' ? 'committed' : 'pulled back'} size={12} />
284
+ {out === 'committed' ? 'committed' : 'pulled back'}
285
+ </span>
286
+ </td>
287
+ </tr>
288
+ );
289
+ })}
290
+ </tbody>
291
+ </table>
292
+ </div>
293
+ <p className="mt-2 text-xs text-ink-muted">
294
+ NLL axis −0.5 to +0.1 nats/token with each run’s limit dashed; share axis 0 to 100% with the 25% limit dashed. Gray dots: the collapse check was not in force when the run executed.
295
+ </p>
296
+ </Panel>
297
+ {anchors.length ? (
298
+ <Panel title="W0 change by layer" subtitle="relative change of each initial fast-weight tensor, on one shared scale">
299
+ <div className="space-y-4">
300
+ {anchors.map(({ run, arm }) => (
301
+ <PerTensorGrid key={`${run.id}-${arm.arm}`} data={(arm.w0_relative_update ?? arm.anchor_relative_update)!} scale={anchorScale} title={`${run.id} · ${ARM_LABEL[arm.arm]}`} />
302
+ ))}
303
+ <ScaleLegend scale={anchorScale} label="‖ΔW0‖ / ‖W0‖" />
304
+ </div>
305
+ </Panel>
306
+ ) : null}
307
+ </div>
308
+ );
309
+ }
310
+
311
+ export function WeightsView(props: Props) {
312
+ const [scope, setScope] = useState<'within' | 'across'>('within');
313
+ return (
314
+ <div className="space-y-3">
315
+ <div role="group" aria-label="Scope" className="inline-flex rounded border border-edge-strong bg-surface-raised p-0.5">
316
+ {(['within', 'across'] as const).map((s) => (
317
+ <button
318
+ key={s}
319
+ type="button"
320
+ aria-pressed={scope === s}
321
+ onClick={() => setScope(s)}
322
+ className={`rounded px-3 py-1 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${scope === s ? 'bg-accent-soft text-accent' : 'text-ink-secondary hover:text-ink-primary'}`}
323
+ >
324
+ {s === 'within' ? 'Within one sleep' : 'Across runs'}
325
+ </button>
326
+ ))}
327
+ </div>
328
+ {scope === 'within' ? (
329
+ <WithinOneSleep {...props} />
330
+ ) : (
331
+ <AcrossRuns
332
+ index={props.index}
333
+ onPick={(run, arm) => {
334
+ setScope('within');
335
+ props.onSelect(run, arm);
336
+ }}
337
+ />
338
+ )}
339
+ </div>
340
+ );
341
+ }
dashboard/src/observatory/scale.ts ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The observatory's one sequential scale: log magnitude mapped onto OBS.ramp (a single hue, dark to light).
2
+ import { OBS } from '../components/charts/theme';
3
+
4
+ function channels(hex: string): [number, number, number] {
5
+ const h = hex.replace('#', '');
6
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16)) as [number, number, number];
7
+ }
8
+
9
+ const STOPS = OBS.ramp.map(channels);
10
+
11
+ /** t in [0, 1] to a color on the ramp. */
12
+ export function rampColor(t: number): string {
13
+ const x = Math.min(1, Math.max(0, t)) * (STOPS.length - 1);
14
+ const i = Math.min(STOPS.length - 2, Math.floor(x));
15
+ const f = x - i;
16
+ const c = STOPS[i].map((v, k) => Math.round(v + (STOPS[i + 1][k] - v) * f));
17
+ return '#' + c.map((v) => v.toString(16).padStart(2, '0')).join('');
18
+ }
19
+
20
+ export const RAMP_CSS = `linear-gradient(to right, ${OBS.ramp.join(', ')})`;
21
+
22
+ /** A log scale over the positive finite values, clipped at the 2nd and 98th percentiles so one outlier cannot wash out the rest. */
23
+ export function logScale(values: (number | null | undefined)[]): { lo: number; hi: number; t: (v: number | null | undefined) => number | null } {
24
+ const pos = values.filter((v): v is number => typeof v === 'number' && Number.isFinite(v) && v > 0).sort((a, b) => a - b);
25
+ if (!pos.length) return { lo: 0, hi: 0, t: () => null };
26
+ const q = (p: number) => pos[Math.min(pos.length - 1, Math.max(0, Math.round(p * (pos.length - 1))))];
27
+ const lo = q(0.02);
28
+ const hi = Math.max(q(0.98), lo * 1.0001);
29
+ const a = Math.log10(lo);
30
+ const b = Math.log10(hi);
31
+ return {
32
+ lo,
33
+ hi,
34
+ t: (v) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.min(1, Math.max(0, (Math.log10(v) - a) / (b - a))) : null),
35
+ };
36
+ }
dashboard/src/playground/App.tsx CHANGED
@@ -1,6 +1,5 @@
1
- import { useEffect } from 'react';
2
  import { Empty } from '../components/panels/Empty';
3
- import { ObservatoryScreen } from '../observatory/ObservatoryScreen';
4
  import { ChatScreen } from './chat/ChatScreen';
5
  import { Header } from './Header';
6
  import { SessionsScreen } from './sessions/SessionsScreen';
@@ -8,6 +7,9 @@ import { SignalsScreen } from './signals/SignalsScreen';
8
  import { TABS, useStore } from './store';
9
  import { Button, ErrorBanner } from './ui';
10
 
 
 
 
11
  function isTyping(target: EventTarget | null): boolean {
12
  if (!(target instanceof HTMLElement)) return false;
13
  return ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName) || target.isContentEditable;
@@ -64,7 +66,9 @@ export default function App() {
64
  </Empty>
65
  ) : (
66
  <div key={tab} className="tab-enter">
67
- <View />
 
 
68
  </div>
69
  )}
70
  </main>
 
1
+ import { lazy, Suspense, useEffect } from 'react';
2
  import { Empty } from '../components/panels/Empty';
 
3
  import { ChatScreen } from './chat/ChatScreen';
4
  import { Header } from './Header';
5
  import { SessionsScreen } from './sessions/SessionsScreen';
 
7
  import { TABS, useStore } from './store';
8
  import { Button, ErrorBanner } from './ui';
9
 
10
+ // the Sleep observatory is loaded on demand so the chat screens do not carry its code
11
+ const ObservatoryScreen = lazy(() => import('../observatory/ObservatoryScreen').then((m) => ({ default: m.ObservatoryScreen })));
12
+
13
  function isTyping(target: EventTarget | null): boolean {
14
  if (!(target instanceof HTMLElement)) return false;
15
  return ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName) || target.isContentEditable;
 
66
  </Empty>
67
  ) : (
68
  <div key={tab} className="tab-enter">
69
+ <Suspense fallback={<p className="py-8 text-sm text-ink-secondary">Loading…</p>}>
70
+ <View />
71
+ </Suspense>
72
  </div>
73
  )}
74
  </main>