import fs from "fs"; const lexPath = "src/services/parse/instruction-lexicon.ts"; let lex = fs.readFileSync(lexPath, "utf8"); if (!lex.includes("isForwardShellSegment")) { lex = lex.replace( `export function isNonInstructionSegment(text: string): boolean { const compact = text.replace(/\\s+/g, " ").trim(); if (compact.length < 6) return true;`, `/** QQ/中间人纯转发壳,无客�?Dear 正文 */ export function isForwardShellSegment(text: string): boolean { const compact = text.replace(/\\s+/g, " ").trim(); if (/发自我的iPhone/.test(compact)) return true; if ( /date@usasinogroup\\.com/i.test(compact) && !/Dear[,,]/.test(compact) && !BODY_ACTION_RE.test(compact) ) { return true; } return false; } export function isNonInstructionSegment(text: string): boolean { const compact = text.replace(/\\s+/g, " ").trim(); if (compact.length < 6) return true; if (isForwardShellSegment(text)) return true;`, ); fs.writeFileSync(lexPath, lex, "utf8"); } const splitPath = "src/services/parse/split-instructions.ts"; let sp = fs.readFileSync(splitPath, "utf8"); if (!sp.includes("bodyForKindDetect")) { sp = sp.replace( `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)); }`, `/** 去掉段内「主�? Re:Re:新增预报」历史主题污�?*/ function bodyForKindDetect(segBody: string): string { if (!BODY_ACTION_RE.test(segBody)) return segBody; return segBody .split(/\\n/) .filter( (line) => !/(?:主题|主旨|Subject)\\s*[�?].*(?:新增预报|Fw:|转发)/i.test(line), ) .join("\\n"); } export function detectKindsForSegment( segSubject: string, segBody: string, ): InstructionUiKind[] { if (isNonInstructionSegment(segBody)) return []; const bodyText = bodyForKindDetect(segBody); const bodyHits = matchKeywordRules(bodyText, "body"); const useSubject = !BODY_ACTION_RE.test(segBody) || /请查收新增预�?.test(bodyText); 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)); }`, ); fs.writeFileSync(splitPath, sp, "utf8"); } console.log( JSON.stringify({ lex: fs.readFileSync(lexPath, "utf8").includes("isForwardShellSegment"), split: fs.readFileSync(splitPath, "utf8").includes("bodyForKindDetect"), }), );