import fs from "fs"; const p = "src/services/parse/split-instructions.ts"; let t = fs.readFileSync(p, "utf8"); t = t.replace( `import { ATTACHMENT_HINT_RE, KEYWORD_RULES, SEGMENT_BOUNDARY_PATTERNS, SEGMENT_START_LINE_RE, matchKeywordRules, type InstructionUiKind, } from "@/services/parse/instruction-lexicon";`, `import { ATTACHMENT_HINT_RE, BODY_ACTION_RE, KEYWORD_RULES, SEGMENT_BOUNDARY_PATTERNS, SEGMENT_START_LINE_RE, isNonInstructionSegment, matchKeywordRules, type InstructionUiKind, } from "@/services/parse/instruction-lexicon";`, ); const oldDetect = `export function detectUiKindsFromText( subject: string, body: string, filenames: string[] = [], ): InstructionUiKind[] { const kinds = new Set(); for (const h of matchKeywordRules(subject, "subject")) kinds.add(h.uiKind); for (const h of matchKeywordRules(body, "body")) kinds.add(h.uiKind); for (const f of filenames) { const whereHits = matchKeywordRules(f, "attachment"); for (const h of whereHits) kinds.add(h.uiKind); if (isDoAttachmentFilename(f)) kinds.add("do_upload"); if (ATTACHMENT_HINT_RE.test(f) && /换标|贴标|覆盖贴|操作指令/.test(f)) { kinds.add("work_order"); } } return UI_KIND_ORDER.filter((k) => kinds.has(k)); }`; const newDetect = `export function detectUiKindsFromText( subject: string, body: string, filenames: string[] = [], ): InstructionUiKind[] { const kinds = new Set(); for (const h of matchKeywordRules(subject, "subject")) kinds.add(h.uiKind); for (const h of matchKeywordRules(body, "body")) kinds.add(h.uiKind); for (const f of filenames) { for (const h of matchKeywordRules(f, "attachment")) kinds.add(h.uiKind); if (isDoAttachmentFilename(f)) kinds.add("do_upload"); if (ATTACHMENT_HINT_RE.test(f) && /换标|贴标|覆盖贴|操作指令/.test(f)) { kinds.add("work_order"); } } return UI_KIND_ORDER.filter((k) => kinds.has(k)); } /** 单段:正文有动作词时,忽�?Re: 链路上的历史「新增预报」主�?*/ export function detectKindsForSegment( segSubject: string, segBody: string, ): InstructionUiKind[] { if (isNonInstructionSegment(segBody)) return []; const bodyHits = matchKeywordRules(segBody, "body"); const useSubject = !BODY_ACTION_RE.test(segBody) || /新增预报|请查收新增预�?.test(segBody); const subjectHits = useSubject ? matchKeywordRules(segSubject, "subject") : []; const kinds = new Set([ ...bodyHits.map((h) => h.uiKind), ...subjectHits.map((h) => h.uiKind), ]); return UI_KIND_ORDER.filter((k) => kinds.has(k)); }`; if (!t.includes(oldDetect)) { console.error("detectUiKindsFromText block not found"); process.exit(1); } t = t.replace(oldDetect, newDetect); t = t.replace( `segments.forEach((seg, i) => { const segSubject = extractSegmentSubject(seg, ""); const kinds = detectUiKindsFromText(segSubject || subject, seg, []);`, `segments.forEach((seg, i) => { if (isNonInstructionSegment(seg)) return; const segSubject = extractSegmentSubject(seg, ""); const kinds = detectKindsForSegment(segSubject, seg);`, ); fs.writeFileSync(p, t, "utf8"); console.log( JSON.stringify({ ok: t.includes("detectKindsForSegment") && t.includes("isNonInstructionSegment") && t.includes("BODY_ACTION_RE"), }), );