The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Hub: notifications reach the backend, their page reads as a list, and Share opens a menu (#1379)
Jacob Pham8a143a3deb92
diff --git a/website/src/app/api/community/[...path]/route.spec.ts b/website/src/app/api/community/[...path]/route.spec.tsindex a2adea392..afa90e712 100644--- a/website/src/app/api/community/[...path]/route.spec.ts+++ b/website/src/app/api/community/[...path]/route.spec.ts@@ -36,6 +36,21 @@ describe('community API boundary', () => {expect(options.headers.get('content-type')).toBe('application/gzip');expect(Buffer.from(options.body).equals(gzipped)).toBe(true);});+ it('forwards every route the Hub calls: notifications, reports, a creator and the rest', async () => {+ vi.stubEnv('COMMUNITY_API_URL', 'http://127.0.0.1:54882');+ const fetcher = vi.fn().mockImplementation(async () => Response.json({ success: true, data: {} })); vi.stubGlobal('fetch', fetcher);+ const id = '0f8fad5b-d9cb-469f-a165-70867728950e';+ const paths = ['harnesses', `harnesses/${id}`, 'harnesses/pac-man-neon-maze-chase-0f8fad5b', `harnesses/${id}/like`, `harnesses/${id}/social`, `harnesses/${id}/comments`, `harnesses/${id}/comments/${id}`,+ 'creators/alice', 'creators/alice/follow', 'notifications', 'notifications/unread', 'notifications/read', 'reports', 'reports/review', 'translate'];+ for (const path of paths) {+ const response = await GET(new Request(`https://harness.example/api/community/${path}`), { params: Promise.resolve({ path: path.split('/') }) });+ expect(response.status, path).toBe(200);+ }+ expect(fetcher).toHaveBeenCalledTimes(paths.length);+ for (const path of ['notifications/all', 'reports/x', 'creators/alice/followers']) {+ expect((await GET(new Request(`https://harness.example/api/community/${path}`), { params: Promise.resolve({ path: path.split('/') }) })).status, path).toBe(404);+ }+ });it('rejects arbitrary proxy destinations and oversized publications before forwarding', async () => {const fetcher = vi.fn(); vi.stubGlobal('fetch', fetcher);expect((await GET(new Request('https://harness.example/api/community/auth'), { params: Promise.resolve({ path: ['..', 'auth'] }) })).status).toBe(404);diff --git a/website/src/app/api/community/[...path]/route.ts b/website/src/app/api/community/[...path]/route.tsindex e4ce4d72b..aea0ac81a 100644--- a/website/src/app/api/community/[...path]/route.ts+++ b/website/src/app/api/community/[...path]/route.ts@@ -2,7 +2,17 @@ import { gzipType } from '@/lib/community/gzip';import { communityApiOrigin } from '@/lib/community/server';type Context = { params: Promise<{ path: string[] }> };-const allowed = /^(?:harnesses(?:\/[a-z0-9-]{1,80}(?:\/like|\/social|\/comments(?:\/[a-f0-9-]{36})?)?)?|creators\/[a-z0-9-]{1,80}\/follow|translate)$/;+/**+ * The backend's community routes a browser may reach (`backend/src/routes/community*.ts`); anything+ * else is answered here. A route added there needs its path here too, or the Hub's page for it fails.+ */+const allowed = new RegExp(`^(?:${[+ String.raw`harnesses(?:/[a-z0-9-]{1,80}(?:/like|/social|/comments(?:/[a-f0-9-]{36})?)?)?`,+ String.raw`creators/[a-z0-9-]{1,80}(?:/follow)?`,+ String.raw`notifications(?:/unread|/read)?`,+ String.raw`reports(?:/review)?`,+ 'translate',+].join('|')})$`);/** A translation asks the model several times over (the backend gives it 50 seconds); every other request answers within the usual wait. */const waitMs = (path: string) => path === 'translate' ? 58_000 : 12_000;const coverPath = /^harnesses\/[a-f0-9-]{36}\/cover$/;diff --git a/website/src/app/hub/community.module.css b/website/src/app/hub/community.module.cssindex 9cfe22f31..15e1d7ad0 100644--- a/website/src/app/hub/community.module.css+++ b/website/src/app/hub/community.module.css@@ -55,10 +55,10 @@.follow{text-decoration:underline;text-underline-offset:3px}/* The reader's actions: one row of quiet 36px buttons that tint on hover and stay tinted while their panel is open, ending in Fork. */.actions{display:flex;align-items:center;gap:4px;margin-left:auto;flex-shrink:0}-.actions>button,.actions>a{display:inline-flex;align-items:center;gap:7px;height:36px;padding:0 11px;border-radius:8px;white-space:nowrap;font-size:13px;color:#555;transition:background-color .15s,color .15s}-.actions>button:hover:not(:disabled),.actions>a:hover{background:#f4f4f2;color:#242424}-.actions>button[aria-pressed=true]{background:#efefec;color:#242424}-.actions>button:focus-visible,.actions>a:focus-visible,.actions .primary:focus-visible{outline:2px solid #242424;outline-offset:2px}+.actions>button,.actions>a,.actions .actionButton{display:inline-flex;align-items:center;gap:7px;height:36px;padding:0 11px;border-radius:8px;white-space:nowrap;font-size:13px;color:#555;transition:background-color .15s,color .15s}+.actions>button:hover:not(:disabled),.actions>a:hover,.actions .actionButton:hover{background:#f4f4f2;color:#242424}+.actions>button[aria-pressed=true],.actions .actionButton[aria-pressed=true]{background:#efefec;color:#242424}+.actions>button:focus-visible,.actions>a:focus-visible,.actions .actionButton:focus-visible,.actions .primary:focus-visible{outline:2px solid #242424;outline-offset:2px}.actions svg{width:16px;height:16px}.actions .handoff{margin-left:8px}.page .actions .primary{height:36px;padding:0 18px;border-radius:8px;transition:background-color .15s}@@ -205,7 +205,7 @@/* Phones: the chips run to the screen's left edge (the gutter is 4vw), and the order shrinks to fit beside them. */@media(max-width:760px){.filters{gap:10px;margin:0 0 24px}.chipsWrap{margin-left:-4vw}.chips{padding-left:4vw;scroll-padding-left:4vw}.chipArrowLeft{left:2vw}.sort span{padding:4px 10px;font-size:12px}.forks{margin-top:50px}}/* Small phones: Files and Share keep their icon; their names stay for screen readers. */-@media(max-width:480px){.actions>button,.actions>a{padding:0 9px}.actionLabel{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}}+@media(max-width:480px){.actions>button,.actions>a,.actions .actionButton{padding:0 9px}.actionLabel{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}}.byline a,.byline button{display:inline-flex;align-items:center}@media(max-width:760px){.chat{scroll-margin-top:104px}}.authorLink:hover{text-decoration:underline}diff --git a/website/src/app/hub/components/DetailHead.tsx b/website/src/app/hub/components/DetailHead.tsxindex bdb2ef22d..31b4bfad8 100644--- a/website/src/app/hub/components/DetailHead.tsx+++ b/website/src/app/hub/components/DetailHead.tsx@@ -5,7 +5,7 @@ import { commentTotal } from '@/lib/community/comments';import type { OpenHarness, SocialState } from '@/lib/community/types';import { ForkButton } from './ForkButton';import { ForkedFrom } from './ForkedFrom';-import { ShareButton } from './ShareButton';+import { ShareMenu } from './ShareMenu';import styles from '../community.module.css';/** What the side of a harness page shows beside its output. */@@ -29,7 +29,7 @@ export function DetailHead({ harness, social, ready, busy, panel, onFollow, onLi<button className={social.liked ? styles.liked : ''} disabled={busy} aria-label={social.liked ? 'Unlike harness' : 'Like harness'} aria-pressed={social.liked} onClick={onLike}><Heart /><span>{ready ? social.likes : 'Like'}</span></button><button aria-label="Comments" aria-pressed={panel === 'comments'} onClick={() => onPanel('comments')}><MessageCircle /><span>{ready ? commentTotal(social) : 'Comments'}</span></button><button aria-label="Source files" aria-pressed={panel === 'files'} onClick={() => onPanel('files')}><FileCode2 /><span className={styles.actionLabel}>Files</span></button>- <ShareButton harness={harness} />+ <ShareMenu harness={harness} />{social.mine && <Link href={`/hub/publish?edit=${harness.id}`}><Pencil /><span>Edit</span></Link>}{/* Not your own, and not a starter: those are the Hub's. */}{!social.mine && !harness.example && <button aria-label="Report harness" onClick={onReport}><Flag /><span className={styles.actionLabel}>Report</span></button>}diff --git a/website/src/app/hub/components/ShareButton.tsx b/website/src/app/hub/components/ShareButton.tsxdeleted file mode 100644index e186cbea0..000000000--- a/website/src/app/hub/components/ShareButton.tsx+++ /dev/null@@ -1,44 +0,0 @@-'use client';-import { useEffect, useState, useSyncExternalStore } from 'react';-import { Check, Link2 } from 'lucide-react';-import { harnessPath } from '@/lib/community/slug';-import styles from '../community.module.css';--type Copy = 'idle' | 'copied' | 'failed';-const labels: Record<Copy, string> = { idle: 'Share', copied: 'Link copied', failed: 'Copy failed' };--const touch = '(pointer: coarse)';-const onPointerChange = (notify: () => void) => {- const query = window.matchMedia?.(touch);- query?.addEventListener('change', notify);- return () => query?.removeEventListener('change', notify);-};-/**- * A touch screen with a share sheet uses it. A mouse copies the link, even where the browser has a- * sheet too (Safari and Chrome on a Mac): the Hub's web is mouse-first. The server draws the copy.- */-function useShareSheet() {- return useSyncExternalStore(onPointerChange, () => typeof navigator.share === 'function' && !!window.matchMedia?.(touch).matches, () => false);-}--/** Shares the harness's address: the phone's sheet, or a copied link that says so for two seconds. */-export function ShareButton({ harness }: { harness: { id: string; title: string } }) {- const [copy, setCopy] = useState<Copy>('idle'), sheet = useShareSheet();- useEffect(() => {- if (copy === 'idle') return;- const timer = setTimeout(() => setCopy('idle'), 2000);- return () => clearTimeout(timer);- }, [copy]);- async function share() {- const url = `${window.location.origin}${harnessPath(harness)}`, title = harness.title;- if (sheet) {- // A sheet closed without choosing anything is not a failure to report.- await navigator.share({ title, url }).catch(() => undefined);- return;- }- try { await navigator.clipboard.writeText(url); setCopy('copied'); } catch { setCopy('failed'); }- }- return <button type="button" aria-label={sheet ? 'Share this harness' : 'Copy link to this harness'} onClick={() => void share()}>- {copy === 'copied' ? <Check /> : <Link2 />}<span className={styles.actionLabel} aria-live="polite">{labels[copy]}</span>- </button>;-}diff --git a/website/src/app/hub/components/ShareMenu.tsx b/website/src/app/hub/components/ShareMenu.tsxnew file mode 100644index 000000000..7e8c5c424--- /dev/null+++ b/website/src/app/hub/components/ShareMenu.tsx@@ -0,0 +1,54 @@+'use client';+import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';+import { Check, Link2, Share2 } from 'lucide-react';+import { harnessPath } from '@/lib/community/slug';+import { shareNetworks, shareUrl } from '@/lib/community/share';+import { SocialIcon } from './SocialIcons';+import { useDismiss } from './useDismiss';+import community from '../community.module.css';+import styles from './share.module.css';++type Copy = 'idle' | 'copied' | 'failed';+const copyLabels: Record<Copy, string> = { idle: 'Copy link', copied: 'Link copied', failed: 'Copy failed' };++const noChange = () => () => {};+/** Whether this browser has a share sheet of its own; the server draws the menu without it. */+const useShareSheet = () => useSyncExternalStore(noChange, () => typeof navigator.share === 'function', () => false);++/** The copied link says so for two seconds, then the menu closes. */+function useCopy(onDone: () => void) {+ const [copy, setCopy] = useState<Copy>('idle');+ useEffect(() => {+ if (copy === 'idle') return;+ const timer = setTimeout(() => { setCopy('idle'); if (copy === 'copied') onDone(); }, copy === 'copied' ? 1200 : 2000);+ return () => clearTimeout(timer);+ }, [copy, onDone]);+ const copyText = (text: string) => navigator.clipboard.writeText(text).then(() => setCopy('copied'), () => setCopy('failed'));+ return { copy, copyText };+}++/** Share opens a menu: copy the harness's address, post it to X, Facebook or LinkedIn, or use the device's own sheet. */+export function ShareMenu({ harness }: { harness: { id: string; title: string } }) {+ const [open, setOpen] = useState(false), root = useRef<HTMLSpanElement>(null), sheet = useShareSheet();+ const close = useCallback(() => setOpen(false), []);+ const { copy, copyText } = useCopy(close);+ useDismiss(root, open, close);+ const url = () => `${window.location.origin}${harnessPath(harness)}`;+ // A sheet closed without choosing anything is not a failure to report.+ const openSheet = () => { close(); void navigator.share({ title: harness.title, url: url() }).catch(() => undefined); };+ return <span ref={root} className={styles.share}>+ <button type="button" className={community.actionButton} aria-haspopup="menu" aria-expanded={open} aria-pressed={open} onClick={() => setOpen(value => !value)}>+ <Link2 /><span className={community.actionLabel}>Share</span>+ </button>+ {open && <div className={styles.menu} role="menu" aria-label="Share this harness">+ <button type="button" role="menuitem" className={copy === 'copied' ? styles.done : ''} onClick={() => void copyText(url())}>+ {copy === 'copied' ? <Check /> : <Link2 />}<span aria-live="polite">{copyLabels[copy]}</span>+ </button>+ <hr />+ {shareNetworks.map(network => <a key={network.id} role="menuitem" href={shareUrl(network.id, url(), harness.title)} target="_blank" rel="noopener noreferrer" onClick={close}>+ <SocialIcon network={network.id} /><span>{network.label}</span>+ </a>)}+ {sheet && <><hr /><button type="button" role="menuitem" onClick={openSheet}><Share2 /><span>More options…</span></button></>}+ </div>}+ </span>;+}diff --git a/website/src/app/hub/components/SocialIcons.tsx b/website/src/app/hub/components/SocialIcons.tsxnew file mode 100644index 000000000..12c95f4f3--- /dev/null+++ b/website/src/app/hub/components/SocialIcons.tsx@@ -0,0 +1,12 @@+import type { ShareNetwork } from '@/lib/community/share';++/** The networks' own marks (Simple Icons, CC0), filled with the text colour like the Hub's other icons. */+const paths: Record<ShareNetwork, string> = {+ x: 'M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z',+ facebook: 'M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036 26.805 26.805 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.686 1.686 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647Z',+ linkedin: 'M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z',+};++export function SocialIcon({ network }: { network: ShareNetwork }) {+ return <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden><path d={paths[network]} /></svg>;+}diff --git a/website/src/app/hub/components/community.spec.tsx b/website/src/app/hub/components/community.spec.tsxindex 451867222..12b720c22 100644--- a/website/src/app/hub/components/community.spec.tsx+++ b/website/src/app/hub/components/community.spec.tsx@@ -129,15 +129,20 @@ describe('community navigation', () => {it('reads a page opened at its slug, then names the publication by its id and shows its own address', async () => {const id = '0f8fad5b-d9cb-469f-a165-70867728950e', slug = 'an-older-title-0f8fad5b';window.history.replaceState(null, '', `/hub/${slug}?comments=1`);- request.mockResolvedValueOnce({ harness: { ...sample, id, example: false }, social: { ...emptySocial, signedIn: true } });- render(<Detail id={slug} initial={null} />);- await screen.findByTitle('Orbit output');- expect(request).toHaveBeenCalledWith(`harnesses/${slug}?files=viewer`);- expect(window.location.pathname + window.location.search).toBe('/hub/orbit-0f8fad5b?comments=1');- request.mockResolvedValueOnce({ liked: true, likes: 1 });- fireEvent.click(screen.getByRole('button', { name: 'Like harness' }));- await waitFor(() => expect(request).toHaveBeenLastCalledWith(`harnesses/${id}/like`, expect.anything()));- window.history.replaceState(null, '', '/');+ try {+ request.mockResolvedValueOnce({ harness: { ...sample, id, example: false }, social: { ...emptySocial, signedIn: true } });+ render(<Detail id={slug} initial={null} />);+ await screen.findByTitle('Orbit output');+ expect(request).toHaveBeenCalledWith(`harnesses/${slug}?files=viewer`);+ // The address moves in an effect after the page draws.+ await waitFor(() => expect(window.location.pathname + window.location.search).toBe('/hub/orbit-0f8fad5b?comments=1'));+ request.mockResolvedValueOnce({ liked: true, likes: 1 });+ fireEvent.click(screen.getByRole('button', { name: 'Like harness' }));+ await waitFor(() => expect(request).toHaveBeenLastCalledWith(`harnesses/${id}/like`, expect.anything()));+ } finally {+ // The next test reads the address: leave none behind, passed or failed.+ window.history.replaceState(null, '', '/');+ }});it('says so when a drawn page cannot load its likes and actions, and retries', async () => {const id = '0f8fad5b-d9cb-469f-a165-70867728950e';@@ -282,14 +287,25 @@ describe('community navigation', () => {expect(screen.getByText('Make an orbit.')).toBeInTheDocument();fetcher.mockRestore();});- it('copies the harness link', async () => {+ it('shares from a menu: the link copied, or a network’s own share page', async () => {request.mockResolvedValue({ harness: null, social: emptySocial });const writeText = vi.fn(async () => {});Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });render(<Detail id={sample.id} initial={sample} />);- fireEvent.click(screen.getByRole('button', { name: 'Copy link to this harness' }));+ const share = screen.getByRole('button', { name: 'Share' });+ fireEvent.click(share);+ expect(share).toHaveAttribute('aria-expanded', 'true');+ const link = encodeURIComponent(`${window.location.origin}/hub/starter-orbit`);+ expect(screen.getByRole('menuitem', { name: 'Share on X' })).toHaveAttribute('href', `https://x.com/intent/tweet?text=Orbit&url=${link}`);+ expect(screen.getByRole('menuitem', { name: 'Share on Facebook' })).toHaveAttribute('href', `https://www.facebook.com/sharer/sharer.php?u=${link}`);+ expect(screen.getByRole('menuitem', { name: 'Share on LinkedIn' })).toHaveAttribute('target', '_blank');+ // No share sheet in this browser: nothing offers one.+ expect(screen.queryByRole('menuitem', { name: 'More options…' })).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole('menuitem', { name: 'Copy link' }));await screen.findByText('Link copied');expect(writeText).toHaveBeenCalledWith(`${window.location.origin}/hub/starter-orbit`);+ fireEvent.keyDown(document, { key: 'Escape' });+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();});it('draws the page the server read at once, then reads it again with the reader’s sign-in', async () => {let answer: (page: unknown) => void = () => {};@@ -419,17 +435,18 @@ describe('community navigation', () => {expect(screen.getByRole('link', { name: /Di commented on Lamp/ })).toHaveAttribute('href', '/hub/lamp-h2?comments=1');await waitFor(() => expect(request).toHaveBeenCalledWith('notifications/read', { method: 'POST' }));});- it('opens a touch screen’s share sheet instead of copying', async () => {+ it('offers the device’s own share sheet in the menu where there is one, and closes on a click outside', async () => {request.mockResolvedValue({ harness: null, social: emptySocial });- const share = vi.fn(async () => {}), writeText = vi.fn(async () => {});+ const share = vi.fn(async () => {});Object.defineProperty(navigator, 'share', { value: share, configurable: true });- Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });- Object.defineProperty(window, 'matchMedia', { configurable: true, value: (query: string) => ({ matches: query === '(pointer: coarse)', addEventListener: vi.fn(), removeEventListener: vi.fn() }) });render(<Detail id={sample.id} initial={sample} />);- fireEvent.click(screen.getByRole('button', { name: 'Share this harness' }));+ fireEvent.click(screen.getByRole('button', { name: 'Share' }));+ fireEvent.click(screen.getByRole('menuitem', { name: 'More options…' }));await waitFor(() => expect(share).toHaveBeenCalledWith({ title: 'Orbit', url: `${window.location.origin}/hub/starter-orbit` }));- expect(writeText).not.toHaveBeenCalled();- Object.defineProperty(window, 'matchMedia', { configurable: true, value: undefined });+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Share' }));+ fireEvent.pointerDown(document.body);+ expect(screen.queryByRole('menu')).not.toBeInTheDocument();Object.defineProperty(navigator, 'share', { value: undefined, configurable: true });});});diff --git a/website/src/app/hub/components/share.module.css b/website/src/app/hub/components/share.module.cssnew file mode 100644index 000000000..16b29026a--- /dev/null+++ b/website/src/app/hub/components/share.module.css@@ -0,0 +1,11 @@+/* Share's menu: a glass card under the button, its rows the height of the actions beside it. */+.share{position:relative;display:inline-flex}+.menu{position:absolute;top:calc(100% + 8px);right:0;z-index:10;display:flex;flex-direction:column;min-width:228px;padding:6px;border-radius:14px;background:rgba(255,255,255,.93);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px);border:1px solid rgba(36,36,36,.08);box-shadow:0 12px 32px rgba(36,36,36,.12),0 2px 6px rgba(36,36,36,.05);animation:menuIn .16s ease-out;transform-origin:top right}+.share .menu>button,.share .menu>a{display:flex;align-items:center;gap:11px;width:100%;height:38px;padding:0 11px;border-radius:9px;font-size:13px;color:#333;text-align:left;white-space:nowrap;transition:background-color .12s}+.share .menu>button:hover,.share .menu>a:hover,.share .menu>button:focus-visible,.share .menu>a:focus-visible{background:rgba(36,36,36,.06);outline:0}+.menu svg{width:16px;height:16px;flex-shrink:0}+.menu hr{height:1px;margin:5px 6px;border:0;background:rgba(36,36,36,.08)}+.share .menu .done{color:#2f7a4f}+@keyframes menuIn{from{opacity:0;transform:translateY(-4px) scale(.98)}}+@media(prefers-reduced-motion:reduce){.menu{animation:none}}+@media(max-width:480px){.menu{right:auto;left:50%;translate:-50% 0;transform-origin:top center}}diff --git a/website/src/app/hub/components/useDismiss.ts b/website/src/app/hub/components/useDismiss.tsnew file mode 100644index 000000000..7dc538c0b--- /dev/null+++ b/website/src/app/hub/components/useDismiss.ts@@ -0,0 +1,14 @@+'use client';+import { useEffect, type RefObject } from 'react';++/** Closes something open (a menu, a popover) when the reader clicks outside `ref` or presses Escape. */+export function useDismiss(ref: RefObject<HTMLElement | null>, open: boolean, onClose: () => void) {+ useEffect(() => {+ if (!open) return;+ const outside = (event: PointerEvent) => { if (!ref.current?.contains(event.target as Node)) onClose(); };+ const escape = (event: KeyboardEvent) => { if (event.key === 'Escape') onClose(); };+ document.addEventListener('pointerdown', outside);+ document.addEventListener('keydown', escape);+ return () => { document.removeEventListener('pointerdown', outside); document.removeEventListener('keydown', escape); };+ }, [ref, open, onClose]);+}diff --git a/website/src/app/hub/components/useUnread.ts b/website/src/app/hub/components/useUnread.tsindex 21e5b623a..764bcb62f 100644--- a/website/src/app/hub/components/useUnread.ts+++ b/website/src/app/hub/components/useUnread.ts@@ -1,17 +1,23 @@'use client';import { useEffect, useState } from 'react';-import { readUnread } from '@/lib/community/notifications';+import { notificationsReadEvent, readUnread } from '@/lib/community/notifications';-/** How many of the reader's notifications are unread: read when signed in, again on returning to the tab. */+/** How many of the reader's notifications are unread: read when signed in, again on returning to the tab, and none once their page marks them read. */export function useUnread(signedIn: boolean | null): number {const [unread, setUnread] = useState(0);useEffect(() => {if (!signedIn) return;- let live = true;- const update = () => { readUnread().then(count => { if (live) setUnread(count); }, () => { /* The bell stays as it was. */ }); };+ // A read that started before the page marked them read must not bring the count back.+ let live = true, generation = 0;+ const update = () => {+ const current = ++generation;+ readUnread().then(count => { if (live && current === generation) setUnread(count); }, () => { /* The bell stays as it was. */ });+ };+ const clear = () => { generation++; setUnread(0); };update();window.addEventListener('focus', update);- return () => { live = false; window.removeEventListener('focus', update); };+ window.addEventListener(notificationsReadEvent, clear);+ return () => { live = false; window.removeEventListener('focus', update); window.removeEventListener(notificationsReadEvent, clear); };}, [signedIn]);return signedIn ? unread : 0;}diff --git a/website/src/app/hub/notifications/NotificationRow.tsx b/website/src/app/hub/notifications/NotificationRow.tsxnew file mode 100644index 000000000..8e55076c7--- /dev/null+++ b/website/src/app/hub/notifications/NotificationRow.tsx@@ -0,0 +1,22 @@+import Link from 'next/link';+import { GitFork, MessageCircle, Reply, type LucideIcon } from 'lucide-react';+import { describeNotification, type HubNotification } from '@/lib/community/notifications';+import { timeAgo } from '@/lib/community/time';+import styles from './notifications.module.css';++const icons: Record<HubNotification['kind'], LucideIcon> = { comment: MessageCircle, reply: Reply, fork: GitFork };++/** One notification: who (their initial, with what they did as a badge), the sentence, and when. */+export function NotificationRow({ item, now }: { item: HubNotification; now: Date }) {+ const { text, verb, href } = describeNotification(item), Icon = icons[item.kind];+ return <li><Link href={href} className={`${styles.row} ${item.read ? '' : styles.unread}`} aria-label={`${text}${item.read ? '' : ', new'}`}>+ <span className={styles.avatar} aria-hidden>{item.actorName.trim().charAt(0).toUpperCase() || '?'}<span className={styles.kind}><Icon /></span></span>+ <span className={styles.text}><strong>{item.actorName}</strong> {verb} <strong>{item.harnessTitle}</strong></span>+ <time className={styles.time} dateTime={item.createdAt} title={new Date(item.createdAt).toLocaleString()}>{timeAgo(item.createdAt, now)}</time>+ </Link></li>;+}++/** Rows in the shape of the list while it loads, so it does not jump when it lands. */+export function NotificationSkeleton() {+ return <ul className={styles.list} aria-hidden>{[0, 1, 2, 3].map(index => <li key={index} className={styles.skeleton}><span /><span /></li>)}</ul>;+}diff --git a/website/src/app/hub/notifications/notifications.module.css b/website/src/app/hub/notifications/notifications.module.cssnew file mode 100644index 000000000..247c20ba9--- /dev/null+++ b/website/src/app/hub/notifications/notifications.module.css@@ -0,0 +1,38 @@+/* The notifications page: the header's width, a quiet list of who did what to your work. */+.inbox{padding:40px 0 100px}+.head{margin-bottom:26px}+.head h1{font-size:30px;font-weight:400;letter-spacing:-.8px;line-height:1.15}+.head p{margin-top:6px;font-size:13px;color:#888}++.list{list-style:none;margin:0;padding:6px;border:1px solid #efefed;border-radius:16px;background:#fff;box-shadow:0 1px 2px rgba(36,36,36,.03)}+.row{position:relative;display:grid;grid-template-columns:40px minmax(0,1fr) auto;align-items:center;gap:14px;padding:12px 14px;border-radius:11px;font-size:14px;line-height:1.45;color:#555;transition:background-color .15s}+.row:hover{background:#f7f7f5}+.row:focus-visible{outline:2px solid #242424;outline-offset:-2px}+.row strong{font-weight:600;color:#242424}+.unread{background:#fafaf8}+.unread::after{content:'';position:absolute;top:50%;right:6px;width:6px;height:6px;margin-top:-3px;border-radius:50%;background:#a4483f}+.unread .time{color:#242424}++.avatar{position:relative;display:inline-flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:50%;background:#f1f0ed;color:#555;font-size:15px;font-weight:600}+.kind{position:absolute;right:-3px;bottom:-3px;display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:50%;background:#242424;color:#fff;box-shadow:0 0 0 2px #fff}+.kind svg{width:11px;height:11px}+.text{min-width:0;overflow-wrap:anywhere}+.time{font-size:12px;color:#999;white-space:nowrap;padding-right:8px}++.skeleton{display:grid;grid-template-columns:40px 1fr;gap:14px;align-items:center;padding:12px 14px}+.skeleton span{height:12px;border-radius:6px;background:linear-gradient(100deg,#efeeeb 40%,#f7f6f3 50%,#efeeeb 60%) 0 0/200% 100%;animation:shimmer 1.4s linear infinite}+.skeleton span:first-child{width:40px;height:40px;border-radius:50%}+.skeleton:nth-child(even) span:last-child{width:72%}+@keyframes shimmer{to{background-position:-200% 0}}++.placeholder{display:flex;flex-direction:column;align-items:center;text-align:center;gap:10px;padding:56px 24px;border:1px solid #efefed;border-radius:16px;background:linear-gradient(180deg,#fafaf8,#fff)}+.placeholder h2{font-size:17px;font-weight:600;color:#242424}+.placeholder p{max-width:340px;margin:0;font-size:13px;line-height:1.6;color:#777}+.placeholderIcon{display:inline-flex;align-items:center;justify-content:center;width:52px;height:52px;margin-bottom:4px;border-radius:50%;background:rgba(255,255,255,.7);border:1px solid #ecebe8;box-shadow:0 6px 18px rgba(36,36,36,.06);color:#777}+.placeholderIcon svg{width:22px;height:22px}+.placeholder .retry{margin-top:6px;height:36px;padding:0 18px;border-radius:8px;background:#242424;color:#fff;font-size:13px}+.placeholder .retry:hover{background:#000}++@media(max-width:760px){.inbox{padding-top:24px}.head h1{font-size:26px}}+@media(max-width:480px){.list{padding:4px;border-radius:14px}.row{grid-template-columns:36px minmax(0,1fr);gap:12px;padding:12px 10px}.avatar{width:36px;height:36px;font-size:14px}.time{grid-column:2;padding:0;margin-top:-6px}.placeholder{padding:40px 18px}}+@media(prefers-reduced-motion:reduce){.skeleton span{animation:none}.row{transition:none}}diff --git a/website/src/app/hub/notifications/page.tsx b/website/src/app/hub/notifications/page.tsxindex 5a5d46d2d..11a1be44b 100644--- a/website/src/app/hub/notifications/page.tsx+++ b/website/src/app/hub/notifications/page.tsx@@ -1,37 +1,35 @@'use client';-import { useEffect, useState } from 'react';+import type { ReactNode } from 'react';import Link from 'next/link';-import { CommunityError } from '@/lib/community/client';-import { describeNotification, markNotificationsRead, readNotifications, type HubNotification } from '@/lib/community/notifications';+import { Bell } from 'lucide-react';import { Header, SignIn } from '../components/Header';-import styles from '../community.module.css';+import { NotificationRow, NotificationSkeleton } from './NotificationRow';+import { useNotifications, type NotificationsState } from './useNotifications';+import community from '../community.module.css';+import styles from './notifications.module.css';-const day = (createdAt: string) => new Date(createdAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });+const subtitle = (state: NotificationsState) => state.status !== 'ready' || !state.items.length ? 'Comments, replies and forks of your work.'+ : state.unread ? `${state.unread} new` : 'You’re all caught up.';-/** The reader's notifications, latest first; opening the page marks them read (what was new stays bold here). */+/** A message in place of the list: no notifications yet, signed out, or a failed read. */+function Placeholder({ title, children }: { title: string; children: ReactNode }) {+ return <div className={styles.placeholder}><span className={styles.placeholderIcon} aria-hidden><Bell /></span><h2>{title}</h2>{children}</div>;+}++function Body({ state, retry }: ReturnType<typeof useNotifications>) {+ if (state.status === 'loading') return <NotificationSkeleton />;+ if (state.status === 'signedOut') return <Placeholder title="Sign in to see your notifications"><SignIn action="see your notifications" /></Placeholder>;+ if (state.status === 'failed') return <Placeholder title="Your notifications could not be loaded"><p role="alert">Check your connection and try again.</p><button type="button" className={styles.retry} onClick={retry}>Try again</button></Placeholder>;+ if (!state.items.length) return <Placeholder title="No notifications yet"><p>When someone comments on, replies to or forks your work, you’ll see it here.</p><Link className={community.textLink} href="/hub">Explore the Hub</Link></Placeholder>;+ const now = new Date();+ return <ul className={styles.list}>{state.items.map(item => <NotificationRow key={item.id} item={item} now={now} />)}</ul>;+}++/** The reader's notifications, latest first. */export default function NotificationsPage() {- const [items, setItems] = useState<HubNotification[] | null>(null), [signedOut, setSignedOut] = useState(false), [error, setError] = useState('');- useEffect(() => {- let live = true;- readNotifications().then(({ notifications, unread }) => {- if (!live) return;- setItems(notifications);- if (unread) void markNotificationsRead().catch(() => { /* They stay unread for next time. */ });- }, (e: unknown) => {- if (!live) return;- if (e instanceof CommunityError && e.status === 401) setSignedOut(true);- else setError('Your notifications could not be loaded.');- });- return () => { live = false; };- }, []);- return <><Header /><main className={`${styles.wrap} ${styles.publish}`}>- <h1>Notifications</h1>- {signedOut && <SignIn action="see your notifications" />}- {error && <p className={styles.error} role="alert">{error}</p>}- {items && !items.length && <p className={styles.notice}>When someone comments on, replies to or forks your work, you will see it here.</p>}- {items?.map(item => {- const { text, href } = describeNotification(item);- return <Link key={item.id} href={href} className={`${styles.notification} ${item.read ? '' : styles.unread}`}><span>{text}</span><small>{day(item.createdAt)}</small></Link>;- })}+ const notifications = useNotifications();+ return <><Header /><main className={`${community.wrap} ${styles.inbox}`}>+ <header className={styles.head}><h1>Notifications</h1><p>{subtitle(notifications.state)}</p></header>+ <Body {...notifications} /></main></>;}diff --git a/website/src/app/hub/notifications/useNotifications.ts b/website/src/app/hub/notifications/useNotifications.tsnew file mode 100644index 000000000..9792003be--- /dev/null+++ b/website/src/app/hub/notifications/useNotifications.ts@@ -0,0 +1,38 @@+'use client';+import { useCallback, useEffect, useRef, useState } from 'react';+import { CommunityError } from '@/lib/community/client';+import { markNotificationsRead, notificationsReadEvent, readNotifications, type HubNotification } from '@/lib/community/notifications';++export type NotificationsState =+ | { status: 'loading' } | { status: 'signedOut' } | { status: 'failed' }+ | { status: 'ready'; items: HubNotification[]; unread: number };++/**+ * The reader's notifications, latest first. Opening them marks them read on the Hub and clears the+ * bell; the ones that were new stay marked as new on this page until it is left.+ */+export function useNotifications() {+ const [state, setState] = useState<NotificationsState>({ status: 'loading' });+ const live = useRef(true);+ const load = useCallback(async () => {+ setState({ status: 'loading' });+ try {+ const { notifications, unread } = await readNotifications();+ if (!live.current) return;+ setState({ status: 'ready', items: notifications, unread });+ if (!unread) return;+ await markNotificationsRead();+ window.dispatchEvent(new Event(notificationsReadEvent));+ } catch (e) {+ if (!live.current) return;+ // Marking them read can fail after they are drawn: they stay unread for next time.+ setState(current => current.status === 'ready' ? current : { status: e instanceof CommunityError && e.status === 401 ? 'signedOut' : 'failed' });+ }+ }, []);+ useEffect(() => {+ live.current = true;+ void load();+ return () => { live.current = false; };+ }, [load]);+ return { state, retry: () => void load() };+}diff --git a/website/src/lib/community/notifications.ts b/website/src/lib/community/notifications.tsindex 5d814aa14..0bacf17de 100644--- a/website/src/lib/community/notifications.ts+++ b/website/src/lib/community/notifications.ts@@ -11,9 +11,14 @@ export const readNotifications = () => communityRequest<{ notifications: HubNotiexport const readUnread = async () => (await communityRequest<{ unread: number }>('notifications/unread')).unread;export const markNotificationsRead = () => communityRequest('notifications/read', { method: 'POST' });-/** What a notification says, and where it leads: the comments it is about, or the fork. */-export function describeNotification({ kind, actorName, harnessTitle, harnessId, targetId }: HubNotification): { text: string; href: string } {- if (kind === 'fork') return { text: `${actorName} forked ${harnessTitle}`, href: `/hub/${targetId}` };- const text = kind === 'reply' ? `${actorName} replied to your comment on ${harnessTitle}` : `${actorName} commented on ${harnessTitle}`;- return { text, href: `${harnessPath({ id: harnessId, title: harnessTitle })}?comments=1` };+const verbs: Record<HubNotification['kind'], string> = { comment: 'commented on', reply: 'replied to your comment on', fork: 'forked' };++/** What a notification says (who, what they did, to which harness), and where it leads: the comments it is about, or the fork. */+export function describeNotification({ kind, actorName, harnessTitle, harnessId, targetId }: HubNotification): { text: string; verb: string; href: string } {+ const verb = verbs[kind], text = `${actorName} ${verb} ${harnessTitle}`;+ if (kind === 'fork') return { text, verb, href: `/hub/${targetId}` };+ return { text, verb, href: `${harnessPath({ id: harnessId, title: harnessTitle })}?comments=1` };}++/** Said when the notifications page marks them read, so the bell clears without waiting for the next read. */+export const notificationsReadEvent = 'hub:notifications-read';diff --git a/website/src/lib/community/share.spec.ts b/website/src/lib/community/share.spec.tsnew file mode 100644index 000000000..f77349d23--- /dev/null+++ b/website/src/lib/community/share.spec.ts@@ -0,0 +1,14 @@+import { describe, expect, it } from 'vitest';+import { shareUrl } from './share';++describe('share links', () => {+ const url = 'https://harness.autonomous.ai/hub/pac-man-neon-maze-chase-fb726d28', title = 'PAC-MAN: Neon Maze Chase';+ it('opens each network’s share page with the harness address in it', () => {+ expect(shareUrl('x', url, title)).toBe('https://x.com/intent/tweet?text=PAC-MAN%3A%20Neon%20Maze%20Chase&url=https%3A%2F%2Fharness.autonomous.ai%2Fhub%2Fpac-man-neon-maze-chase-fb726d28');+ expect(shareUrl('facebook', url, title)).toBe('https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fharness.autonomous.ai%2Fhub%2Fpac-man-neon-maze-chase-fb726d28');+ expect(shareUrl('linkedin', url, title)).toBe('https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fharness.autonomous.ai%2Fhub%2Fpac-man-neon-maze-chase-fb726d28');+ });+ it('keeps a title’s own characters out of the address', () => {+ expect(shareUrl('x', url, 'Rock & roll #1?')).toContain('text=Rock%20%26%20roll%20%231%3F&url=');+ });+});diff --git a/website/src/lib/community/share.ts b/website/src/lib/community/share.tsnew file mode 100644index 000000000..5e79cb2ae--- /dev/null+++ b/website/src/lib/community/share.ts@@ -0,0 +1,16 @@+/** Where a harness can be shared, each a page that network opens with the link already in it. */+export type ShareNetwork = 'x' | 'facebook' | 'linkedin';++export const shareNetworks: { id: ShareNetwork; label: string }[] = [+ { id: 'x', label: 'Share on X' },+ { id: 'facebook', label: 'Share on Facebook' },+ { id: 'linkedin', label: 'Share on LinkedIn' },+];++/** The network's own share page for this address; X also takes the title as the post's words. */+export function shareUrl(network: ShareNetwork, url: string, title: string): string {+ const link = encodeURIComponent(url);+ if (network === 'x') return `https://x.com/intent/tweet?text=${encodeURIComponent(title)}&url=${link}`;+ if (network === 'facebook') return `https://www.facebook.com/sharer/sharer.php?u=${link}`;+ return `https://www.linkedin.com/sharing/share-offsite/?url=${link}`;+}diff --git a/website/src/lib/community/time.spec.ts b/website/src/lib/community/time.spec.tsnew file mode 100644index 000000000..fac152fa5--- /dev/null+++ b/website/src/lib/community/time.spec.ts@@ -0,0 +1,16 @@+import { describe, expect, it } from 'vitest';+import { timeAgo } from './time';++describe('timeAgo', () => {+ const now = new Date('2026-10-16T12:00:00Z');+ it('counts minutes, hours and days in the last week', () => {+ expect(timeAgo('2026-10-16T11:59:30Z', now)).toBe('now');+ expect(timeAgo('2026-10-16T11:55:00Z', now)).toBe('5m');+ expect(timeAgo('2026-10-16T09:00:00Z', now)).toBe('3h');+ expect(timeAgo('2026-10-14T12:00:00Z', now)).toBe('2d');+ });+ it('names the date past a week, and the year once it is another year', () => {+ expect(timeAgo('2026-10-04T12:00:00Z', now)).toBe('Oct 4');+ expect(timeAgo('2025-12-30T12:00:00Z', now)).toBe('Dec 30, 2025');+ });+});diff --git a/website/src/lib/community/time.ts b/website/src/lib/community/time.tsnew file mode 100644index 000000000..d1da2259d--- /dev/null+++ b/website/src/lib/community/time.ts@@ -0,0 +1,12 @@+const minute = 60_000, hour = 60 * minute, day = 24 * hour;++/** How long ago, as a feed says it: "now", "5m", "3h", "2d", then the date ("Oct 4"; with the year once it is another year's). */+export function timeAgo(at: string | Date, now: Date = new Date()): string {+ const then = new Date(at), elapsed = now.getTime() - then.getTime();+ if (elapsed < minute) return 'now';+ if (elapsed < hour) return `${Math.floor(elapsed / minute)}m`;+ if (elapsed < day) return `${Math.floor(elapsed / hour)}h`;+ if (elapsed < 7 * day) return `${Math.floor(elapsed / day)}d`;+ const year = then.getFullYear() === now.getFullYear() ? {} : { year: 'numeric' as const };+ return then.toLocaleDateString('en-US', { month: 'short', day: 'numeric', ...year });+}