import assert from 'node:assert/strict' import { readFileSync, writeFileSync } from 'node:fs' import { resolve } from 'node:path' const evidencePath = resolve('.tmp/rea-runtime-scripts.json') const outputPath = resolve('src/renderer/src/workbuddy/conversation/streaming-loading-tips.ts') const evidence = JSON.parse(readFileSync(evidencePath, 'utf8')) assert.equal(evidence.evidence_id, 'ev_717fa5e846e64d67ac19c8925d121bff632c0d3aefb3603b10858559cabb2dcb') const sourceRecord = evidence.items.find(item => item.file_path.endsWith('src-0FGg1seX.js')) assert.ok(sourceRecord?.source?.artifact?.text, 'REA evidence must contain the recovered conversation module') assert.equal(sourceRecord.source.artifact.sha256, 'f2c6dbae949041b4e2bb456e8a23ae2837f2d7893ac24bf471485f77c7b15178') const source = sourceRecord.source.artifact.text const localeFunction = source.indexOf('function normalizeLocale') assert.ok(localeFunction > 0, 'Source locale resolver must be present') function extractTips(name, delimiter) { const tick = String.fromCharCode(96) const assignment = source.lastIndexOf(`${name}=${tick}`, localeFunction) assert.ok(assignment >= 0, `Source ${name} tip list must be present`) const contentStart = assignment + name.length + 2 const contentEnd = source.indexOf(tick, contentStart) assert.ok(contentEnd > contentStart, `Source ${name} template literal must be closed`) assert.ok(source.startsWith(`${tick}.split(${tick}${delimiter}${tick})`, contentEnd), `Source ${name} list must use its recorded ${JSON.stringify(delimiter)} separator`) const values = source.slice(contentStart, contentEnd) .split(delimiter) .filter(Boolean) .map(value => value .replace(/\\u([0-9a-f]{4})/gi, (_match, hex) => String.fromCharCode(Number.parseInt(hex, 16))) .replace(/\\"/g, '"')) assert.ok(values.length > 0, `Source ${name} tip list must not be empty`) return values } const englishTips = [...extractTips('dD', '.'), ...extractTips('fD', '(')] const chineseTips = [...extractTips('mD', '.'), ...extractTips('hD', '.')] const output = `// Generated from REA ${evidence.evidence_id}; src-0FGg1seX.js SHA-256 ${sourceRecord.source.artifact.sha256}.\n` + '// WorkBuddy 5.8.2 getLoadingTips() arrays; brand substitution happens in the host component.\n' + 'export const SOURCE_LOADING_TIPS = {\n' + ` en: ${JSON.stringify(englishTips, null, 2).replaceAll('\n', '\n ')},\n` + ` zh: ${JSON.stringify(chineseTips, null, 2).replaceAll('\n', '\n ')}\n` + '} as const\n' if (process.argv.includes('--check')) { assert.equal(readFileSync(outputPath, 'utf8'), output, 'Recovered streaming loading tips are stale') console.log(`streaming loading tips check passed (${englishTips.length} en / ${chineseTips.length} zh)`) } else { writeFileSync(outputPath, output, 'utf8') console.log(`recovered streaming loading tips (${englishTips.length} en / ${chineseTips.length} zh) to ${outputPath}`) }