store

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArcBoundary

type ArcBoundary struct {
	IsArcEnd    bool // 是否为弧内最后一章
	IsVolumeEnd bool // 是否同时为卷内最后一章
	Volume      int  // 当前章所在卷
	Arc         int  // 当前章所在弧
	NextVolume  int  // 下一章所在卷(0 = 全书结束)
	NextArc     int  // 下一章所在弧(0 = 全书结束)
}

ArcBoundary 弧边界信息。

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 封装小说输出目录,提供所有状态读写操作。

func NewStore

func NewStore(dir string) *Store

NewStore 创建状态管理器,dir 为小说输出根目录。

func (*Store) AppendDraft

func (s *Store) AppendDraft(chapter int, content string) error

AppendDraft 追加内容到现有草稿(续写模式)。 读取和写入在同一个写锁内完成,防止并发追加丢失数据。

func (*Store) AppendStateChanges

func (s *Store) AppendStateChanges(changes []domain.StateChange) error

AppendStateChanges 追加角色状态变化到 meta/state_changes.json。

func (*Store) AppendSteerEntry

func (s *Store) AppendSteerEntry(entry domain.SteerEntry) error

AppendSteerEntry 追加用户干预记录到 meta/run.json。

func (*Store) AppendTimelineEvents

func (s *Store) AppendTimelineEvents(newEvents []domain.TimelineEvent) error

AppendTimelineEvents 追加时间线事件。

func (*Store) CheckArcBoundary

func (s *Store) CheckArcBoundary(chapter int) (*ArcBoundary, error)

CheckArcBoundary 检查某章是否为弧/卷的最后一章。 非分层大纲或未找到章节时返回 nil。

func (*Store) ClearHandledSteer

func (s *Store) ClearHandledSteer() error

ClearHandledSteer 原子性地清除 PendingSteer 并重置 FlowSteering 状态。 同时操作 run.json 和 progress.json,在同一个写锁内完成,避免崩溃导致不一致。

func (*Store) ClearInProgress

func (s *Store) ClearInProgress() error

ClearInProgress 清除进度中间状态(章节提交后调用)。

func (*Store) ClearLastCommit

func (s *Store) ClearLastCommit() error

ClearLastCommit 清除 commit 信号文件,防止重复消费。

func (*Store) ClearLastReview

func (s *Store) ClearLastReview() error

ClearLastReview 清除审阅信号文件,防止重复消费。

func (*Store) ClearLayeredOutline

func (s *Store) ClearLayeredOutline() error

ClearLayeredOutline 清理分层大纲文件,供从长篇降级为普通大纲时使用。

func (*Store) ClearPendingRewrites

func (s *Store) ClearPendingRewrites() error

ClearPendingRewrites 强制清空重写队列。

func (*Store) ClearPendingSteer

func (s *Store) ClearPendingSteer() error

ClearPendingSteer 清除已处理的 Steer 指令。

func (*Store) ClearStaleSignals

func (s *Store) ClearStaleSignals()

ClearStaleSignals 清理残留的信号文件。 在进程重启时调用,防止上次崩溃遗留的信号被误消费。

func (*Store) CompleteRewrite

func (s *Store) CompleteRewrite(chapter int) error

CompleteRewrite 从待重写队列中移除已完成的章节。 队列清空时自动将 Flow 重置为 writing 并清除 RewriteReason。

func (*Store) Dir

func (s *Store) Dir() string

Dir 返回输出根目录。

func (*Store) ExtractDialogue

func (s *Store) ExtractDialogue(characterName string, aliases []string, maxSamples int) []string

ExtractDialogue 从已提交章节中提取指定角色的对话片段。 通过检查对话所在段落是否包含角色名/别名来关联。

func (*Store) ExtractStyleAnchors

func (s *Store) ExtractStyleAnchors(maxAnchors int) []string

ExtractStyleAnchors 从已提交章节中提取代表性段落作为风格锚点。 选取描写密度高(非对话、非短句)的段落。

func (*Store) GetChapterFromLayered

func (s *Store) GetChapterFromLayered(chapter int) (*domain.OutlineEntry, error)

GetChapterFromLayered 从分层大纲中按全局章节号查找。

func (*Store) GetChapterOutline

func (s *Store) GetChapterOutline(chapter int) (*domain.OutlineEntry, error)

GetChapterOutline 获取指定章节的大纲条目。

func (*Store) Init

func (s *Store) Init() error

Init 创建所需的子目录结构。

func (*Store) InitProgress

func (s *Store) InitProgress(novelName string, totalChapters int) error

