diff --git a/assets/agent-notes-board.html b/assets/agent-notes-board.html index 95f6892..21d042b 100644 --- a/assets/agent-notes-board.html +++ b/assets/agent-notes-board.html @@ -2,6 +2,7 @@ + 工程决策看板 @@ -869,13 +870,30 @@ async function loadSavedDirHandle() { } catch { return null; } } +function escapeHtml(str) { + if (!str) return ''; + return String(str) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + function parseMarkdown(text) { if (!text) return ''; - let s = text.replace(/&/g, '&').replace(//g, '>'); + let s = text.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); s = s.replace(/```([\s\S]*?)```/g, (m, c) => `
${c.trim()}
`); s = s.replace(/`([^`\n]+)`/g, '$1'); s = s.replace(/\*\*([^*]+)\*\*/g, '$1'); - s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); + s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, linkText, href) => { + const cleanHref = href.trim(); + if (/^(?:javascript|data|vbscript):/i.test(cleanHref)) { + return linkText; + } + const safeHref = escapeHtml(cleanHref); + return `${linkText}`; + }); s = s.replace(/^- (.*)$/gm, '• $1'); return s.split(/\n{2,}/).map(p => { p = p.trim(); @@ -1055,13 +1073,13 @@ function renderBaseline() { ]; document.getElementById('kpi-row').innerHTML = kpis.map(k => ` -
+
- ${k.label} + ${escapeHtml(k.label)}
${k.count}
-
${k.desc}
+
${escapeHtml(k.desc)}
`).join(''); @@ -1073,21 +1091,26 @@ function renderBaseline() { document.getElementById('pillars-vault').innerHTML = pillars.map(n => { const cites = Core.inCount.get(n.id) || 0; - const title = n.title; - const desc = n.decision || n.problem || '系统核心架构协议'; + const title = escapeHtml(n.title); + const desc = escapeHtml((n.decision || n.problem || '系统核心架构协议').replace(/<[^>]+>/g, '')); + const safeCls = escapeHtml(n.cls); + const clsLabel = escapeHtml(CLASS_LABELS[n.cls] || n.cls); + const safeDate = escapeHtml(n.date || '进行中'); + const safeSlug = escapeHtml(n.slug); + const safeId = escapeHtml(n.id); return ` -
+
- ${CLASS_LABELS[n.cls] || n.cls} + ${clsLabel} 被引用 × ${cites}
${title}
-
${desc.replace(/<[^>]+>/g, '')}
+
${desc}
- ${n.date || '进行中'} - #${n.slug} + ${safeDate} + #${safeSlug}
`; @@ -1096,21 +1119,22 @@ function renderBaseline() { const activeNodes = nodes.filter(n => n.lifecycle === 'implemented' || n.lifecycle === 'proposed'); document.getElementById('matrix-chambers').innerHTML = CLASSES.map(c => { const colNodes = activeNodes.filter(n => n.cls === c); + const clsLabel = escapeHtml(CLASS_LABELS[c] || c); return `
- ${CLASS_LABELS[c]} + ${clsLabel} ${colNodes.length}
${colNodes.length ? colNodes.map(n => ` -
-
${n.title}
+
+
${escapeHtml(n.title)}
- ${n.date || '—'} + ${escapeHtml(n.date || '—')} ${(Core.inCount.get(n.id) || 0) ? `↗${Core.inCount.get(n.id)}` : ''}
@@ -1209,18 +1233,18 @@ function renderTimeline() { for (const [mo, items] of filteredMonthsMap.entries()) { html += `
-
${mo} · ${items.length} 条
+
${escapeHtml(mo)} · ${items.length} 条
${items.map(n => ` -
+
- 📅 ${n.date || '进行中'} - ${CLASS_LABELS[n.cls] || n.cls} - ${STATUS_LABELS[n.lifecycle]} - ${n.title} + 📅 ${escapeHtml(n.date || '进行中')} + ${escapeHtml(CLASS_LABELS[n.cls] || n.cls)} + ${escapeHtml(STATUS_LABELS[n.lifecycle] || n.lifecycle)} + ${escapeHtml(n.title)}
-
${(n.problem || n.decision || '').slice(0, 180)}...
+
${escapeHtml((n.problem || n.decision || '').slice(0, 180))}...
`).join('')}
@@ -1280,16 +1304,16 @@ function renderAlternatives() { }); document.getElementById('pitfalls-grid').innerHTML = filtered.length ? filtered.map(item => ` -
+
- ${CLASS_LABELS[item.cls] || item.cls} - #${item.nodeId.split('/').pop().replace('.md','')} + ${escapeHtml(CLASS_LABELS[item.cls] || item.cls)} + #${escapeHtml(item.nodeId.split('/').pop().replace('.md',''))}
-
🚫 放弃备选:${item.discarded}
-
💡 权衡依据:${item.crux}
+
🚫 放弃备选:${escapeHtml(item.discarded)}
+
💡 权衡依据:${escapeHtml(item.crux)}
-
✅ ${item.winner}
+
✅ ${escapeHtml(item.winner)}
`).join('') : `
// 未检索到相关避坑记录
`; } @@ -1318,12 +1342,12 @@ function renderDirectory() { document.getElementById('matrix-rows-stream').innerHTML = list.length ? list.map((n, idx) => { const cites = Core.inCount.get(n.id) || 0; return ` -
+
#${String(idx + 1).padStart(3, '0')} - ${CLASS_LABELS[n.cls] || n.cls} - ${n.title} - ${STATUS_LABELS[n.lifecycle]} - ${n.date || '—'} + ${escapeHtml(CLASS_LABELS[n.cls] || n.cls)} + ${escapeHtml(n.title)} + ${escapeHtml(STATUS_LABELS[n.lifecycle] || n.lifecycle)} + ${escapeHtml(n.date || '—')} ${cites ? `↗ ${cites}` : ''}
`; @@ -1338,7 +1362,7 @@ function openConsole(id) { const stBadge = document.getElementById('dr-status-badge'); stBadge.className = `status-badge st-${n.lifecycle}`; - stBadge.textContent = STATUS_LABELS[n.lifecycle]; + stBadge.textContent = STATUS_LABELS[n.lifecycle] || n.lifecycle; const clsBadge = document.getElementById('dr-class-badge'); clsBadge.className = `class-badge cls-${n.cls}`; @@ -1356,9 +1380,9 @@ function openConsole(id) { document.getElementById('dr-headline').textContent = n.title; document.getElementById('dr-timestamp-bar').innerHTML = ` - ${n.date || '无日期'} + ${escapeHtml(n.date || '无日期')} · - ${n.slug} + ${escapeHtml(n.slug)} ${(Core.inCount.get(n.id) || 0) ? `·被引用 ${Core.inCount.get(n.id)} 次` : ''} `; @@ -1376,7 +1400,7 @@ function openConsole(id) {
前置先决依据:
- ${outgoing.map(o => `
↖ ${o.title}
`).join('')} + ${outgoing.map(o => `
↖ ${escapeHtml(o.title)}
`).join('')}
`; @@ -1386,7 +1410,7 @@ function openConsole(id) {
派生制约影响:
- ${incoming.map(i => `
↘ ${i.title}
`).join('')} + ${incoming.map(i => `
↘ ${escapeHtml(i.title)}
`).join('')}
`; @@ -1504,19 +1528,19 @@ async function startMission() { selectedSearchIdx = -1; if (!topMatches.length) { - searchPopover.innerHTML = `
// 未找到与 "${q}" 匹配的决策记录
`; + searchPopover.innerHTML = `
// 未找到与 "${escapeHtml(q)}" 匹配的决策记录
`; } else { searchPopover.innerHTML = topMatches.map((n, idx) => { - const title = n.title; + const title = escapeHtml(n.title); const cites = Core.inCount.get(n.id) || 0; return ` -
+
${title}
- ${CLASS_LABELS[n.cls] || n.cls} - ${n.date || '进行中'} - #${n.slug} + ${escapeHtml(CLASS_LABELS[n.cls] || n.cls)} + ${escapeHtml(n.date || '进行中')} + #${escapeHtml(n.slug)}
${cites ? `↗${cites}` : ''} @@ -1578,6 +1602,21 @@ async function startMission() { }); document.addEventListener('click', e => { + const nodeTrigger = e.target.closest('[data-node-id]'); + if (nodeTrigger) { + const id = nodeTrigger.getAttribute('data-node-id'); + if (id) { + openConsole(id); + return; + } + } + const deepLink = e.target.closest('.md-deep-link'); + if (deepLink) { + e.preventDefault(); + const target = deepLink.getAttribute('data-deep-link'); + if (target) handleDeepLink(target); + return; + } if (!e.target.closest('.hud-search')) { searchPopover.classList.remove('open'); } diff --git a/index.html b/index.html index 95f6892..21d042b 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,7 @@ + 工程决策看板 @@ -869,13 +870,30 @@ async function loadSavedDirHandle() { } catch { return null; } } +function escapeHtml(str) { + if (!str) return ''; + return String(str) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + function parseMarkdown(text) { if (!text) return ''; - let s = text.replace(/&/g, '&').replace(//g, '>'); + let s = text.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); s = s.replace(/```([\s\S]*?)```/g, (m, c) => `
${c.trim()}
`); s = s.replace(/`([^`\n]+)`/g, '$1'); s = s.replace(/\*\*([^*]+)\*\*/g, '$1'); - s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); + s = s.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, linkText, href) => { + const cleanHref = href.trim(); + if (/^(?:javascript|data|vbscript):/i.test(cleanHref)) { + return linkText; + } + const safeHref = escapeHtml(cleanHref); + return `${linkText}`; + }); s = s.replace(/^- (.*)$/gm, '• $1'); return s.split(/\n{2,}/).map(p => { p = p.trim(); @@ -1055,13 +1073,13 @@ function renderBaseline() { ]; document.getElementById('kpi-row').innerHTML = kpis.map(k => ` -
+
- ${k.label} + ${escapeHtml(k.label)}
${k.count}
-
${k.desc}
+
${escapeHtml(k.desc)}
`).join(''); @@ -1073,21 +1091,26 @@ function renderBaseline() { document.getElementById('pillars-vault').innerHTML = pillars.map(n => { const cites = Core.inCount.get(n.id) || 0; - const title = n.title; - const desc = n.decision || n.problem || '系统核心架构协议'; + const title = escapeHtml(n.title); + const desc = escapeHtml((n.decision || n.problem || '系统核心架构协议').replace(/<[^>]+>/g, '')); + const safeCls = escapeHtml(n.cls); + const clsLabel = escapeHtml(CLASS_LABELS[n.cls] || n.cls); + const safeDate = escapeHtml(n.date || '进行中'); + const safeSlug = escapeHtml(n.slug); + const safeId = escapeHtml(n.id); return ` -
+
- ${CLASS_LABELS[n.cls] || n.cls} + ${clsLabel} 被引用 × ${cites}
${title}
-
${desc.replace(/<[^>]+>/g, '')}
+
${desc}
- ${n.date || '进行中'} - #${n.slug} + ${safeDate} + #${safeSlug}
`; @@ -1096,21 +1119,22 @@ function renderBaseline() { const activeNodes = nodes.filter(n => n.lifecycle === 'implemented' || n.lifecycle === 'proposed'); document.getElementById('matrix-chambers').innerHTML = CLASSES.map(c => { const colNodes = activeNodes.filter(n => n.cls === c); + const clsLabel = escapeHtml(CLASS_LABELS[c] || c); return `
- ${CLASS_LABELS[c]} + ${clsLabel} ${colNodes.length}
${colNodes.length ? colNodes.map(n => ` -
-
${n.title}
+
+
${escapeHtml(n.title)}
- ${n.date || '—'} + ${escapeHtml(n.date || '—')} ${(Core.inCount.get(n.id) || 0) ? `↗${Core.inCount.get(n.id)}` : ''}
@@ -1209,18 +1233,18 @@ function renderTimeline() { for (const [mo, items] of filteredMonthsMap.entries()) { html += `
-
${mo} · ${items.length} 条
+
${escapeHtml(mo)} · ${items.length} 条
${items.map(n => ` -
+
- 📅 ${n.date || '进行中'} - ${CLASS_LABELS[n.cls] || n.cls} - ${STATUS_LABELS[n.lifecycle]} - ${n.title} + 📅 ${escapeHtml(n.date || '进行中')} + ${escapeHtml(CLASS_LABELS[n.cls] || n.cls)} + ${escapeHtml(STATUS_LABELS[n.lifecycle] || n.lifecycle)} + ${escapeHtml(n.title)}
-
${(n.problem || n.decision || '').slice(0, 180)}...
+
${escapeHtml((n.problem || n.decision || '').slice(0, 180))}...
`).join('')}
@@ -1280,16 +1304,16 @@ function renderAlternatives() { }); document.getElementById('pitfalls-grid').innerHTML = filtered.length ? filtered.map(item => ` -
+
- ${CLASS_LABELS[item.cls] || item.cls} - #${item.nodeId.split('/').pop().replace('.md','')} + ${escapeHtml(CLASS_LABELS[item.cls] || item.cls)} + #${escapeHtml(item.nodeId.split('/').pop().replace('.md',''))}
-
🚫 放弃备选:${item.discarded}
-
💡 权衡依据:${item.crux}
+
🚫 放弃备选:${escapeHtml(item.discarded)}
+
💡 权衡依据:${escapeHtml(item.crux)}
-
✅ ${item.winner}
+
✅ ${escapeHtml(item.winner)}
`).join('') : `
// 未检索到相关避坑记录
`; } @@ -1318,12 +1342,12 @@ function renderDirectory() { document.getElementById('matrix-rows-stream').innerHTML = list.length ? list.map((n, idx) => { const cites = Core.inCount.get(n.id) || 0; return ` -
+
#${String(idx + 1).padStart(3, '0')} - ${CLASS_LABELS[n.cls] || n.cls} - ${n.title} - ${STATUS_LABELS[n.lifecycle]} - ${n.date || '—'} + ${escapeHtml(CLASS_LABELS[n.cls] || n.cls)} + ${escapeHtml(n.title)} + ${escapeHtml(STATUS_LABELS[n.lifecycle] || n.lifecycle)} + ${escapeHtml(n.date || '—')} ${cites ? `↗ ${cites}` : ''}
`; @@ -1338,7 +1362,7 @@ function openConsole(id) { const stBadge = document.getElementById('dr-status-badge'); stBadge.className = `status-badge st-${n.lifecycle}`; - stBadge.textContent = STATUS_LABELS[n.lifecycle]; + stBadge.textContent = STATUS_LABELS[n.lifecycle] || n.lifecycle; const clsBadge = document.getElementById('dr-class-badge'); clsBadge.className = `class-badge cls-${n.cls}`; @@ -1356,9 +1380,9 @@ function openConsole(id) { document.getElementById('dr-headline').textContent = n.title; document.getElementById('dr-timestamp-bar').innerHTML = ` - ${n.date || '无日期'} + ${escapeHtml(n.date || '无日期')} · - ${n.slug} + ${escapeHtml(n.slug)} ${(Core.inCount.get(n.id) || 0) ? `·被引用 ${Core.inCount.get(n.id)} 次` : ''} `; @@ -1376,7 +1400,7 @@ function openConsole(id) {
前置先决依据:
- ${outgoing.map(o => `
↖ ${o.title}
`).join('')} + ${outgoing.map(o => `
↖ ${escapeHtml(o.title)}
`).join('')}
`; @@ -1386,7 +1410,7 @@ function openConsole(id) {
派生制约影响:
- ${incoming.map(i => `
↘ ${i.title}
`).join('')} + ${incoming.map(i => `
↘ ${escapeHtml(i.title)}
`).join('')}
`; @@ -1504,19 +1528,19 @@ async function startMission() { selectedSearchIdx = -1; if (!topMatches.length) { - searchPopover.innerHTML = `
// 未找到与 "${q}" 匹配的决策记录
`; + searchPopover.innerHTML = `
// 未找到与 "${escapeHtml(q)}" 匹配的决策记录
`; } else { searchPopover.innerHTML = topMatches.map((n, idx) => { - const title = n.title; + const title = escapeHtml(n.title); const cites = Core.inCount.get(n.id) || 0; return ` -
+
${title}
- ${CLASS_LABELS[n.cls] || n.cls} - ${n.date || '进行中'} - #${n.slug} + ${escapeHtml(CLASS_LABELS[n.cls] || n.cls)} + ${escapeHtml(n.date || '进行中')} + #${escapeHtml(n.slug)}
${cites ? `↗${cites}` : ''} @@ -1578,6 +1602,21 @@ async function startMission() { }); document.addEventListener('click', e => { + const nodeTrigger = e.target.closest('[data-node-id]'); + if (nodeTrigger) { + const id = nodeTrigger.getAttribute('data-node-id'); + if (id) { + openConsole(id); + return; + } + } + const deepLink = e.target.closest('.md-deep-link'); + if (deepLink) { + e.preventDefault(); + const target = deepLink.getAttribute('data-deep-link'); + if (target) handleDeepLink(target); + return; + } if (!e.target.closest('.hud-search')) { searchPopover.classList.remove('open'); } diff --git a/scripts/archive-agent-note.ts b/scripts/archive-agent-note.ts index 7a2249a..b8d6f9a 100644 --- a/scripts/archive-agent-note.ts +++ b/scripts/archive-agent-note.ts @@ -54,6 +54,12 @@ const archivedDir = join(agentNoteRoot, "archived", cls); mkdirSync(archivedDir, { recursive: true }); const archivedPath = join(archivedDir, filename); +if (existsSync(archivedPath)) { + console.error(`Error: target archived note already exists at ${archivedPath}`); + console.error("Refusing to overwrite existing archived note. Please inspect and resolve name collision manually."); + process.exit(1); +} + writeFileSync(targetPath, updatedContent, "utf8"); renameSync(targetPath, archivedPath); console.log(`Moved: ${relToRoot} -> archived/${cls}/${filename}`); diff --git a/scripts/build-board.ts b/scripts/build-board.ts index 56dcae9..0eb8075 100644 --- a/scripts/build-board.ts +++ b/scripts/build-board.ts @@ -15,14 +15,32 @@ if (!existsSync(templatePath)) { process.exit(1); } -// 检查是否为 --init 模式(日常开发:生成 69KB 轻量模板,不内联数据,直连本地目录) +// 检查参数 const isInitMode = args.includes('--init'); -const cleanArgs = args.filter((a: string) => a !== '--init' && a !== '--bundle'); +const isForce = args.includes('--force') || args.includes('-f'); +const isMetadataOnly = args.includes('--metadata-only'); +const cleanArgs = args.filter((a: string) => !a.startsWith('--') && !a.startsWith('-')); + +function checkTargetSafety(targetPath: string) { + if (existsSync(targetPath) && !isForce) { + try { + const existing = readFileSync(targetPath, 'utf8'); + const isBoard = existing.includes('generator" content="agent-notes-board"') || existing.includes('id="brand-project-title"'); + if (!isBoard) { + console.error(`❌ 错误:目标文件已存在 (${targetPath}) 且并非看板生成文件!`); + console.error(`💡 为防止意外覆盖已有项目页面(如 Vite/React/Vue 项目的 index.html),请指定其他输出路径或传入 --force 确认覆盖。`); + process.exit(1); + } + } catch {} + } +} if (isInitMode) { const targetPath = cleanArgs[0] ? resolve(cleanArgs[0]) : resolve(process.cwd(), 'index.html'); const projectName = cleanArgs[1] || '工程决策看板'; + checkTargetSafety(targetPath); + let template = readFileSync(templatePath, 'utf8'); template = template.replace('id="brand-project-title">工程决策看板<', () => `id="brand-project-title">${projectName}<`); @@ -37,6 +55,8 @@ const notesDir = cleanArgs[0] ? resolve(cleanArgs[0]) : resolve(process.cwd(), ' const outputPath = cleanArgs[1] ? resolve(cleanArgs[1]) : resolve(process.cwd(), 'demo.html'); const projectName = cleanArgs[2] || '工程决策看板'; +checkTargetSafety(outputPath); + const LIFECYCLES = ['implemented', 'proposed', 'rejected', 'archived']; if (!existsSync(notesDir)) { @@ -168,6 +188,19 @@ console.log(`🔍 [打包模式] 正在扫描笔记目录: ${notesDir}`); const notes = walk(notesDir); console.log(`✅ 解析完成,共发现 ${notes.length} 篇有效 Agent Notes。`); +if (isMetadataOnly) { + console.log('🔒 [安全脱敏] 启用 --metadata-only 模式,已剥离所有笔记的具体正文和详细论证,仅保留决策元数据与关联拓扑。'); + for (const n of notes) { + n.problem = '[正文已脱敏]'; + n.decision = '[正文已脱敏]'; + n.alternatives = ''; + n.consequences = ''; + n.rawBody = `# Agent Note: ${n.title}\n\nStatus: ${n.status}\n\n`; + } +} else { + console.log('⚠️ [安全提示] 正在生成包含完整正文的数据包。如需对外公开发布且避免泄露内部决策细节,请添加 --metadata-only 参数。'); +} + let template = readFileSync(templatePath, 'utf8'); // 注入项目名 @@ -181,5 +214,5 @@ template = template.replace( ); writeFileSync(outputPath, template, 'utf8'); -console.log(`🎉 [打包完成] 自包含大单体看板已生成: ${outputPath}`); -console.log(`💡 该文件内置了全部 ${notes.length} 篇笔记数据,可脱机分发、离线演示或部署至 GitHub Pages。`); +console.log(`🎉 [打包完成] 看板已生成: ${outputPath}`); +console.log(`💡 该文件内置了 ${notes.length} 篇笔记数据,可脱机分发、离线演示或部署至 GitHub Pages。`);