Spaces:
Build error
Build error
Sync from GitHub via hub-sync
Browse files- dashboard/src/components/charts/theme.ts +23 -0
- dashboard/src/observatory/ObservatoryScreen.tsx +98 -0
- dashboard/src/observatory/RunsView.test.tsx +51 -0
- dashboard/src/observatory/RunsView.tsx +484 -0
- dashboard/src/observatory/data.test.ts +69 -0
- dashboard/src/observatory/data.ts +70 -0
- dashboard/src/observatory/format.ts +109 -0
- dashboard/src/observatory/legibility.test.ts +27 -0
- dashboard/src/observatory/parts.tsx +183 -0
- dashboard/src/observatory/testData.ts +21 -0
- dashboard/src/observatory/types.ts +290 -0
- dashboard/src/playground/App.tsx +5 -3
- dashboard/src/playground/store.ts +8 -3
- dashboard/tailwind.config.js +6 -0
dashboard/src/components/charts/theme.ts
CHANGED
|
@@ -16,6 +16,29 @@ export const CHART = {
|
|
| 16 |
reference: '#c792ea',
|
| 17 |
} as const;
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
export const SERIES_COLORS = ['#58a6ff', '#3fd17a', '#f0b429', '#c792ea', '#56d4dd'] as const;
|
| 20 |
|
| 21 |
export const tooltipContentStyle: CSSProperties = {
|
|
|
|
| 16 |
reference: '#c792ea',
|
| 17 |
} as const;
|
| 18 |
|
| 19 |
+
/**
|
| 20 |
+
* Sleep observatory: one sequential ramp (a single hue, dark to light) for every magnitude, so no chart needs a
|
| 21 |
+
* categorical palette; status hues stay reserved for decisions and gate outcomes; illustrative content has its own hue.
|
| 22 |
+
*/
|
| 23 |
+
export const OBS = {
|
| 24 |
+
ramp: ['#1c242e', '#1f4f8f', '#58a6ff', '#e9eff5'],
|
| 25 |
+
line: '#58a6ff',
|
| 26 |
+
lineMuted: '#94a3b4',
|
| 27 |
+
illustrative: '#c792ea',
|
| 28 |
+
illustrativeSoft: '#1b1626',
|
| 29 |
+
pass: '#3fd17a',
|
| 30 |
+
fail: '#ff6b6b',
|
| 31 |
+
notInForce: '#94a3b4',
|
| 32 |
+
flag: '#f0b429',
|
| 33 |
+
surface: '#151b23',
|
| 34 |
+
inset: '#090d12',
|
| 35 |
+
edge: '#2c3642',
|
| 36 |
+
edgeStrong: '#3d4a59',
|
| 37 |
+
ink: '#e9eff5',
|
| 38 |
+
inkSecondary: '#b8c4d0',
|
| 39 |
+
inkMuted: '#94a3b4',
|
| 40 |
+
} as const;
|
| 41 |
+
|
| 42 |
export const SERIES_COLORS = ['#58a6ff', '#3fd17a', '#f0b429', '#c792ea', '#56d4dd'] as const;
|
| 43 |
|
| 44 |
export const tooltipContentStyle: CSSProperties = {
|
dashboard/src/observatory/ObservatoryScreen.tsx
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useCallback, useEffect, useState } from 'react';
|
| 2 |
+
import { Empty } from '../components/panels/Empty';
|
| 3 |
+
import { Button } from '../playground/ui';
|
| 4 |
+
import { loadIndex } from './data';
|
| 5 |
+
import { RunsView } from './RunsView';
|
| 6 |
+
import type { ObservatoryIndex } from './types';
|
| 7 |
+
|
| 8 |
+
export const VIEWS = ['runs'] as const;
|
| 9 |
+
export type View = (typeof VIEWS)[number];
|
| 10 |
+
const VIEW_LABEL: Record<View, string> = { runs: 'Runs' };
|
| 11 |
+
|
| 12 |
+
export interface Route {
|
| 13 |
+
view: View;
|
| 14 |
+
run: string | null;
|
| 15 |
+
arm: string | null;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/** #sleep/<view>/<run>/<arm>: every screen state has a shareable link. */
|
| 19 |
+
export function parseRoute(hash: string): Route {
|
| 20 |
+
const [head, view, run, arm] = hash.replace(/^#/, '').split('/');
|
| 21 |
+
return {
|
| 22 |
+
view: head === 'sleep' && (VIEWS as readonly string[]).includes(view) ? (view as View) : 'runs',
|
| 23 |
+
run: run ? decodeURIComponent(run) : null,
|
| 24 |
+
arm: arm ? decodeURIComponent(arm) : null,
|
| 25 |
+
};
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
export function formatRoute(r: Route): string {
|
| 29 |
+
return ['#sleep', r.view, r.run, r.run ? r.arm : null].filter(Boolean).map((p, i) => (i === 0 ? p : encodeURIComponent(p as string))).join('/');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
export function ObservatoryScreen() {
|
| 33 |
+
const [index, setIndex] = useState<ObservatoryIndex | null>(null);
|
| 34 |
+
const [error, setError] = useState<string | null>(null);
|
| 35 |
+
const [route, setRoute] = useState<Route>(() => parseRoute(window.location.hash));
|
| 36 |
+
|
| 37 |
+
const load = useCallback(() => {
|
| 38 |
+
setError(null);
|
| 39 |
+
loadIndex().then(setIndex, (e: unknown) => setError(e instanceof Error ? e.message : String(e)));
|
| 40 |
+
}, []);
|
| 41 |
+
useEffect(load, [load]);
|
| 42 |
+
|
| 43 |
+
useEffect(() => {
|
| 44 |
+
const onHash = () => setRoute(parseRoute(window.location.hash));
|
| 45 |
+
window.addEventListener('hashchange', onHash);
|
| 46 |
+
return () => window.removeEventListener('hashchange', onHash);
|
| 47 |
+
}, []);
|
| 48 |
+
|
| 49 |
+
const go = useCallback((patch: Partial<Route>) => {
|
| 50 |
+
setRoute((prev) => {
|
| 51 |
+
const next = { ...prev, ...patch };
|
| 52 |
+
window.history.replaceState(null, '', formatRoute(next));
|
| 53 |
+
return next;
|
| 54 |
+
});
|
| 55 |
+
}, []);
|
| 56 |
+
|
| 57 |
+
if (error) {
|
| 58 |
+
return (
|
| 59 |
+
<Empty title="Sleep runs could not be loaded." detail={error}>
|
| 60 |
+
<Button onClick={load}>Retry</Button>
|
| 61 |
+
</Empty>
|
| 62 |
+
);
|
| 63 |
+
}
|
| 64 |
+
if (!index) return <p className="py-8 text-sm text-ink-secondary">Loading Sleep runs…</p>;
|
| 65 |
+
|
| 66 |
+
const runId = route.run && index.runs.some((r) => r.id === route.run) ? route.run : null;
|
| 67 |
+
|
| 68 |
+
return (
|
| 69 |
+
<div className="space-y-4">
|
| 70 |
+
<div className="flex flex-wrap items-end justify-between gap-3">
|
| 71 |
+
<div>
|
| 72 |
+
<h1 className="text-2xl font-bold tracking-tight text-ink-primary">Sleep</h1>
|
| 73 |
+
<p className="mt-1 max-w-3xl text-base text-ink-secondary">
|
| 74 |
+
Can what a model learns during a conversation become a lasting change to the model? Each run teaches facts in a session, consolidates the accepted learning into a candidate child model, then tests it from a fresh start.
|
| 75 |
+
</p>
|
| 76 |
+
</div>
|
| 77 |
+
{VIEWS.length > 1 ? (
|
| 78 |
+
<nav aria-label="Sleep views" className="flex rounded-lg border border-edge-strong bg-surface-raised p-1">
|
| 79 |
+
{VIEWS.map((v) => (
|
| 80 |
+
<button
|
| 81 |
+
key={v}
|
| 82 |
+
type="button"
|
| 83 |
+
aria-current={route.view === v ? 'page' : undefined}
|
| 84 |
+
onClick={() => go({ view: v })}
|
| 85 |
+
className={`rounded px-3 py-1.5 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${
|
| 86 |
+
route.view === v ? 'bg-accent-soft text-accent' : 'text-ink-secondary hover:text-ink-primary'
|
| 87 |
+
}`}
|
| 88 |
+
>
|
| 89 |
+
{VIEW_LABEL[v]}
|
| 90 |
+
</button>
|
| 91 |
+
))}
|
| 92 |
+
</nav>
|
| 93 |
+
) : null}
|
| 94 |
+
</div>
|
| 95 |
+
<RunsView index={index} runId={runId} arm={route.arm} onSelect={(run, arm) => go({ run, arm })} />
|
| 96 |
+
</div>
|
| 97 |
+
);
|
| 98 |
+
}
|
dashboard/src/observatory/RunsView.test.tsx
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @vitest-environment jsdom
|
| 2 |
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
| 3 |
+
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
| 4 |
+
import { clearObservatoryCache } from './data';
|
| 5 |
+
import { ObservatoryScreen } from './ObservatoryScreen';
|
| 6 |
+
import { exportFetch } from './testData';
|
| 7 |
+
|
| 8 |
+
beforeEach(() => {
|
| 9 |
+
clearObservatoryCache();
|
| 10 |
+
vi.stubGlobal('fetch', vi.fn(exportFetch));
|
| 11 |
+
window.history.replaceState(null, '', '/#sleep/runs');
|
| 12 |
+
});
|
| 13 |
+
afterEach(() => {
|
| 14 |
+
cleanup();
|
| 15 |
+
vi.unstubAllGlobals();
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
describe('Sleep observatory: runs', () => {
|
| 19 |
+
it('opens on the latest run with a pulled-back arm: no child, the failed check and its value', async () => {
|
| 20 |
+
render(<ObservatoryScreen />);
|
| 21 |
+
await screen.findByRole('heading', { name: 'final_step250_seed0_exclude' });
|
| 22 |
+
const armPanel = (await screen.findByText('locality gate failed')).closest('section')!;
|
| 23 |
+
expect(within(armPanel).getByText('no child')).toBeTruthy();
|
| 24 |
+
expect(within(armPanel).getByText(/Pulled back: the child was discarded/)).toBeTruthy();
|
| 25 |
+
expect(within(armPanel).getByRole('img', { name: /largest identical-reply share: value 0\.308, limit 0\.250, failed/ })).toBeTruthy();
|
| 26 |
+
expect(within(armPanel).getByText('selected')).toBeTruthy();
|
| 27 |
+
expect(screen.queryByText(/Illustrative/)).toBeNull(); // synthetic numbers never appear in the archive view
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
it('shows a later rule as not in force on a run that predates it, and keeps the recorded outcome', async () => {
|
| 31 |
+
render(<ObservatoryScreen />);
|
| 32 |
+
fireEvent.click(await screen.findByRole('button', { name: /sleep_controls_step100_all40/ }));
|
| 33 |
+
await screen.findByRole('heading', { name: 'sleep_controls_step100_all40' });
|
| 34 |
+
await waitFor(() => expect(window.location.hash).toBe('#sleep/runs/sleep_controls_step100_all40'));
|
| 35 |
+
const img = await screen.findByRole('img', { name: /largest identical-reply share: value 0\.467, limit 0\.250, not in force/ });
|
| 36 |
+
const armPanel = img.closest('section')!;
|
| 37 |
+
expect(within(armPanel).getAllByText('Committed').length).toBeGreaterThan(0);
|
| 38 |
+
expect(within(armPanel).getByText(/not published/)).toBeTruthy();
|
| 39 |
+
expect(within(armPanel).getByText('selection not recorded for this run')).toBeTruthy();
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
it('filters replies by group and to hits', async () => {
|
| 43 |
+
window.history.replaceState(null, '', '/#sleep/runs/final_step250_seed0_exclude/floor');
|
| 44 |
+
render(<ObservatoryScreen />);
|
| 45 |
+
await screen.findByRole('heading', { name: 'Floor' });
|
| 46 |
+
fireEvent.click(screen.getByRole('button', { name: 'General' }));
|
| 47 |
+
fireEvent.click(screen.getByLabelText('hits only'));
|
| 48 |
+
const rows = screen.getAllByText('hit');
|
| 49 |
+
expect(rows.length).toBe(6); // 3/7 verbatim + 3/7 unseen wording at the floor
|
| 50 |
+
});
|
| 51 |
+
});
|
dashboard/src/observatory/RunsView.tsx
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useMemo, useState } from 'react';
|
| 2 |
+
import { Panel } from '../components/panels/Panel';
|
| 3 |
+
import { loadRun } from './data';
|
| 4 |
+
import {
|
| 5 |
+
ARM_LABEL,
|
| 6 |
+
ARM_ROLE,
|
| 7 |
+
GROUP_LABEL,
|
| 8 |
+
GROUP_ORDER,
|
| 9 |
+
dateLabel,
|
| 10 |
+
hits,
|
| 11 |
+
isSleep,
|
| 12 |
+
methodLine,
|
| 13 |
+
num,
|
| 14 |
+
outcome,
|
| 15 |
+
pct,
|
| 16 |
+
ratio,
|
| 17 |
+
signed,
|
| 18 |
+
} from './format';
|
| 19 |
+
import { Big, Chip, GateCheckRow, Label, OutcomeBadge, OutcomeGlyph, TurnsBar, useAsync } from './parts';
|
| 20 |
+
import type { Arm, GroupName, IndexRun, ObservatoryIndex, ProbeRow, Run, SleepArm } from './types';
|
| 21 |
+
|
| 22 |
+
const REPO = 'https://github.com/DMontgomery40/plastic/blob/main/';
|
| 23 |
+
|
| 24 |
+
interface Props {
|
| 25 |
+
index: ObservatoryIndex;
|
| 26 |
+
runId: string | null;
|
| 27 |
+
arm: string | null;
|
| 28 |
+
onSelect: (run: string | null, arm: string | null) => void;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/** The run shown when none is chosen: the most recent run that consolidated anything. */
|
| 32 |
+
export function defaultRunId(index: ObservatoryIndex): string | null {
|
| 33 |
+
const withSleep = index.runs.filter((r) => r.arms.some((a) => a.status !== null));
|
| 34 |
+
return (withSleep[withSleep.length - 1] ?? index.runs[index.runs.length - 1])?.id ?? null;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/** The arm shown when none is chosen: a pulled-back arm if the run has one, else its first consolidation arm. */
|
| 38 |
+
export function defaultArm(run: Run): string | null {
|
| 39 |
+
const sleep = run.arms.filter(isSleep);
|
| 40 |
+
return (sleep.find((a) => a.lineage.outcome === 'pulled back') ?? sleep[0] ?? run.arms[0])?.arm ?? null;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function groupRuns(runs: IndexRun[]): { key: string; label: string; runs: IndexRun[] }[] {
|
| 44 |
+
const order: { key: string; label: string; test: (r: IndexRun) => boolean }[] = [
|
| 45 |
+
{ key: 'final', label: 'Final chat checkpoint', test: (r) => r.checkpoint.step === 250 },
|
| 46 |
+
{ key: 'step100', label: 'SFT step 100 (intermediate)', test: (r) => r.checkpoint.step === 100 },
|
| 47 |
+
{ key: 'step50', label: 'SFT step 50 (intermediate)', test: (r) => r.checkpoint.step === 50 },
|
| 48 |
+
{ key: 'base', label: 'Base model, not chat-tuned', test: (r) => r.checkpoint.step === null },
|
| 49 |
+
];
|
| 50 |
+
return order.map((g) => ({ key: g.key, label: g.label, runs: runs.filter(g.test).slice().reverse() })).filter((g) => g.runs.length);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function RunList({ index, active, onSelect }: { index: ObservatoryIndex; active: string | null; onSelect: (id: string) => void }) {
|
| 54 |
+
const groups = useMemo(() => groupRuns(index.runs), [index]);
|
| 55 |
+
return (
|
| 56 |
+
<nav aria-label="Archived runs" className="space-y-4">
|
| 57 |
+
{groups.map((g) => (
|
| 58 |
+
<section key={g.key}>
|
| 59 |
+
<Label>{g.label}</Label>
|
| 60 |
+
<ul className="mt-1.5 space-y-1">
|
| 61 |
+
{g.runs.map((r) => {
|
| 62 |
+
const sleepArms = r.arms.filter((a) => a.status !== null);
|
| 63 |
+
const selected = r.id === active;
|
| 64 |
+
return (
|
| 65 |
+
<li key={r.id}>
|
| 66 |
+
<button
|
| 67 |
+
type="button"
|
| 68 |
+
onClick={() => onSelect(r.id)}
|
| 69 |
+
aria-current={selected ? 'true' : undefined}
|
| 70 |
+
className={`w-full rounded border px-3 py-2 text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${
|
| 71 |
+
selected ? 'border-accent bg-accent-soft' : 'border-edge bg-surface-raised hover:border-edge-strong'
|
| 72 |
+
}`}
|
| 73 |
+
>
|
| 74 |
+
<div className={`truncate font-mono text-xs font-semibold ${selected ? 'text-accent' : 'text-ink-primary'}`}>{r.id}</div>
|
| 75 |
+
{r.summary ? <div className="mt-0.5 line-clamp-2 text-xs text-ink-secondary">{r.summary}</div> : null}
|
| 76 |
+
<div className="mt-1.5 flex flex-wrap gap-x-2.5 gap-y-1">
|
| 77 |
+
{sleepArms.length === 0 ? <span className="text-micro text-ink-muted">controls only</span> : null}
|
| 78 |
+
{sleepArms.map((a) => (
|
| 79 |
+
<span key={a.arm} className="inline-flex items-center gap-1 text-micro font-semibold text-ink-secondary" title={`${ARM_LABEL[a.arm]}: ${a.status}`}>
|
| 80 |
+
<OutcomeGlyph outcome={a.status === 'rejected' ? 'pulled back' : 'committed'} size={11} />
|
| 81 |
+
{a.arm}
|
| 82 |
+
</span>
|
| 83 |
+
))}
|
| 84 |
+
</div>
|
| 85 |
+
</button>
|
| 86 |
+
</li>
|
| 87 |
+
);
|
| 88 |
+
})}
|
| 89 |
+
</ul>
|
| 90 |
+
</section>
|
| 91 |
+
))}
|
| 92 |
+
</nav>
|
| 93 |
+
);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
function RunHeader({ run }: { run: Run }) {
|
| 97 |
+
const p = run.protocol;
|
| 98 |
+
const readme = run.id === 'base_dryrun' ? run.sources[0]?.file.replace(/[^/]+$/, 'README.md') : `${run.sources[0]?.file.replace(/[^/]+$/, '')}`;
|
| 99 |
+
return (
|
| 100 |
+
<div className="space-y-2">
|
| 101 |
+
<div className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
| 102 |
+
<h2 className="font-mono text-lg font-semibold text-ink-primary">{run.id}</h2>
|
| 103 |
+
<span className="text-xs text-ink-muted">{dateLabel(run.started_at_unix)}</span>
|
| 104 |
+
</div>
|
| 105 |
+
{run.summary ? <p className="text-base text-ink-secondary">{run.summary}</p> : null}
|
| 106 |
+
<div className="flex flex-wrap gap-1.5">
|
| 107 |
+
<Chip title={run.checkpoint.label}>{run.checkpoint.label}</Chip>
|
| 108 |
+
{run.checkpoint.digest_prefix ? <Chip title="checkpoint digest (sha256 prefix)">{run.checkpoint.digest_prefix}</Chip> : null}
|
| 109 |
+
<Chip title={run.code.archive_readme ?? undefined}>code {run.code.recorded_at_launch ?? 'unrecorded'}</Chip>
|
| 110 |
+
{p.facts !== null ? <Chip>{p.facts} facts{p.poison ? ' + planted' : ''}</Chip> : null}
|
| 111 |
+
{p.steps !== null ? <Chip>{p.target === 'w0' ? 'W0' : p.target} × {p.steps} steps</Chip> : null}
|
| 112 |
+
{p.lr !== null ? <Chip>lr {p.lr}</Chip> : null}
|
| 113 |
+
{p.flagged_policy ? <Chip title="rule for harness-accepted turns that carried an intervention flag">flagged turns: {p.flagged_policy}</Chip> : null}
|
| 114 |
+
{p.ceiling_mode ? <Chip>ceiling: {p.ceiling_mode === 'single' ? 'one fact at a time' : 'all facts'}</Chip> : null}
|
| 115 |
+
{p.augment && p.augment !== 'none' ? <Chip>teaching: {p.augment} set</Chip> : null}
|
| 116 |
+
</div>
|
| 117 |
+
<p className="text-xs text-ink-muted">
|
| 118 |
+
<a className="text-accent hover:text-accent-hover" href={REPO + readme} target="_blank" rel="noreferrer">
|
| 119 |
+
Archived files
|
| 120 |
+
</a>
|
| 121 |
+
{' · '}
|
| 122 |
+
<a className="text-accent hover:text-accent-hover" href={REPO + 'docs/research/2026-09-23-sleep-consolidation.md'} target="_blank" rel="noreferrer">
|
| 123 |
+
Method and readings
|
| 124 |
+
</a>
|
| 125 |
+
</p>
|
| 126 |
+
</div>
|
| 127 |
+
);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
function RecallCell({ c, variant }: { c: Parameters<typeof ratio>[0]; variant?: 'verbatim' | 'paraphrase' }) {
|
| 131 |
+
const text = ratio(c, variant);
|
| 132 |
+
const lit = hits(c, variant) > 0;
|
| 133 |
+
return <td className={`px-2 py-2 text-right font-mono ${text === 'n/a' ? 'text-ink-muted' : lit ? 'font-semibold text-ink-primary' : 'text-ink-secondary'}`}>{text}</td>;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
function ArmMatrix({ run, active, onSelect }: { run: Run; active: string | null; onSelect: (arm: string) => void }) {
|
| 137 |
+
const groups = GROUP_ORDER.filter((g) => run.arms.some((a) => a.recall.after.by_group?.[g]));
|
| 138 |
+
const recounted = run.arms.some((a) => a.recall.after.source === 'recounted');
|
| 139 |
+
const hasTotalsOnly = groups.length === 0;
|
| 140 |
+
return (
|
| 141 |
+
<div>
|
| 142 |
+
<div className="overflow-x-auto">
|
| 143 |
+
<table className="w-full min-w-[720px] border-collapse text-sm">
|
| 144 |
+
<caption className="sr-only">Recall after a reset, locality and outcome per arm</caption>
|
| 145 |
+
<thead>
|
| 146 |
+
<tr className="border-b border-edge text-left">
|
| 147 |
+
<th scope="col" className="px-2 py-2 text-label font-semibold uppercase tracking-wide text-ink-muted">Arm</th>
|
| 148 |
+
{hasTotalsOnly ? (
|
| 149 |
+
<th scope="col" className="px-2 py-2 text-right text-label font-semibold uppercase tracking-wide text-ink-muted">Recall</th>
|
| 150 |
+
) : (
|
| 151 |
+
groups.map((g) => (
|
| 152 |
+
<th key={g} scope="col" className="px-2 py-2 text-right text-label font-semibold uppercase tracking-wide text-ink-muted">
|
| 153 |
+
{GROUP_LABEL[g]}
|
| 154 |
+
</th>
|
| 155 |
+
))
|
| 156 |
+
)}
|
| 157 |
+
{groups.includes('taught') ? <th scope="col" className="px-2 py-2 text-right text-label font-semibold uppercase tracking-wide text-ink-muted">Taught, unseen wording</th> : null}
|
| 158 |
+
<th scope="col" className="px-2 py-2 text-right text-label font-semibold uppercase tracking-wide text-ink-muted">Held-out NLL</th>
|
| 159 |
+
<th scope="col" className="px-2 py-2 text-right text-label font-semibold uppercase tracking-wide text-ink-muted">Same-reply share</th>
|
| 160 |
+
<th scope="col" className="px-2 py-2 text-label font-semibold uppercase tracking-wide text-ink-muted">Outcome</th>
|
| 161 |
+
</tr>
|
| 162 |
+
</thead>
|
| 163 |
+
<tbody>
|
| 164 |
+
{run.arms.map((a) => {
|
| 165 |
+
const g = a.recall.after.by_group ?? {};
|
| 166 |
+
const selected = a.arm === active;
|
| 167 |
+
const share = isSleep(a) ? a.gate?.checks.find((c) => c.name === 'reply_cluster_share')?.value ?? a.recall.totals_after?.max_cluster_share ?? null : a.max_cluster_share.value;
|
| 168 |
+
const nll = isSleep(a) ? a.heldout_nll : null;
|
| 169 |
+
return (
|
| 170 |
+
<tr
|
| 171 |
+
key={a.arm}
|
| 172 |
+
onClick={() => onSelect(a.arm)}
|
| 173 |
+
className={`cursor-pointer border-b border-edge ${selected ? 'bg-accent-soft' : 'hover:bg-surface-overlay'}`}
|
| 174 |
+
>
|
| 175 |
+
<th scope="row" className="px-2 py-2 text-left">
|
| 176 |
+
<button type="button" onClick={() => onSelect(a.arm)} aria-pressed={selected} className="text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-accent">
|
| 177 |
+
<span className={`block font-semibold ${selected ? 'text-accent' : 'text-ink-primary'}`}>{ARM_LABEL[a.arm]}</span>
|
| 178 |
+
<span className="block text-micro font-normal text-ink-muted">{ARM_ROLE[a.arm]}</span>
|
| 179 |
+
</button>
|
| 180 |
+
</th>
|
| 181 |
+
{hasTotalsOnly ? (
|
| 182 |
+
<td className="px-2 py-2 text-right font-mono text-ink-secondary">
|
| 183 |
+
{isSleep(a) && a.recall.totals_after ? `${a.recall.totals_after.recalled}/${a.recall.totals_after.n_probes}` : 'n/a'}
|
| 184 |
+
</td>
|
| 185 |
+
) : (
|
| 186 |
+
groups.map((grp) => <RecallCell key={grp} c={g[grp]} />)
|
| 187 |
+
)}
|
| 188 |
+
{groups.includes('taught') ? <RecallCell c={g.taught} variant="paraphrase" /> : null}
|
| 189 |
+
<td className="whitespace-nowrap px-2 py-2 text-right font-mono text-ink-secondary">
|
| 190 |
+
{nll?.before?.mean != null ? (
|
| 191 |
+
<>
|
| 192 |
+
{num(nll.before.mean)} <span className="text-ink-muted">→</span> <span className="text-ink-primary">{num(nll.after?.mean)}</span>
|
| 193 |
+
</>
|
| 194 |
+
) : (
|
| 195 |
+
<span className="text-ink-muted">n/a</span>
|
| 196 |
+
)}
|
| 197 |
+
</td>
|
| 198 |
+
<td className="px-2 py-2 text-right font-mono text-ink-secondary">{pct(share)}</td>
|
| 199 |
+
<td className="px-2 py-2">
|
| 200 |
+
<OutcomeBadge outcome={outcome(a)} label={isSleep(a) ? undefined : a.arm === 'floor' ? 'Baseline' : 'In context'} />
|
| 201 |
+
</td>
|
| 202 |
+
</tr>
|
| 203 |
+
);
|
| 204 |
+
})}
|
| 205 |
+
</tbody>
|
| 206 |
+
</table>
|
| 207 |
+
</div>
|
| 208 |
+
<p className="mt-2 text-xs text-ink-muted">
|
| 209 |
+
Recall in a fresh session after consolidation; hits over probes.{recounted ? ' Counts recounted from saved replies.' : ''}
|
| 210 |
+
</p>
|
| 211 |
+
</div>
|
| 212 |
+
);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
function ProbeTable({ probes }: { probes: ProbeRow[] }) {
|
| 216 |
+
const present = GROUP_ORDER.filter((g) => probes.some((p) => p.group === g));
|
| 217 |
+
const [group, setGroup] = useState<GroupName | 'all'>(present.includes('taught') ? 'taught' : 'all');
|
| 218 |
+
const [onlyHits, setOnlyHits] = useState(false);
|
| 219 |
+
const [expanded, setExpanded] = useState(false);
|
| 220 |
+
const rows = probes.filter((p) => (group === 'all' || p.group === group) && (!onlyHits || p.hit));
|
| 221 |
+
const shown = expanded ? rows : rows.slice(0, 12);
|
| 222 |
+
return (
|
| 223 |
+
<div>
|
| 224 |
+
<div className="flex flex-wrap items-center gap-2">
|
| 225 |
+
<Label>Replies</Label>
|
| 226 |
+
<div className="flex flex-wrap gap-1" role="group" aria-label="Probe group">
|
| 227 |
+
{(['all', ...present] as const).map((g) => (
|
| 228 |
+
<button
|
| 229 |
+
key={g}
|
| 230 |
+
type="button"
|
| 231 |
+
aria-pressed={group === g}
|
| 232 |
+
onClick={() => setGroup(g)}
|
| 233 |
+
className={`rounded border px-2 py-0.5 text-xs font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${
|
| 234 |
+
group === g ? 'border-accent bg-accent-soft text-accent' : 'border-edge-strong bg-surface-overlay text-ink-secondary hover:text-ink-primary'
|
| 235 |
+
}`}
|
| 236 |
+
>
|
| 237 |
+
{g === 'all' ? 'All' : GROUP_LABEL[g]}
|
| 238 |
+
</button>
|
| 239 |
+
))}
|
| 240 |
+
</div>
|
| 241 |
+
<label className="ml-auto flex items-center gap-2 text-xs text-ink-secondary">
|
| 242 |
+
<input type="checkbox" checked={onlyHits} onChange={(e) => setOnlyHits(e.target.checked)} />
|
| 243 |
+
hits only
|
| 244 |
+
</label>
|
| 245 |
+
</div>
|
| 246 |
+
<div className="mt-2 overflow-x-auto">
|
| 247 |
+
<table className="w-full min-w-[720px] border-collapse text-sm">
|
| 248 |
+
<thead>
|
| 249 |
+
<tr className="border-b border-edge text-left text-label font-semibold uppercase tracking-wide text-ink-muted">
|
| 250 |
+
<th scope="col" className="px-2 py-1.5">Question</th>
|
| 251 |
+
<th scope="col" className="px-2 py-1.5">Expected</th>
|
| 252 |
+
<th scope="col" className="px-2 py-1.5">Reply</th>
|
| 253 |
+
<th scope="col" className="px-2 py-1.5 text-right">Hit</th>
|
| 254 |
+
</tr>
|
| 255 |
+
</thead>
|
| 256 |
+
<tbody>
|
| 257 |
+
{shown.map((p, i) => (
|
| 258 |
+
<tr key={`${p.question}-${p.variant}-${i}`} className="border-b border-edge align-top">
|
| 259 |
+
<td className="px-2 py-1.5 text-ink-secondary">
|
| 260 |
+
{p.question}
|
| 261 |
+
<span className="ml-1.5 text-micro text-ink-muted">{p.variant === 'paraphrase' ? 'unseen wording' : ''}</span>
|
| 262 |
+
</td>
|
| 263 |
+
<td className="px-2 py-1.5 font-mono text-ink-primary">{p.expected}</td>
|
| 264 |
+
<td className="px-2 py-1.5 text-ink-primary">
|
| 265 |
+
{p.reply}
|
| 266 |
+
{p.reply_truncated ? '…' : ''}
|
| 267 |
+
</td>
|
| 268 |
+
<td className={`px-2 py-1.5 text-right text-xs font-semibold ${p.hit ? 'text-status-commit' : 'text-ink-muted'}`}>{p.hit ? 'hit' : 'miss'}</td>
|
| 269 |
+
</tr>
|
| 270 |
+
))}
|
| 271 |
+
{shown.length === 0 ? (
|
| 272 |
+
<tr>
|
| 273 |
+
<td colSpan={4} className="px-2 py-3 text-sm text-ink-secondary">
|
| 274 |
+
No replies match.
|
| 275 |
+
</td>
|
| 276 |
+
</tr>
|
| 277 |
+
) : null}
|
| 278 |
+
</tbody>
|
| 279 |
+
</table>
|
| 280 |
+
</div>
|
| 281 |
+
{rows.length > 12 ? (
|
| 282 |
+
<button type="button" onClick={() => setExpanded(!expanded)} className="mt-2 text-sm font-semibold text-accent hover:text-accent-hover">
|
| 283 |
+
{expanded ? 'Show fewer' : `Show all ${rows.length}`}
|
| 284 |
+
</button>
|
| 285 |
+
) : null}
|
| 286 |
+
</div>
|
| 287 |
+
);
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
function Lineage({ run, arm }: { run: Run; arm: SleepArm }) {
|
| 291 |
+
const out = arm.lineage.outcome;
|
| 292 |
+
return (
|
| 293 |
+
<div className="flex flex-wrap items-center gap-2 text-sm">
|
| 294 |
+
<span className="rounded border border-edge-strong bg-surface-overlay px-2.5 py-1 font-mono text-ink-primary">{arm.lineage.parent ?? 'parent'}</span>
|
| 295 |
+
<span className="text-ink-muted" aria-hidden="true">
|
| 296 |
+
──
|
| 297 |
+
</span>
|
| 298 |
+
<span className="rounded border border-edge bg-surface-inset px-2.5 py-1 text-ink-secondary">
|
| 299 |
+
{arm.method} · {methodLine(arm)}
|
| 300 |
+
</span>
|
| 301 |
+
<span className="text-ink-muted" aria-hidden="true">
|
| 302 |
+
──
|
| 303 |
+
</span>
|
| 304 |
+
{out === 'committed' ? (
|
| 305 |
+
<span className="rounded border border-status-commit bg-surface-overlay px-2.5 py-1 font-mono text-ink-primary">child {arm.lineage.child}</span>
|
| 306 |
+
) : (
|
| 307 |
+
<span className="rounded border border-dashed border-status-rollback bg-surface-overlay px-2.5 py-1 text-ink-primary">no child</span>
|
| 308 |
+
)}
|
| 309 |
+
<span className="basis-full text-xs text-ink-muted">
|
| 310 |
+
{out === 'committed' ? 'Registered in the run’s experiment store; not published.' : 'Pulled back: the child was discarded and the parent is unchanged.'}
|
| 311 |
+
{run.checkpoint.digest_prefix ? ` Parent checkpoint ${run.checkpoint.digest_prefix}.` : ''}
|
| 312 |
+
</span>
|
| 313 |
+
</div>
|
| 314 |
+
);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
function SleepArmDetail({ run, arm }: { run: Run; arm: SleepArm }) {
|
| 318 |
+
const before = arm.heldout_nll.before;
|
| 319 |
+
const after = arm.heldout_nll.after;
|
| 320 |
+
const tb = arm.recall.totals_before;
|
| 321 |
+
const ta = arm.recall.totals_after;
|
| 322 |
+
const taughtBefore = arm.recall.before.by_group?.taught;
|
| 323 |
+
const taughtAfter = arm.recall.after.by_group?.taught;
|
| 324 |
+
return (
|
| 325 |
+
<div className="space-y-5">
|
| 326 |
+
<div className="flex flex-wrap items-center gap-3">
|
| 327 |
+
<h3 className="text-lg font-semibold text-ink-primary">{ARM_LABEL[arm.arm]}</h3>
|
| 328 |
+
<OutcomeBadge outcome={outcome(arm)} />
|
| 329 |
+
{arm.reason ? <span className="text-sm text-ink-secondary">{arm.reason}</span> : null}
|
| 330 |
+
</div>
|
| 331 |
+
<Lineage run={run} arm={arm} />
|
| 332 |
+
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
| 333 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 334 |
+
<Label>Taught facts recalled</Label>
|
| 335 |
+
<Big>
|
| 336 |
+
{taughtAfter ? `${ratio(taughtBefore)} → ${ratio(taughtAfter)}` : tb && ta ? `${tb.recalled}/${tb.n_probes} → ${ta.recalled}/${ta.n_probes}` : 'n/a'}
|
| 337 |
+
</Big>
|
| 338 |
+
<div className="text-micro text-ink-muted">{taughtAfter ? 'fresh session, before → after' : 'all probes, fresh session, before → after'}</div>
|
| 339 |
+
</div>
|
| 340 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 341 |
+
<Label>Held-out NLL (nats/token)</Label>
|
| 342 |
+
<Big>
|
| 343 |
+
{num(before?.mean)} → {num(after?.mean)}
|
| 344 |
+
</Big>
|
| 345 |
+
<div className="text-micro text-ink-muted">change {signed(before?.mean != null && after?.mean != null ? after.mean - before.mean : null)} · {before?.tokens ?? 'n/a'} tokens</div>
|
| 346 |
+
</div>
|
| 347 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 348 |
+
<Label>Expected-answer log-prob</Label>
|
| 349 |
+
<Big>
|
| 350 |
+
{num(tb?.mean_answer_logprob, 2)} → {num(ta?.mean_answer_logprob, 2)}
|
| 351 |
+
</Big>
|
| 352 |
+
<div className="text-micro text-ink-muted">mean per token, verbatim probes</div>
|
| 353 |
+
</div>
|
| 354 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 355 |
+
<Label>Same-reply share</Label>
|
| 356 |
+
<Big>
|
| 357 |
+
{pct(tb?.max_cluster_share)} → {pct(ta?.max_cluster_share)}
|
| 358 |
+
</Big>
|
| 359 |
+
<div className="text-micro text-ink-muted">largest group of identical replies</div>
|
| 360 |
+
</div>
|
| 361 |
+
</div>
|
| 362 |
+
{arm.gate ? (
|
| 363 |
+
<div>
|
| 364 |
+
<Label>Locality gate</Label>
|
| 365 |
+
<ul className="mt-2 space-y-2">
|
| 366 |
+
{arm.gate.checks.map((c) => (
|
| 367 |
+
<GateCheckRow key={c.name} check={c} />
|
| 368 |
+
))}
|
| 369 |
+
</ul>
|
| 370 |
+
</div>
|
| 371 |
+
) : null}
|
| 372 |
+
{arm.harvest ? (
|
| 373 |
+
<div>
|
| 374 |
+
<Label>Turns this arm trained on</Label>
|
| 375 |
+
<div className="mt-2">
|
| 376 |
+
<TurnsBar harvest={arm.harvest} />
|
| 377 |
+
</div>
|
| 378 |
+
</div>
|
| 379 |
+
) : null}
|
| 380 |
+
{arm.dreams ? (
|
| 381 |
+
<div>
|
| 382 |
+
<Label>Dreams</Label>
|
| 383 |
+
<p className="mt-1 text-sm text-ink-secondary">
|
| 384 |
+
<span className="font-mono font-semibold text-ink-primary">{arm.dreams.generated ?? 'n/a'}</span> generated,{' '}
|
| 385 |
+
<span className="font-mono font-semibold text-ink-primary">{arm.dreams.kept_count}</span> kept
|
| 386 |
+
{Object.entries(arm.dreams.rejected_reasons).map(([k, v]) => `, ${v} removed as ${k}`).join('')}
|
| 387 |
+
</p>
|
| 388 |
+
{arm.dreams.kept.slice(0, 2).map((d, i) => (
|
| 389 |
+
<blockquote key={i} className="mt-2 rounded border border-edge bg-surface-inset px-3 py-2 text-sm text-ink-primary">
|
| 390 |
+
{d.text}
|
| 391 |
+
<footer className="mt-1 font-mono text-xs text-ink-muted">
|
| 392 |
+
gain {signed(d.gain, 2)} · no-quote session score {signed(d.fastweight_gain, 2)} nats/token
|
| 393 |
+
</footer>
|
| 394 |
+
</blockquote>
|
| 395 |
+
))}
|
| 396 |
+
</div>
|
| 397 |
+
) : null}
|
| 398 |
+
<ProbeTable probes={arm.probes} />
|
| 399 |
+
</div>
|
| 400 |
+
);
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
function ControlArmDetail({ arm }: { arm: Arm }) {
|
| 404 |
+
if (isSleep(arm)) return null;
|
| 405 |
+
return (
|
| 406 |
+
<div className="space-y-4">
|
| 407 |
+
<div className="flex flex-wrap items-center gap-3">
|
| 408 |
+
<h3 className="text-lg font-semibold text-ink-primary">{ARM_LABEL[arm.arm]}</h3>
|
| 409 |
+
<span className="text-sm text-ink-secondary">{ARM_ROLE[arm.arm]}</span>
|
| 410 |
+
</div>
|
| 411 |
+
<div className="grid gap-3 sm:grid-cols-3">
|
| 412 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 413 |
+
<Label>Taught facts recalled</Label>
|
| 414 |
+
<Big>{ratio(arm.recall.after.by_group?.taught)}</Big>
|
| 415 |
+
<div className="text-micro text-ink-muted">unseen wording {ratio(arm.recall.after.by_group?.taught, 'paraphrase')}</div>
|
| 416 |
+
</div>
|
| 417 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 418 |
+
<Label>Expected-answer log-prob</Label>
|
| 419 |
+
<Big>{num(arm.mean_answer_logprob, 2)}</Big>
|
| 420 |
+
<div className="text-micro text-ink-muted">mean per token, verbatim probes</div>
|
| 421 |
+
</div>
|
| 422 |
+
<div className="rounded border border-edge bg-surface-overlay px-3 py-2.5">
|
| 423 |
+
<Label>Same-reply share</Label>
|
| 424 |
+
<Big>{pct(arm.max_cluster_share.value)}</Big>
|
| 425 |
+
<div className="text-micro text-ink-muted">{arm.max_cluster_share.source}</div>
|
| 426 |
+
</div>
|
| 427 |
+
</div>
|
| 428 |
+
<ProbeTable probes={arm.probes} />
|
| 429 |
+
</div>
|
| 430 |
+
);
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
export function RunsView({ index, runId, arm, onSelect }: Props) {
|
| 434 |
+
const id = runId ?? defaultRunId(index);
|
| 435 |
+
const { data: run, error } = useAsync(id ? () => loadRun(id) : null, [id]);
|
| 436 |
+
const activeArm = run ? (arm && run.arms.some((a) => a.arm === arm) ? arm : defaultArm(run)) : null;
|
| 437 |
+
const selected = run?.arms.find((a) => a.arm === activeArm) ?? null;
|
| 438 |
+
const sleepArms = index.runs.flatMap((r) => r.arms.filter((a) => a.status !== null));
|
| 439 |
+
const committed = sleepArms.filter((a) => a.status !== 'rejected').length;
|
| 440 |
+
return (
|
| 441 |
+
<div className="space-y-4">
|
| 442 |
+
<div className="grid gap-3 sm:grid-cols-4">
|
| 443 |
+
<div className="rounded-lg border border-edge bg-surface-raised px-4 py-3">
|
| 444 |
+
<Label>Archived runs</Label>
|
| 445 |
+
<Big>{index.runs.length}</Big>
|
| 446 |
+
</div>
|
| 447 |
+
<div className="rounded-lg border border-edge bg-surface-raised px-4 py-3">
|
| 448 |
+
<Label>Consolidation attempts</Label>
|
| 449 |
+
<Big>{sleepArms.length}</Big>
|
| 450 |
+
</div>
|
| 451 |
+
<div className="rounded-lg border border-edge bg-surface-raised px-4 py-3">
|
| 452 |
+
<Label>Committed a child</Label>
|
| 453 |
+
<Big tone="pass">{committed}</Big>
|
| 454 |
+
</div>
|
| 455 |
+
<div className="rounded-lg border border-edge bg-surface-raised px-4 py-3">
|
| 456 |
+
<Label>Pulled back by the gate</Label>
|
| 457 |
+
<Big tone="fail">{sleepArms.length - committed}</Big>
|
| 458 |
+
</div>
|
| 459 |
+
</div>
|
| 460 |
+
<div className="grid gap-4 lg:grid-cols-[300px_minmax(0,1fr)]">
|
| 461 |
+
<RunList index={index} active={id} onSelect={(r) => onSelect(r, null)} />
|
| 462 |
+
<div className="min-w-0 space-y-4">
|
| 463 |
+
{error ? <p className="text-sm text-status-rollback">This run could not be loaded: {error}</p> : null}
|
| 464 |
+
{!run && !error ? <p className="text-sm text-ink-secondary">Loading run…</p> : null}
|
| 465 |
+
{run ? (
|
| 466 |
+
<>
|
| 467 |
+
<Panel title="Run" subtitle="one protocol, several consolidation arms from the same parent and sessions">
|
| 468 |
+
<RunHeader run={run} />
|
| 469 |
+
<div className="mt-4">
|
| 470 |
+
<ArmMatrix run={run} active={activeArm} onSelect={(a) => onSelect(run.id, a)} />
|
| 471 |
+
</div>
|
| 472 |
+
</Panel>
|
| 473 |
+
{selected ? (
|
| 474 |
+
<Panel title="Arm" subtitle={isSleep(selected) ? 'what was consolidated, how it was checked, and what the child answered' : 'a control from the parent model'}>
|
| 475 |
+
{isSleep(selected) ? <SleepArmDetail run={run} arm={selected} /> : <ControlArmDetail arm={selected} />}
|
| 476 |
+
</Panel>
|
| 477 |
+
) : null}
|
| 478 |
+
</>
|
| 479 |
+
) : null}
|
| 480 |
+
</div>
|
| 481 |
+
</div>
|
| 482 |
+
</div>
|
| 483 |
+
);
|
| 484 |
+
}
|
dashboard/src/observatory/data.test.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
| 2 |
+
import { clearObservatoryCache, isRun, loadIndex, loadRun, loadTrajectory, ObservatoryDataError } from './data';
|
| 3 |
+
import { checkState, ratio } from './format';
|
| 4 |
+
import { formatRoute, parseRoute } from './ObservatoryScreen';
|
| 5 |
+
import { exportFetch, readExport } from './testData';
|
| 6 |
+
import type { ObservatoryIndex, Run } from './types';
|
| 7 |
+
|
| 8 |
+
beforeEach(() => {
|
| 9 |
+
clearObservatoryCache();
|
| 10 |
+
vi.stubGlobal('fetch', vi.fn(exportFetch));
|
| 11 |
+
});
|
| 12 |
+
afterEach(() => {
|
| 13 |
+
vi.unstubAllGlobals();
|
| 14 |
+
});
|
| 15 |
+
|
| 16 |
+
describe('observatory data', () => {
|
| 17 |
+
it('loads the committed index and every run it lists', async () => {
|
| 18 |
+
const index = await loadIndex();
|
| 19 |
+
expect(index.runs.length).toBeGreaterThan(10);
|
| 20 |
+
for (const r of index.runs) {
|
| 21 |
+
const run = await loadRun(r.id);
|
| 22 |
+
expect(isRun(run)).toBe(true);
|
| 23 |
+
expect(run.id).toBe(r.id);
|
| 24 |
+
}
|
| 25 |
+
for (const id of index.sessions) {
|
| 26 |
+
const t = await loadTrajectory(id);
|
| 27 |
+
expect(t.per_layer.layers * t.per_layer.tensors.length).toBe(t.sessions[0].chunks[0].per_layer?.length);
|
| 28 |
+
}
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
it('rejects unsafe ids and unexpected formats, and retries after a failure', async () => {
|
| 32 |
+
await expect(loadRun('../index')).rejects.toBeInstanceOf(ObservatoryDataError);
|
| 33 |
+
await expect(loadRun('no_such_run')).rejects.toThrow('HTTP 404');
|
| 34 |
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ schema: 'other' }))));
|
| 35 |
+
clearObservatoryCache();
|
| 36 |
+
await expect(loadIndex()).rejects.toThrow('unexpected format');
|
| 37 |
+
vi.stubGlobal('fetch', vi.fn(exportFetch));
|
| 38 |
+
clearObservatoryCache();
|
| 39 |
+
await expect(loadIndex()).resolves.toMatchObject({ schema: 'plastic.sleep-observatory/1' });
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
it('keeps absent apart from zero', () => {
|
| 43 |
+
expect(ratio(undefined)).toBe('n/a');
|
| 44 |
+
expect(ratio({ n: 0, recalled: 0, n_paraphrase: 0, recalled_paraphrase: 0 })).toBe('n/a');
|
| 45 |
+
expect(ratio({ n: 24, recalled: 0, n_paraphrase: 24, recalled_paraphrase: 2 })).toBe('0/24');
|
| 46 |
+
expect(ratio({ n: 24, recalled: 0, n_paraphrase: 24, recalled_paraphrase: 2 }, 'paraphrase')).toBe('2/24');
|
| 47 |
+
const index = readExport<ObservatoryIndex>('index.json');
|
| 48 |
+
const seed0 = readExport<Run>('runs/final_step250_seed0_exclude.json');
|
| 49 |
+
expect(index.runs.find((r) => r.id === seed0.id)?.session_trajectory).toBe('sessions/final_step250_seed0_exclude.json');
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
it('never gives a verdict for a check that was not in force', () => {
|
| 53 |
+
const all40 = readExport<Run>('runs/sleep_controls_step100_all40.json');
|
| 54 |
+
const replay = all40.arms.find((a) => a.arm === 'replay');
|
| 55 |
+
expect(replay?.kind).toBe('sleep');
|
| 56 |
+
if (replay?.kind !== 'sleep') return;
|
| 57 |
+
const share = replay.gate?.checks.find((c) => c.name === 'reply_cluster_share');
|
| 58 |
+
expect(share && checkState(share)).toBe('not in force');
|
| 59 |
+
expect(replay.status).toBe('accepted');
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
it('round-trips shareable routes', () => {
|
| 63 |
+
const r = { view: 'runs' as const, run: 'final_step250_seed0_exclude', arm: 'dream' };
|
| 64 |
+
expect(parseRoute(formatRoute(r))).toEqual(r);
|
| 65 |
+
expect(parseRoute('#sleep')).toEqual({ view: 'runs', run: null, arm: null });
|
| 66 |
+
expect(parseRoute('#chat')).toEqual({ view: 'runs', run: null, arm: null });
|
| 67 |
+
expect(formatRoute({ view: 'runs', run: null, arm: 'dream' })).toBe('#sleep/runs');
|
| 68 |
+
});
|
| 69 |
+
});
|
dashboard/src/observatory/data.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Loads the exported observatory JSON. The files ship with the dashboard build under assets/observatory/
|
| 2 |
+
// (a byte-identical mirror of docs/research/results/sleep-observatory/), so this works with the API offline.
|
| 3 |
+
|
| 4 |
+
import type { ObservatoryIndex, Run, Trajectory } from './types';
|
| 5 |
+
|
| 6 |
+
export const SCHEMA = 'plastic.sleep-observatory/1';
|
| 7 |
+
|
| 8 |
+
export class ObservatoryDataError extends Error {}
|
| 9 |
+
|
| 10 |
+
function base(): string {
|
| 11 |
+
const root = typeof document !== 'undefined' ? document.baseURI : 'http://localhost/';
|
| 12 |
+
return new URL('assets/observatory/', root).toString();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
const cache = new Map<string, Promise<unknown>>();
|
| 16 |
+
|
| 17 |
+
async function getJson<T>(path: string, check: (value: unknown) => value is T): Promise<T> {
|
| 18 |
+
const url = base() + path;
|
| 19 |
+
if (!cache.has(url)) {
|
| 20 |
+
cache.set(
|
| 21 |
+
url,
|
| 22 |
+
(async () => {
|
| 23 |
+
const res = await fetch(url);
|
| 24 |
+
if (!res.ok) throw new ObservatoryDataError(`${path}: HTTP ${res.status}`);
|
| 25 |
+
return res.json();
|
| 26 |
+
})().catch((err) => {
|
| 27 |
+
cache.delete(url); // a failed fetch can be retried
|
| 28 |
+
throw err;
|
| 29 |
+
})
|
| 30 |
+
);
|
| 31 |
+
}
|
| 32 |
+
const value = await cache.get(url);
|
| 33 |
+
if (!check(value)) throw new ObservatoryDataError(`${path}: unexpected format`);
|
| 34 |
+
return value;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
|
| 38 |
+
|
| 39 |
+
export function isIndex(v: unknown): v is ObservatoryIndex {
|
| 40 |
+
return isObject(v) && v.schema === SCHEMA && Array.isArray(v.runs) && Array.isArray(v.sessions);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export function isRun(v: unknown): v is Run {
|
| 44 |
+
return isObject(v) && typeof v.id === 'string' && Array.isArray(v.arms) && isObject(v.checkpoint) && isObject(v.protocol);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export function isTrajectory(v: unknown): v is Trajectory {
|
| 48 |
+
return isObject(v) && v.schema === SCHEMA && Array.isArray(v.sessions) && isObject(v.per_layer);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
const safeId = (id: string) => /^[A-Za-z0-9._-]+$/.test(id);
|
| 52 |
+
|
| 53 |
+
export function loadIndex(): Promise<ObservatoryIndex> {
|
| 54 |
+
return getJson('index.json', isIndex);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
export function loadRun(id: string): Promise<Run> {
|
| 58 |
+
if (!safeId(id)) return Promise.reject(new ObservatoryDataError(`invalid run id ${id}`));
|
| 59 |
+
return getJson(`runs/${id}.json`, isRun);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export function loadTrajectory(id: string): Promise<Trajectory> {
|
| 63 |
+
if (!safeId(id)) return Promise.reject(new ObservatoryDataError(`invalid run id ${id}`));
|
| 64 |
+
return getJson(`sessions/${id}.json`, isTrajectory);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
/** Test hook: forget cached responses. */
|
| 68 |
+
export function clearObservatoryCache(): void {
|
| 69 |
+
cache.clear();
|
| 70 |
+
}
|
dashboard/src/observatory/format.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Labels for the Sleep observatory. Each names a state or a quantity once; research readings live in the docs.
|
| 2 |
+
|
| 3 |
+
import type { Arm, ArmName, GateCheck, GroupCounts, GroupName, SleepArm } from './types';
|
| 4 |
+
|
| 5 |
+
export const ARM_LABEL: Record<ArmName, string> = {
|
| 6 |
+
floor: 'Floor',
|
| 7 |
+
ceiling: 'Ceiling',
|
| 8 |
+
anchor: 'Anchor',
|
| 9 |
+
replay: 'Replay',
|
| 10 |
+
distill: 'Distill',
|
| 11 |
+
dream: 'Dream',
|
| 12 |
+
ungated: 'Ungated replay',
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
/** What each arm is, in a few words. */
|
| 16 |
+
export const ARM_ROLE: Record<ArmName, string> = {
|
| 17 |
+
floor: 'parent model, fresh session',
|
| 18 |
+
ceiling: 'parent model, facts taught in the same session',
|
| 19 |
+
anchor: 'W0 moved toward the session fast weights',
|
| 20 |
+
replay: 'trained on selected turns plus replay data',
|
| 21 |
+
distill: 'session-state teacher distilled into the reset model',
|
| 22 |
+
dream: 'teacher-generated study items distilled',
|
| 23 |
+
ungated: 'replay on every turn, rolled-back and flagged included',
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
export const GROUP_LABEL: Record<GroupName, string> = {
|
| 27 |
+
taught: 'Taught',
|
| 28 |
+
boundary: 'Boundary',
|
| 29 |
+
rolled: 'Rolled back',
|
| 30 |
+
poison: 'Planted false',
|
| 31 |
+
general: 'General',
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
export const GROUP_ORDER: GroupName[] = ['taught', 'boundary', 'rolled', 'poison', 'general'];
|
| 35 |
+
|
| 36 |
+
export function isSleep(arm: Arm): arm is SleepArm {
|
| 37 |
+
return arm.kind === 'sleep';
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/** "3/24", or "n/a" when the group was not probed. */
|
| 41 |
+
export function ratio(c: GroupCounts | null | undefined, variant: 'verbatim' | 'paraphrase' = 'verbatim'): string {
|
| 42 |
+
if (!c) return 'n/a';
|
| 43 |
+
const [hit, n] = variant === 'verbatim' ? [c.recalled, c.n] : [c.recalled_paraphrase, c.n_paraphrase];
|
| 44 |
+
return n > 0 ? `${hit}/${n}` : 'n/a';
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export function hits(c: GroupCounts | null | undefined, variant: 'verbatim' | 'paraphrase' = 'verbatim'): number {
|
| 48 |
+
if (!c) return 0;
|
| 49 |
+
return variant === 'verbatim' ? c.recalled : c.recalled_paraphrase;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
export function num(v: number | null | undefined, digits = 3): string {
|
| 53 |
+
if (typeof v !== 'number' || !Number.isFinite(v)) return 'n/a';
|
| 54 |
+
if (v === 0) return '0';
|
| 55 |
+
const a = Math.abs(v);
|
| 56 |
+
if (a >= 100) return v.toFixed(0);
|
| 57 |
+
if (a >= 10) return v.toFixed(1);
|
| 58 |
+
if (a >= 0.01) return v.toFixed(digits);
|
| 59 |
+
return v.toExponential(1);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export function signed(v: number | null | undefined, digits = 3): string {
|
| 63 |
+
if (typeof v !== 'number' || !Number.isFinite(v)) return 'n/a';
|
| 64 |
+
return `${v > 0 ? '+' : v < 0 ? '−' : ''}${num(Math.abs(v), digits)}`;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
export function pct(v: number | null | undefined): string {
|
| 68 |
+
return typeof v === 'number' && Number.isFinite(v) ? `${Math.round(v * 100)}%` : 'n/a';
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
export type CheckState = 'passed' | 'failed' | 'not in force' | 'not measured';
|
| 72 |
+
|
| 73 |
+
export function checkState(c: GateCheck): CheckState {
|
| 74 |
+
if (!c.in_force) return 'not in force';
|
| 75 |
+
if (c.passed === null || c.value === null) return 'not measured';
|
| 76 |
+
return c.passed ? 'passed' : 'failed';
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
export type Outcome = 'committed' | 'pulled back' | 'control' | 'unknown';
|
| 80 |
+
|
| 81 |
+
export function outcome(arm: Arm): Outcome {
|
| 82 |
+
if (!isSleep(arm)) return 'control';
|
| 83 |
+
return arm.lineage.outcome;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
export const OUTCOME_LABEL: Record<Outcome, string> = {
|
| 87 |
+
committed: 'Committed',
|
| 88 |
+
'pulled back': 'Pulled back',
|
| 89 |
+
control: 'Control',
|
| 90 |
+
unknown: 'Unknown',
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
export function stepLabel(step: number | null): string {
|
| 94 |
+
if (step === null) return 'base';
|
| 95 |
+
return step === 250 ? 'final' : `step ${step}`;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
export function dateLabel(unix: number | null): string {
|
| 99 |
+
if (typeof unix !== 'number') return 'n/a';
|
| 100 |
+
const d = new Date(unix * 1000);
|
| 101 |
+
return `${d.toISOString().slice(0, 10)} ${d.toISOString().slice(11, 16)} UTC`;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
export function methodLine(arm: SleepArm): string {
|
| 105 |
+
const cfg = arm.config ?? {};
|
| 106 |
+
const target = arm.target === 'w0' ? 'W0' : arm.target === 'all' ? 'all parameters' : arm.target ?? '';
|
| 107 |
+
if (arm.method === 'anchor') return `${target}, λ ${cfg.anchor_lambda ?? 'n/a'}`;
|
| 108 |
+
return `${target} × ${cfg.steps ?? 'n/a'} steps, lr ${cfg.lr ?? 'n/a'}`;
|
| 109 |
+
}
|
dashboard/src/observatory/legibility.test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// The dashboard legibility floor, checked on the observatory sources: no text below 11px, colors only from tokens,
|
| 2 |
+
// no opacity-based text de-emphasis, no emoji.
|
| 3 |
+
import { describe, expect, it } from 'vitest';
|
| 4 |
+
|
| 5 |
+
const RAW = import.meta.glob(['./*.ts', './*.tsx', '!./*.test.ts', '!./*.test.tsx', '!./testData.ts'], { eager: true, query: '?raw', import: 'default' }) as Record<string, string>;
|
| 6 |
+
const sources = Object.entries(RAW);
|
| 7 |
+
|
| 8 |
+
describe('observatory legibility floor', () => {
|
| 9 |
+
it('has sources to check', () => expect(sources.length).toBeGreaterThan(3));
|
| 10 |
+
|
| 11 |
+
for (const [file, text] of sources) {
|
| 12 |
+
it(`${file}: colors come from tokens, not literals`, () => {
|
| 13 |
+
expect(text.match(/#[0-9a-fA-F]{3,8}\b/g) ?? []).toEqual([]);
|
| 14 |
+
expect(text.match(/\brgba?\(/g) ?? []).toEqual([]);
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
it(`${file}: nothing below 11px`, () => {
|
| 18 |
+
const px = [...text.matchAll(/text-\[(\d+(?:\.\d+)?)px\]|fontSize[=:]\s*\{?\s*(\d+(?:\.\d+)?)/g)].map((m) => Number(m[1] ?? m[2]));
|
| 19 |
+
expect(px.filter((v) => v < 11)).toEqual([]);
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
it(`${file}: no opacity on text, no emoji`, () => {
|
| 23 |
+
expect(text.match(/\b(?:text-opacity|opacity)-\d+/g) ?? []).toEqual([]);
|
| 24 |
+
expect(text.match(/\p{Extended_Pictographic}/gu) ?? []).toEqual([]);
|
| 25 |
+
});
|
| 26 |
+
}
|
| 27 |
+
});
|
dashboard/src/observatory/parts.tsx
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Small building blocks shared by the three observatory views. Legibility floor: nothing below 11px, solid
|
| 2 |
+
// backgrounds, text in ink tokens (status hue only on marks and short state words), no opacity on text.
|
| 3 |
+
|
| 4 |
+
import { useEffect, useState, type ReactNode } from 'react';
|
| 5 |
+
import { OBS } from '../components/charts/theme';
|
| 6 |
+
import { checkState, num, OUTCOME_LABEL, type CheckState, type Outcome } from './format';
|
| 7 |
+
import type { GateCheck, Harvest } from './types';
|
| 8 |
+
|
| 9 |
+
export function useAsync<T>(load: (() => Promise<T>) | null, deps: unknown[]): { data: T | null; error: string | null } {
|
| 10 |
+
const [state, setState] = useState<{ data: T | null; error: string | null }>({ data: null, error: null });
|
| 11 |
+
useEffect(() => {
|
| 12 |
+
if (!load) {
|
| 13 |
+
setState({ data: null, error: null });
|
| 14 |
+
return;
|
| 15 |
+
}
|
| 16 |
+
let live = true;
|
| 17 |
+
setState({ data: null, error: null });
|
| 18 |
+
load().then(
|
| 19 |
+
(data) => live && setState({ data, error: null }),
|
| 20 |
+
(e: unknown) => live && setState({ data: null, error: e instanceof Error ? e.message : String(e) })
|
| 21 |
+
);
|
| 22 |
+
return () => {
|
| 23 |
+
live = false;
|
| 24 |
+
};
|
| 25 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 26 |
+
}, deps);
|
| 27 |
+
return state;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
const OUTCOME_TONE: Record<Outcome, string> = {
|
| 31 |
+
committed: 'text-status-commit border-status-commit',
|
| 32 |
+
'pulled back': 'text-status-rollback border-status-rollback',
|
| 33 |
+
control: 'text-ink-secondary border-edge-strong',
|
| 34 |
+
unknown: 'text-ink-secondary border-edge-strong',
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
/** Outcome glyph: a check for committed, a cross for pulled back, a dash for controls. Shape carries the state too. */
|
| 38 |
+
export function OutcomeGlyph({ outcome, size = 14 }: { outcome: Outcome; size?: number }) {
|
| 39 |
+
const color = outcome === 'committed' ? OBS.pass : outcome === 'pulled back' ? OBS.fail : OBS.inkMuted;
|
| 40 |
+
return (
|
| 41 |
+
<svg width={size} height={size} viewBox="0 0 16 16" aria-hidden="true" className="shrink-0">
|
| 42 |
+
{outcome === 'committed' ? (
|
| 43 |
+
<path d="M3 8.5l3.2 3.2L13 5" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" />
|
| 44 |
+
) : outcome === 'pulled back' ? (
|
| 45 |
+
<path d="M4 4l8 8M12 4l-8 8" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round" />
|
| 46 |
+
) : (
|
| 47 |
+
<path d="M4 8h8" fill="none" stroke={color} strokeWidth="2.2" strokeLinecap="round" />
|
| 48 |
+
)}
|
| 49 |
+
</svg>
|
| 50 |
+
);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export function OutcomeBadge({ outcome, label }: { outcome: Outcome; label?: string }) {
|
| 54 |
+
return (
|
| 55 |
+
<span className={`inline-flex items-center gap-1.5 whitespace-nowrap rounded border bg-surface-overlay px-2 py-0.5 text-xs font-semibold ${OUTCOME_TONE[outcome]}`}>
|
| 56 |
+
<OutcomeGlyph outcome={outcome} size={12} />
|
| 57 |
+
{label ?? OUTCOME_LABEL[outcome]}
|
| 58 |
+
</span>
|
| 59 |
+
);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export function Chip({ children, title }: { children: ReactNode; title?: string }) {
|
| 63 |
+
return (
|
| 64 |
+
<span title={title} className="inline-flex items-center rounded border border-edge-strong bg-surface-overlay px-2 py-0.5 font-mono text-xs text-ink-secondary">
|
| 65 |
+
{children}
|
| 66 |
+
</span>
|
| 67 |
+
);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/** Marks content that is not a measurement. Appears on every illustrative element, not only on the toggle. */
|
| 71 |
+
export function IllustrativeTag() {
|
| 72 |
+
return (
|
| 73 |
+
<span className="inline-flex items-center rounded border border-illustrative bg-illustrative-soft px-2 py-0.5 text-xs font-semibold text-illustrative">
|
| 74 |
+
Illustrative, not measured
|
| 75 |
+
</span>
|
| 76 |
+
);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
export function Label({ children }: { children: ReactNode }) {
|
| 80 |
+
return <div className="text-label font-semibold uppercase tracking-wide text-ink-muted">{children}</div>;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
export function Big({ children, tone = 'default' }: { children: ReactNode; tone?: 'default' | 'pass' | 'fail' | 'accent' | 'illustrative' }) {
|
| 84 |
+
const cls = { default: 'text-ink-primary', pass: 'text-status-commit', fail: 'text-status-rollback', accent: 'text-accent', illustrative: 'text-illustrative' }[tone];
|
| 85 |
+
return <div className={`font-mono text-xl font-semibold ${cls}`}>{children}</div>;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
const CHECK_TONE: Record<CheckState, { dot: string; text: string }> = {
|
| 89 |
+
passed: { dot: OBS.pass, text: 'text-status-commit' },
|
| 90 |
+
failed: { dot: OBS.fail, text: 'text-status-rollback' },
|
| 91 |
+
'not in force': { dot: OBS.notInForce, text: 'text-ink-secondary' },
|
| 92 |
+
'not measured': { dot: OBS.notInForce, text: 'text-ink-secondary' },
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* One locality check as a value-against-limit track. The track spans zero, the limit and the value; the dashed line
|
| 97 |
+
* is the limit, the dot is the measured value. A check that was not in force shows its value (if any) without a verdict.
|
| 98 |
+
*/
|
| 99 |
+
export function GateCheckRow({ check }: { check: GateCheck }) {
|
| 100 |
+
const state = checkState(check);
|
| 101 |
+
const tone = CHECK_TONE[state];
|
| 102 |
+
const v = check.value;
|
| 103 |
+
const limit = check.limit;
|
| 104 |
+
const lo = Math.min(0, v ?? 0, limit ?? 0);
|
| 105 |
+
const hi = Math.max(0, v ?? 0, limit ?? 0);
|
| 106 |
+
const pad = (hi - lo || 1) * 0.15;
|
| 107 |
+
const x = (t: number) => `${((t - lo + pad) / (hi - lo + 2 * pad)) * 100}%`;
|
| 108 |
+
return (
|
| 109 |
+
<li className="grid grid-cols-[minmax(9rem,13rem)_1fr_auto] items-center gap-3">
|
| 110 |
+
<div className="min-w-0">
|
| 111 |
+
<div className="text-sm font-semibold text-ink-primary">{check.label}</div>
|
| 112 |
+
{check.value_source && check.value_source !== 'recorded measurement' ? <div className="text-micro text-ink-muted">{check.value_source}</div> : null}
|
| 113 |
+
</div>
|
| 114 |
+
<div className="relative h-11" role="img" aria-label={`${check.label}: value ${num(v)}, limit ${num(limit)}, ${state}`}>
|
| 115 |
+
<div className="absolute inset-x-0 top-3.5 h-px bg-edge-strong" />
|
| 116 |
+
{lo < 0 ? (
|
| 117 |
+
<>
|
| 118 |
+
<div className="absolute top-1.5 h-4 w-px bg-edge-strong" style={{ left: x(0) }} />
|
| 119 |
+
<span className="absolute top-6 -translate-x-1/2 font-mono text-micro text-ink-muted" style={{ left: x(0) }}>0</span>
|
| 120 |
+
</>
|
| 121 |
+
) : null}
|
| 122 |
+
{limit !== null ? (
|
| 123 |
+
<>
|
| 124 |
+
<div className="absolute top-0 h-7 border-l-2 border-dashed border-ink-muted" style={{ left: x(limit) }} />
|
| 125 |
+
<span className="absolute top-7 -translate-x-1/2 whitespace-nowrap text-micro text-ink-muted" style={{ left: x(limit) }}>limit</span>
|
| 126 |
+
</>
|
| 127 |
+
) : null}
|
| 128 |
+
{v !== null ? (
|
| 129 |
+
<div className="absolute top-3.5 h-3.5 w-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2" style={{ left: x(v), backgroundColor: tone.dot, borderColor: OBS.surface }} />
|
| 130 |
+
) : null}
|
| 131 |
+
</div>
|
| 132 |
+
<div className="text-right font-mono text-sm">
|
| 133 |
+
<span className="text-ink-primary">{num(v)}</span>
|
| 134 |
+
<span className="text-ink-muted"> / {num(limit)}</span>
|
| 135 |
+
<div className={`text-xs font-semibold ${tone.text}`}>{state}</div>
|
| 136 |
+
</div>
|
| 137 |
+
</li>
|
| 138 |
+
);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/** What the arm's text selection kept, as a proportional bar with counts. Absent selections are said to be absent. */
|
| 142 |
+
export function TurnsBar({ harvest }: { harvest: Harvest }) {
|
| 143 |
+
const tbr = harvest.turns_by_reason ?? {};
|
| 144 |
+
const accepted = tbr.accepted ?? 0;
|
| 145 |
+
const rejected = Object.entries(tbr).filter(([k]) => k !== 'accepted').reduce((a, [, v]) => a + (v ?? 0), 0);
|
| 146 |
+
const all = String(harvest.provenance ?? '').startsWith('all');
|
| 147 |
+
const sel = harvest.selected_turns.value;
|
| 148 |
+
const flaggedOut = harvest.flagged_excluded ?? 0;
|
| 149 |
+
const segments =
|
| 150 |
+
sel === null
|
| 151 |
+
? [
|
| 152 |
+
{ n: accepted, label: 'accepted online', color: OBS.line },
|
| 153 |
+
{ n: rejected, label: 'rolled back', color: OBS.fail },
|
| 154 |
+
]
|
| 155 |
+
: all
|
| 156 |
+
? [{ n: sel, label: `selected (${accepted} accepted, ${rejected} rolled back)`, color: OBS.line }]
|
| 157 |
+
: [
|
| 158 |
+
{ n: sel, label: 'selected', color: OBS.line },
|
| 159 |
+
{ n: flaggedOut, label: 'flagged, excluded', color: OBS.flag },
|
| 160 |
+
{ n: rejected, label: 'rolled back, excluded', color: OBS.fail },
|
| 161 |
+
];
|
| 162 |
+
const total = segments.reduce((a, s) => a + s.n, 0) || 1;
|
| 163 |
+
return (
|
| 164 |
+
<div>
|
| 165 |
+
<div className="flex h-3 w-full gap-0.5 overflow-hidden rounded-sm bg-surface-inset" role="img" aria-label={segments.map((s) => `${s.n} ${s.label}`).join(', ')}>
|
| 166 |
+
{segments.filter((s) => s.n > 0).map((s) => (
|
| 167 |
+
<div key={s.label} style={{ width: `${(s.n / total) * 100}%`, backgroundColor: s.color }} />
|
| 168 |
+
))}
|
| 169 |
+
</div>
|
| 170 |
+
<ul className="mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs text-ink-secondary">
|
| 171 |
+
{segments.map((s) => (
|
| 172 |
+
<li key={s.label} className="flex items-center gap-1.5">
|
| 173 |
+
<span className="inline-block h-2.5 w-2.5 rounded-sm" style={{ backgroundColor: s.color }} />
|
| 174 |
+
<span className="font-mono font-semibold text-ink-primary">{s.n}</span> {s.label}
|
| 175 |
+
</li>
|
| 176 |
+
))}
|
| 177 |
+
<li className="text-ink-muted">
|
| 178 |
+
{sel === null ? 'selection not recorded for this run' : harvest.selected_turns.source === 'recorded' ? 'selection recorded' : 'selection derived from recorded counts'}
|
| 179 |
+
</li>
|
| 180 |
+
</ul>
|
| 181 |
+
</div>
|
| 182 |
+
);
|
| 183 |
+
}
|
dashboard/src/observatory/testData.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Test helper: serve the committed observatory export (dashboard/public/assets/observatory) through a stubbed fetch.
|
| 2 |
+
// Bundled with Vite's raw glob, so tests need no Node file APIs.
|
| 3 |
+
const FILES = import.meta.glob('../../public/assets/observatory/**/*.json', { eager: true, query: '?raw', import: 'default' }) as Record<string, string>;
|
| 4 |
+
const PREFIX = '../../public/assets/observatory/';
|
| 5 |
+
|
| 6 |
+
export function exportFiles(): string[] {
|
| 7 |
+
return Object.keys(FILES).map((k) => k.slice(PREFIX.length));
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export function readExport<T = unknown>(rel: string): T {
|
| 11 |
+
const text = FILES[PREFIX + rel];
|
| 12 |
+
if (text === undefined) throw new Error(`no exported file ${rel}`);
|
| 13 |
+
return JSON.parse(text) as T;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export async function exportFetch(url: string | URL | Request): Promise<Response> {
|
| 17 |
+
const path = String(url).split('assets/observatory/')[1] ?? '';
|
| 18 |
+
const text = FILES[PREFIX + path];
|
| 19 |
+
if (!path || path.includes('..') || text === undefined) return new Response('not found', { status: 404 });
|
| 20 |
+
return new Response(text, { status: 200, headers: { 'Content-Type': 'application/json' } });
|
| 21 |
+
}
|
dashboard/src/observatory/types.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Shapes of the exported observatory JSON (scripts/export_sleep_observatory.py, schema plastic.sleep-observatory/1).
|
| 2 |
+
// Every nullable field is nullable because the source may not have recorded it: null means absent, never zero.
|
| 3 |
+
|
| 4 |
+
export type GroupName = 'taught' | 'boundary' | 'rolled' | 'poison' | 'general';
|
| 5 |
+
export type ArmName = 'floor' | 'ceiling' | 'anchor' | 'replay' | 'distill' | 'dream' | 'ungated';
|
| 6 |
+
export type ArmStatus = 'accepted' | 'rejected' | 'accepted_unmeasured';
|
| 7 |
+
|
| 8 |
+
export interface GroupCounts {
|
| 9 |
+
n: number;
|
| 10 |
+
recalled: number;
|
| 11 |
+
n_paraphrase: number;
|
| 12 |
+
recalled_paraphrase: number;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export interface CountsView {
|
| 16 |
+
by_group: Partial<Record<GroupName, GroupCounts>> | null;
|
| 17 |
+
source: 'saved' | 'saved, confirmed by recount' | 'recounted' | 'counted from replies' | 'absent';
|
| 18 |
+
saved: Partial<Record<GroupName, GroupCounts>> | null;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export interface RecallTotals {
|
| 22 |
+
n_probes: number | null;
|
| 23 |
+
recalled: number | null;
|
| 24 |
+
n_paraphrase: number | null;
|
| 25 |
+
recalled_paraphrase: number | null;
|
| 26 |
+
mean_answer_logprob: number | null;
|
| 27 |
+
max_cluster_share: number | null;
|
| 28 |
+
distinct_ratio: number | null;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export interface GateCheck {
|
| 32 |
+
name: string;
|
| 33 |
+
label: string;
|
| 34 |
+
value: number | null;
|
| 35 |
+
limit: number | null;
|
| 36 |
+
/** null when the check was not in force at execution */
|
| 37 |
+
passed: boolean | null;
|
| 38 |
+
in_force: boolean;
|
| 39 |
+
value_source?: string | null;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export interface Gate {
|
| 43 |
+
measured: boolean | null;
|
| 44 |
+
passed: boolean | null;
|
| 45 |
+
checks: GateCheck[];
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
export interface Nll {
|
| 49 |
+
mean?: number | null;
|
| 50 |
+
median?: number | null;
|
| 51 |
+
tokens?: number | null;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
export interface HarvestSession {
|
| 55 |
+
session_id: string;
|
| 56 |
+
log_only: boolean | null;
|
| 57 |
+
turns: number | null;
|
| 58 |
+
accepted_turns: number | null;
|
| 59 |
+
has_committed_state: boolean | null;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export interface Harvest {
|
| 63 |
+
sessions: HarvestSession[];
|
| 64 |
+
turns_by_reason: Record<string, number> | null;
|
| 65 |
+
accepted_tokens: number | null;
|
| 66 |
+
excluded_tokens: number | null;
|
| 67 |
+
accepted_turns_flagged: number | null;
|
| 68 |
+
flagged_excluded: number | null;
|
| 69 |
+
provenance: string | null;
|
| 70 |
+
flagged_policy: string | null;
|
| 71 |
+
source_sessions: string[] | null;
|
| 72 |
+
selected_turns: { value: number | null; source: string };
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
export interface ProbeRow {
|
| 76 |
+
group: GroupName | null;
|
| 77 |
+
group_attribution: string | null;
|
| 78 |
+
variant: 'verbatim' | 'paraphrase';
|
| 79 |
+
question: string;
|
| 80 |
+
expected: string;
|
| 81 |
+
reply: string;
|
| 82 |
+
reply_truncated: boolean;
|
| 83 |
+
hit: boolean;
|
| 84 |
+
exact: boolean;
|
| 85 |
+
answer_logprob: number | null;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
export interface DreamKept {
|
| 89 |
+
prompt: string | null;
|
| 90 |
+
turn: string | null;
|
| 91 |
+
text: string;
|
| 92 |
+
session_id: string | null;
|
| 93 |
+
reply_len: number | null;
|
| 94 |
+
teacher_logprob: number | null;
|
| 95 |
+
student_logprob: number | null;
|
| 96 |
+
fastweight_logprob: number | null;
|
| 97 |
+
gain: number | null;
|
| 98 |
+
fastweight_gain: number | null;
|
| 99 |
+
token_gain: (number | null)[] | null;
|
| 100 |
+
token_fw_gain: (number | null)[] | null;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
export interface Dreams {
|
| 104 |
+
generated: number | null;
|
| 105 |
+
kept_count: number;
|
| 106 |
+
filtered: Record<string, number | null>;
|
| 107 |
+
rejected_reasons: Record<string, number>;
|
| 108 |
+
rejected_samples: { reason: string; text: string }[];
|
| 109 |
+
kept: DreamKept[];
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
export interface PerTensor {
|
| 113 |
+
quantity: string;
|
| 114 |
+
tensors: string[];
|
| 115 |
+
/** [layer][tensor] */
|
| 116 |
+
values: (number | null)[][];
|
| 117 |
+
total?: number | null;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
export interface GradientNorms {
|
| 121 |
+
quantity: string;
|
| 122 |
+
steps: number[];
|
| 123 |
+
total: (number | null)[];
|
| 124 |
+
per_layer: (number | null)[][];
|
| 125 |
+
other: (number | null)[] | null;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
export interface Lineage {
|
| 129 |
+
parent: string | null;
|
| 130 |
+
child: string | null;
|
| 131 |
+
outcome: 'committed' | 'pulled back' | 'unknown';
|
| 132 |
+
where: string | null;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
export interface SleepArm {
|
| 136 |
+
arm: ArmName;
|
| 137 |
+
kind: 'sleep';
|
| 138 |
+
method: string;
|
| 139 |
+
target: string | null;
|
| 140 |
+
status: ArmStatus | null;
|
| 141 |
+
status_conflict: boolean;
|
| 142 |
+
reason: string | null;
|
| 143 |
+
lineage: Lineage;
|
| 144 |
+
gate: Gate | null;
|
| 145 |
+
heldout_nll: { before: Nll | null; after: Nll | null };
|
| 146 |
+
recall: { before: CountsView; after: CountsView; totals_before: RecallTotals | null; totals_after: RecallTotals | null };
|
| 147 |
+
harvest: Harvest | null;
|
| 148 |
+
batch: Record<string, unknown> | null;
|
| 149 |
+
packed: Record<string, number> | null;
|
| 150 |
+
losses: number[] | null;
|
| 151 |
+
loss_terms: string | null;
|
| 152 |
+
dreams: Dreams | null;
|
| 153 |
+
anchor_relative_update: PerTensor | null;
|
| 154 |
+
w0_relative_update: PerTensor | null;
|
| 155 |
+
gradient_norms: GradientNorms | null;
|
| 156 |
+
config: Record<string, unknown> | null;
|
| 157 |
+
probes: ProbeRow[];
|
| 158 |
+
report: { file: string; sha256: string; run_id: string | null; head_at_arm_start: string | null; code_at_import?: string | null; seconds: number | null } | null;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
export interface ControlArm {
|
| 162 |
+
arm: ArmName;
|
| 163 |
+
kind: 'control';
|
| 164 |
+
method: null;
|
| 165 |
+
status: null;
|
| 166 |
+
recall: { after: CountsView };
|
| 167 |
+
mean_answer_logprob: number | null;
|
| 168 |
+
max_cluster_share: { value: number | null; source: string };
|
| 169 |
+
probes: ProbeRow[];
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
export type Arm = SleepArm | ControlArm;
|
| 173 |
+
|
| 174 |
+
export interface Checkpoint {
|
| 175 |
+
name: string | null;
|
| 176 |
+
step: number | null;
|
| 177 |
+
label: string;
|
| 178 |
+
digest_prefix: string | null;
|
| 179 |
+
published: boolean;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
export interface Protocol {
|
| 183 |
+
facts: number | null;
|
| 184 |
+
poison: boolean | null;
|
| 185 |
+
seed: number | null;
|
| 186 |
+
steps: number | null;
|
| 187 |
+
target: string | null;
|
| 188 |
+
lr: number | null;
|
| 189 |
+
replay_ratio: number | null;
|
| 190 |
+
batch_size: number | null;
|
| 191 |
+
session_loss: string | null;
|
| 192 |
+
prompt_loss_weight: number | null;
|
| 193 |
+
augment: string | null;
|
| 194 |
+
teach_temperature: number | null;
|
| 195 |
+
dream_temperature: number | null;
|
| 196 |
+
replay_revision: string | null;
|
| 197 |
+
device: string | null;
|
| 198 |
+
ceiling_mode: string | null;
|
| 199 |
+
flagged_policy: string | null;
|
| 200 |
+
wall_seconds: number | null;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
export interface Run {
|
| 204 |
+
id: string;
|
| 205 |
+
question: string | null;
|
| 206 |
+
summary: string | null;
|
| 207 |
+
started_at_unix: number | null;
|
| 208 |
+
checkpoint: Checkpoint;
|
| 209 |
+
code: { recorded_at_launch: string | null; archive_readme: string | null };
|
| 210 |
+
protocol: Protocol;
|
| 211 |
+
arms: Arm[];
|
| 212 |
+
notes: { recount: boolean };
|
| 213 |
+
sources: { file: string; sha256: string }[];
|
| 214 |
+
session_trajectory: string | null;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
export interface IndexArm {
|
| 218 |
+
arm: ArmName;
|
| 219 |
+
status: ArmStatus | null;
|
| 220 |
+
method: string | null;
|
| 221 |
+
taught: GroupCounts | null;
|
| 222 |
+
totals: RecallTotals | null;
|
| 223 |
+
nll_before: number | null;
|
| 224 |
+
nll_after: number | null;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
export interface IndexRun {
|
| 228 |
+
id: string;
|
| 229 |
+
summary: string | null;
|
| 230 |
+
started_at_unix: number | null;
|
| 231 |
+
checkpoint: Checkpoint;
|
| 232 |
+
code_recorded: string | null;
|
| 233 |
+
facts: number | null;
|
| 234 |
+
flagged_policy: string | null;
|
| 235 |
+
steps: number | null;
|
| 236 |
+
target: string | null;
|
| 237 |
+
session_trajectory: string | null;
|
| 238 |
+
arms: IndexArm[];
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
export interface ObservatoryIndex {
|
| 242 |
+
schema: string;
|
| 243 |
+
exporter_version: string;
|
| 244 |
+
archive_digest: string;
|
| 245 |
+
archive: string;
|
| 246 |
+
chat_eval: Record<string, unknown> | null;
|
| 247 |
+
runs: IndexRun[];
|
| 248 |
+
sessions: string[];
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
export interface Chunk {
|
| 252 |
+
i: number;
|
| 253 |
+
pos: [number, number];
|
| 254 |
+
n: number | null;
|
| 255 |
+
source: 'user' | 'model';
|
| 256 |
+
chunk_loss: number | null;
|
| 257 |
+
surprise_mean: number | null;
|
| 258 |
+
surprise_max: number | null;
|
| 259 |
+
write_norm_sum: number | null;
|
| 260 |
+
proposed: number | null;
|
| 261 |
+
accepted: number | null;
|
| 262 |
+
per_layer: (number | null)[] | null;
|
| 263 |
+
requested: string | null;
|
| 264 |
+
applied: string | null;
|
| 265 |
+
scale: number | null;
|
| 266 |
+
flags: string[];
|
| 267 |
+
applied_reasons: string[];
|
| 268 |
+
read_only: boolean;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
export interface TrajectorySession {
|
| 272 |
+
session_id: string;
|
| 273 |
+
log_only: boolean;
|
| 274 |
+
enable_rollback: boolean | null;
|
| 275 |
+
z_rollback: number | null;
|
| 276 |
+
z_scale: number | null;
|
| 277 |
+
calibrated: boolean;
|
| 278 |
+
counts: Record<string, number | null>;
|
| 279 |
+
turns: { i: number; prompt: string; completion: string; tx: [number, number] }[];
|
| 280 |
+
chunks: Chunk[];
|
| 281 |
+
source: { transactions: string | null; transactions_sha256: string; trace_sha256: string | null };
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
export interface Trajectory {
|
| 285 |
+
run_id: string;
|
| 286 |
+
schema: string;
|
| 287 |
+
provenance: { kind: string; controls_sha256: string; checks: string[] };
|
| 288 |
+
per_layer: { quantity: string; layers: number; tensors: string[]; order: string };
|
| 289 |
+
sessions: TrajectorySession[];
|
| 290 |
+
}
|
dashboard/src/playground/App.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import { 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';
|
|
@@ -26,7 +27,7 @@ export default function App() {
|
|
| 26 |
void bootstrap();
|
| 27 |
}, [bootstrap]);
|
| 28 |
|
| 29 |
-
// keys
|
| 30 |
useEffect(() => {
|
| 31 |
const onKey = (e: KeyboardEvent) => {
|
| 32 |
if (e.metaKey || e.ctrlKey || e.altKey || isTyping(e.target)) return;
|
|
@@ -40,8 +41,9 @@ export default function App() {
|
|
| 40 |
return () => window.removeEventListener('keydown', onKey);
|
| 41 |
}, [setTab]);
|
| 42 |
|
| 43 |
-
|
| 44 |
-
const
|
|
|
|
| 45 |
|
| 46 |
return (
|
| 47 |
<div className="min-h-screen bg-surface">
|
|
|
|
| 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';
|
|
|
|
| 27 |
void bootstrap();
|
| 28 |
}, [bootstrap]);
|
| 29 |
|
| 30 |
+
// number keys switch screens when not typing
|
| 31 |
useEffect(() => {
|
| 32 |
const onKey = (e: KeyboardEvent) => {
|
| 33 |
if (e.metaKey || e.ctrlKey || e.altKey || isTyping(e.target)) return;
|
|
|
|
| 41 |
return () => window.removeEventListener('keydown', onKey);
|
| 42 |
}, [setTab]);
|
| 43 |
|
| 44 |
+
// the Sleep observatory reads archived runs shipped with the page, so it stays available without the service
|
| 45 |
+
const offline = healthChecked && health === null && tab !== 'sleep';
|
| 46 |
+
const View = tab === 'chat' ? ChatScreen : tab === 'signals' ? SignalsScreen : tab === 'sleep' ? ObservatoryScreen : SessionsScreen;
|
| 47 |
|
| 48 |
return (
|
| 49 |
<div className="min-h-screen bg-surface">
|
dashboard/src/playground/store.ts
CHANGED
|
@@ -18,9 +18,14 @@ import type {
|
|
| 18 |
TransactionRecord,
|
| 19 |
} from './types';
|
| 20 |
|
| 21 |
-
export const TABS = ['chat', 'signals', 'sessions'] as const;
|
| 22 |
export type Tab = (typeof TABS)[number];
|
| 23 |
-
export const TAB_LABELS: Record<Tab, string> = { chat: 'Chat', signals: 'Signals', sessions: 'Sessions' };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
const NO_CAPABILITIES: Capabilities = { create_session: false, fork: false, reset: false, delete: false, resume: false, calibrate: false, sleep: false };
|
| 26 |
|
|
@@ -83,7 +88,7 @@ export const useStore = create<PlaygroundState>((set, get) => ({
|
|
| 83 |
lastChat: null,
|
| 84 |
stale: false,
|
| 85 |
sampling: { max_new_tokens: 96, temperature: 0.7, top_k: 40, seed: null },
|
| 86 |
-
tab:
|
| 87 |
busy: { chat: false, session: false, mutation: false },
|
| 88 |
calibrating: null,
|
| 89 |
sleepRuns: [],
|
|
|
|
| 18 |
TransactionRecord,
|
| 19 |
} from './types';
|
| 20 |
|
| 21 |
+
export const TABS = ['chat', 'signals', 'sessions', 'sleep'] as const;
|
| 22 |
export type Tab = (typeof TABS)[number];
|
| 23 |
+
export const TAB_LABELS: Record<Tab, string> = { chat: 'Chat', signals: 'Signals', sessions: 'Sessions', sleep: 'Sleep' };
|
| 24 |
+
|
| 25 |
+
/** A shared link to the Sleep observatory (#sleep/...) opens that tab. */
|
| 26 |
+
function initialTab(): Tab {
|
| 27 |
+
return typeof window !== 'undefined' && window.location.hash.startsWith('#sleep') ? 'sleep' : 'chat';
|
| 28 |
+
}
|
| 29 |
|
| 30 |
const NO_CAPABILITIES: Capabilities = { create_session: false, fork: false, reset: false, delete: false, resume: false, calibrate: false, sleep: false };
|
| 31 |
|
|
|
|
| 88 |
lastChat: null,
|
| 89 |
stale: false,
|
| 90 |
sampling: { max_new_tokens: 96, temperature: 0.7, top_k: 40, seed: null },
|
| 91 |
+
tab: initialTab(),
|
| 92 |
busy: { chat: false, session: false, mutation: false },
|
| 93 |
calibrating: null,
|
| 94 |
sleepRuns: [],
|
dashboard/tailwind.config.js
CHANGED
|
@@ -55,6 +55,12 @@ export default {
|
|
| 55 |
project: '#1f4f8f',
|
| 56 |
readonly: '#48545f',
|
| 57 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
series: {
|
| 59 |
a: '#58a6ff', // base / first series
|
| 60 |
b: '#3fd17a', // frozen / second series
|
|
|
|
| 55 |
project: '#1f4f8f',
|
| 56 |
readonly: '#48545f',
|
| 57 |
},
|
| 58 |
+
// Illustrative (not measured) content in the Sleep observatory: its own hue, never used for data or status.
|
| 59 |
+
// ink-primary on illustrative.soft is 15.2:1; illustrative on surface.raised is 7.2:1, on illustrative.soft 7.3:1.
|
| 60 |
+
illustrative: {
|
| 61 |
+
DEFAULT: '#c792ea',
|
| 62 |
+
soft: '#1b1626',
|
| 63 |
+
},
|
| 64 |
series: {
|
| 65 |
a: '#58a6ff', // base / first series
|
| 66 |
b: '#3fd17a', // frozen / second series
|