refactor: Agent驱动重构,整章写入替代场景拼接

This commit is contained in:
voocel
2026-03-15 14:14:46 +08:00
parent 25e219e934
commit 568ef0b1d1
27 changed files with 942 additions and 568 deletions

View File

@@ -2,24 +2,9 @@ package domain
import (
"fmt"
"strings"
"unicode/utf8"
)
// MergeScenes 将多个场景草稿按顺序合并为完整章节正文。
// 返回合并后的正文和总字数(按 rune 计)。
func MergeScenes(scenes []SceneDraft) (string, int) {
var b strings.Builder
for i, s := range scenes {
if i > 0 {
b.WriteString("\n\n")
}
b.WriteString(s.Content)
}
content := b.String()
return content, utf8.RuneCountInString(content)
}
// ReviewInterval 全局审阅间隔(每 N 章触发一次)。
const ReviewInterval = 5
@@ -32,7 +17,6 @@ func ShouldReview(completedCount int) (bool, string) {
}
// ShouldArcReview 长篇模式下判断是否需要弧级/卷级评审。
// 弧结束时触发评审,替代固定间隔。
func ShouldArcReview(isArcEnd, isVolumeEnd bool, volume, arc int) (bool, string) {
if isVolumeEnd {
return true, fmt.Sprintf("第 %d 卷第 %d 弧结束(卷结束),触发弧级+卷级评审", volume, arc)
@@ -42,3 +26,8 @@ func ShouldArcReview(isArcEnd, isVolumeEnd bool, volume, arc int) (bool, string)
}
return false, ""
}
// WordCount 按 rune 计算字数。
func WordCount(content string) int {
return utf8.RuneCountInString(content)
}

View File

@@ -1,30 +1,15 @@
package domain
// ChapterPlan 章节规划,写入 drafts/{ch}.plan.json
// ChapterPlan 章节写作构思Writer 自主生成
// 不再强制场景拆分Agent 自己决定如何组织内容。
type ChapterPlan struct {
Chapter int `json:"chapter"`
Title string `json:"title"`
Goal string `json:"goal"`
Conflict string `json:"conflict"`
Scenes []ScenePlan `json:"scenes"`
Hook string `json:"hook"`
EmotionArc string `json:"emotion_arc,omitempty"`
}
// ScenePlan 场景规划。
type ScenePlan struct {
Index int `json:"index"`
Summary string `json:"summary"`
POV string `json:"pov,omitempty"`
Location string `json:"location,omitempty"`
}
// SceneDraft 场景草稿。
type SceneDraft struct {
Chapter int `json:"chapter"`
Scene int `json:"scene"`
Content string `json:"content"`
WordCount int `json:"word_count"`
Chapter int `json:"chapter"`
Title string `json:"title"`
Goal string `json:"goal"`
Conflict string `json:"conflict"`
Hook string `json:"hook"`
EmotionArc string `json:"emotion_arc,omitempty"`
Notes string `json:"notes,omitempty"` // Agent 的自由备忘
}
// ChapterSummary 章节摘要,供后续章节的上下文窗口使用。
@@ -57,25 +42,31 @@ type CharacterSnapshot struct {
Volume int `json:"volume"`
Arc int `json:"arc"`
Name string `json:"name"`
Status string `json:"status"` // 存活/受伤/失踪...
Power string `json:"power,omitempty"` // 能力变化
Motivation string `json:"motivation"` // 当前动机
Relations string `json:"relations,omitempty"` // 关键关系变化
Status string `json:"status"`
Power string `json:"power,omitempty"`
Motivation string `json:"motivation"`
Relations string `json:"relations,omitempty"`
}
// OutlineFeedback Writer 对大纲的反馈,提交章节时可选。
type OutlineFeedback struct {
Deviation string `json:"deviation"` // 偏离描述
Suggestion string `json:"suggestion"` // 调整建议
}
// CommitResult 是 commit_chapter 工具的结构化返回值。
// 宿主程序和 Coordinator 读取此信号做控制决策。
type CommitResult struct {
Chapter int `json:"chapter"`
Committed bool `json:"committed"`
WordCount int `json:"word_count"`
SceneCount int `json:"scene_count"`
NextChapter int `json:"next_chapter"`
ReviewRequired bool `json:"review_required"`
ReviewReason string `json:"review_reason,omitempty"`
HookType string `json:"hook_type,omitempty"` // 钩子类型crisis/mystery/desire/emotion/choice
DominantStrand string `json:"dominant_strand,omitempty"` // 本章主导线quest/fire/constellation
// 长篇分层信号(仅 Layered 模式)
Chapter int `json:"chapter"`
Committed bool `json:"committed"`
WordCount int `json:"word_count"`
NextChapter int `json:"next_chapter"`
ReviewRequired bool `json:"review_required"`
ReviewReason string `json:"review_reason,omitempty"`
HookType string `json:"hook_type,omitempty"`
DominantStrand string `json:"dominant_strand,omitempty"`
Feedback *OutlineFeedback `json:"feedback,omitempty"`
// 长篇分层信号
ArcEnd bool `json:"arc_end,omitempty"`
VolumeEnd bool `json:"volume_end,omitempty"`
Volume int `json:"volume,omitempty"`