import { requestIntentText } from '../runtime/requestIntent.js'; /** Conservative text-delivery signals, not a claim of semantic understanding. * Keep tiny acknowledgements/questions cheap; substantive text is an artifact too. */ // 计算机 / 对比度 merely contain an analysis term; they are not analysis requests. const ANALYSIS_TASK = /分析|调研|评估|比较|对比(?!度)|审查|复核|计算(?!机)|设计|方案|analy[sz]|research|evaluat|compar|review|calculat|design/i; /** An explicit continuation of the previous request, not a new short request. */ const FOLLOW_UP = /^(?:继续|接着|然后呢|展开|详细|深入|再说|还有呢|为什么|为啥|怎么说|第[一二三四五六七八九十\d]+[点条项个]|go on|continue|elaborate|more detail|why)/i; const CONCLUSION_REQUEST = /建议|推荐|结论|成本|费用|计费|预算|价格|多少钱|风险|冲突|估算|该用|选哪|哪个好|怎么选|是否应该|值不值|值得|recommend|conclusion|cost|pricing|price|budget|estimate|conflict|risk|should (?:i|we)|which (?:one|is better|should)/i; /** * Whether this request asks for a substantive text deliverable — analysis, * research, comparison, calculation, design, a recommendation or a cost/risk * judgement. Decided from the request alone, before any draft exists, so the * host knows up front whether an answer may be held for review and can stream * every other answer live. This mirrors how the advisor is meant to be used: * consult on substantive work and before declaring it done, not on short * reactive exchanges. It used to key off the draft's wording too, so any * 40-character reply containing 建议/风险 was force-reviewed. */ export function requestNeedsTextReview(request: string, previousRequest?: string): boolean { request = requestIntentText(request); if (isReviewProcessQuestion(request)) return false; if (ANALYSIS_TASK.test(request) || CONCLUSION_REQUEST.test(request)) return true; // "继续"/"展开第二点" continue the previous request's deliverable, so they // inherit its review need — otherwise a long analysis continued with // "继续" would skip review just because the follow-up itself is terse. return previousRequest !== undefined && FOLLOW_UP.test(request.trim()) && requestNeedsTextReview(previousRequest); } /** The draft can only exempt itself: a clarifying question or a one-liner in * reply to such a request is not the deliverable yet. */ export function needsTextDeliveryReview(request: string, draft: string, previousRequest?: string): boolean { const text = draft.trim(); if (!text || !requestNeedsTextReview(request, previousRequest)) return false; // Length alone is not substance: clarification questions must not become // reviews merely because they exceed a character cap. if (/^(请提供|请问|能否提供|please provide|could you provide)/i.test(text)) return false; if (/[??]$/.test(text)) return false; // Numeric estimates and decisions can be short and still deserve review. return text.length >= 40 || (text.length >= 20 && /\d/.test(text)); } /** Explain the review process without recursively reviewing that explanation. * A request to change code or review real deliverables is not a process question. */ export function isReviewProcessQuestion(request: string): boolean { request = requestIntentText(request); const actions = request.replace(/(?:不要|不用|无需|不必|不需要)(?:再|去)?\s*(?:修复|重构|实现|开发|部署|修改|审查|评审)(?:代码)?|\b(?:do not|don't|no need to)\s+(?:implement|refactor|deploy|fix)\b/gi, ''); if (/修复|重构|实现|开发|部署|修改|审查代码|评审代码|\b(?:implement|refactor|deploy|fix)\b/i.test(actions)) return false; return /顾问|咨询|advisor/i.test(request) && /几次|次数|频繁|频率|太多|重复咨询|咨询时机|触发|流程|顺序|正常吗|为什么|为何|\b(?:why|how many|too often|frequency)\b/i.test(request); } /** Narrow, explicit maintenance scope, not a line-count-based risk exemption. */ export function isRoutineMaintenanceRequest(request: string): boolean { request = requestIntentText(request); if (/权限|认证|密钥|安全|支付|迁移|部署|协议|架构|删除|\b(?:auth|secret|security|payment|migration|deploy|delete)\b/i.test(request)) return false; return isCosmeticRequest(request) || /^(?:请)?(?:只|仅)(?:修改|修正|改|调整|更新|整理).{0,40}(?:注释|README|\.gitignore|忽略规则)[。.!!]?$/i.test(request.trim()); } export function isRoutineMaintenancePath(path: string): boolean { return /(?:^|[\\/])(?:README(?:\.(?:md|txt|rst))?|\.gitignore)$/i.test(path); } export function reviewSignal(text: string): 'user_dissatisfaction' | 'evidence_conflict' | 'uncertainty' | undefined { text = requestIntentText(text); if (isReviewProcessQuestion(text)) return; // Topic discussion and explicit absence of conflict are not incident signals. if (/^(?:什么是|解释一下|介绍一下|如何处理|what is|explain)\s*/i.test(text.trim())) return; text = text.replace(/(?:没有|不存在|未发现|并无).{0,8}(?:冲突|矛盾|不一致)/g, ''); if (/你.{0,12}(又错了|还是不对|根本没解决|没有解决|答非所问)|我.{0,6}(不满意|不能接受)|\b(?:your (?:answer|solution) is wrong|still not fixed|not what I asked)\b/i.test(text)) return 'user_dissatisfaction'; if (/(?:证据|来源|数据|文档|结论).{0,12}(?:冲突|矛盾|不一致)|\bconflicting (?:evidence|sources|data)\b/i.test(text)) return 'evidence_conflict'; if (/无法(?:判断|确定|解决)|没有把握|高度不确定|\b(?:cannot determine|unable to resolve)\b/i.test(text)) return 'uncertainty'; } /** Only explicit cosmetic edits skip implementation review; ambiguous edits do not. */ export function isCosmeticRequest(request: string): boolean { request = requestIntentText(request); return /^(?:请)?(?:只|仅)(?:修改|修正|改|调整).{0,30}(?:错别字|拼写|标点|文案|typo|spelling)[。.!!]?$/i.test(request.trim()); }