/** commit 信息规范: [业务域/页面名] 动作: 摘要 (动作 ∈ 新增|重构|更新|修复|标注|元数据|初始化|门户) * 已合规则原样;不合规则自动包装(从暂存清单推页面名,新文件判"新增") */ const MSG_RE = /^\[[^\]]+\]\s*(新增|重构|更新|修复|标注|元数据|初始化|门户)\s*[::]/; export function normalizeMsg(rawMsg, stagedLines) { const m = (rawMsg || "").trim(); if (MSG_RE.test(m)) return m; const pageFiles = stagedLines.map(l => l.slice(3).trim()).filter(f => /\.html?$/i.test(f)); let scope; if (pageFiles.length === 1) scope = pageFiles[0].replace(/\.html?$/i, ""); else if (pageFiles.length > 1) { const dirs = pageFiles.map(f => f.split("/")[0]); scope = dirs.every(d => d === dirs[0]) ? dirs[0] : "原型库"; } else scope = "原型库"; const action = stagedLines.some(l => /^A/.test(l)) ? "新增" : "更新"; return `[${scope}] ${action}: ${m || "原型改动"}`; }