InitProgress 创建初始进度。

func (*Store) InitRunMeta

func (s *Store) InitRunMeta(style, provider, model string) error

InitRunMeta 初始化或更新运行元信息,保留已有的 SteerHistory。

func (*Store) LoadActiveForeshadow

func (s *Store) LoadActiveForeshadow() ([]domain.ForeshadowEntry, error)

LoadActiveForeshadow 返回未回收的伏笔条目(status != "resolved")。

func (*Store) LoadAllSummaries

func (s *Store) LoadAllSummaries(current int) ([]domain.ChapterSummary, error)

LoadAllSummaries 加载 current 章之前的所有摘要(短篇全量模式)。

func (*Store) LoadAllVolumeSummaries

func (s *Store) LoadAllVolumeSummaries() ([]domain.VolumeSummary, error)

LoadAllVolumeSummaries 加载所有已有卷摘要。 从分层大纲获取实际卷数,无分层大纲时扫描到首个缺失为止。

func (*Store) LoadAndClearLastCommit

func (s *Store) LoadAndClearLastCommit() (*domain.CommitResult, error)

LoadAndClearLastCommit 原子性读取并清除 commit 信号,防止 TOCTOU 竞态。

func (*Store) LoadAndClearLastReview

func (s *Store) LoadAndClearLastReview() (*domain.ReviewEntry, error)

LoadAndClearLastReview 原子性读取并清除审阅信号,防止 TOCTOU 竞态。

func (*Store) LoadArcSummaries

func (s *Store) LoadArcSummaries(volume int) ([]domain.ArcSummary, error)

LoadArcSummaries 加载一卷内所有已有弧摘要。 从分层大纲获取实际弧数,无分层大纲时扫描到首个缺失为止。

func (*Store) LoadArcSummary

func (s *Store) LoadArcSummary(volume, arc int) (*domain.ArcSummary, error)

LoadArcSummary 读取指定弧的摘要。

func (*Store) LoadChapterContent

func (s *Store) LoadChapterContent(chapter int) (string, int, error)

LoadChapterContent 加载章节草稿正文及字数。

func (*Store) LoadChapterPlan

func (s *Store) LoadChapterPlan(chapter int) (*domain.ChapterPlan, error)

LoadChapterPlan 读取章节构思。

func (*Store) LoadChapterRange

func (s *Store) LoadChapterRange(from, to, maxRunes int) (map[int]string, error)

LoadChapterRange 读取指定范围的终稿原文片段(每章截取前 maxRunes 个字符)。

func (*Store) LoadChapterText

func (s *Store) LoadChapterText(chapter int) (string, error)

LoadChapterText 读取已提交的终稿原文。

func (*Store) LoadCharacters

func (s *Store) LoadCharacters() ([]domain.Character, error)

LoadCharacters 从 characters.json 读取角色档案。

func (*Store) LoadDraft

func (s *Store) LoadDraft(chapter int) (string, error)

LoadDraft 读取整章草稿。

func (*Store) LoadForeshadowLedger

func (s *Store) LoadForeshadowLedger() ([]domain.ForeshadowEntry, error)

LoadForeshadowLedger 读取伏笔账本。

func (*Store) LoadLastCommit

func (s *Store) LoadLastCommit() (*domain.CommitResult, error)

LoadLastCommit 读取最近一次 commit 结果。

func (*Store) LoadLastReview

func (s *Store) LoadLastReview(fromChapter int) (*domain.ReviewEntry, error)

LoadLastReview 读取最近一次全局审阅。从 chapter 往前搜索。

func (*Store) LoadLastReviewSignal

func (s *Store) LoadLastReviewSignal() (*domain.ReviewEntry, error)

LoadLastReviewSignal 读取审阅信号文件。

func (*Store) LoadLatestSnapshots

func (s *Store) LoadLatestSnapshots() ([]domain.CharacterSnapshot, error)

LoadLatestSnapshots 加载最近一次角色快照(按卷弧倒序查找)。 从分层大纲获取实际卷弧数量,避免盲扫。

func (*Store) LoadLayeredOutline

func (s *Store) LoadLayeredOutline() ([]domain.VolumeOutline, error)

LoadLayeredOutline 读取分层大纲。

func (*Store) LoadOutline

func (s *Store) LoadOutline() ([]domain.OutlineEntry, error)

LoadOutline 从 outline.json 读取结构化大纲。

func (*Store) LoadPremise

func (s *Store) LoadPremise() (string, error)

LoadPremise 读取 premise.md。不存在时返回空字符串。

