#!/usr/bin/env node // kill_src58.cjs (QA-GATE, 31 Oct): which lane file each LIVE page really registers every kill from (def.src58, set by K58.kill from // document.currentScript; the last registration wins, conditional registrations (X2TEST / APPROVED / X7ON / has()) count only when // they run). _tools/weapon_audit.py resolves each key's region with it (static load order is only the fallback). // node _tools/kill_src58.cjs [page.html ...] [--out _tools/coord/kill_src58.json] (no pages: every 58k_*.html with K58.page) // Runs headless Chrome one page at a time: on the Mac only niced and when it is quiet; the VM: tools/vm_slot.sh. const fs = require('fs'), os = require('os'), path = require('path'); let chromium; try { ({ chromium } = require('playwright')); } catch (e) { ({ chromium } = require('/Users/basha/node_modules/playwright')); } const A = process.argv.slice(2), pages = [], opt = {}; for (let i = 0; i < A.length; i++) { const a = A[i]; if (a.startsWith('--')) opt[a.slice(2)] = A[++i]; else pages.push(a); } const CHROME = ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/usr/bin/google-chrome', '/usr/bin/chromium'].find((p) => fs.existsSync(p)); const ROOT = opt.root || path.resolve(__dirname, '..'); if (!pages.length) for (const f of fs.readdirSync(ROOT).sort()) if (/^58k_.*\.html$/.test(f) && /K58\.page\(\{/.test(fs.readFileSync(path.join(ROOT, f), 'utf8'))) pages.push(f); if (!opt.out) opt.out = path.join(__dirname, 'coord', 'kill_src58.json'); (async () => { const udd = fs.mkdtempSync(path.join(os.tmpdir(), 'k58src-')), out = {}; const ctx = await chromium.launchPersistentContext(udd, Object.assign({ headless: true, args: ['--headless=new', '--allow-file-access-from-files'], viewport: { width: 800, height: 600 } }, CHROME ? { executablePath: CHROME } : {})); try { for (const pg of pages) { const page = await ctx.newPage(); try { await page.goto('file://' + path.join(ROOT, pg)); await page.waitForFunction(() => document.documentElement.classList.contains('k58-loaded'), null, { timeout: 120000 }); out[pg] = await page.evaluate(() => { const o = {}; for (const k of Object.keys(K58.ALL || {})) o[k] = (K58.ALL[k] && K58.ALL[k].src58) || ''; o.__failed = Object.keys(K58.failed || {}); return o; }); console.log(pg, Object.keys(out[pg]).length, 'kills'); } catch (e) { console.log(pg, 'ERROR', String(e).slice(0, 120)); out[pg] = { __err: String(e) }; } await Promise.race([page.close(), new Promise((r) => setTimeout(r, 8000))]); } } finally { await Promise.race([ctx.close(), new Promise((r) => setTimeout(r, 10000))]); try { fs.rmSync(udd, { recursive: true, force: true }); } catch (e) {} } const keys = {}; for (const pg in out) for (const k in out[pg]) if (k.indexOf('__') !== 0 && out[pg][k] && !keys[k]) keys[k] = out[pg][k]; const failed = {}; for (const pg in out) if (out[pg].__failed && out[pg].__failed.length) failed[pg] = out[pg].__failed; fs.writeFileSync(opt.out, JSON.stringify({ generated: new Date().toISOString(), note: 'key -> the lane file the live page registers it from (def.src58); by kill_src58.cjs', keys, failed, pages: Object.keys(out) }, null, 1)); console.log('kill_src58: ' + Object.keys(keys).length + ' keys from ' + Object.keys(out).length + ' pages -> ' + opt.out + (Object.keys(failed).length ? '; FAILED files: ' + JSON.stringify(failed) : '')); })().catch((e) => { console.error(e); process.exit(3); });