581 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GooseFactory — Confidence Meter</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #111;
--card: #1a1a2e;
--text: #e0e0e0;
--muted: #777;
--green: #00CC55;
--yellow: #FFD700;
--orange: #FF8C00;
--red: #FF3333;
--blue: #00AAFF;
--radius: 14px;
}
body {
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
padding: 24px 16px;
overflow-x: hidden;
}
/* ── Header ── */
.header {
text-align: center;
margin-bottom: 8px;
width: 100%;
max-width: 480px;
}
.header .context-badge {
display: inline-block;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 1.2px;
color: var(--green);
background: rgba(0,204,85,0.1);
border: 1px solid rgba(0,204,85,0.3);
padding: 4px 12px;
border-radius: 8px;
margin-bottom: 12px;
}
.header h2 {
font-size: 20px;
font-weight: 800;
margin-bottom: 6px;
}
.header .subtitle {
font-size: 13px;
color: var(--muted);
line-height: 1.5;
}
/* ── Gauge Container ── */
.gauge-container {
width: 100%;
max-width: 340px;
margin: 24px auto 8px;
position: relative;
touch-action: none;
user-select: none;
-webkit-user-select: none;
}
.gauge-svg {
width: 100%;
height: auto;
overflow: visible;
}
/* Zone labels */
.zone-labels {
display: flex;
justify-content: space-between;
padding: 0 10px;
margin-top: -4px;
margin-bottom: 16px;
}
.zone-label {
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--muted);
text-align: center;
flex: 1;
}
.zone-label.active {
font-weight: 700;
transition: color 0.3s;
}
/* Current confidence display */
.confidence-display {
text-align: center;
margin-bottom: 24px;
}
.confidence-value {
font-size: 52px;
font-weight: 900;
line-height: 1;
transition: color 0.3s;
}
.confidence-zone {
font-size: 14px;
font-weight: 600;
margin-top: 4px;
transition: color 0.3s;
}
.confidence-hint {
font-size: 12px;
color: var(--muted);
margin-top: 4px;
}
/* ── Delegation section ── */
.delegation-section {
width: 100%;
max-width: 480px;
background: var(--card);
border: 1px solid #2a2a3e;
border-radius: var(--radius);
padding: 18px 20px;
margin-bottom: 20px;
}
.delegation-title {
font-size: 12px;
text-transform: uppercase;
letter-spacing: 1.2px;
color: var(--muted);
margin-bottom: 14px;
}
.checkbox-row {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 0;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
user-select: none;
min-height: 48px;
}
.checkbox-row + .checkbox-row {
border-top: 1px solid #222;
}
.custom-checkbox {
width: 28px;
height: 28px;
min-width: 28px;
border-radius: 8px;
border: 2px solid #444;
background: #1a1a1a;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.25s;
font-size: 16px;
}
.checkbox-row.checked .custom-checkbox {
border-color: var(--blue);
background: rgba(0,170,255,0.15);
}
.checkbox-label {
flex: 1;
font-size: 14px;
line-height: 1.4;
}
.checkbox-label .emoji { margin-right: 6px; }
.checkbox-label .detail {
display: block;
font-size: 11px;
color: var(--muted);
margin-top: 2px;
}
/* ── Submit ── */
.submit-row {
width: 100%;
max-width: 480px;
}
.submit-btn {
width: 100%;
padding: 16px;
border: none;
border-radius: 12px;
font-size: 16px;
font-weight: 700;
cursor: pointer;
background: linear-gradient(135deg, var(--blue), #0088dd);
color: #fff;
transition: all 0.25s;
min-height: 48px;
-webkit-tap-highlight-color: transparent;
}
.submit-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,170,255,0.3); }
.submit-btn:active { transform: scale(0.98); }
/* ── Done ── */
.done-overlay {
position: fixed;
inset: 0;
background: var(--bg);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0;
pointer-events: none;
transition: opacity 0.4s;
z-index: 200;
}
.done-overlay.visible { opacity: 1; pointer-events: auto; }
.done-overlay .emoji { font-size: 64px; margin-bottom: 12px; }
.done-overlay .text { font-size: 18px; color: var(--muted); }
</style>
</head>
<body>
<div class="header">
<div class="context-badge" id="contextBadge">✅ You approved this</div>
<h2>How confident are you?</h2>
<div class="subtitle" id="itemContext">Rate your confidence in the decision you just made</div>
</div>
<div class="gauge-container" id="gaugeContainer">
<svg class="gauge-svg" viewBox="0 0 300 180" id="gaugeSvg">
<!-- Background arc zones -->
<!-- Zone 1: Guessing (0-25%) — Red -->
<path d="M 30 160 A 120 120 0 0 1 75.36 46.18"
fill="none" stroke="#661111" stroke-width="24" stroke-linecap="butt" opacity="0.6"/>
<!-- Zone 2: Somewhat Sure (25-50%) — Orange -->
<path d="M 75.36 46.18 A 120 120 0 0 1 150 40"
fill="none" stroke="#663300" stroke-width="24" stroke-linecap="butt" opacity="0.6"/>
<!-- Zone 3: Pretty Confident (50-75%) — Yellow -->
<path d="M 150 40 A 120 120 0 0 1 224.64 46.18"
fill="none" stroke="#665500" stroke-width="24" stroke-linecap="butt" opacity="0.6"/>
<!-- Zone 4: Dead Certain (75-100%) — Green -->
<path d="M 224.64 46.18 A 120 120 0 0 1 270 160"
fill="none" stroke="#114411" stroke-width="24" stroke-linecap="butt" opacity="0.6"/>
<!-- Active glow arc (drawn dynamically) -->
<path id="activeArc" d="" fill="none" stroke="var(--red)" stroke-width="24" stroke-linecap="round" opacity="0.9"/>
<!-- Tick marks -->
<line x1="30" y1="160" x2="30" y2="148" stroke="#555" stroke-width="2"/>
<line x1="75.36" y1="46.18" x2="80.8" y2="54.6" stroke="#555" stroke-width="2"/>
<line x1="150" y1="40" x2="150" y2="52" stroke="#555" stroke-width="2"/>
<line x1="224.64" y1="46.18" x2="219.2" y2="54.6" stroke="#555" stroke-width="2"/>
<line x1="270" y1="160" x2="270" y2="148" stroke="#555" stroke-width="2"/>
<!-- Needle pivot -->
<circle cx="150" cy="160" r="12" fill="#222" stroke="#444" stroke-width="2"/>
<!-- Needle -->
<line id="needle" x1="150" y1="160" x2="30" y2="160"
stroke="var(--red)" stroke-width="4" stroke-linecap="round"
style="transition: transform 0.15s ease-out; transform-origin: 150px 160px;"/>
<!-- Needle tip glow -->
<circle id="needleTip" cx="30" cy="160" r="6" fill="var(--red)" opacity="0.8">
</circle>
<!-- Center cap -->
<circle cx="150" cy="160" r="8" fill="#333" stroke="#555" stroke-width="1"/>
</svg>
</div>
<div class="zone-labels">
<span class="zone-label" id="z1">🎲 Guessing</span>
<span class="zone-label" id="z2">🤔 Somewhat Sure</span>
<span class="zone-label" id="z3">💪 Pretty Confident</span>
<span class="zone-label" id="z4">💎 Dead Certain</span>
</div>
<div class="confidence-display">
<div class="confidence-value" id="confidenceValue">0%</div>
<div class="confidence-zone" id="confidenceZone">Drag the needle →</div>
<div class="confidence-hint">Drag anywhere on the gauge</div>
</div>
<div class="delegation-section">
<div class="delegation-title">Delegation Calibration</div>
<div class="checkbox-row" id="bubaCheck" tabindex="0" role="checkbox" aria-checked="false">
<div class="custom-checkbox" id="bubaCheckbox"></div>
<div class="checkbox-label">
<span class="emoji">🤖</span> Could Buba have made this call?
<span class="detail">Would you trust the AI to decide this without you?</span>
</div>
</div>
<div class="checkbox-row" id="expertCheck" tabindex="0" role="checkbox" aria-checked="false">
<div class="custom-checkbox" id="expertCheckbox"></div>
<div class="checkbox-label">
<span class="emoji">👤</span> Should someone else also review?
<span class="detail">Might benefit from a second pair of eyes</span>
</div>
</div>
</div>
<div class="submit-row">
<button class="submit-btn" id="submitBtn">📊 Submit Confidence</button>
</div>
<div class="done-overlay" id="doneOverlay">
<div class="emoji">📊</div>
<div class="text">Confidence calibrated!</div>
</div>
<script>
(function() {
'use strict';
const ctx = window.__FACTORY_CONTEXT__ || {};
const modalType = 'confidence-meter';
const modalVersion = '1.0.0';
const startTime = Date.now();
// ── Metrics ──
let interactionCount = 0;
let firstInteractionTime = null;
let dragJourney = [];
let needleMoved = false;
function trackInteraction() {
interactionCount++;
if (!firstInteractionTime) firstInteractionTime = Date.now();
}
function post(msg) { try { window.parent.postMessage(msg, '*'); } catch(e) {} }
post({ type: 'factory_modal_ready', modalType, version: modalVersion });
// ── Context ──
if (ctx.itemName) {
document.getElementById('itemContext').textContent = `Your call on "${ctx.itemName}" — how sure are you?`;
}
// ── Gauge State ──
let confidencePercent = 0; // 0-100
let bubaCanDecide = false;
let needsExpertReview = false;
const gaugeSvg = document.getElementById('gaugeSvg');
const gaugeContainer = document.getElementById('gaugeContainer');
const needle = document.getElementById('needle');
const needleTip = document.getElementById('needleTip');
const activeArc = document.getElementById('activeArc');
const confidenceValueEl = document.getElementById('confidenceValue');
const confidenceZoneEl = document.getElementById('confidenceZone');
const zoneLabels = [
document.getElementById('z1'),
document.getElementById('z2'),
document.getElementById('z3'),
document.getElementById('z4'),
];
// Gauge geometry: semicircle from 180° (left) to 0° (right)
// Center at (150, 160), radius 120
const cx = 150, cy = 160, r = 120;
function pctToAngle(pct) {
// 0% → 180° (left), 100% → 0° (right)
return Math.PI * (1 - pct / 100);
}
function angleToPoint(angle) {
return {
x: cx + r * Math.cos(angle),
y: cy - r * Math.sin(angle),
};
}
function getZone(pct) {
if (pct < 25) return { name: 'Guessing', key: 'guess', color: 'var(--red)', idx: 0 };
if (pct < 50) return { name: 'Somewhat Sure', key: 'educated_guess', color: 'var(--orange)', idx: 1 };
if (pct < 75) return { name: 'Pretty Confident', key: 'confident', color: 'var(--yellow)', idx: 2 };
return { name: 'Dead Certain', key: 'certain', color: 'var(--green)', idx: 3 };
}
function buildArcPath(pct) {
if (pct <= 0) return '';
const startAngle = Math.PI; // 180° (left)
const endAngle = pctToAngle(pct);
const start = angleToPoint(startAngle);
const end = angleToPoint(endAngle);
const largeArc = pct > 50 ? 1 : 0;
return `M ${start.x} ${start.y} A ${r} ${r} 0 ${largeArc} 1 ${end.x} ${end.y}`;
}
function updateGauge(pct) {
confidencePercent = Math.max(0, Math.min(100, Math.round(pct)));
const zone = getZone(confidencePercent);
// Needle rotation: 0% → 0° rotation (pointing left), 100% → 180° rotation (pointing right)
const rotationDeg = (confidencePercent / 100) * 180;
needle.style.transform = `rotate(${rotationDeg}deg)`;
needle.style.stroke = zone.color;
// Needle tip
const tipPoint = angleToPoint(pctToAngle(confidencePercent));
needleTip.setAttribute('cx', tipPoint.x);
needleTip.setAttribute('cy', tipPoint.y);
needleTip.setAttribute('fill', zone.color);
// Active arc
activeArc.setAttribute('d', buildArcPath(confidencePercent));
activeArc.style.stroke = zone.color;
// Value display
confidenceValueEl.textContent = confidencePercent + '%';
confidenceValueEl.style.color = zone.color;
confidenceZoneEl.textContent = zone.name;
confidenceZoneEl.style.color = zone.color;
// Zone label highlights
zoneLabels.forEach((label, i) => {
label.classList.toggle('active', i === zone.idx);
if (i === zone.idx) label.style.color = zone.color;
else label.style.color = '';
});
}
// ── Drag interaction ──
let isDragging = false;
function getPercentFromEvent(e) {
const rect = gaugeContainer.getBoundingClientRect();
const svgWidth = rect.width;
const svgHeight = rect.height;
// Map to SVG viewBox coordinates
const viewBoxWidth = 300;
const viewBoxHeight = 180;
const scaleX = viewBoxWidth / svgWidth;
const scaleY = viewBoxHeight / svgHeight;
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
const clientY = e.touches ? e.touches[0].clientY : e.clientY;
const localX = (clientX - rect.left) * scaleX;
const localY = (clientY - rect.top) * scaleY;
// Calculate angle from center
const dx = localX - cx;
const dy = cy - localY; // flip Y
let angle = Math.atan2(dy, dx); // radians
// Clamp to semicircle (0 to PI)
if (angle < 0) angle = 0;
if (angle > Math.PI) angle = Math.PI;
// Convert angle to percentage: PI → 0%, 0 → 100%
const pct = ((Math.PI - angle) / Math.PI) * 100;
return pct;
}
gaugeContainer.addEventListener('pointerdown', (e) => {
isDragging = true;
needleMoved = true;
trackInteraction();
gaugeContainer.setPointerCapture(e.pointerId);
const pct = getPercentFromEvent(e);
updateGauge(pct);
dragJourney.push(Math.round(pct));
});
gaugeContainer.addEventListener('pointermove', (e) => {
if (!isDragging) return;
const pct = getPercentFromEvent(e);
updateGauge(pct);
// Sample drag journey (throttle to ~every 3%)
const last = dragJourney[dragJourney.length - 1];
if (Math.abs(pct - last) >= 3) {
dragJourney.push(Math.round(pct));
}
});
gaugeContainer.addEventListener('pointerup', () => { isDragging = false; });
gaugeContainer.addEventListener('pointercancel', () => { isDragging = false; });
// ── Checkboxes ──
const bubaRow = document.getElementById('bubaCheck');
const expertRow = document.getElementById('expertCheck');
bubaRow.addEventListener('click', () => {
trackInteraction();
bubaCanDecide = !bubaCanDecide;
bubaRow.classList.toggle('checked', bubaCanDecide);
bubaRow.setAttribute('aria-checked', bubaCanDecide);
document.getElementById('bubaCheckbox').textContent = bubaCanDecide ? '✓' : '';
});
expertRow.addEventListener('click', () => {
trackInteraction();
needsExpertReview = !needsExpertReview;
expertRow.classList.toggle('checked', needsExpertReview);
expertRow.setAttribute('aria-checked', needsExpertReview);
document.getElementById('expertCheckbox').textContent = needsExpertReview ? '✓' : '';
});
// Keyboard support
[bubaRow, expertRow].forEach(row => {
row.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
row.click();
}
});
});
// ── Submit ──
document.getElementById('submitBtn').addEventListener('click', () => {
trackInteraction();
const responseTimeMs = Date.now() - startTime;
const zone = getZone(confidencePercent);
const payload = {
type: 'factory_modal_response',
modalType,
modalVersion,
pipelineId: ctx.pipelineId || 'unknown',
itemId: ctx.itemId || 'unknown',
sessionId: ctx.sessionId || 'sess_' + Date.now(),
timestamp: new Date().toISOString(),
responseTimeMs,
feedback: {
confidence: {
confidencePercent: confidencePercent,
zone: zone.key,
wouldDelegateToAI: bubaCanDecide,
needsExpertReview: needsExpertReview,
isTrainingExample: confidencePercent >= 80,
},
custom: {
dragJourney: dragJourney,
needleMoved: needleMoved,
finalZoneName: zone.name,
},
},
meta: {
timeToFirstInteractionMs: firstInteractionTime ? firstInteractionTime - startTime : null,
timeToDecisionMs: responseTimeMs,
totalInteractions: interactionCount,
fieldsModified: [
...(needleMoved ? ['confidence'] : []),
...(bubaCanDecide ? ['wouldDelegateToAI'] : []),
...(needsExpertReview ? ['needsExpertReview'] : []),
],
deviceType: window.innerWidth < 768 ? 'mobile' : 'desktop',
viewportSize: { width: window.innerWidth, height: window.innerHeight },
},
};
post(payload);
document.getElementById('doneOverlay').classList.add('visible');
setTimeout(() => {
post({ type: 'factory_modal_close', reason: 'completed' });
}, 1200);
});
// ── Init gauge at 0 ──
updateGauge(0);
})();
</script>
</body>
</html>