func (*Store) LoadProgress

func (s *Store) LoadProgress() (*domain.Progress, error)

LoadProgress 读取 meta/progress.json。不存在时返回 nil。

func (*Store) LoadRecentStateChanges

func (s *Store) LoadRecentStateChanges(currentChapter, count int) ([]domain.StateChange, error)

LoadRecentStateChanges 加载指定章节之前最近 count 章的状态变化。

func (*Store) LoadRecentSummaries

func (s *Store) LoadRecentSummaries(current, count int) ([]domain.ChapterSummary, error)

LoadRecentSummaries 加载 current 章之前最近 count 章的摘要。

func (*Store) LoadRecentTimeline

func (s *Store) LoadRecentTimeline(current, window int) ([]domain.TimelineEvent, error)

LoadRecentTimeline 返回最近 window 章内的时间线事件(chapter >= current-window)。

func (*Store) LoadRelationships

func (s *Store) LoadRelationships() ([]domain.RelationshipEntry, error)

LoadRelationships 读取人物关系状态。

func (*Store) LoadReview

func (s *Store) LoadReview(chapter int) (*domain.ReviewEntry, error)

LoadReview 读取章节审阅结果。

func (*Store) LoadRunMeta

func (s *Store) LoadRunMeta() (*domain.RunMeta, error)

LoadRunMeta 读取运行元信息。

func (*Store) LoadSnapshots

func (s *Store) LoadSnapshots(volume, arc int) ([]domain.CharacterSnapshot, error)

LoadSnapshots 读取指定卷弧的角色快照。

func (*Store) LoadStateChanges

func (s *Store) LoadStateChanges() ([]domain.StateChange, error)

LoadStateChanges 读取全部状态变化记录。

func (*Store) LoadSummary

func (s *Store) LoadSummary(chapter int) (*domain.ChapterSummary, error)

LoadSummary 读取指定章节的摘要。

func (*Store) LoadTimeline

func (s *Store) LoadTimeline() ([]domain.TimelineEvent, error)

LoadTimeline 读取时间线。

func (*Store) LoadVolumeSummary

func (s *Store) LoadVolumeSummary(volume int) (*domain.VolumeSummary, error)

LoadVolumeSummary 读取指定卷的摘要。

func (*Store) LoadWorldRules

func (s *Store) LoadWorldRules() ([]domain.WorldRule, error)

LoadWorldRules 读取世界规则。

func (*Store) LocateChapter

func (s *Store) LocateChapter(chapter int) (volume, arc int, err error)

LocateChapter 根据全局章节号定位所在的卷和弧。

func (*Store) MarkChapterComplete

func (s *Store) MarkChapterComplete(chapter, wordCount int, hookType, dominantStrand string) error

MarkChapterComplete 标记章节完成,原子性更新进度。 支持重写场景:如果章节已完成,先减去旧字数再加新字数。 hookType 和 dominantStrand 用于节奏追踪,可为空。

func (*Store) MarkComplete

func (s *Store) MarkComplete() error

MarkComplete 标记全书创作完成。

func (*Store) SaveArcSummary

func (s *Store) SaveArcSummary(sum domain.ArcSummary) error

SaveArcSummary 保存弧级摘要到 summaries/arc-v{vol}a{arc}.json。

func (*Store) SaveChapterPlan

func (s *Store) SaveChapterPlan(plan domain.ChapterPlan) error

SaveChapterPlan 保存章节构思到 drafts/{ch}.plan.json。

func (*Store) SaveCharacterSnapshots

func (s *Store) SaveCharacterSnapshots(volume, arc int, snapshots []domain.CharacterSnapshot) error

SaveCharacterSnapshots 保存角色状态快照到 meta/snapshots/v{vol}a{arc}.json。

func (*Store) SaveCharacters

func (s *Store) SaveCharacters(chars []domain.Character) error

SaveCharacters 同时保存 characters.json 和 characters.md。

func (*Store) SaveCheckpoint

func (s *Store) SaveCheckpoint(label string) error

SaveCheckpoint 保存当前进度快照到 meta/checkpoints/。

func (*Store) SaveDraft

func (s *Store) SaveDraft(chapter int, content string) error

SaveDraft 保存整章草稿到 drafts/{ch}.draft.md。

func (*Store) SaveFinalChapter

func (s *Store) SaveFinalChapter(chapter int, content string) error

SaveFinalChapter 保存最终章节正文到 chapters/{ch}.md。

func (*Store) SaveForeshadowLedger

func (s *Store) SaveForeshadowLedger(entries []domain.ForeshadowEntry) error

