This commit is contained in:
dahyeon committed 2026-08-12 02:11:40 -07:00
1 parent 77a5f5248c
commit f0bba7e7b9
68 files changed
+5149 -142

No files matched your search

+30 -30
View File
@@ -67,16 +67,16 @@ function formatDuration(milliseconds: number) {
function Metric({ label, value, tone = 'normal' }: { label: string; value: string; tone?: 'normal' | 'good' | 'warn' }) {
return (
<div className="rounded-xl border border-white/8 bg-black/20 px-3 py-2.5">
<p className="text-[9px] uppercase tracking-[0.18em] text-zinc-600">{label}</p>
<p className={`mt-1 font-mono text-xs ${tone === 'good' ? 'text-emerald-300' : tone === 'warn' ? 'text-amber-300' : 'text-zinc-300'}`}>{value}</p>
<div className="rounded-xl border border-line-soft bg-canvas px-3 py-2.5">
<p className="text-[9px] uppercase tracking-[0.18em] text-ink-muted">{label}</p>
<p className={`mt-1 font-mono text-xs ${tone === 'good' ? 'text-success' : tone === 'warn' ? 'text-warning' : 'text-ink'}`}>{value}</p>
</div>
)
}
function SampleGraph({ estimate }: { estimate: ClockEstimate }) {
const accepted = estimate.samples.filter((sample) => sample.accepted).slice(-60)
if (accepted.length < 2) return <div className="flex h-28 items-center justify-center text-[10px] text-zinc-700">표본을 수집하는 중입니다.</div>
if (accepted.length < 2) return <div className="flex h-28 items-center justify-center text-[10px] text-ink-muted">표본을 수집하는 중입니다.</div>
const width = 600
const height = 112
const maxRtt = Math.max(1, ...accepted.map((sample) => sample.rttMs))
@@ -88,17 +88,17 @@ function SampleGraph({ estimate }: { estimate: ClockEstimate }) {
}).join(' ')
return (
<div className="overflow-hidden rounded-xl border border-white/8 bg-black/30 p-2">
<div className="overflow-hidden rounded-xl border border-line-soft bg-canvas p-2">
<svg viewBox={`0 0 ${width} ${height}`} className="h-28 w-full" role="img" aria-label="최근 서버시간 표본 그래프">
<line x1="0" x2={width} y1={height / 2} y2={height / 2} stroke="rgba(255,255,255,.08)" />
<line x1="0" x2={width} y1={height / 2} y2={height / 2} stroke="rgba(13,11,8,.12)" />
{accepted.map((sample, index) => {
const barWidth = Math.max(2, width / accepted.length - 2)
const barHeight = sample.rttMs / maxRtt * height * 0.35
return <rect key={sample.id} x={index * width / accepted.length} y={height - barHeight} width={barWidth} height={barHeight} fill="rgba(52,211,153,.16)" />
return <rect key={sample.id} x={index * width / accepted.length} y={height - barHeight} width={barWidth} height={barHeight} fill="rgba(49,84,186,.22)" />
})}
<polyline points={points} fill="none" stroke="rgb(252 211 77)" strokeWidth="2" vectorEffect="non-scaling-stroke" />
<polyline points={points} fill="none" stroke="var(--color-primary)" strokeWidth="2" vectorEffect="non-scaling-stroke" />
</svg>
<div className="flex justify-between px-1 text-[9px] text-zinc-700"><span>노란선: 오프셋 편차</span><span>초록막대: RTT</span></div>
<div className="flex justify-between px-1 text-[9px] text-ink-muted"><span>붉은 선: 오프셋 편차</span><span>파란 막대: RTT</span></div>
</div>
)
}
@@ -256,18 +256,18 @@ export default function AutomationPanel({
return (
<section className="panel-card overflow-hidden" aria-label="자동 예약 및 서버시간">
<div className="border-b border-white/8 p-5 sm:p-6">
<div className="border-b border-line-soft p-5 sm:p-6">
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<p className="text-[10px] font-semibold uppercase tracking-[0.26em] text-amber-300/70">Precision clock</p>
<h2 className="mt-1 text-base font-semibold text-white">관측 서버시간</h2>
<p className="mt-1 text-[10px] leading-4 text-zinc-600">HTTP Date는 초 단위이며 아래 값은 RTT 보정 추정치와 신뢰구간입니다.</p>
<p className="text-[10px] font-semibold uppercase tracking-[0.26em] text-primary">Precision clock</p>
<h2 className="mt-1 text-base font-semibold text-ink">관측 서버시간</h2>
<p className="mt-1 text-[10px] leading-4 text-ink-muted">HTTP Date는 초 단위이며 아래 값은 RTT 보정 추정치와 신뢰구간입니다.</p>
</div>
<button onClick={toggleMonitor} disabled={busy === 'monitor' || armed} className={`rounded-full border px-3 py-2 text-[11px] font-semibold transition ${clock?.monitoring ? 'border-emerald-300/25 bg-emerald-300/10 text-emerald-200' : 'border-white/10 text-zinc-400 hover:text-white'} disabled:opacity-40`}>
<button onClick={toggleMonitor} disabled={busy === 'monitor' || armed} className={`rounded-full border px-3 py-2 text-[11px] font-semibold transition ${clock?.monitoring ? 'border-success/30 bg-success/10 text-success' : 'border-line text-ink-muted hover:text-ink'} disabled:opacity-40`}>
{busy === 'monitor' ? '측정 중…' : clock?.monitoring ? '모니터 중지' : '모니터 시작'}
</button>
</div>
<p className="mt-5 font-mono text-xl tracking-tight text-white sm:text-2xl" aria-label="관측 서버시간 값">{formatClock(liveServerTimeMs)}</p>
<p className="mt-5 font-mono text-xl tracking-tight text-ink sm:text-2xl" aria-label="관측 서버시간 값">{formatClock(liveServerTimeMs)}</p>
<div className="mt-4 grid grid-cols-2 gap-2 sm:grid-cols-4">
<Metric label="offset" value={`${(clock?.offsetMs ?? 0).toFixed(1)}ms`} tone={qualityTone} />
<Metric label="raw offset" value={`${(clock?.rawOffsetMs ?? 0).toFixed(1)}ms`} />
@@ -291,9 +291,9 @@ export default function AutomationPanel({
recommendedCorrectionMs: 0, calibrationReady: false, calibrationApplied: false,
calibrationSettings: CLOCK_CALIBRATION_DEFAULTS, remoteIp: '', quality: 'unavailable', samples: [],
}} /></div>
{clock?.warning && <p className="mt-2 text-[10px] leading-4 text-amber-300/70">{clock.warning} 품질이 낮아도 마지막 유효 추정값으로 1회 실행합니다.</p>}
<div className="mt-3 flex justify-end"><button onClick={() => setSettingsOpen((value) => !value)} disabled={armed} className="rounded-full border border-white/10 px-3 py-2 text-[10px] font-semibold text-zinc-400 hover:text-white disabled:opacity-40">정밀 보정 설정</button></div>
{settingsOpen && <div className="mt-3 rounded-xl border border-white/10 bg-black/25 p-4">
{clock?.warning && <p className="mt-2 text-[10px] leading-4 text-warning">{clock.warning} 품질이 낮아도 마지막 유효 추정값으로 1회 실행합니다.</p>}
<div className="mt-3 flex justify-end"><button onClick={() => setSettingsOpen((value) => !value)} disabled={armed} className="rounded-full border border-line px-3 py-2 text-[10px] font-semibold text-ink-muted hover:text-ink disabled:opacity-40">정밀 보정 설정</button></div>
{settingsOpen && <div className="mt-3 rounded-xl border border-line-soft bg-canvas p-4">
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{([
['scanWindowMs', '경계 탐색 범위 (ms)', 100, 450],
@@ -305,32 +305,32 @@ export default function AutomationPanel({
['maxProbeRttMs', '최대 허용 RTT (ms)', 100, 1500],
['maintenanceIntervalSec', '안정화 후 재검증 (초)', 5, 120],
['sampleWindowSize', '표본 보관 수', 60, 600],
] as const).map(([key, label, min, max]) => <label key={key} className="space-y-1"><span className="text-[9px] font-semibold text-zinc-500">{label}</span><input type="number" min={min} max={max} value={clockSettings[key]} onChange={(event) => setClockSettings((current) => ({ ...current, [key]: Number(event.target.value) }))} className="w-full rounded-lg border border-white/10 bg-black/30 px-3 py-2 font-mono text-xs text-white outline-none focus:border-amber-300/50" /></label>)}
] as const).map(([key, label, min, max]) => <label key={key} className="space-y-1"><span className="text-[9px] font-semibold text-ink-muted">{label}</span><input type="number" min={min} max={max} value={clockSettings[key]} onChange={(event) => setClockSettings((current) => ({ ...current, [key]: Number(event.target.value) }))} className="w-full rounded-lg border border-line bg-surface px-3 py-2 font-mono text-xs text-ink outline-none focus:border-accent" /></label>)}
</div>
<div className="mt-3 flex flex-wrap items-center justify-between gap-3 text-[10px] text-zinc-500"><div className="flex gap-4"><label className="flex items-center gap-2"><input type="checkbox" checked={clockSettings.enabled} onChange={(event) => setClockSettings((current) => ({ ...current, enabled: event.target.checked }))} />초 경계 정밀 측정</label><label className="flex items-center gap-2"><input type="checkbox" checked={clockSettings.autoApply} onChange={(event) => setClockSettings((current) => ({ ...current, autoApply: event.target.checked }))} />검증 후 자동 적용</label></div><div className="flex gap-2"><button onClick={() => setClockSettings({ ...CLOCK_CALIBRATION_DEFAULTS })} className="rounded-lg border border-white/10 px-3 py-2">기본값</button><button onClick={saveClockSettings} disabled={busy !== null} className="rounded-lg bg-amber-300 px-3 py-2 font-bold text-black disabled:opacity-40">설정 적용</button></div></div>
<p className="mt-3 text-[9px] leading-4 text-zinc-600">최소 경계 수와 편차 조건을 모두 통과한 경우에만 추천 보정을 자동 적용합니다. 설정은 앱 메모리에만 유지됩니다.</p>
<div className="mt-3 flex flex-wrap items-center justify-between gap-3 text-[10px] text-ink-muted"><div className="flex gap-4"><label className="flex items-center gap-2"><input type="checkbox" checked={clockSettings.enabled} onChange={(event) => setClockSettings((current) => ({ ...current, enabled: event.target.checked }))} className="accent-primary" />초 경계 정밀 측정</label><label className="flex items-center gap-2"><input type="checkbox" checked={clockSettings.autoApply} onChange={(event) => setClockSettings((current) => ({ ...current, autoApply: event.target.checked }))} className="accent-primary" />검증 후 자동 적용</label></div><div className="flex gap-2"><button onClick={() => setClockSettings({ ...CLOCK_CALIBRATION_DEFAULTS })} className="rounded-lg border border-line px-3 py-2 text-ink-muted hover:text-ink">기본값</button><button onClick={saveClockSettings} disabled={busy !== null} className="rounded-lg bg-primary px-3 py-2 font-bold text-primary-tint disabled:opacity-40">설정 적용</button></div></div>
<p className="mt-3 text-[9px] leading-4 text-ink-muted">최소 경계 수와 편차 조건을 모두 통과한 경우에만 추천 보정을 자동 적용합니다. 설정은 앱 메모리에만 유지됩니다.</p>
</div>}
</div>
<div className="border-b border-white/8 p-5 sm:p-6">
<div className="border-b border-line-soft p-5 sm:p-6">
<div className="flex items-center justify-between gap-3">
<div><h3 className="text-sm font-semibold text-white">시간 테스트</h3><p className="mt-1 text-[10px] text-zinc-600">3초 뒤 HEAD 요청으로 스케줄러와 도착 오차를 측정합니다.</p></div>
<button onClick={runTimingTest} disabled={busy === 'test' || armed} className="rounded-full border border-white/10 px-3 py-2 text-[11px] font-semibold text-zinc-300 hover:border-white/25 hover:text-white disabled:opacity-40">{busy === 'test' ? '테스트 중…' : '3초 테스트'}</button>
<div><h3 className="text-sm font-semibold text-ink">시간 테스트</h3><p className="mt-1 text-[10px] text-ink-muted">3초 뒤 HEAD 요청으로 스케줄러와 도착 오차를 측정합니다.</p></div>
<button onClick={runTimingTest} disabled={busy === 'test' || armed} className="rounded-full border border-line px-3 py-2 text-[11px] font-semibold text-ink-muted hover:border-ink hover:text-ink disabled:opacity-40">{busy === 'test' ? '테스트 중…' : '3초 테스트'}</button>
</div>
{timingTest && <div className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4"><Metric label="arrival error" value={`${timingTest.arrivalErrorMs >= 0 ? '+' : ''}${timingTest.arrivalErrorMs.toFixed(1)}ms`} tone={Math.abs(timingTest.arrivalErrorMs) <= timingTest.uncertaintyMs ? 'good' : 'warn'} /><Metric label="timer jitter" value={`${timingTest.schedulerJitterMs >= 0 ? '+' : ''}${timingTest.schedulerJitterMs.toFixed(1)}ms`} /><Metric label="RTT" value={`${timingTest.rttMs.toFixed(1)}ms`} /><Metric label="socket" value={timingTest.reusedSocket ? 'reused' : 'new'} /></div>}
</div>
<div className="p-5 sm:p-6">
<div className="flex items-start justify-between gap-4"><div><h3 className="text-sm font-semibold text-white">단일 요청 자동 예약</h3><p className="mt-1 text-[10px] leading-4 text-zinc-600">목표 서버 도착 시각에 토큰 1개를 소비해 정확히 한 번 제출합니다.</p></div><span className={`rounded-full px-2.5 py-1 text-[9px] font-semibold uppercase tracking-wider ${armed ? 'bg-amber-300/15 text-amber-200' : autoState.status === 'succeeded' ? 'bg-emerald-300/15 text-emerald-200' : autoState.status === 'failed' ? 'bg-red-300/15 text-red-200' : 'bg-white/5 text-zinc-500'}`}>{autoState.status}</span></div>
<div className="flex items-start justify-between gap-4"><div><h3 className="text-sm font-semibold text-ink">단일 요청 자동 예약</h3><p className="mt-1 text-[10px] leading-4 text-ink-muted">목표 서버 도착 시각에 토큰 1개를 소비해 정확히 한 번 제출합니다.</p></div><span className={`rounded-full px-2.5 py-1 text-[9px] font-semibold uppercase tracking-wider ${armed ? 'bg-coral text-coral-ink' : autoState.status === 'succeeded' ? 'bg-success/10 text-success' : autoState.status === 'failed' ? 'bg-danger/10 text-danger' : 'bg-chrome text-ink-muted'}`}>{autoState.status}</span></div>
<div className="mt-4 grid gap-3 sm:grid-cols-[1fr_140px]">
<label className="space-y-2"><span className="text-[10px] font-semibold text-zinc-500">실행 시각 (KST, ms)</span><input type="datetime-local" step="0.001" value={targetInput} onChange={(event) => setTargetInput(event.target.value)} disabled={armed} className="w-full rounded-xl border border-white/10 bg-black/25 px-3 py-3 font-mono text-xs text-white outline-none focus:border-amber-300/50 disabled:opacity-50" /></label>
<label className="space-y-2"><span className="text-[10px] font-semibold text-zinc-500">도착 오프셋 (ms)</span><input type="number" min="-5000" max="5000" step="1" value={userOffsetMs} onChange={(event) => setUserOffsetMs(Math.max(-5_000, Math.min(5_000, Number(event.target.value))))} disabled={armed} className="w-full rounded-xl border border-white/10 bg-black/25 px-3 py-3 font-mono text-xs text-white outline-none focus:border-amber-300/50 disabled:opacity-50" /></label>
<label className="space-y-2"><span className="text-[10px] font-semibold text-ink-muted">실행 시각 (KST, ms)</span><input type="datetime-local" step="0.001" value={targetInput} onChange={(event) => setTargetInput(event.target.value)} disabled={armed} className="w-full rounded-xl border border-line bg-surface px-3 py-3 font-mono text-xs text-ink outline-none focus:border-accent disabled:opacity-50" /></label>
<label className="space-y-2"><span className="text-[10px] font-semibold text-ink-muted">도착 오프셋 (ms)</span><input type="number" min="-5000" max="5000" step="1" value={userOffsetMs} onChange={(event) => setUserOffsetMs(Math.max(-5_000, Math.min(5_000, Number(event.target.value))))} disabled={armed} className="w-full rounded-xl border border-line bg-surface px-3 py-3 font-mono text-xs text-ink outline-none focus:border-accent disabled:opacity-50" /></label>
</div>
<div className="mt-3 grid grid-cols-2 gap-2"><Metric label="countdown" value={formatDuration(countdownMs)} tone={countdownMs > 0 ? 'good' : 'warn'} /><Metric label="token at target" value={Number.isFinite(tokenAgeAtTargetMs) ? formatDuration(tokenAgeAtTargetMs) : '토큰 없음'} tone={tokenReady ? 'good' : 'warn'} /></div>
<div className="mt-3 rounded-xl border border-white/8 bg-black/20 p-3 text-[10px] leading-5 text-zinc-500"><div className="flex justify-between gap-3"><span>토큰</span><span className={tokenReady ? 'text-emerald-300' : 'text-amber-300'}>{captchaToken ? `${captchaToken.slice(0, 6)}••••${captchaToken.slice(-4)} · ${formatDuration(tokenAgeMs)}` : '입력되지 않음'}</span></div>{autoState.snapshot && <><div className="flex justify-between gap-3"><span>고정 스냅샷</span><span className="text-right text-zinc-300">{autoState.snapshot.themeName} · {autoState.snapshot.date} {autoState.snapshot.timeLabel} · {autoState.snapshot.person}명</span></div><div className="flex justify-between gap-3"><span>예정 발송</span><span className="font-mono text-zinc-300">{autoState.timeline?.plannedSendAtMs ? formatClock(autoState.timeline.plannedSendAtMs) : '계산 중'}</span></div></>}</div>
<div className="mt-3 rounded-xl border border-line-soft bg-canvas p-3 text-[10px] leading-5 text-ink-muted"><div className="flex justify-between gap-3"><span>토큰</span><span className={tokenReady ? 'font-semibold text-success' : 'font-semibold text-warning'}>{captchaToken ? `${captchaToken.slice(0, 6)}••••${captchaToken.slice(-4)} · ${formatDuration(tokenAgeMs)}` : '입력되지 않음'}</span></div>{autoState.snapshot && <><div className="flex justify-between gap-3"><span>고정 스냅샷</span><span className="text-right text-ink">{autoState.snapshot.themeName} · {autoState.snapshot.date} {autoState.snapshot.timeLabel} · {autoState.snapshot.person}명</span></div><div className="flex justify-between gap-3"><span>예정 발송</span><span className="font-mono text-ink">{autoState.timeline?.plannedSendAtMs ? formatClock(autoState.timeline.plannedSendAtMs) : '계산 중'}</span></div></>}</div>
{autoState.timeline?.actualSendAtMs && <div className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4"><Metric label="actual send" value={formatClock(autoState.timeline.actualSendAtMs).split(' ').at(-1) ?? '—'} /><Metric label="arrival error" value={autoState.timeline.arrivalErrorMs === undefined ? '—' : `${autoState.timeline.arrivalErrorMs >= 0 ? '+' : ''}${autoState.timeline.arrivalErrorMs.toFixed(1)}ms`} /><Metric label="response RTT" value={autoState.timeline.rttMs === undefined ? '—' : `${autoState.timeline.rttMs.toFixed(1)}ms`} /><Metric label="HTTP / socket" value={`${autoState.timeline.httpStatus ?? '—'} / ${autoState.timeline.reusedSocket ? 'reused' : 'new'}`} /></div>}
{(error || autoState.message) && <p role="alert" className={`mt-3 rounded-xl border px-3 py-2 text-[10px] leading-4 ${error || autoState.status === 'failed' ? 'border-red-300/15 bg-red-300/5 text-red-200' : 'border-emerald-300/15 bg-emerald-300/5 text-emerald-200'}`}>{error || autoState.message}</p>}
<div className="mt-4 grid grid-cols-2 gap-2">{armed ? <button onClick={disarm} disabled={autoState.status === 'firing'} className="col-span-2 rounded-xl border border-red-300/20 py-3 text-xs font-semibold text-red-200 hover:bg-red-300/8 disabled:opacity-40">자동 예약 해제</button> : <button onClick={arm} disabled={busy === 'arm' || !request || !tokenReady} className="col-span-2 rounded-xl bg-amber-300 py-3 text-xs font-bold text-black hover:bg-amber-200 disabled:cursor-not-allowed disabled:bg-zinc-800 disabled:text-zinc-600">{busy === 'arm' ? '무장 중…' : '자동 예약 무장'}</button>}</div>
{(error || autoState.message) && <p role="alert" className={`mt-3 rounded-xl border px-3 py-2 text-[10px] leading-4 ${error || autoState.status === 'failed' ? 'border-danger/25 bg-danger/8 text-danger' : 'border-success/25 bg-success/8 text-success'}`}>{error || autoState.message}</p>}
<div className="mt-4 grid grid-cols-2 gap-2">{armed ? <button onClick={disarm} disabled={autoState.status === 'firing'} className="col-span-2 rounded-xl border border-danger/30 py-3 text-xs font-semibold text-danger hover:bg-danger/8 disabled:opacity-40">자동 예약 해제</button> : <button onClick={arm} disabled={busy === 'arm' || !request || !tokenReady} className="col-span-2 rounded-xl bg-primary py-3 text-xs font-bold text-primary-tint hover:bg-primary-strong disabled:cursor-not-allowed disabled:bg-chrome disabled:text-ink-muted">{busy === 'arm' ? '무장 중…' : '자동 예약 무장'}</button>}</div>
</div>
</section>
)