Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,70 @@
# ── Dependencies ──────────────────────────────────────────────
node_modules/
.pnp
.pnp.js

# ── Build output ──────────────────────────────────────────────
dist/
build/
out/
.output/
apps/web/dist/
apps/*/dist/
packages/*/dist/

# ── Environment & secrets ──────────────────────────────────────
.env
.env.local
.env.*.local
# Keep the example safe:
!.env.example

# ── Database & data ────────────────────────────────────────────
data/*
!data/.gitkeep
.cache/

# ── Logs ──────────────────────────────────────────────────────
*.log
.DS_Store
apps/web/dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
logs/

# ── Cache & temp ──────────────────────────────────────────────
.cache/
.turbo/
.vite/
.swc/
*.tsbuildinfo
.eslintcache
.stylelintcache

# ── Test artefacts ────────────────────────────────────────────
playwright-report/
test-results/
coverage/
.nyc_output/

# ── Benchmark ─────────────────────────────────────────────────
.bench/

# ── OS cruft ──────────────────────────────────────────────────
.DS_Store
Thumbs.db
desktop.ini

# ── Editor / IDE ──────────────────────────────────────────────
.vscode/settings.json
.idea/
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# ── Misc ──────────────────────────────────────────────────────
*.pem
.vercel
.netlify
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,17 @@ SQLite via Node's built-in `node:sqlite` (no native module to compile). Four for
A **real MCP client** with a deterministic intent router (pay or buy, scam question, trust a payee, status, family decision). It fails closed on any error, signs family sessions with an HMAC cookie plus a CSRF header, streams live events over SSE, and forwards the trace id to the server. The demo is exactly this component driving the real server.

### Web app (`apps/web`)
React 19 and Vite, about 96 kB gzipped: the live demo screen and the Family Console. Accessible (axe-checked on every page), responsive down to phone width, live updates without reloads.
React 19 and Vite. The live demo screen and the Family Console, rebuilt with an **enterprise-grade design system**:

- **Design tokens** ([`tokens.css`](apps/web/src/styles/tokens.css)): a full CSS custom-property palette covering light and dark themes — refined slate surfaces for light mode, deep obsidian/navy for dark mode. WCAG AA-certified colour pairs for brand, status (ok/warn/danger/info), glass surfaces, elevation shadows, 8pt spacing grid, fluid font scale, and spring-curve transition tokens.
- **Typography**: [Plus Jakarta Sans](https://fonts.google.com/specimen/Plus+Jakarta+Sans) (variable 300–800) for UI text; [JetBrains Mono](https://www.jetbrains.com/lp/mono/) for trace output and PIN fields. Loaded via Google Fonts with `font-display: swap`.
- **Glassmorphism header** with `backdrop-filter: blur(16px)`, sticky positioning, and a live health-status pill (MCP server + SSE connection).
- **Micro-animations**: `bubble-enter` for chat messages, `risk-enter` for red-flag cards, `pulse-ring` for the active microphone button, `toast-in` for system notifications, `translateY` lift on card/button hover — all governed by `prefers-reduced-motion`.
- **Hardware simulations**: Echo Show device frame (with Alexa light-ring bar) and a smartphone frame (with a Dynamic Island pill) for the live demo.
- **Status badges** and **quorum segments** with glow effects.
- **Gradient progress bars**, animated bar fills (600 ms spring), and timeline nodes.
- **Fully responsive** down to 320 px; sidebar reflows to a horizontal scroll strip on mobile.
- Accessible (axe-checked on every page, every interactive element ≥ 44 px).

### Guard SDK (`packages/guard-sdk`) and merchant example
Any MCP tool that moves money can be guarded in a few lines. It checks first, holds when risky, blocks when the rules say so, and **refuses to run** if the guard cannot be reached. A held order runs only after a family approval, and never twice.
Expand Down Expand Up @@ -348,7 +358,7 @@ second-opinion/
apps/
mcp-server/ MCP server: tools, OAuth, MCP App card, HTTP guards, jobs, metrics
simulator/ Alexa+ stand-in: MCP client, intent router, family sessions, live events
web/ React app: live demo + Family Console
web/ React app: live demo + Family Console (enterprise design system)
packages/
shared/ Types, errors, ids, clock
engine/ Risk engine: rules, playbooks, behavior, fusion, versioned rule sets
Expand Down
2 changes: 1 addition & 1 deletion apps/simulator/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function createSimApp(deps: SimDeps) {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('Referrer-Policy', 'no-referrer');
res.setHeader('X-Frame-Options', 'DENY');
res.setHeader('Content-Security-Policy', "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'");
res.setHeader('Content-Security-Policy', "default-src 'self'; font-src 'self' data: https://fonts.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data:; frame-ancestors 'none'");
next();
});

Expand Down
5 changes: 4 additions & 1 deletion apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Second Opinion: a spoken second opinion and family approval before risky payments through Alexa+." />
<meta name="color-scheme" content="light dark" />
<title>Second Opinion</title>
<title>Second Opinion — Enterprise Payment Guard for Alexa+</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300..800;1,300..800&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet" />
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%232457d6'/%3E%3Cpath d='M16 6l8 3v6c0 5-3.4 8.6-8 11-4.6-2.4-8-6-8-11V9z' fill='white'/%3E%3C/svg%3E" />
</head>
<body>
Expand Down
177 changes: 156 additions & 21 deletions apps/web/src/components/ElderDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export interface Message {

export const HERO_TEXT = 'The bank says I have to buy five $200 gift cards today or my account is frozen.';

export const SCENARIOS: Array<{ label: string; text: string }> = [
{ label: 'Buy gift cards (a scam)', text: HERO_TEXT },
{ label: 'Pay the pharmacy $24', text: 'Pay Greenleaf Pharmacy $24' },
{ label: 'Is this text a scam?', text: 'I got a text saying my package is held and I must pay $2 to release it. Is this a scam?' },
{ label: 'Pay my neighbour $50', text: 'Send $50 to my neighbour' },
{ label: "What's pending?", text: "What's pending?" },
{ label: 'Try to approve it myself', text: 'approve it' },
export const SCENARIOS: Array<{ label: string; text: string; icon: string }> = [
{ label: 'Buy gift cards (a scam)', text: HERO_TEXT, icon: '🚨' },
{ label: 'Pay the pharmacy $24', text: 'Pay Greenleaf Pharmacy $24', icon: '💊' },
{ label: 'Is this text a scam?', text: 'I got a text saying my package is held and I must pay $2 to release it. Is this a scam?', icon: '📦' },
{ label: 'Pay my neighbour $50', text: 'Send $50 to my neighbour', icon: '🤝' },
{ label: "What's pending?", text: "What's pending?", icon: '📋' },
{ label: 'Try to approve it myself', text: 'approve it', icon: '🛡️' },
];

interface Props {
Expand All @@ -43,7 +43,9 @@ export function ElderDevice({ messages, onMessages, onHeld, readAloud }: Props)
const speech = useSpeech();
const end = useRef<HTMLDivElement>(null);

useEffect(() => { end.current?.scrollIntoView?.({ block: 'end' }); }, [messages.length]);
useEffect(() => {
end.current?.scrollIntoView?.({ block: 'end' });
}, [messages.length]);

async function send(t: string) {
const said = t.trim();
Expand Down Expand Up @@ -76,18 +78,106 @@ export function ElderDevice({ messages, onMessages, onHeld, readAloud }: Props)
return (
<section className="card device" aria-labelledby="elder-title">
<div className="device-head">
<span aria-hidden="true" style={{ fontSize: '1.4rem' }}>🔊</span>
<span
aria-hidden="true"
style={{
fontSize: '1.4rem',
width: 38,
height: 38,
borderRadius: '50%',
background: 'var(--brand-soft)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: 'var(--brand)',
boxShadow: '0 0 12px var(--brand-glow)',
}}
>
🔊
</span>
<div className="grow">
<h2 id="elder-title" style={{ margin: 0 }}>Dorothy's Echo</h2>
<span className="muted small">Simulated Alexa+ in the kitchen</span>
<div className="row" style={{ gap: 'var(--space-2)' }}>
<h2 id="elder-title" style={{ margin: 0, fontSize: 'var(--text-lg)' }}>
Dorothy's Echo
</h2>
<span
className="badge ok"
style={{ fontSize: '0.72rem', padding: '2px 8px' }}
>
Alexa+ Active
</span>
</div>
<span className="muted small">Simulated Alexa+ in the kitchen · Hands-free voice assistant</span>
</div>
<div className="row" aria-hidden="true" style={{ gap: 6, opacity: 0.7 }}>
<span style={{ fontSize: '0.85rem' }}>📶</span>
<span style={{ fontSize: '0.85rem' }}>🔋 100%</span>
</div>
</div>

{/* Voice Wave Visualizer Banner when active */}
{(speech.listening || busy) && (
<div
role="presentation"
aria-hidden="true"
style={{
background: 'linear-gradient(90deg, rgba(37,99,235,0.08) 0%, rgba(0,202,238,0.15) 50%, rgba(37,99,235,0.08) 100%)',
padding: '8px 16px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: 4,
borderBottom: '1px solid var(--border)',
}}
>
<span className="small" style={{ color: 'var(--brand)', fontWeight: 600, marginRight: 8 }}>
{speech.listening ? 'Listening to Dorothy…' : 'Alexa+ is checking with Second Opinion…'}
</span>
{[12, 24, 18, 30, 16, 22, 14].map((h, i) => (
<span
key={i}
style={{
width: 3,
height: h,
borderRadius: 2,
background: 'var(--brand)',
display: 'inline-block',
animation: `soundwave 0.8s ease-in-out infinite alternate ${i * 0.1}s`,
}}
/>
))}
<style>{`@keyframes soundwave { 0% { transform: scaleY(0.4); opacity: 0.5; } 100% { transform: scaleY(1.2); opacity: 1; } }`}</style>
</div>
)}