SaveForeshadowLedger 全量写入 foreshadow_ledger.json + foreshadow_ledger.md。

func (*Store) SaveLastCommit

func (s *Store) SaveLastCommit(result domain.CommitResult) error

SaveLastCommit 保存最近一次 commit 结果到 meta/last_commit.json。 用于宿主程序读取结构化信号。

func (*Store) SaveLastReview

func (s *Store) SaveLastReview(r domain.ReviewEntry) error

SaveLastReview 保存最近一次审阅结果到 meta/last_review.json,供宿主读取。

func (*Store) SaveLayeredOutline

func (s *Store) SaveLayeredOutline(volumes []domain.VolumeOutline) error

SaveLayeredOutline 保存分层大纲(长篇模式)。 同时保存 layered_outline.json(机器读)和 layered_outline.md(人读)。

func (*Store) SaveOutline

func (s *Store) SaveOutline(entries []domain.OutlineEntry) error

SaveOutline 同时保存 outline.json(机器读)和 outline.md(人读)。

func (*Store) SavePremise

func (s *Store) SavePremise(content string) error

SavePremise 保存故事前提到 premise.md。

func (*Store) SaveProgress

func (s *Store) SaveProgress(p *domain.Progress) error

SaveProgress 保存进度到 meta/progress.json。

func (*Store) SaveRelationships

func (s *Store) SaveRelationships(entries []domain.RelationshipEntry) error

SaveRelationships 全量写入 relationship_state.json + relationship_state.md。

func (*Store) SaveReview

func (s *Store) SaveReview(r domain.ReviewEntry) error

SaveReview 保存审阅结果。scope=chapter 写 reviews/{ch}.json,scope=global 写 reviews/{ch}-global.json。

func (*Store) SaveRunMeta

func (s *Store) SaveRunMeta(meta domain.RunMeta) error

SaveRunMeta 保存运行元信息到 meta/run.json。

func (*Store) SaveSummary

func (s *Store) SaveSummary(sum domain.ChapterSummary) error

SaveSummary 保存章节摘要到 summaries/{ch}.json。

func (*Store) SaveTimeline

func (s *Store) SaveTimeline(events []domain.TimelineEvent) error

SaveTimeline 全量写入 timeline.json + timeline.md。

func (*Store) SaveVolumeSummary

func (s *Store) SaveVolumeSummary(sum domain.VolumeSummary) error

SaveVolumeSummary 保存卷级摘要到 summaries/vol-v{vol}.json。

func (*Store) SaveWorldRules

func (s *Store) SaveWorldRules(rules []domain.WorldRule) error

SaveWorldRules 全量写入 world_rules.json + world_rules.md。

func (*Store) SetFlow

func (s *Store) SetFlow(flow domain.FlowState) error

SetFlow 更新当前流程状态。

func (*Store) SetLayered

func (s *Store) SetLayered(layered bool) error

SetLayered 设置分层模式标志。

func (*Store) SetPendingRewrites

func (s *Store) SetPendingRewrites(chapters []int, reason string) error

SetPendingRewrites 设置待重写章节队列和原因。

func (*Store) SetPendingSteer

func (s *Store) SetPendingSteer(input string) error

SetPendingSteer 记录未完成的 Steer 指令,用于中断恢复。

func (*Store) SetPlanningTier

func (s *Store) SetPlanningTier(tier domain.PlanningTier) error

SetPlanningTier 记录当前作品采用的规划级别。

func (*Store) SetTotalChapters

func (s *Store) SetTotalChapters(n int) error

SetTotalChapters 根据大纲长度设定总章节数。

func (*Store) UpdateForeshadow

func (s *Store) UpdateForeshadow(chapter int, updates []domain.ForeshadowUpdate) error

UpdateForeshadow 批量应用伏笔增量操作。

func (*Store) UpdatePhase

func (s *Store) UpdatePhase(phase domain.Phase) error

UpdatePhase 更新创作阶段。

func (*Store) UpdateRelationships

func (s *Store) UpdateRelationships(changes []domain.RelationshipEntry) error

UpdateRelationships 合并关系变化。相同人物对的关系会被更新为最新值。

func (*Store) UpdateVolumeArc

func (s *Store) UpdateVolumeArc(volume, arc int) error

UpdateVolumeArc 更新当前卷弧位置。

func (*Store) ValidateChapterCommit

func (s *Store) ValidateChapterCommit(chapter int) error

ValidateChapterCommit 校验当前章节是否允许提交。 在重写/打磨流程中,只允许提交待处理队列中的章节。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL