fix(webapp): the final review's three page findings

- The arrow keys reached the legacy per-index waveform route in serial mode,
  even with no list loaded (an unlocked MiniMate chain walk + 5A on the same
  modem session).  perIndexLive() is now the one rule for the per-index
  buttons, the chips and the keyboard: live only for a list loaded without a
  serial that has events.
- A failed reconnect left the previous unit's confirmation live (badge,
  Diagnostics incl. the unguarded blind/slow-drip stops, call-home read).
  connectUnit() now drops it before it identifies; only this answer confirms.
- Unit strings reached innerHTML: the Device tab's cards (active_setup, new in
  1c) and its compliance/project tables now render as text, and Diagnostics'
  error spans go through escapeHtml().
- CLAUDE.md: the ring-path Runs A/B are a merge gate (the spec's prerequisite
  to a webapp sending serial), not only a use-time one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-29 12:16:49 -04:00
1 parent 073284fc88
commit 9082236c5e
3 files changed
+42 -9

No files matched your search

+26 -6
View File
@@ -1613,6 +1613,18 @@ function settingsRows(st) {
return rows;
}
// The legacy per-index routes (Load / Save / Download, prev/next, the arrow
// keys) address events by position on the MiniMate path: live only for a list
// loaded without a serial that has events.
function perIndexLive({ bySerial, count }) { return !bySerial && count > 0; }
// A unit's own string (setup name, project, an error naming a serial) placed
// into markup must stay text.
function escapeHtml(v) {
return String(v ?? '').replace(/[&<>"']/g,
c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
}
function downloadSummary(body) {
if (body.inserted === false) return `already stored — ${body.stored_filename}`;
return `stored ${body.stored_filename}, ${body.filesize} bytes, check: ${(body.detail || {}).check}`;
@@ -1790,6 +1802,9 @@ function switchTab(name) {
// ── Connect ────────────────────────────────────────────────────────────────────
async function connectUnit() {
if (!devHost()) { setStatus('Enter a device host first.', 'error'); return; }
// Whatever answered last time no longer counts: only this identify confirms.
unitConfirmed = null;
applyControls();
const btn = document.getElementById('connect-btn');
btn.disabled = true;
@@ -1852,14 +1867,15 @@ function setEventButtonsEnabled() {
// A list loaded by serial is downloaded row by row (by event_id); these
// per-index buttons belong to the legacy list.
const bySerial = eventsBySerial;
const live = perIndexLive({ bySerial, count: n });
for (const id of ['load-btn', 'save-btn', 'download-btn']) {
const el = document.getElementById(id);
if (el.dataset.legacyTitle === undefined) el.dataset.legacyTitle = el.title;
el.disabled = n === 0 || bySerial;
el.disabled = !live;
el.title = bySerial ? 'For a list loaded without a serial — use a row\'s Download' : el.dataset.legacyTitle;
}
document.getElementById('prev-btn').disabled = true;
document.getElementById('next-btn').disabled = n <= 1 || bySerial;
document.getElementById('next-btn').disabled = !live || n <= 1;
}
// ── Event list (opt-in — this is the slow chain walk) ──────────────────────────
@@ -2083,7 +2099,9 @@ function populateDeviceTab() {
for (const {label, value} of cardData) {
const c = document.createElement('div');
c.className = 'dev-card';
c.innerHTML = `<div class="dev-card-label">${label}</div><div class="dev-card-value">${value}</div>`;
const l = document.createElement('div'); l.className = 'dev-card-label'; l.textContent = label;
const v = document.createElement('div'); v.className = 'dev-card-value'; v.textContent = value;
c.append(l, v);
cards.appendChild(c);
}
@@ -2101,7 +2119,7 @@ function populateDeviceTab() {
['ADC Scale Factor (geo)', cc.geo_adc_scale != null ? `${cc.geo_adc_scale.toFixed(4)} in/s` : '—'],
['Setup Name', cc.setup_name || '—'],
];
renderTable('compliance-table', complianceRows);
renderTextTable('compliance-table', complianceRows);
// Project table
const projectRows = [
@@ -2111,7 +2129,7 @@ function populateDeviceTab() {
['Sensor Location', cc.sensor_location || '—'],
['Notes', cc.notes || '—'],
];
renderTable('project-table', projectRows);
renderTextTable('project-table', projectRows);
}
function renderTextTable(id, rows) {
@@ -2192,7 +2210,7 @@ async function refreshDiagnostics() {
if (!store._err) storageInfo = store;
const err = v => `<span style="color:var(--red)">${v}</span>`;
const err = v => `<span style="color:var(--red)">${escapeHtml(v)}</span>`;
const rows = [];
rows.push(['Monitoring', mon._err ? err(mon._err)
@@ -2589,6 +2607,8 @@ function populateSerialEventTable() {
}
function selectEvent(idx) {
// The arrow keys reach here too: they obey the same rule as the buttons.
if (!perIndexLive({ bySerial: eventsBySerial, count: eventList.length })) return;
currentEvent = idx;
document.querySelectorAll('.event-chip').forEach((c, i) => c.classList.toggle('active', i === idx));
document.getElementById('prev-btn').disabled = idx <= 0;