fix(dingtalk): 推理正文边界支持「首行即正文」并补齐卡片结构诊断
- BodyStartOffset:内容首个非空行即结构行时正文从头开始,避免收尾裁剪 把标题+首段一起删掉(118 条生产样本中 31 条、最多 526 字) - 语料回归守卫:隐藏前缀不得含结构行、上限 600 字;单测补 suffix 断言 - 卡片诊断新增 body_ok/body_line/body_prefix_runes/banner_pos/first_heading_line (定位流式残留推理末句,只看结构不看文本)
This commit is contained in:
@@ -57,14 +57,23 @@ func TrimReasoningNarration(content string) string {
|
||||
}
|
||||
|
||||
// BodyStartOffset returns the byte offset where the final answer body starts.
|
||||
// A line qualifies as the body start only when it is a structural Markdown
|
||||
// line (heading, bold-only line, table row or blockquote), directly follows a
|
||||
// blank line and is not inside a fenced code block.
|
||||
// A line qualifies as the body start when it is a structural Markdown line
|
||||
// (heading, bold-only line, table row or blockquote) and is not inside a
|
||||
// fenced code block, either directly following a blank line or being the very
|
||||
// first non-blank line of the content.
|
||||
//
|
||||
// The first-line rule matters: 31 of 118 production reasoning answers open
|
||||
// directly with their body ("# 标题" first). Without it the scan would skip
|
||||
// that opening line and fire on the *next* structural line, so finalize
|
||||
// deleted the answer's title plus its opening paragraph (up to 526 chars) while
|
||||
// the streaming feed, whose display inserts blank lines between steps, kept
|
||||
// them - mid-stream and finalize text disagreed.
|
||||
func BodyStartOffset(content string) (int, bool) {
|
||||
lines := strings.Split(content, "\n")
|
||||
fence := ""
|
||||
offset := 0
|
||||
previousBlank := false
|
||||
seenContent := false
|
||||
for i, raw := range lines {
|
||||
trimmed := strings.TrimSpace(raw)
|
||||
if marker := answerFenceLineRE.FindString(trimmed); marker != "" &&
|
||||
@@ -74,12 +83,21 @@ func BodyStartOffset(content string) (int, bool) {
|
||||
} else {
|
||||
fence = ""
|
||||
}
|
||||
seenContent = true
|
||||
previousBlank = false
|
||||
offset += len(raw) + 1
|
||||
continue
|
||||
}
|
||||
if i > 0 && fence == "" && previousBlank && isAnswerBodyLine(trimmed) {
|
||||
return offset, true
|
||||
if fence == "" {
|
||||
if !seenContent && isAnswerBodyLine(trimmed) {
|
||||
return offset, true
|
||||
}
|
||||
if i > 0 && previousBlank && isAnswerBodyLine(trimmed) {
|
||||
return offset, true
|
||||
}
|
||||
}
|
||||
if trimmed != "" {
|
||||
seenContent = true
|
||||
}
|
||||
previousBlank = trimmed == ""
|
||||
offset += len(raw) + 1
|
||||
|
||||
Reference in New Issue
Block a user