// Chatbot knowledge guard (Marty, 2026-09-16: "ensure the chatbot is completely current, and keep it that way"). // Compares chatbot.js KNOWLEDGE_DATE with the newest public release note. If a note is newer, the // chatbot was not brought up to date with that change: fix chatbot.js (canned + prompt), bump the date. // Since the knowledge base (2026-10-20, kb.js) the assistant also answers from Admin > Knowledge base, so a // KB change made after a release counts too: the guard takes the later of KNOWLEDGE_DATE and the site's // newest KB edit by a person (/api/chat/kb-stamp, a Central-time day; seed refreshes from the code do not count). Either way a release must be followed by a // knowledge update, in the code or in the admin pane. // node qa/chatbot-sync.mjs (checks the live site's /api/releases) // LOCAL=http://127.0.0.1:8796 node qa/chatbot-sync.mjs import fs from 'node:fs'; const B = process.env.LOCAL || 'https://instantadpay.com'; const src = fs.readFileSync(new URL('../chatbot.js', import.meta.url), 'utf8'); const m = /KNOWLEDGE_DATE = '(\d{4}-\d{2}-\d{2})'/.exec(src); if (!m) { console.log('[bug] chatbot.js has no KNOWLEDGE_DATE constant'); process.exit(1); } let known = m[1], via = 'chatbot.js KNOWLEDGE_DATE'; try { const st = await (await fetch(B + '/api/chat/kb-stamp')).json(); if (st && /^\d{4}-\d{2}-\d{2}$/.test(st.updated || '') && st.updated > known) { known = st.updated; via = 'knowledge base (' + st.count + ' entries)'; } } catch (e) { console.log('[warn] no knowledge-base stamp from ' + B + ' (' + e.message + '), using KNOWLEDGE_DATE only'); } let notes = []; try { const r = await (await fetch(B + '/api/releases')).json(); notes = r.notes || []; } catch (e) { console.log('[warn] could not read ' + B + '/api/releases: ' + e.message); process.exit(0); } const newer = notes.filter(n => (n.date || '') > known); if (newer.length) { console.log('[bug] chatbot knowledge date ' + known + ' is older than ' + newer.length + ' release note(s):'); for (const n of newer) console.log(' ' + n.date + ' ' + n.title); console.log(' -> update chatbot.js (canned answers + systemPrompt) or the entries in Admin > Knowledge base for each, then bump KNOWLEDGE_DATE.'); process.exit(1); } console.log('chatbot knowledge date ' + known + ' (' + via + ') covers all ' + notes.length + ' release notes (newest ' + (notes[0] ? notes[0].date : 'none') + ')');