独家
Quiet Alarm <mv-quiet-alarm>
缺席检测器:当某件平常会发生的事停止发生时(订单、webhook、websocket 消息、传感器读数、日志行),它会发出警报。
文化出处
银色马,阿瑟·柯南·道尔(1892 年,书籍)。决定性的线索是“夜里那条狗的奇怪表现”:狗什么也没做,侦探注意到的是一件本该发生却没有发生的事。在界面中,组件会学习通常会发生什么、何时发生,并恰好在预期的心跳没有到来时发出警报。
工作原理
缺失检测器:当某件通常会发生的事情停止发生时(订单、webhook、websocket 消息、传感器读数、日志行)发出警报。应用通过 beat()、具名 DOM 事件(listen)或向被监视区域添加的行(watch)提供心跳;组件根据稳健的到达间隔统计(最近 40 个间隔的中位数和第 90 百分位,排除异常值和过往事故)学习通常的节奏,或使用指定的预期间隔,并在当前的沉默超出正常范围时按 learning → normal → overdue → silent 逐级升级:“Unusually quiet · no new orders for 14 min (usually every 2 min)”。紧凑的节奏条把最近的心跳画成刻度,向左滑过固定的 “now” 标记,前方用阴影标出预计下一次心跳的窗口,之后是斜线填充的 overdue 和 silent 区域,因此在任何警报响起之前你就能看到下一次心跳迟到了。沉默按活跃时间计算:安静时段("22:00-07:00, Sat-Sun 00:00-24:00")和预期暂停(pause("20m", { reason }))从不计入,并以色带显示。Snooze 会静音警报,但不会谎报状态,并在下一次心跳时结束;可取消的 mv-escalate 让应用否决它能解释的警报,可取消的 mv-beat 用于过滤心跳,mv-resume 报告中断持续了多久。seed() 根据服务器历史预置节奏,persist 让它在重新加载后保留,因此仪表盘在刷新后也不会失明。提供卡片和内联(标题栏或工具栏)两种变体。
| 分类 | 反馈 |
|---|---|
| 类型 | Web Component(<mv-quiet-alarm>) |
| 状态 | 稳定版 |
| 套件 | 没有告警疲劳的监控 |
| 同时安装 | button |
| Keywords | exclusive, culture, absence, heartbeat, watchdog, monitoring, anomaly, silence, rhythm, inter-arrival, ops, dashboard, e-commerce, iot, websocket, webhook, alert, status, snooze, quiet-hours |
When to use
- An ops or e-commerce dashboard must notice when orders, sign-ups or payments quietly stop arriving, not just when errors appear
- A webhook, websocket or job queue can fail silently and the only symptom is that its messages stop coming
- IoT or monitoring screens show sensors that report on a rhythm and a missing reading matters more than a bad one
- A support or chat backend should flag an unusually long lull in incoming conversations during business hours
Avoid when
- The deadline is fixed and known in advance (a session or an offer that ends at a set time) → use Hatch instead
- You need to show what did change while the user was away, not what failed to happen → use While Away instead
- The content is edited by hand and should just look stale after a while without review → use Content Age instead
安装
node scripts/add.mjs quiet-alarm --out ./src/marvelous通过 Marvelous UI MCP 服务器使用 AI 智能体:install_components({ slugs: ["quiet-alarm"], target_dir: "<absolute path>/src/marvelous", framework: "react" })。
复制的文件(含依赖):tokens/tokens.css, core/base.css, components/button/button.css, core/dom.js, core/element.js, core/motion.js, core/observe.js, components/quiet-alarm/quiet-alarm.js, components/quiet-alarm/quiet-alarm.css。
用法
快速开始,最小可运行标记:
<mv-quiet-alarm label="Orders · US storefront" subject="orders" expected="5m" listen="order:created"></mv-quiet-alarm>标准标记,可在此基础上通过属性、data-* 和 CSS 变量进行定制:
<div id="qa-demo" style="width:min(100%,60rem);margin-inline:auto">
<style>
#qa-demo { display:grid; gap:1rem; align-content:start }
#qa-demo .qa-bar { display:flex; align-items:center; justify-content:space-between; gap:.75rem 1rem; flex-wrap:wrap; padding:.625rem .75rem .625rem 1rem; border:1px solid var(--mv-border); border-radius:var(--mv-radius-xl); background:var(--mv-surface) }
#qa-demo .qa-brand { display:flex; align-items:center; gap:.625rem; min-width:0 }
#qa-demo .qa-logo { display:grid; place-items:center; flex:none; width:1.875rem; height:1.875rem; border-radius:var(--mv-radius-md); background:var(--mv-accent); color:var(--mv-fg-on-accent) }
#qa-demo .qa-logo svg { width:1rem; height:1rem }
#qa-demo .qa-brand b { display:block; font-size:.9375rem; letter-spacing:-.01em }
#qa-demo .qa-brand span { display:block; color:var(--mv-fg-muted); font-size:.75rem }
#qa-demo .qa-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:1rem }
#qa-demo .qa-panel { min-width:0; padding:1rem; border:1px solid var(--mv-border); border-radius:var(--mv-radius-xl); background:var(--mv-surface) }
#qa-demo .qa-panel h4 { display:flex; align-items:center; justify-content:space-between; gap:.5rem; margin:0 0 .75rem; font-size:.8125rem; font-weight:600 }
#qa-demo .qa-panel h4 span { color:var(--mv-fg-subtle); font-weight:500; font-size:.75rem }
#qa-demo .qa-feed { list-style:none; margin:0; padding:0; display:grid; gap:.375rem }
#qa-demo .qa-feed li { display:grid; grid-template-columns:4.25rem minmax(0,1fr) auto; gap:.75rem; align-items:center; padding:.4375rem .625rem; border-radius:var(--mv-radius-md); background:var(--mv-bg-subtle); font-size:.8125rem; font-variant-numeric:tabular-nums }
#qa-demo .qa-feed li:first-child { animation:qa-in var(--mv-duration-slow) var(--mv-ease-out) }
#qa-demo .qa-feed .qa-id { color:var(--mv-fg-subtle); font:.75rem var(--mv-font-mono) }
#qa-demo .qa-feed .qa-who { overflow:hidden; text-overflow:ellipsis; white-space:nowrap }
#qa-demo .qa-feed .qa-who small { color:var(--mv-fg-muted); font-size:.75rem }
#qa-demo .qa-feed .qa-amt { font-weight:600 }
@keyframes qa-in { from { opacity:0; translate:0 -4px } }
#qa-demo .qa-controls { display:grid; gap:.875rem }
#qa-demo .qa-row { display:flex; align-items:center; justify-content:space-between; gap:.75rem; flex-wrap:wrap }
#qa-demo .qa-row > span { font-size:.8125rem; color:var(--mv-fg-muted) }
#qa-demo .qa-actions { display:flex; gap:.5rem; flex-wrap:wrap }
#qa-demo .qa-log { list-style:none; margin:0; padding:.625rem .75rem; display:grid; gap:.25rem; min-height:4.75rem; border-radius:var(--mv-radius-md); background:var(--mv-bg-subtle); color:var(--mv-fg-muted); font:.75rem/1.5 var(--mv-font-mono) }
#qa-demo .qa-log b { color:var(--mv-fg); font-weight:600 }
#qa-demo .qa-note { margin:0; color:var(--mv-fg-subtle); font-size:.75rem; text-align:center }
@media (prefers-reduced-motion: reduce) { #qa-demo .qa-feed li:first-child { animation:none } }
@media (max-width:44rem) { #qa-demo .qa-grid { grid-template-columns:minmax(0,1fr) } }
</style>
<header class="qa-bar">
<div class="qa-brand">
<span class="qa-logo" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9h16l-1.2 10.2a2 2 0 0 1-2 1.8H7.2a2 2 0 0 1-2-1.8z"/><path d="M8.5 9V7a3.5 3.5 0 0 1 7 0v2"/></svg></span>
<div><b>Kestrel Market · Operations</b><span>US storefront · all systems</span></div>
</div>
<mv-quiet-alarm id="qa-sensor" variant="inline" label="Cold room 3" subject="readings" expected="3s" snooze-for="1m"></mv-quiet-alarm>
</header>
<div class="qa-grid">
<mv-quiet-alarm id="qa-orders" label="Orders · US storefront" subject="orders" watch="#qa-feed" snooze-for="30s"></mv-quiet-alarm>
<mv-quiet-alarm id="qa-hooks" label="Payment webhooks" subject="webhooks" listen="payment:webhook" listen-on="#qa-demo" snooze-for="20s"></mv-quiet-alarm>
<section class="qa-panel" aria-labelledby="qa-feed-h">
<h4 id="qa-feed-h">Live orders <span>newest first</span></h4>
<ul class="qa-feed" id="qa-feed" aria-label="Latest orders">
<li><span class="qa-id">#10481</span><span class="qa-who">Kenji Watanabe <small>· Osaka</small></span><span class="qa-amt">$42.90</span></li>
<li><span class="qa-id">#10480</span><span class="qa-who">Sofia Rossi <small>· Milan</small></span><span class="qa-amt">$128.00</span></li>
<li><span class="qa-id">#10479</span><span class="qa-who">Amara Okafor <small>· Lagos</small></span><span class="qa-amt">$64.50</span></li>
<li><span class="qa-id">#10478</span><span class="qa-who">Lucas Martin <small>· Lyon</small></span><span class="qa-amt">$19.99</span></li>
</ul>
</section>
<section class="qa-panel qa-controls" aria-labelledby="qa-sim-h">
<h4 id="qa-sim-h" style="margin:0">Simulation <span>time runs in seconds here</span></h4>
<label class="mv-choice" data-control="end">
<input type="checkbox" role="switch" class="mv-switch" id="qa-flow" checked>
<span class="mv-choice-text"><span class="mv-choice-title">Orders flowing</span><span class="mv-choice-description">Turn off to simulate a broken checkout</span></span>
</label>
<div class="qa-row">
<span id="qa-sens-l">Orders sensitivity</span>
<mv-segmented id="qa-sens" aria-labelledby="qa-sens-l" value="normal">
<button value="low">Low</button>
<button value="normal">Normal</button>
<button value="high">High</button>
</mv-segmented>
</div>
<div class="qa-actions">
<button type="button" class="mv-button" data-variant="outline" data-size="sm" id="qa-deploy">Pause orders 20 s (deploy)</button>
<button type="button" class="mv-button" data-variant="outline" data-size="sm" id="qa-hook">Deliver a webhook</button>
</div>
<ol class="qa-log" id="qa-log" aria-label="State changes"><li>State changes appear here.</li></ol>
</section>
</div>
<p class="qa-note">Each monitor learns its own rhythm from the beats it sees and only speaks up when the silence is longer than usual.</p>
<script type="module">
const root = document.getElementById("qa-demo");
await customElements.whenDefined("mv-quiet-alarm");
const $ = (id) => document.getElementById(id);
const orders = $("qa-orders"), hooks = $("qa-hooks"), sensor = $("qa-sensor");
const feed = $("qa-feed"), log = $("qa-log");
const timers = new Set();
const later = (fn, ms) => { const t = setTimeout(() => { timers.delete(t); if (root.isConnected) fn(); }, ms); timers.add(t); };
// Deterministic history so the page opens on a real rhythm.
let s = 20260923;
const rnd = () => ((s = (s * 16807) % 2147483647) / 2147483647);
const history = (count, min, max, endAgo) => {
const out = [];
let t = Date.now() - endAgo;
for (let i = 0; i < count; i++) { out.unshift(t); t -= (min + rnd() * (max - min)); }
return out;
};
orders.seed(history(22, 1200, 3200, 900));
hooks.seed(history(18, 1100, 1900, 5200)); // stopped five seconds ago
sensor.seed(history(12, 2900, 3100, 1400));
// Orders: rows appended to the watched feed are the beats.
const people = [["Priya Nair", "Bengaluru"], ["Mateo García", "Madrid"], ["Emma Schneider", "Berlin"], ["Noah Williams", "Austin"], ["Aisha Rahman", "Dubai"], ["Chloé Dubois", "Montréal"], ["Liam O'Brien", "Dublin"], ["Yuna Kim", "Seoul"], ["Lucas Martin", "Lyon"], ["Amara Okafor", "Lagos"]];
let id = 10481;
const addOrder = () => {
const [name, city] = people[id % people.length];
const li = document.createElement("li");
const a = Object.assign(document.createElement("span"), { className: "qa-id", textContent: `#${++id}` });
const who = Object.assign(document.createElement("span"), { className: "qa-who", textContent: `${name} ` });
who.append(Object.assign(document.createElement("small"), { textContent: `· ${city}` }));
const amt = Object.assign(document.createElement("span"), { className: "qa-amt", textContent: `$${(12 + rnd() * 180).toFixed(2)}` });
li.append(a, who, amt);
feed.prepend(li);
while (feed.children.length > 4) feed.lastElementChild.remove();
};
const flow = $("qa-flow");
const orderLoop = () => { if (flow.checked) addOrder(); later(orderLoop, 1200 + rnd() * 2000); };
later(orderLoop, 1300);
// Sensor: the app calls beat() on every reading.
const sensorLoop = () => { sensor.beat(); later(sensorLoop, 2900 + rnd() * 200); };
later(sensorLoop, 1600);
// Webhooks: a DOM event on the demo root is a beat.
$("qa-hook").addEventListener("click", () => root.dispatchEvent(new CustomEvent("payment:webhook", { detail: { count: 1 } })));
$("qa-deploy").addEventListener("click", () => orders.pause("20s", { reason: "a deploy" }));
$("qa-sens").addEventListener("mv-change", (e) => { orders.sensitivity = e.detail.value; });
const clock = new Intl.DateTimeFormat("en-US", { hour: "numeric", minute: "2-digit", second: "2-digit" });
const names = { learning: "Learning", normal: "Normal", overdue: "Overdue", silent: "Silent", paused: "Paused" };
root.addEventListener("mv-change", (e) => {
if (e.target.localName !== "mv-quiet-alarm") return;
const li = document.createElement("li");
const b = Object.assign(document.createElement("b"), { textContent: e.target.label });
li.append(`${clock.format(new Date())} · `, b, ` → ${names[e.detail.state]}`);
if (!log.querySelector("b")) log.replaceChildren();
log.prepend(li);
while (log.children.length > 3) log.lastElementChild.remove();
});
</script>
</div>API
Attributes
| Name | 类型 | Default | Description |
|---|---|---|---|
label | string | Activity | What is watched, shown as the title and used as the group's accessible name and in announcements (“Orders · US storefront”). |
subject | string (plural noun) | events | Plural noun used in sentences: “no new {subject} for 14 min”, “Waiting for {subject}”. |
subject-one | string | Singular noun (“Last {one} 40 sec ago”). Defaults to subject without its final s; set it for irregular nouns. | |
expected | time ("2m", "30s", "1h", ms number) | Known interval between beats. Skips learning, becomes the typical gap, and silence counts from the first connection even before any beat (“no new orders for 14 min” on a page that never saw one). | |
sensitivity | low | normal | high | number | normal | Multiplies the automatic thresholds: low = 1.5 (more tolerant), normal = 1, high = 0.7; a number is used as is. Overdue = k × max(2.5 × typical, 1.5 × p90); silent = max(1.6 × overdue, k × max(6 × typical, 3 × p90)). |
overdue-after / silent-after | time | Absolute thresholds in active time, overriding the learned ones (silent is kept at least 1.25 × overdue). | |
learn | number | 6 | Beats to see before the rhythm is trusted (the learning state shows “3 of 6 orders so far”). Ignored with expected. |
memory | number | 40 | How many recent gaps the statistics use, so the rhythm follows the time of day. Gaps interrupted by a pause or quiet hours, gaps longer than 12 × the median, and silences that reached silent are never learned; an overdue gap is, so a lasting slowdown is absorbed after a few beats. |
quiet-hours | string | Comma-separated local time ranges when silence is expected and never counts: "22:00-07:00" (overnight wraps), "Sat-Sun 00:00-24:00", "Mon 12:00-13:00". The state is paused while inside one (“Quiet hours · alerts resume at 7:00 AM”) and the ranges are drawn as bands on the strip. | |
listen | string | Event type(s), space- or comma-separated, that count as a beat ("order:created"). A numeric event.detail.count counts as a burst of that many. | |
listen-on | window | document | self | CSS selector | window | Where the listen events are caught (window also receives bubbling events from anywhere in the page). |
watch | CSS selector | Element(s) whose new direct children count as beats (a feed, a log, a table body); rows added together are one beat of N. Elements matching later are picked up automatically; removals are ignored. | |
snooze-for | time | 30m | Duration of the built-in Snooze button shown while overdue or silent, and default for snooze(). "0" hides the button. |
span | time | Past time range drawn on the strip. Auto by default: a round value (10 s … 7 d) covering about 12 typical gaps and the silent threshold; the future quarter to the right of now shows the expected-next window. | |
variant | card | inline | card | inline: one row (icon, label, short status, mini strip, icon-only actions) for headers, toolbars and table cells. |
announce | "off" | "off" silences the live-region announcements (visible status and events stay). | |
persist | string | localStorage key suffix: the recent beats are saved and restored on reload, so learning is not lost (storage failures are ignored). | |
locale | BCP 47 | en-US | Locale for durations (Intl unit format) and clock times. |
data-state | learning | normal | overdue | silent | paused | Set by the component (styleable). data-snoozed is added while snoozed. |
Properties
| Name | 类型 | Description |
|---|---|---|
state | "learning" | "normal" | "overdue" | "silent" | "paused" | Current state (read-only). |
silence | number (ms) | Active time since the last beat, quiet hours and pauses excluded (read-only). |
typical | number (ms) | null | Expected interval, or the learned median gap; null while learning (read-only). |
thresholds | { overdueAfter, silentAfter } | null | Current thresholds in active ms (read-only). |
lastBeat | Date | null | Time of the latest beat (read-only). |
beats | { at: Date, count }[] | Recorded beats, oldest first (read-only copy). |
paused | { reason, until: Date | null } | null | Current pause or quiet period (reason "quiet-hours" for the latter). |
snoozedUntil | Date | null | End of the current snooze (read-only). |
strings | Partial<Record<string, string>> | Overrides for every visible text and announcement, with {placeholders} (keys: learning, normal, overdue, silent, paused, snoozedPill, waiting, learningText, normalText, watchingText, overdueText, silentText, pausedText, pausedOpenText, quietText, snoozedSuffix, short*, justNow, ago, snooze, unsnooze, resume, spanAgo, now, strip, stripLast, stripNext, announceOverdue, announceSilent, announceResume, announceSnooze, announceUnsnooze). English defaults. |
label / subject / expected / sensitivity / quietHours / listen / watch / snoozeFor / span / variant … | reflected | Mirror the attributes. |
Methods
| Name | Description |
|---|---|
beat({ at?, count?, source? }) | Something happened (at defaults to now; a Date or ms number is also accepted directly). Beats less than 100 ms apart merge into one burst. Emits the cancelable mv-beat; returns false when vetoed. |
seed(times) | Primes the rhythm with past beats (Date, ms or { at, count }) from your server, without events, so the monitor starts in a real state. |
pause(duration?, { reason? }) | Expected pause (deploy, maintenance, store closed): silence stops counting until it ends; open-ended without a duration. The state is paused with a Resume button. |
resume() | Ends the current pause now. |
snooze(duration?) | Mutes announcements and calms the alarm look for a while (default snooze-for), without changing the state; ends early on the next beat. Emits the cancelable mv-snooze. |
unsnooze() | Ends the snooze; an ongoing alarm is announced again. |
reset() | Forgets beats, pauses and snooze and starts learning again. |
Events
| Name | Description |
|---|---|
mv-beat | Cancelable, before a beat is recorded. detail: { at, count, source: "api" | "event" | "mutation", event, nodes }. preventDefault() ignores it (e.g. keep only rows with a given class). |
mv-escalate | Cancelable, before entering overdue or silent. detail: { from, to, silence, typical, overdueAfter, silentAfter }. preventDefault() vetoes that level until the next beat (a vetoed overdue can still become silent later). |
mv-change | The state changed. detail: { state, previous, silence, typical, snoozed, pause }. |
mv-resume | A beat ended an alarm. detail: { silence (ms of active silence), previous ("overdue" | "silent"), at, count }. |
mv-snooze | Cancelable, before a snooze. detail: { until, duration }. |
Content structure
| Name | Description |
|---|---|
actions | Children with slot="actions" (a runbook link, “Open status page”) are placed next to the built-in Snooze / Resume buttons. Any other children are replaced by the generated UI. |
CSS classes
| Name | Description |
|---|---|
mv-quiet-alarm-head | Row with -icon (data-icon per state, one-shot ping on each beat, slow beacon while alarmed), -title, -pill (state word + icon) and -actions (.mv-quiet-alarm-snooze / -unsnooze / -resume). |
mv-quiet-alarm-text | The status sentence; the part before “ · ” is in <strong>. |
mv-quiet-alarm-strip | role="img" rhythm strip: -track, -reel (slides with time), -tick (data-last, data-kind="resume", --_h = burst height), -silence (flat line since the last beat), -zone[data-zone="window | overdue | silent"], -usual (dashed typical mark), -band (pauses and quiet hours), -now, -axis. |
CSS variables
| Name | Default | Description |
|---|---|---|
--mv-quiet-alarm-normal | var(--mv-success) | Normal state and expected-next window tint. |
--mv-quiet-alarm-learning | var(--mv-info) | Learning state tint. |
--mv-quiet-alarm-overdue | var(--mv-warning) | Overdue state and zone. |
--mv-quiet-alarm-silent | var(--mv-danger) | Silent state and zone. |
--mv-quiet-alarm-paused | var(--mv-fg-subtle) | Paused state. |
--mv-quiet-alarm-height | 2.75rem | Height of the strip (card variant). |
--mv-quiet-alarm-inline-width | 6.5rem | Width of the mini strip in the inline variant. |
Accessibility
The element is a role="group" named by its label and described by the status sentence, which is always visible as text (in the inline variant a visually hidden copy of the full sentence is the description, the short text is aria-hidden). State is never conveyed by color alone: each state has its own icon and word in the pill (Learning, Normal, Overdue, Silent, Paused, plus “Snoozed”), the silence line changes from solid to dashed to thick, and the overdue and silent zones are hatched with different densities. The visible text updates every second but is not a live region, so nothing chatters; transitions are announced once in dedicated live regions: entering overdue politely, entering silent assertively, a resumption politely (“Orders: orders resumed after 14 minutes of silence”), snooze and unsnooze politely; announcements are skipped while snoozed and at page load, and announce="off" silences them. The rhythm strip is role="img" with a text summary (“22 orders in the last 45 seconds. Last one 2 sec ago. Next expected within 4 seconds.”) and is otherwise non-interactive. Snooze, Resume alerts and Resume are native buttons (icon-only with aria-label and title in the inline variant) that appear only when relevant; focus is never moved, except when a focused button disappears (Snooze once snoozed, Resume once resumed): focus then goes to the next visible action, or to the group itself, instead of the page. Reduced motion (OS or data-motion="reduce"): the strip steps instead of sliding, the beat ping, new-tick grow and alarm beacon are off. Forced colors: ticks, now marker, pill and borders use system colors; silent adds a thicker border. Timers are derived from Date.now() (robust to throttled background tabs, catches up on return), rendering pauses when the element is offscreen or the tab hidden while state changes and events still fire on time, and every listener, observer and timer stops when the element is removed.