Documentation
¶
Overview ¶
Package imp 实现外部小说章节的导入与反推。
核心思路:用 LLM 反推 foundation + 每章事实,复用现有 save_foundation / commit_chapter 工具的原子三件套落盘。导入完成后 store 状态等同于"写完 N 章 后崩溃",调用方调 host.Resume() 即可无缝续写。
导入是确定性回放,不属于 LLM 决策范畴。本包直接调 LLM 客户端 + 工具。
Index ¶
- func PersistChapter(ctx context.Context, st *store.Store, commitTool *tools.CommitChapterTool, ...) error
- func PersistFoundation(ctx context.Context, st *store.Store, scale domain.PlanningTier, ...) error
- func Run(ctx context.Context, deps Deps, opts Options) (<-chan Event, error)
- type Chapter
- type ChapterAnalysis
- type Deps
- type Event
- type FoundationResult
- type LLMChat
- type Options
- type Prompts
- type Stage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PersistChapter ¶
func PersistChapter( ctx context.Context, st *store.Store, commitTool *tools.CommitChapterTool, chapter int, title, content string, a *ChapterAnalysis, ) error
PersistChapter 把分析结果落盘:先写章节草稿,再调 commit_chapter 执行原子三件套。 已完成章节会被 commit_chapter 自身的幂等检查跳过,仍返回 nil 让循环继续。
func PersistFoundation ¶
func PersistFoundation(ctx context.Context, st *store.Store, scale domain.PlanningTier, fr *FoundationResult) error
PersistFoundation 把反推结果写入 Store,顺序与 Architect 长篇 prompt 一致: premise → characters → world_rules → layered_outline → compass。导入正文作为第一卷 落成分层大纲,使导入的书可被续写、可扩展。每步都触发 save_foundation 同款落盘逻辑。
不直接调 SaveFoundationTool 是因为这里是确定性回放,无需走 LLM 工具调度。 但保持与 SaveFoundationTool 相同的副作用:phase 推进、checkpoint 追加。
Types ¶
type ChapterAnalysis ¶
type ChapterAnalysis struct {
Summary string
Characters []string
KeyEvents []string
TimelineEvents []domain.TimelineEvent
ForeshadowUpdates []domain.ForeshadowUpdate
RelationshipChanges []domain.RelationshipEntry
StateChanges []domain.StateChange
HookType string
DominantStrand string
}
ChapterAnalysis 是单章反推的结构化产物,字段直接对齐 commit_chapter 入参。
func AnalyzeChapter ¶
func AnalyzeChapter( ctx context.Context, llm LLMChat, systemPrompt string, chapter int, chapterTitle, chapterContent string, premise, charactersBlock string, activeHooks []domain.ForeshadowEntry, ) (*ChapterAnalysis, error)
AnalyzeChapter 用一次 LLM 调用,从单章正文反推 commit_chapter 所需事实。 hooksContext 是已知伏笔池的快照(可空),用于让 LLM 复用既有 ID。
type Deps ¶
type Deps struct {
Store *store.Store
CommitTool *tools.CommitChapterTool
LLM LLMChat // 同一模型即可,foundation/analyzer 都是结构化反推
Prompts Prompts
}
Deps 把 runner 需要的可插拔依赖一次性传入,方便测试 mock。
type Event ¶
type Event struct {
Time time.Time
Stage Stage
Current int // chapter 阶段的当前章号;其它阶段为 0
Total int // 总章数
Message string // 人类可读描述
Err error // StageError 时携带
}
Event 是导入流程对外发出的进度事件。
type FoundationResult ¶
type FoundationResult struct {
Premise string // Markdown 字符串
Characters []domain.Character // 角色档案
WorldRules []domain.WorldRule // 世界规则
Volumes []domain.VolumeOutline // 分层大纲:导入正文作为第一卷(可续写、可扩展)
Compass *domain.StoryCompass // 续写方向锚点(ending_direction / open_threads / estimated_scale)
}
FoundationResult 是 Foundation 反推的结构化产物。
func ReverseFoundation ¶
func ReverseFoundation(ctx context.Context, llm LLMChat, systemPrompt string, chapters []Chapter) (*FoundationResult, error)
ReverseFoundation 用一次 LLM 调用,从已切分的章节正文反推 foundation。 不调用 save_foundation,纯函数;持久化由调用方决定。
type LLMChat ¶
type LLMChat interface {
Generate(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, opts ...agentcore.CallOption) (*agentcore.LLMResponse, error)
}
LLMChat 是 imp 包对 ChatModel 的最小依赖:仅需要一次普通文本生成。 抽出独立接口便于单测注入 mock,避免直接耦合 agentcore 客户端。
type Options ¶
type Options struct {
// SourcePath 必填。单个 txt/md 文件路径。
SourcePath string
// ResumeFrom 可选。从第 N 章开始导入;0 / 1 表示从头。
// 若 > 1,会跳过 Foundation 反推(认为已落盘)。
ResumeFrom int
}
Options 控制导入行为。