diff --git a/src/commands/form/_ai.ts b/src/commands/form/_ai.ts index 240248f..6ac2d24 100644 --- a/src/commands/form/_ai.ts +++ b/src/commands/form/_ai.ts @@ -220,10 +220,12 @@ export async function callAiForm(keyword: string): Promise { return await callSswAiRepair(keyword, 'NCPF 429 retry exhausted') } - // 场景 A: 后端错误 (SYS181 / JSON 解析失败) → fallback SSW + // 场景 A: 后端错误 (SYS181 / 截断 / 转换失败) → fallback SSW + // v0.15+ 修复 (2026-07-02 audit FINDING-F1): 删 'json'/'parse' 子串 (过宽, 误判正常错误) + // 保留: 'sys181' (截断特征) / '响应缺' (NCPF 静默截断) / '转换失败' (LLM 输出无法序列化) if (r.code !== 200) { const m = (r.msg || '').toLowerCase() - const isTruncationErr = ['sys181', 'json', '转换失败', '响应缺', 'parse'].some(s => m.includes(s)) + const isTruncationErr = ['sys181', '转换失败', '响应缺'].some(s => m.includes(s)) if (isTruncationErr) { log.warn(`! jnpf 后端 AI 建表失败 (code=${r.code}): ${r.msg} → fallback SSW 修复`) return await callSswAiRepair(keyword, 'jnpf 后端错误') @@ -232,11 +234,17 @@ export async function callAiForm(keyword: string): Promise { } // 场景 B: 静默截断 (code=200 但 data 空) → fallback SSW + // v0.15+ 修复 (2026-07-02 audit FINDING-F2): 加 fieldCount 检测, 避免中间截断 (enCode 有但 fields=[]) 漏判 const data = r.data || {} const isEmpty = !data.enCode && !data.fullName && (!data.aiModelList || data.aiModelList.length === 0) - const fieldCount = estimateFieldCount(keyword) - if (isEmpty) { - log.warn(`! jnpf 后端 AI 响应为空 → fallback SSW 修复 (字段数: ${fieldCount})`) + // 估算 keyword 实际要求字段数 (每个"/"或"字段"/"列"分隔符 +1) + const requiredFieldCount = estimateFieldCount(keyword) + // 实际返回字段数 (aiModelList[0].fields.length) + const actualFieldCount = (data.aiModelList && data.aiModelList[0]?.fields?.length) || 0 + // 截断判定: 用户要求 N 字段, 但 N=0 或 (N>=3 但实际 0) → 中间截断 + const isSilentTruncation = isEmpty || (requiredFieldCount >= 3 && actualFieldCount === 0) + if (isSilentTruncation) { + log.warn(`! jnpf 后端 AI 响应截断 → fallback SSW 修复 (要求 ${requiredFieldCount} 字段, 实际 ${actualFieldCount})`) return await callSswAiRepair(keyword, 'jnpf 后端静默截断') }