// 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. // 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); } const known = m[1]; 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) for each, then bump KNOWLEDGE_DATE.'); process.exit(1); } console.log('chatbot knowledge date ' + known + ' covers all ' + notes.length + ' release notes (newest ' + (notes[0] ? notes[0].date : 'none') + ')');