<div className="device-body caption-size" role="log" aria-live="polite" aria-label="Conversation">
{messages.length === 0 && <div className="bubble note">Press the microphone, type, or tap an example below.</div>}
{messages.length === 0 && (
<div className="bubble note" style={{ padding: 'var(--space-4)' }}>
<span aria-hidden="true" style={{ fontSize: '1.8rem', display: 'block', marginBottom: 8 }}>🎙️</span>
Press the microphone, type, or tap an example below.
</div>
)}
{messages.map((m) => (
<div key={m.id} style={{ display: 'grid' }}>
<div className={`bubble ${m.who}`}>{m.text}</div>
<div key={m.id} style={{ display: 'grid', gap: 'var(--space-2)' }}>
<div className={`bubble ${m.who}`}>
{m.who === 'bot' && (
<span
aria-hidden="true"
style={{
display: 'block',
fontSize: '0.78rem',
fontWeight: 700,
color: 'var(--brand)',
marginBottom: 4,
letterSpacing: '0.04em',
textTransform: 'uppercase',
}}
>
Alexa+ Response
</span>
)}
{m.text}
</div>
{m.card && m.card.level !== 'allow' && <RiskCard card={m.card} />}
</div>
))}
Expand All @@ -97,25 +187,70 @@ export function ElderDevice({ messages, onMessages, onHeld, readAloud }: Props)
<div className="device-foot">
<div className="chips" aria-label="Examples">
{SCENARIOS.map((s) => (
<button key={s.label} type="button" className="chip" disabled={busy} onClick={() => void send(s.text)}>{s.label}</button>
<button
key={s.label}
type="button"
className="chip"
disabled={busy}
onClick={() => void send(s.text)}
>
<span aria-hidden="true">{s.icon}</span>
{s.label}
</button>
))}
</div>
<form onSubmit={submit} className="row">
<form onSubmit={submit} className="row" style={{ gap: 'var(--space-2)' }}>
{speech.canListen && (
<button type="button" className="btn mic" aria-pressed={speech.listening} aria-label={speech.listening ? 'Stop listening' : 'Speak'} disabled={busy} onClick={() => speech.listen((t) => void send(t))}>
<button
type="button"
className="btn mic"
aria-pressed={speech.listening}
aria-label={speech.listening ? 'Stop listening' : 'Speak'}
disabled={busy}
onClick={() => speech.listen((t) => void send(t))}
>
🎤
</button>
)}
<label className="grow">
<label className="grow" style={{ minWidth: 0 }}>
<span className="sr-only">What do you want to say?</span>
<input value={text} onChange={(e) => setText(e.target.value)} placeholder="Type what Dorothy would say…" maxLength={2000} disabled={busy} />
<input
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="Type what Dorothy would say…"
maxLength={2000}
disabled={busy}
style={{
borderRadius: 'var(--radius-full)',
paddingLeft: '18px',
paddingRight: '18px',
}}
/>
</label>
<button type="submit" className="btn primary" disabled={busy || !text.trim()}>{busy ? 'Checking…' : 'Send'}</button>
<button
type="submit"
className="btn primary"
disabled={busy || !text.trim()}
style={{ borderRadius: 'var(--radius-full)', padding: '10px 22px' }}
>
{busy ? (
'Checking…'
) : (
<>
<span>Send</span>
<span aria-hidden="true">→</span>
</>
)}
</button>
</form>
{error && <ErrorNote message={error} />}
<details>
<summary>Developer trace: the real MCP calls</summary>
{lastTrace ? <TraceView trace={lastTrace.trace} traceId={lastTrace.traceId} /> : <p className="muted small">Say something to see the tool calls.</p>}
{lastTrace ? (
<TraceView trace={lastTrace.trace} traceId={lastTrace.traceId} />
) : (
<p className="muted small">Say something to see the tool calls.</p>
)}
</details>
</div>
</section>
Expand Down
Loading
Loading