// Regenerate the root README overview with existing Playwright and local Chrome. // node utils/diagrams/render-ai-workflow.mjs (no network access) import fs from 'node:fs/promises' import { fileURLToPath } from 'node:url' import { chromium } from 'playwright' const directory = fileURLToPath(new URL('../../docs/public/diagrams/', import.meta.url)) const width = 2600, height = 3350 const xml = value => value.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]) const layout = [ [1040, 110, 520, 70, 'blue'], [1040, 220, 520, 110, 'blue'], [40, 880, 480, 220, 'green'], [1570, 880, 480, 220, 'purple'], [1040, 1210, 520, 150, 'blue'], [1040, 1418, 520, 136, 'blue'], [1040, 2960, 520, 112, 'blue'], [1040, 3130, 520, 144, 'dark'], [550, 880, 480, 220, 'orange'], [1060, 880, 480, 220, 'green'], [2080, 880, 480, 220, 'purple'], [1040, 370, 520, 110, 'blue'], [1040, 520, 520, 142, 'blue'], [1130, 700, 340, 100, 'green'], [1760, 530, 560, 132, 'orange'], [1040, 1600, 520, 140, 'green'], [1720, 1600, 580, 132, 'orange'], [1040, 1810, 520, 140, 'purple'], [540, 2150, 480, 130, 'blue'], [540, 2330, 480, 160, 'blue'], [560, 2550, 440, 140, 'green'], [1080, 2150, 440, 130, 'purple'], [1590, 2150, 450, 130, 'purple'], [1590, 2550, 520, 140, 'orange'], [540, 2750, 480, 90, 'green'], [40, 2300, 440, 160, 'orange'], [1590, 2340, 520, 140, 'blue'], ] const skillsByNode = [ [], ['library-workflow'], [], ['library-spec-planning'], [], [], ['library-doc-sync'], ['library-knowledge', 'library-spec-archive'], ['library-bugfix'], ['library-spec-delivery'], ['library-doc-sync'], ['library-context'], [], [], [], [], [], [], ['library-qa'], ['library-browser-qa'], [], [], [], [], [], ['library-bugfix'], [], ] const domainSkills = [ ['library-component', '组件', 'Components'], ['library-translation', '翻译', 'Translation'], ['library-theme', '主题', 'Themes'], ['library-doc-playground', '文档/演练场', 'Docs / playground'], ['library-build', '构建', 'Build'], ['library-release', '发布/CI', 'Publication / CI'], ['library-ai', 'AI 知识/工具', 'AI knowledge / tools'], ] const palette = { blue: ['#f0f6ff', '#acc8ed', '#173e70'], green: ['#edf8f2', '#9bd1b5', '#17634b'], purple: ['#f5f1fc', '#c9b6e9', '#634091'], dark: ['#173e70', '#173e70', '#ffffff'], orange: ['#fff6e9', '#e5b97b', '#85571a'], } const languages = [ { suffix: '', title: '组件库 AI 开发工作流总览', subtitle: '按影响分流 · 逐项实现 · 验证与证据闭环 · 标注各阶段 Skill', nodes: [ ['需求输入与已有差异'], ['自动分流:评估公共契约影响与不确定性'], ['1. 清晰局部修改', '直接定位目标模块与现有契约'], ['4. 公共契约变化/跨包增强', '1. 需求(requirements.md)', '2. 设计(design.md)', '3. 任务(tasks.md)', '4. 用例(test-cases.md)'], ['组件或目标模块实现', '保留类型、双主题、语言与生命周期契约'], ['补充测试工程自动化测试代码执行必要验证', '根据需求新增 qa 测试用例', '按改动风险选择测试层,完成差异自审', '记录实际执行、失败与未覆盖范围'], ['同步受影响文档与证据', '包说明/公开文档/AI 知识按需更新'], ['交付 → 经验提炼 → 按需归档'], ['2. Bug 修复/回归/失败诊断', '复现 → 根因 → 最小回归', '按需记录 bugfix.md', '公共行为变化 → 转规格'], ['3. 已有规格/继续任务', '回读 tasks.md 与关联规格、验证证据'], ['5. 文档编写/说明调整', '核对事实 → 组织内容 → 示例与链接校验'], ['上下文快速加载', '明确文件直接进入,否则只读命中索引'], ['模块上下文', '目标说明/契约 → 关联源码 → 直接相关测试', '已定义 AI_CONTEXT_END 时可先读到标记'], ['证据是否足够?'], ['沿实际关系补充上下文', '调用方/共享配置/包导出/构建链路', '读取下一个直接相关模块,再判断'], ['适用验证门槛达标?', '核对必要检查与实际结果'], ['保留未完成:补测或修复', '失败记为 FAILED;必要检查未执行保持未完成', '环境受阻记录缺口,不伪造通过'], ['用户是否请求完整 QA?', '沿用当前任务授权,不重复询问'], ['完整 QA:审查与验收汇总', '按授权范围组织验收与记录'], ['无头浏览器动态验收(按需)', 'Playwright/Chrome:操作与结果断言', '按影响验证主题、语言、移动端和浮层'], ['QA 结果?'], ['未请求完整 QA', 'NOT_REQUESTED', '保留必要验证结果'], ['用户明确拒绝完整 QA', 'SKIPPED_BY_USER', '记录跳过范围与限制'], ['验收环境受阻', 'NEEDS_MANUAL', '记录缺少环境、验证范围和恢复条件'], ['PASSED:记录验收证据'], ['QA 失败:定位并修复', '保留 FAILED 与失败证据', '修复后返回测试工程补测'], ['环境恢复后继续验收', '补齐环境,核对恢复条件', '沿用原授权范围,重新执行受阻项'], ], decision: '关键决定明确后实施', fail: '失败 → 修复', pass: '通过', specTask: '(规格任务)', domainTitle: '按任务选择领域 Skill', domainNote: '只读取相关领域,按实际影响组合', enough: '是 → 进入已选流程', insufficient: '否 → 补充证据', gatePass: '达标', gateFail: '失败/未执行', qaRequested: '已请求', qaNotRequested: '未请求', qaDeclined: '明确拒绝', qaPass: '通过', qaFail: '不通过', qaRetest: '修复后补测', qaBlocked: '环境受阻', qaRecovered: '环境恢复', qaResume: '重新验收', qaStillBlocked: '未恢复:保留缺口', testTitle: '测试工程', testLines: [ '测试架构', '├─ checks project', '│ ├─ 单元:组件行为、事件、插槽与生命周期', '│ ├─ 工程:工程与发布脚本', '│ └─ AI:离线知识、CLI/MCP', '├─ build project', '│ └─ 真实产物加载、导出与打包', '├─ 类型验证', '│ ├─ 源码检查:yarn typecheck(构建前检查 Vue/TS)', '│ ├─ 消费者测试:yarn test:types(公共 API、Vue 模板与类型推断)', '│ └─ 构建后声明:build project(使用生成的 .d.ts 编译消费者示例)', '└─ 浏览器测试:交互、布局、主题与演练场', ], testRequirements: [ ['• **常规发版要求**:测试通过率 **100%**,行、语句、函数、分支覆盖率分别 **≥99%**。'], ['• **复用构建发版**:沿用现有reuse规则,跳过测试与覆盖率要求', ' 复用构建产物直接发布。'], ['• **日常开发要求**:相关必要测试通过;用户明确要求覆盖率达标时,也纳入该判断。'], ], qaNote: '完整 QA 的选择不免除必要验证;失败或环境受阻不标通过。', footer: '发布另需明确授权;常规发布沿用完整预检,测试全通过、四项覆盖率分别 ≥99%。', }, { suffix: '.en', title: 'AI workflow for library development', subtitle: 'Route by impact · Implement · Verify · Skills mapped to each stage', nodes: [ ['Request and existing changes'], ['Auto-routing: assess contracts and uncertainty'], ['1. Focused local change', 'Locate the module and existing contracts'], ['4. Public contract / cross-package change', '1. Requirements (requirements.md)', '2. Design (design.md)', '3. Tasks (tasks.md)', '4. Test cases (test-cases.md)'], ['Component / module implementation', 'Types · Both themes · Languages · Lifecycle'], ['Add automated tests and run necessary checks', 'Add QA test cases as required', 'Choose test layers by risk; review the diff', 'Record actual runs, failures and coverage gaps'], ['Update affected docs and evidence', 'Package docs · Public docs · AI knowledge'], ['Deliver → Lessons → Optional archival'], ['2. Bug / regression / failure diagnosis', 'Reproduce → Root cause → Regression case', 'Optional record: bugfix.md', 'Public behavior change → Specification'], ['3. Existing specification / resume tasks', 'Read tasks.md, linked specs and evidence'], ['5. Documentation authoring', 'Check facts → Write → Validate examples / links'], ['Load context on demand', 'Explicit file, or the matching module index entry'], ['Module context', 'Contracts → Relevant source → Directly related tests', 'Read to AI_CONTEXT_END only where defined'], ['Enough evidence?'], ['Expand along actual dependencies', 'Callers / Shared config / Exports / Build chain', 'Read the next relevant module; reassess'], ['Applicable checks passed?', 'Verify necessary checks and actual results'], ['Keep incomplete: test or fix', 'FAILED; unexecuted necessary checks stay incomplete', 'Record environment gaps; never claim a pass'], ['Full QA requested?', 'Reuse the current choice; do not ask again'], ['Full QA: review and acceptance', 'Coordinate the authorized scope and evidence'], ['Headless browser acceptance, as needed', 'Playwright / Chrome: actions and assertions', 'Relevant themes, locales, mobile and overlays'], ['QA result?'], ['Full QA not requested', 'NOT_REQUESTED', 'Preserve necessary check results'], ['Full QA explicitly declined', 'SKIPPED_BY_USER', 'Record skipped scope and limitations'], ['Acceptance environment blocked', 'NEEDS_MANUAL', 'Record gaps, scope and recovery conditions'], ['PASSED: record acceptance evidence'], ['QA failed: diagnose and fix', 'Keep FAILED and failure evidence', 'Return to test engineering for regression'], ['Resume QA after environment recovery', 'Restore prerequisites and verify recovery', 'Rerun blocked checks within the original scope'], ], decision: 'Resolve key decisions first', fail: 'Fail → Fix', pass: 'Pass', specTask: ' (spec tasks)', domainTitle: 'Select domain skills by task', domainNote: 'Load only relevant domains; combine as needed', enough: 'Yes → Enter selected workflow', insufficient: 'No → Gather evidence', gatePass: 'Passed', gateFail: 'Failed / Not run', qaRequested: 'Requested', qaNotRequested: 'Not requested', qaDeclined: 'Declined', qaPass: 'Passed', qaFail: 'Failed', qaRetest: 'Retest after fixing', qaBlocked: 'Environment blocked', qaRecovered: 'Environment restored', qaResume: 'Rerun acceptance', qaStillBlocked: 'Still blocked: preserve gaps', testTitle: 'Test engineering', testLines: [ 'Test architecture', '├─ checks project', '│ ├─ Unit: component behavior, events, slots and lifecycle', '│ ├─ Engineering: engineering and publication scripts', '│ └─ AI: offline knowledge and CLI/MCP', '├─ build project', '│ └─ Real outputs, exports and package contents', '├─ Type validation', '│ ├─ Source: yarn typecheck (Vue/TS checks before building)', '│ ├─ Consumers: yarn test:types (public APIs, Vue templates and inference)', '│ └─ Built declarations: build project (compile consumers against generated .d.ts)', '└─ Browser tests: interactions, layout, themes and playground', ], testRequirements: [ ['• **Regular publication**: test pass rate **100%**;', ' lines, statements, functions and branches each **≥99%**.'], ['• **Reuse-build publication**: follow existing reuse rules; skip tests and coverage checks,', ' and publish the existing build artifacts directly.'], ['• **Daily development**: relevant necessary tests pass;', ' include coverage targets when the user explicitly requests them.'], ], qaNote: 'Full QA choices do not waive necessary checks; failures or environment gaps are not passes.', footer: 'Publication needs explicit authorization; full preflight requires all tests passing and each coverage metric ≥99%.', }, ] function draw(language) { const richText = value => value.split(/(\*\*.*?\*\*)/g).map(part => part.startsWith('**') ? `${xml(part.slice(2, -2))}` : xml(part)).join('') const nodes = language.nodes.map((lines, index) => { const [x, y, w, h, color] = layout[index], [fill, stroke, foreground] = palette[color] const skills = skillsByNode[index] const titleLineCount = index === 5 ? 2 : 1 const firstY = y + h / 2 - (lines.length + skills.length - 1) * 16 const shape = [13, 15, 17, 20].includes(index) ? `` : `` return `${shape} ${lines.map((line, i) => `${xml(line)}`).join('')}${skills.map((skill, i) => `${xml(skill + (skill === 'library-spec-delivery' ? language.specTask : ''))}`).join('')}` }).join('\n') const edges = [ 'M1300 180 V216', 'M1300 330 V366', 'M1300 480 V516', 'M1300 662 V696', 'M1470 750 H2040 V666', 'M1760 596 H1564', ...[280, 790, 1300, 1810, 2320].map(x => `M1300 800 V840 H${x} V876`), ...[280, 790, 1810].map(x => `M${x} 1100 V1170 H1300 V1206`), 'M1300 1100 V1206', 'M2320 1100 V1150 H2580 V3016 H1564', 'M1300 1360 V1414', 'M1300 1554 V1596', 'M1560 1670 H1716', 'M2300 1670 H2490 V1285 H1564', 'M1300 1740 V1806', 'M1040 1880 H1000 V2090 H780 V2146', 'M1300 1950 V2146', 'M1560 1880 H1815 V2146', 'M780 2280 V2326', 'M780 2490 V2546', 'M780 2690 V2746', 'M1000 2620 H1586', 'M780 2840 V2900 H1300 V2956', 'M1300 2280 V2956', 'M2040 2215 H2350 V2900 H1300 V2956', 'M1850 2690 V2900 H1300 V2956', 'M1300 3072 V3126', ] const domainPanel = ` ${xml(language.domainTitle)} ${domainSkills.map(([skill, chinese, english], i) => `${xml((language.suffix ? english : chinese) + ' · ' + skill)}`).join('')} ${xml(language.domainNote)}` const testPanel = ` ${xml(language.testTitle)} ${language.testLines.map((line, i) => `${xml(line)}`).join('')} ${language.testRequirements.map((lines, i) => { const y = 1880 + language.testRequirements.slice(0, i).reduce((offset, previous) => offset + previous.length * 24 + 8, 0) return lines.map((line, j) => `${richText(line)}`).join('') }).join('')}` return ` ${xml(language.title)} ${xml(language.nodes.flat().join('; ') + '; ' + language.testLines.join('; ') + '; ' + language.testRequirements.flat().join(' ').replaceAll('**', '') + '; ' + [...new Set([...skillsByNode.flat(), ...domainSkills.map(([skill]) => skill)])].join('; ') + '; ' + language.qaNote + '; ' + language.footer)} ${xml(language.title)} ${xml(language.subtitle)} ${edges.map(d => ``).join('')} ${nodes} ${domainPanel} ${testPanel} ${xml(language.enough)} ${xml(language.insufficient)} ${xml(language.decision)} ${xml(language.gatePass)} ${xml(language.gateFail)} ${xml(language.qaRequested)} ${xml(language.qaNotRequested)} ${xml(language.qaDeclined)} ${xml(language.qaPass)} ${xml(language.qaFail)} ${xml(language.qaRetest)} ${xml(language.qaBlocked)} ${xml(language.qaRecovered)} ${xml(language.qaResume)} ${xml(language.qaStillBlocked)} ${xml(language.qaNote)} ${xml(language.footer)} \n` } const browser = await chromium.launch({ channel: 'chrome', headless: true }) try { const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 2 }) await page.route('**/*', route => route.abort()) for (const language of languages) { const name = `ai-workflow${language.suffix}`, svg = draw(language) await fs.writeFile(`${directory}/${name}.svg`, svg) await page.setContent(`${svg}`) await page.evaluate(() => document.fonts.ready) const overflowing = await page.locator('[data-node]').evaluateAll(nodes => nodes.filter(node => { const box = node.querySelector('rect, polygon').getBBox() return [...node.querySelectorAll('text')].some(label => { const text = label.getBBox() return text.x < box.x + 10 || text.y < box.y + 5 || text.x + text.width > box.x + box.width - 10 || text.y + text.height > box.y + box.height - 5 }) }).map(node => node.getAttribute('data-node'))) if (overflowing.length) throw new Error(`Overflowing labels: ${overflowing.join(', ')}`) await page.locator('svg').screenshot({ path: `${directory}/${name}.png` }) console.log(`Generated ${name}.svg and ${name}.png; no node label overflow.`) } } finally { await browser.close() }