feat(ui): security notices, shown only to users of the affected CLI

A hand-maintained src/web/public/security-notices.json carries warnings
about things outside Codeman that its users should act on. The first:
OpenCode's report of unauthorized access to its legacy Console, which
may have exposed provider API keys saved there.

- Pure core in constants.js (CodemanSecurityNotices): select() keeps the
  notices that apply now (inclusive local-day dates, not yet seen, https
  links, malformed entries skipped), and one naming a CLI only when
  window.__codemanCliAvailable[cli] === true. Unknown means not
  installed: a warning about software you do not have is noise. The CLI
  id is data in the JSON; no code branches on it. plan() decides the
  surface, so a load shows each notice once.
- An existing install on a new version gets the notice INSIDE the
  release's update toast: the highlights as before, a warning section,
  and the notice's link next to "See what's new". With no notice the
  update toast is the plain one it always was.
- Everyone else (a fresh install, a same-version reload) gets its own
  card in the toast stack: shield, "Security notice" eyebrow, title,
  message, the link, Dismiss and the ×; amber-to-red accent bar, theme
  tokens only (dark and light skins), full width on phones, an
  opacity/transform entrance and none under prefers-reduced-motion,
  role=alert.
- A notice is recorded as seen only when the user closes it, dismisses it
  or follows its link, never when it appears. Storage blocked shows
  nothing. The notice's own text is textContent and carries its own
  zh-CN, so i18n.js leaves it alone; the card's own copy translates.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-18 08:59:39 +02:00
1 parent ada2309721
commit 50bae2d371
6 files changed
+677 -26

No files matched your search

+92 -16
View File
@@ -378,32 +378,108 @@ Object.assign(CodemanApp.prototype, {
* The notes come from /whats-new.json, which `npm run version-packages` regenerates from
* CHANGELOG.md for each release. A browser that has never seen any version just records the
* current one, so a fresh install is not greeted with "what's new".
*
* The same pass places the security notices (/security-notices.json, see
* _loadSecurityNotices), so a load shows ONE notification per notice:
* CodemanSecurityNotices.plan() (constants.js) puts every selected notice INSIDE the update
* toast when that toast shows (showUpdateNotice), and gives each its own card otherwise, a
* fresh install or a reload on the same version (showSecurityNotice). With no notice
* selected the update toast is the plain one it always was. Storage blocked shows neither:
* nothing could remember a close.
*/
async checkWhatsNew(runningVersion) {
if (this._whatsNewChecked) return;
this._whatsNewChecked = true;
const KEY = 'codeman-whats-new-seen';
let seen = null;
try { seen = localStorage.getItem(KEY); } catch { /* storage blocked: skip the announcement */ return; }
if (seen === runningVersion) return;
try { seen = localStorage.getItem(KEY); } catch { /* storage blocked: skip the announcement and the notices */ return; }
const remember = () => { try { localStorage.setItem(KEY, runningVersion); } catch { /* ignore */ } };
if (!seen) { remember(); return; }
try {
const res = await fetch('/whats-new.json', { cache: 'no-cache' });
if (!res.ok) return;
const notes = await res.json();
if (notes?.version !== runningVersion || !Array.isArray(notes.highlights) || !notes.highlights.length) return;
const [notes, notices] = await Promise.all([
seen && seen !== runningVersion ? this._fetchWhatsNewNotes() : null,
this._loadSecurityNotices(),
]);
const plan = window.CodemanSecurityNotices.plan({ seenVersion: seen, runningVersion, notes, notices });
if (plan.recordVersion) remember();
if (plan.update) {
const shown = notes.highlights.slice(0, 3).join(' · ');
const more = notes.highlights.length > 3 ? ` (+${notes.highlights.length - 3} more)` : '';
remember();
this.showToast(`Codeman updated to v${runningVersion}: ${shown}${more}`, 'info', {
duration: 20000,
action: {
label: "See what's new",
onClick: () => window.open(`https://github.com/Ark0N/Codeman/releases/tag/codeman%40${runningVersion}`, '_blank', 'noopener'),
},
const text = `Codeman updated to v${runningVersion}: ${shown}${more}`;
const releaseUrl = `https://github.com/Ark0N/Codeman/releases/tag/codeman%40${runningVersion}`;
if (plan.updateNotices.length) {
this.showUpdateNotice({
text,
releaseUrl,
notices: plan.updateNotices,
onNoticeSeen: (id) => this._rememberSecurityNotice(id),
});
} else {
this.showToast(text, 'info', {
duration: 20000,
action: {
label: "See what's new",
onClick: () => window.open(releaseUrl, '_blank', 'noopener'),
},
});
}
}
for (const notice of plan.cards) {
this.showSecurityNotice(notice, { onClose: () => this._rememberSecurityNotice(notice.id) });
}
},
/** This release's notes, or null (offline or malformed: try again next load). */
async _fetchWhatsNewNotes() {
try {
const res = await fetch('/whats-new.json', { cache: 'no-cache' });
return res.ok ? await res.json() : null;
} catch {
return null;
}
},
/**
* The security notices this browser should see now, from the HAND-maintained
* /security-notices.json (docs/releasing.md says how to add and retire one), selected by
* CodemanSecurityNotices.select() in constants.js: dates, the seen list, and for a notice
* naming a CLI, `window.__codemanCliAvailable[cli] === true` only (unknown means not
* installed). [] on any failure, and when storage is blocked (a close could not be
* remembered, so the card would return on every load).
*/
async _loadSecurityNotices() {
let seen;
try { seen = this._readSecurityNoticesSeen(); } catch { /* storage blocked: show nothing */ return []; }
try {
const res = await fetch(CodemanBase.url('/security-notices.json'), { cache: 'no-cache' });
if (!res.ok) return [];
const data = await res.json();
return window.CodemanSecurityNotices.select(data?.notices, {
available: window.__codemanCliAvailable,
seen,
now: Date.now(),
lang: window.CodemanI18n?.language || window.__codemanLanguage,
});
} catch { /* offline or malformed: try again next load */ }
} catch { /* offline or malformed: try again next load */ return []; }
},
/** The ids the user closed or followed (`codeman-security-notices-seen`). Throws when storage is blocked. */
_readSecurityNoticesSeen() {
const raw = localStorage.getItem('codeman-security-notices-seen');
let ids = [];
try { ids = raw ? JSON.parse(raw) : []; } catch { /* a corrupt value counts as nothing seen */ }
return Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
},
/**
* Record a notice as seen. Only a user action calls this (a close, Dismiss, its link), never
* the card appearing, so one shown while nobody was looking comes back on the next load.
* Re-reads first: another tab may have recorded a notice since this one loaded.
*/
_rememberSecurityNotice(id) {
try {
const ids = this._readSecurityNoticesSeen();
if (!ids.includes(id)) ids.push(id);
localStorage.setItem('codeman-security-notices-seen', JSON.stringify(ids));
} catch { /* storage blocked since load: it shows again next load */ }
},
openAppSettings() {