Documentation
¶
Overview ¶
Package store 提供基于文件系统的持久化存储。
架构:1 个 IO 基座 + 多个子存储 + 1 个组合根。 每个子存储持有独立的 IO 实例和独立的 sync.RWMutex。 主要领域(Progress、Outline、Drafts、Summaries 等)的读写互不阻塞; WorldStore 将多个低频小领域合并共享一把锁。
组合根 Store 持有所有子存储的引用,并串行协调跨域操作 (ExpandArc、AppendVolume、ClearHandledSteer);多个文件不构成事务原子提交, 调用依靠安全写入顺序、显式错误与同参数幂等重放恢复。
子存储划分:
- ProgressStore: 进度主状态(meta/progress.json)
- OutlineStore: 前提、大纲(扁平/分层)、指南针
- DraftStore: 章节构思、草稿、终稿
- SummaryStore: 章/弧/卷摘要
- RunMetaStore: 运行元数据(模型、干预历史)
- SignalStore: 一次性信号文件(PendingCommit 恢复)
- CheckpointStore: step 级 checkpoint(meta/checkpoints.jsonl)
- RuntimeStore: 运行时事件队列(meta/runtime/*.jsonl)
- CharacterStore: 角色档案、状态快照
- WorldStore: 时间线、伏笔、关系、状态变化、世界规则、风格规则、审阅
Index ¶
- Constants
- func IsCompacted(text string) bool
- type ArcBoundary
- type CastStore
- type ChapterFeedback
- type ChapterViolations
- type CharacterStore
- func (s *CharacterStore) Load() ([]domain.Character, error)
- func (s *CharacterStore) LoadLatestSnapshots() ([]domain.CharacterSnapshot, error)
- func (s *CharacterStore) LoadSnapshots(volume, arc int) ([]domain.CharacterSnapshot, error)
- func (s *CharacterStore) Save(chars []domain.Character) error
- func (s *CharacterStore) SaveSnapshots(volume, arc int, snapshots []domain.CharacterSnapshot) error
- type CheckpointStore
- func (cs *CheckpointStore) All() []domain.Checkpoint
- func (cs *CheckpointStore) Append(scope domain.Scope, step, artifact, digest string) (*domain.Checkpoint, error)
- func (cs *CheckpointStore) AppendArtifact(scope domain.Scope, step, artifact string) (*domain.Checkpoint, error)
- func (cs *CheckpointStore) AppendArtifacts(scope domain.Scope, step string, artifacts ...string) (*domain.Checkpoint, error)
- func (cs *CheckpointStore) InitError() error
- func (cs *CheckpointStore) Latest(scope domain.Scope) *domain.Checkpoint
- func (cs *CheckpointStore) LatestByStep(scope domain.Scope, step string) *domain.Checkpoint
- func (cs *CheckpointStore) LatestGlobal() *domain.Checkpoint
- func (cs *CheckpointStore) Reset() error
- type DecisionRecord
- type DecisionStore
- type DraftStore
- func (s *DraftStore) AppendDraft(chapter int, content string) error
- func (s *DraftStore) ExtractDialogue(characterName string, aliases []string, maxSamples, maxCompletedChapter int) ([]string, error)
- func (s *DraftStore) ExtractStyleAnchors(maxAnchors, maxCompletedChapter int) ([]string, error)
- func (s *DraftStore) LoadChapterContent(chapter int) (string, int, error)
- func (s *DraftStore) LoadChapterPlan(chapter int) (*domain.ChapterPlan, error)
- func (s *DraftStore) LoadChapterRange(from, to, maxRunes int) (map[int]string, error)
- func (s *DraftStore) LoadChapterText(chapter int) (string, error)
- func (s *DraftStore) LoadDraft(chapter int) (string, error)
- func (s *DraftStore) SaveChapterPlan(plan domain.ChapterPlan) error
- func (s *DraftStore) SaveDraft(chapter int, content string) error
- func (s *DraftStore) SaveFinalChapter(chapter int, content string) error
- type IO
- func (io *IO) AppendLine(rel string, data []byte) error
- func (io *IO) AppendLineUnlocked(rel string, data []byte) error
- func (io *IO) EnsureDirs(dirs []string) error
- func (io *IO) ReadFile(rel string) ([]byte, error)
- func (io *IO) ReadFileUnlocked(rel string) ([]byte, error)
- func (io *IO) ReadJSON(rel string, v any) error
- func (io *IO) ReadJSONUnlocked(rel string, v any) error
- func (io *IO) RemoveFile(rel string) error
- func (io *IO) RemoveFileUnlocked(rel string) error
- func (io *IO) WithWriteLock(fn func() error) error
- func (io *IO) WriteFileUnlocked(rel string, data []byte) error
- func (io *IO) WriteJSON(rel string, v any) error
- func (io *IO) WriteJSONUnlocked(rel string, v any) error
- func (io *IO) WriteMarkdown(rel string, content string) error
- func (io *IO) WriteMarkdownUnlocked(rel string, content string) error
- type ModelLookup
- type OutlineStore
- func (s *OutlineStore) AppendOutlineFeedback(fb ChapterFeedback) error
- func (s *OutlineStore) CheckArcBoundary(chapter int) (*ArcBoundary, error)
- func (s *OutlineStore) ClearLayeredOutline() error
- func (s *OutlineStore) ClearOutlineFeedback() error
- func (s *OutlineStore) GetChapterFromLayered(chapter int) (*domain.OutlineEntry, error)
- func (s *OutlineStore) GetChapterOutline(chapter int) (*domain.OutlineEntry, error)
- func (s *OutlineStore) LoadCompass() (*domain.StoryCompass, error)
- func (s *OutlineStore) LoadFoundationAudit() (*domain.FoundationAudit, error)
- func (s *OutlineStore) LoadLayeredOutline() ([]domain.VolumeOutline, error)
- func (s *OutlineStore) LoadOutline() ([]domain.OutlineEntry, error)
- func (s *OutlineStore) LoadPendingOutlineFeedback() ([]ChapterFeedback, error)
- func (s *OutlineStore) LoadPremise() (string, error)
- func (s *OutlineStore) LocateChapter(chapter int) (volume, arc int, err error)
- func (s *OutlineStore) SaveCompass(compass domain.StoryCompass) error
- func (s *OutlineStore) SaveFoundationAudit(a domain.FoundationAudit) error
- func (s *OutlineStore) SaveLayeredOutline(volumes []domain.VolumeOutline) error
- func (s *OutlineStore) SaveOutline(entries []domain.OutlineEntry) error
- func (s *OutlineStore) SavePremise(content string) error
- type ProgressStore
- func (s *ProgressStore) ApplyReviewOutcome(flow domain.FlowState, chapters []int, reason string) (*domain.Progress, error)
- func (s *ProgressStore) ClearInProgress() error
- func (s *ProgressStore) ClearPendingRewrites() error
- func (s *ProgressStore) CompleteRewrite(chapter int) error
- func (s *ProgressStore) Init(novelName string, totalChapters int) error
- func (s *ProgressStore) IsChapterCompleted(chapter int) (bool, error)
- func (s *ProgressStore) Load() (*domain.Progress, error)
- func (s *ProgressStore) MarkChapterComplete(chapter, wordCount int, hookType, dominantStrand string) error
- func (s *ProgressStore) MarkComplete() error
- func (s *ProgressStore) Reopen(chapters []int, reason string) error
- func (s *ProgressStore) ReopenContinue() error
- func (s *ProgressStore) Save(p *domain.Progress) error
- func (s *ProgressStore) SetFlow(flow domain.FlowState) error
- func (s *ProgressStore) SetLayered(layered bool) error
- func (s *ProgressStore) SetNovelName(name string) error
- func (s *ProgressStore) SetPendingRewrites(chapters []int, reason string) error
- func (s *ProgressStore) SetTotalChapters(n int) error
- func (s *ProgressStore) StartChapter(chapter int) error
- func (s *ProgressStore) UpdatePhase(phase domain.Phase) error
- func (s *ProgressStore) UpdateVolumeArc(volume, arc int) error
- func (s *ProgressStore) ValidateChapterWork(chapter int) error
- func (s *ProgressStore) ValidatePendingRewrites(chapters []int) error
- type RunMetaStore
- func (s *RunMetaStore) ClearAdvanceHold(expected domain.AdvanceHold) error
- func (s *RunMetaStore) ClearAdvancePermit(chapter int) error
- func (s *RunMetaStore) ClearPendingSteer() error
- func (s *RunMetaStore) GrantAdvancePermit(chapter int) error
- func (s *RunMetaStore) Init(style, provider, model string) error
- func (s *RunMetaStore) Load() (*domain.RunMeta, error)
- func (s *RunMetaStore) Save(meta domain.RunMeta) error
- func (s *RunMetaStore) SetAdvanceHold(hold domain.AdvanceHold) error
- func (s *RunMetaStore) SetAdvanceMode(mode domain.ChapterAdvanceMode) error
- func (s *RunMetaStore) SetPendingSteer(input string) error
- func (s *RunMetaStore) SetPlanStart(rec domain.PlanStartRecord) error
- func (s *RunMetaStore) SetPlanningTier(tier domain.PlanningTier) error
- func (s *RunMetaStore) SetStartPrompt(prompt string) error
- type RuntimeStore
- func (s *RuntimeStore) AppendQueue(item domain.RuntimeQueueItem) (domain.RuntimeQueueItem, error)
- func (s *RuntimeStore) AppendTaskLog(taskID string, entry domain.RuntimeTaskLogEntry) error
- func (s *RuntimeStore) LoadQueue() ([]domain.RuntimeQueueItem, error)
- func (s *RuntimeStore) LoadQueueAfter(afterSeq int64) ([]domain.RuntimeQueueItem, error)
- func (s *RuntimeStore) LoadTaskLog(taskID string) ([]domain.RuntimeTaskLogEntry, error)
- func (s *RuntimeStore) Reset() error
- type SessionStore
- type SignalStore
- func (s *SignalStore) ClearLastCommit() error
- func (s *SignalStore) ClearLastReview() error
- func (s *SignalStore) ClearPendingCommit() error
- func (s *SignalStore) ClearStaleSignals()
- func (s *SignalStore) LoadAndClearLastCommit() (*domain.CommitResult, error)
- func (s *SignalStore) LoadAndClearLastReview() (*domain.ReviewEntry, error)
- func (s *SignalStore) LoadLastCommit() (*domain.CommitResult, error)
- func (s *SignalStore) LoadLastReviewSignal() (*domain.ReviewEntry, error)
- func (s *SignalStore) LoadPendingCommit() (*domain.PendingCommit, error)
- func (s *SignalStore) SaveLastCommit(result domain.CommitResult) error
- func (s *SignalStore) SaveLastReview(r domain.ReviewEntry) error
- func (s *SignalStore) SavePendingCommit(pending domain.PendingCommit) error
- type SimulationStore
- type Store
- func (s *Store) AppendVolume(vol domain.VolumeOutline) error
- func (s *Store) CheckConsistency() []string
- func (s *Store) ClearHandledSteer() error
- func (s *Store) Dir() string
- func (s *Store) ExpandArc(volumeIdx, arcIdx int, expansion domain.ArcExpansion) error
- func (s *Store) FoundationFingerprint() (string, error)
- func (s *Store) FoundationMissing() ([]string, error)
- func (s *Store) Init() error
- func (s *Store) ReviseOutline(fromChapter int, replacement []domain.OutlineEntry) (int, error)
- type SummaryStore
- func (s *SummaryStore) FindCharacterAppearances(names []string, endChapter, recentWindow int) map[string]int
- func (s *SummaryStore) HasArcSummary(volume, arc int) (bool, error)
- func (s *SummaryStore) HasVolumeSummary(volume int) (bool, error)
- func (s *SummaryStore) LoadAllVolumeSummaries() ([]domain.VolumeSummary, error)
- func (s *SummaryStore) LoadArcSummaries(volume int) ([]domain.ArcSummary, error)
- func (s *SummaryStore) LoadArcSummary(volume, arc int) (*domain.ArcSummary, error)
- func (s *SummaryStore) LoadRecentSummaries(current, count int) ([]domain.ChapterSummary, error)
- func (s *SummaryStore) LoadSummary(chapter int) (*domain.ChapterSummary, error)
- func (s *SummaryStore) LoadVolumeSummary(volume int) (*domain.VolumeSummary, error)
- func (s *SummaryStore) SaveArcSummary(sum domain.ArcSummary) error
- func (s *SummaryStore) SaveSummary(sum domain.ChapterSummary) error
- func (s *SummaryStore) SaveVolumeSummary(sum domain.VolumeSummary) error
- type UsageStore
- type UserRulesStore
- type WorldStore
- func (s *WorldStore) AppendStateChanges(changes []domain.StateChange) error
- func (s *WorldStore) AppendTimelineEvents(newEvents []domain.TimelineEvent) error
- func (s *WorldStore) HasArcReview(chapter int) (bool, error)
- func (s *WorldStore) HasGlobalReview(chapter int) (bool, error)
- func (s *WorldStore) LoadActiveForeshadow() ([]domain.ForeshadowEntry, error)
- func (s *WorldStore) LoadForeshadowLedger() ([]domain.ForeshadowEntry, error)
- func (s *WorldStore) LoadLastReview(fromChapter int) (*domain.ReviewEntry, error)
- func (s *WorldStore) LoadRecentTimeline(current, window int) ([]domain.TimelineEvent, error)
- func (s *WorldStore) LoadRelationships() ([]domain.RelationshipEntry, error)
- func (s *WorldStore) LoadReview(chapter int) (*domain.ReviewEntry, error)
- func (s *WorldStore) LoadReviewsAffectingChapter(chapter int) ([]domain.ReviewEntry, error)
- func (s *WorldStore) LoadRuleViolations(chapter int) []rules.Violation
- func (s *WorldStore) LoadStateChanges() ([]domain.StateChange, error)
- func (s *WorldStore) LoadStyleRules() (*domain.WritingStyleRules, error)
- func (s *WorldStore) LoadTimeline() ([]domain.TimelineEvent, error)
- func (s *WorldStore) LoadWorldRules() ([]domain.WorldRule, error)
- func (s *WorldStore) SaveForeshadowLedger(entries []domain.ForeshadowEntry) error
- func (s *WorldStore) SaveRelationships(entries []domain.RelationshipEntry) error
- func (s *WorldStore) SaveReview(r domain.ReviewEntry) error
- func (s *WorldStore) SaveRuleViolations(chapter int, violations []rules.Violation) error
- func (s *WorldStore) SaveStyleRules(rules domain.WritingStyleRules) error
- func (s *WorldStore) SaveTimeline(events []domain.TimelineEvent) error
- func (s *WorldStore) SaveWorldRules(rules []domain.WorldRule) error
- func (s *WorldStore) UpdateForeshadow(chapter int, updates []domain.ForeshadowUpdate) error
- func (s *WorldStore) UpdateRelationships(changes []domain.RelationshipEntry) error
Constants ¶
const CompactTag = "[session_compact:"
CompactTag 是占位标记前缀,方便搜索和还原。
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArcBoundary ¶
type ArcBoundary struct {
IsArcEnd bool
IsVolumeEnd bool
Volume int
Arc int
StartChapter int
EndChapter int
NextVolume int
NextArc int
NeedsExpansion bool
NeedsNewVolume bool // 卷末且当前 layered_outline 没有下一卷
}
ArcBoundary 弧边界信息。
func (*ArcBoundary) HasNextArc ¶ added in v0.0.2
func (b *ArcBoundary) HasNextArc() bool
HasNextArc 是否还有后续弧。
type CastStore ¶ added in v0.4.0
type CastStore struct {
// contains filtered or unexported fields
}
CastStore 管理配角名册(meta/cast_ledger.json)。
配角名册记录"出现过的有名字的次要角色",与 characters.json(核心角色档案)正交:
- characters.json:Architect 显式设计的主角 + 关键配角,写作期不修改
- cast_ledger.json:commit_chapter 工具自动累加,所有有名字的非核心配角
MergeAppearances 是幂等的:同一章重复 commit 不会重复累加 AppearanceCount。
func NewCastStore ¶ added in v0.4.0
func (*CastStore) MergeAppearances ¶ added in v0.4.0
func (s *CastStore) MergeAppearances( chapter int, characters []string, intros []domain.CastIntro, knownCore map[string]bool, ) error
MergeAppearances 把本章出场记录合并进名册。
参数:
- chapter: 本章号
- characters: 本章出场名字数组(来自 commit_chapter.Characters)
- intros: Writer 显式声明的新角色简介(首次出场或补全 BriefRole)
- knownCore: characters.json 中已有的核心角色名集合(这些跳过 ledger 写入)
行为:
- 名字在 knownCore 中:跳过(核心角色档案是其唯一记录入口)
- 名字已在 ledger 且 chapter 已在 AppearanceChapters:完全跳过(幂等)
- 名字已在 ledger 但 chapter 是新的:更新 LastSeenChapter + 追加 chapter + count++
- 名字未在 ledger:新增条目
- intros 中的 BriefRole 仅在 ledger 条目 BriefRole 仍为空时采用,避免覆盖更早的简介
func (*CastStore) RecentActive ¶ added in v0.4.0
RecentActive 返回最近活跃的 N 条配角条目(按 LastSeenChapter 倒序)。 用于 novel_context 召回 Writer 写下一章时可能需要的"近期出场配角"。
已升格到 characters.json 的条目(Promoted=true)会被跳过,避免与核心档案重复召回。
type ChapterFeedback ¶ added in v0.7.0
type ChapterFeedback struct {
Chapter int `json:"chapter"`
Deviation string `json:"deviation,omitempty"`
Suggestion string `json:"suggestion,omitempty"`
At string `json:"at"`
}
ChapterFeedback 一条带章节号的大纲反馈。
type ChapterViolations ¶ added in v0.7.0
type ChapterViolations struct {
Chapter int `json:"chapter"`
Violations []rules.Violation `json:"violations"`
At string `json:"at"`
}
ChapterViolations 一章的机械违规记录。
type CharacterStore ¶ added in v0.0.3
type CharacterStore struct {
// contains filtered or unexported fields
}
CharacterStore 管理角色档案和状态快照。
func NewCharacterStore ¶ added in v0.0.3
func NewCharacterStore(io *IO, outline *OutlineStore) *CharacterStore
func (*CharacterStore) Load ¶ added in v0.0.3
func (s *CharacterStore) Load() ([]domain.Character, error)
Load 从 characters.json 读取角色档案。
func (*CharacterStore) LoadLatestSnapshots ¶ added in v0.0.3
func (s *CharacterStore) LoadLatestSnapshots() ([]domain.CharacterSnapshot, error)
LoadLatestSnapshots 加载最近一次角色快照(按卷弧倒序查找)。
func (*CharacterStore) LoadSnapshots ¶ added in v0.0.3
func (s *CharacterStore) LoadSnapshots(volume, arc int) ([]domain.CharacterSnapshot, error)
LoadSnapshots 读取指定卷弧的角色快照。
func (*CharacterStore) Save ¶ added in v0.0.3
func (s *CharacterStore) Save(chars []domain.Character) error
Save 同时保存 characters.json 和 characters.md(原子写入)。
func (*CharacterStore) SaveSnapshots ¶ added in v0.0.3
func (s *CharacterStore) SaveSnapshots(volume, arc int, snapshots []domain.CharacterSnapshot) error
SaveSnapshots 保存角色状态快照到 meta/snapshots/v{vol}a{arc}.json。
type CheckpointStore ¶ added in v0.1.0
type CheckpointStore struct {
// contains filtered or unexported fields
}
CheckpointStore 管理 step 级 checkpoint 的追加与查询。 磁盘格式:meta/checkpoints.jsonl,只追加;查询走内存镜像。 不变量:cache 是 checkpoints.jsonl 的镜像,由 Append/Reset 单点维护。 并发:cache 受 io.mu 保护,写走 Lock、读走 RLock。
func NewCheckpointStore ¶ added in v0.1.0
func NewCheckpointStore(io *IO) *CheckpointStore
NewCheckpointStore 创建 checkpoint 存储,从磁盘一次性加载已有 checkpoint 到 cache。
func (*CheckpointStore) All ¶ added in v0.1.0
func (cs *CheckpointStore) All() []domain.Checkpoint
All 返回全部 checkpoint 列表副本(按 seq 递增)。
func (*CheckpointStore) Append ¶ added in v0.1.0
func (cs *CheckpointStore) Append(scope domain.Scope, step, artifact, digest string) (*domain.Checkpoint, error)
Append 追加一条 checkpoint。 幂等:相同 Scope + Step + Digest 已存在则跳过写入,直接返回已有记录。
func (*CheckpointStore) AppendArtifact ¶ added in v0.3.0
func (cs *CheckpointStore) AppendArtifact(scope domain.Scope, step, artifact string) (*domain.Checkpoint, error)
AppendArtifact 计算 artifact 内容指纹后追加 checkpoint。
func (*CheckpointStore) AppendArtifacts ¶ added in v0.7.4
func (cs *CheckpointStore) AppendArtifacts(scope domain.Scope, step string, artifacts ...string) (*domain.Checkpoint, error)
AppendArtifacts 为同一步骤的多个正式工件生成组合指纹。 Artifact 保留第一个主工件路径;任一关联工件变化都会产生新 checkpoint。
func (*CheckpointStore) InitError ¶ added in v0.7.3
func (cs *CheckpointStore) InitError() error
InitError 返回构造时加载 checkpoint 镜像的错误。Store.Init 必须先检查它, 防止损坏的 jsonl 被解释成“没有 checkpoint”。
func (*CheckpointStore) Latest ¶ added in v0.1.0
func (cs *CheckpointStore) Latest(scope domain.Scope) *domain.Checkpoint
Latest 返回指定 scope 的最新 checkpoint。
func (*CheckpointStore) LatestByStep ¶ added in v0.1.0
func (cs *CheckpointStore) LatestByStep(scope domain.Scope, step string) *domain.Checkpoint
LatestByStep 返回指定 scope + step 的最新 checkpoint。
func (*CheckpointStore) LatestGlobal ¶ added in v0.1.0
func (cs *CheckpointStore) LatestGlobal() *domain.Checkpoint
LatestGlobal 返回全局最新 checkpoint(不区分 scope)。
func (*CheckpointStore) Reset ¶ added in v0.1.0
func (cs *CheckpointStore) Reset() error
Reset 清空 checkpoint 文件与 cache。仅在新建小说时使用。 先删文件再清内存:删除失败时保留 cache 与 seqGen,避免内存与磁盘状态错位。
type DecisionRecord ¶ added in v0.7.0
type DecisionRecord struct {
SchemaVersion int `json:"schema_version"`
ID string `json:"id"`
At string `json:"at"`
Kind string `json:"kind"` // intervention | plan_start | volume_end | ...
Decider string `json:"decider"` // arbiter | architect(卷末评审)
CheckpointSeq int64 `json:"checkpoint_seq,omitempty"`
Input string `json:"input,omitempty"`
InputTruncated bool `json:"input_truncated,omitempty"`
Facts json.RawMessage `json:"facts,omitempty"`
Decision json.RawMessage `json:"decision,omitempty"`
Reason string `json:"reason,omitempty"`
Error string `json:"error,omitempty"` // 裁定失败时的错误文本——失败也是审计事实,没有它排障只能靠推理
Model string `json:"model,omitempty"`
DurationMs int64 `json:"duration_ms,omitempty"`
}
DecisionRecord 一次语义裁定的审计记录。facts 只存结构化事实与引用,不复制正文。 input 保留在记录内(离线重放必需);脱敏发生在 diag export 边界,不在落盘时。
type DecisionStore ¶ added in v0.7.0
type DecisionStore struct {
// contains filtered or unexported fields
}
DecisionStore 审计运行时的 LLM 语义裁定(meta/decisions.jsonl,append-only)。
定位(docs/engine-arbiter.md §4.3):审计与离线重放的数据源——记录"当时看到什么 事实、做了什么裁定",供 eval 回归与未来 Arbiter 的 A/B 对照。它**不是**事件溯源, 也**不是**恢复数据源(恢复只依赖 Progress/Checkpoint/RunMeta 等事实层)。
func NewDecisionStore ¶ added in v0.7.0
func NewDecisionStore(io *IO) *DecisionStore
func (*DecisionStore) Append ¶ added in v0.7.0
func (s *DecisionStore) Append(rec DecisionRecord) (DecisionRecord, error)
Append 落盘一条裁定记录;SchemaVersion/At/ID 由本方法补齐,input 超限截断。 返回补齐后的记录(ID 供调用方关联,如 PlanStartRecord.DecisionID)。
func (*DecisionStore) Recent ¶ added in v0.7.0
func (s *DecisionStore) Recent(n int) ([]DecisionRecord, error)
Recent 返回最近 n 条记录(旧→新);文件缺失返回空。
已提交损坏行必须显式返回错误——Arbiter 不能在缺失部分历史的事实包上继续裁定。 崩溃打断的尾部残行(末字节非 '\n')由 committedDataUnlocked 截断并显式告警;这不是 猜测式修复,因为本文件协议规定只有换行结束的记录才算提交。
type DraftStore ¶ added in v0.0.3
type DraftStore struct {
// contains filtered or unexported fields
}
DraftStore 管理章节构思、草稿和终稿。
func NewDraftStore ¶ added in v0.0.3
func NewDraftStore(io *IO) *DraftStore
func (*DraftStore) AppendDraft ¶ added in v0.0.3
func (s *DraftStore) AppendDraft(chapter int, content string) error
AppendDraft 追加内容到现有草稿(续写模式)。
func (*DraftStore) ExtractDialogue ¶ added in v0.0.3
func (s *DraftStore) ExtractDialogue(characterName string, aliases []string, maxSamples, maxCompletedChapter int) ([]string, error)
ExtractDialogue 从已提交章节中提取指定角色的对话片段。 maxCompletedChapter 由调用方传入,避免跨域依赖。
func (*DraftStore) ExtractStyleAnchors ¶ added in v0.0.3
func (s *DraftStore) ExtractStyleAnchors(maxAnchors, maxCompletedChapter int) ([]string, error)
ExtractStyleAnchors 从已提交章节中提取代表性段落作为风格锚点。 maxCompletedChapter 由调用方传入,避免跨域依赖。
func (*DraftStore) LoadChapterContent ¶ added in v0.0.3
func (s *DraftStore) LoadChapterContent(chapter int) (string, int, error)
LoadChapterContent 加载章节草稿正文及字数。
func (*DraftStore) LoadChapterPlan ¶ added in v0.0.3
func (s *DraftStore) LoadChapterPlan(chapter int) (*domain.ChapterPlan, error)
LoadChapterPlan 读取章节构思。
func (*DraftStore) LoadChapterRange ¶ added in v0.0.3
func (s *DraftStore) LoadChapterRange(from, to, maxRunes int) (map[int]string, error)
LoadChapterRange 读取指定范围的终稿原文片段。
func (*DraftStore) LoadChapterText ¶ added in v0.0.3
func (s *DraftStore) LoadChapterText(chapter int) (string, error)
LoadChapterText 读取已提交的终稿原文。
func (*DraftStore) LoadDraft ¶ added in v0.0.3
func (s *DraftStore) LoadDraft(chapter int) (string, error)
LoadDraft 读取整章草稿。
func (*DraftStore) SaveChapterPlan ¶ added in v0.0.3
func (s *DraftStore) SaveChapterPlan(plan domain.ChapterPlan) error
SaveChapterPlan 保存章节构思到 drafts/{ch}.plan.json。
func (*DraftStore) SaveDraft ¶ added in v0.0.3
func (s *DraftStore) SaveDraft(chapter int, content string) error
SaveDraft 保存整章草稿到 drafts/{ch}.draft.md。
func (*DraftStore) SaveFinalChapter ¶ added in v0.0.3
func (s *DraftStore) SaveFinalChapter(chapter int, content string) error
SaveFinalChapter 保存最终章节正文到 chapters/{ch}.md。
type IO ¶ added in v0.0.3
type IO struct {
// contains filtered or unexported fields
}
IO 封装文件系统读写操作,提供加锁和原子写入。 每个子存储持有独立的 IO 实例,拥有各自的 sync.RWMutex。
func (*IO) AppendLineUnlocked ¶ added in v0.1.0
func (*IO) EnsureDirs ¶ added in v0.0.3
EnsureDirs 创建指定的子目录。
func (*IO) ReadFileUnlocked ¶ added in v0.0.3
func (*IO) ReadJSONUnlocked ¶ added in v0.0.3
func (*IO) RemoveFile ¶ added in v0.0.3
func (*IO) RemoveFileUnlocked ¶ added in v0.0.3
func (*IO) WithWriteLock ¶ added in v0.0.3
func (*IO) WriteFileUnlocked ¶ added in v0.0.3
func (*IO) WriteJSONUnlocked ¶ added in v0.0.3
func (*IO) WriteMarkdown ¶ added in v0.0.3
func (*IO) WriteMarkdownUnlocked ¶ added in v0.0.3
WriteMarkdownUnlocked 写出 .md sidecar。约定:每个 .md 都是对应 .json 的 best-effort 人类可读视图,绝非数据源——运行时与导出一律从 .json 重新渲染。 各 Save 方法在同一写锁内先写 .json 再写此 .md,是两次独立的 tmp+rename; 二者之间崩溃会留下 .md 落后于 .json,这是可接受的(无人把 .md 当数据读, 下次写同一 scope 即自愈)。故意不为此加两文件原子提交——那是过度设计。
type ModelLookup ¶ added in v0.4.0
ModelLookup 在 logger 写入时按 agent 名查"当时生效"的 provider/model。 用 func 类型而不是 interface,方便调用方用闭包注入归一规则(如 architect_short → architect)。 返回空字符串表示未知,调用方仍照常写入但不带 _meta,replay 时退回 ModelSet fallback。
type OutlineStore ¶ added in v0.0.3
type OutlineStore struct {
// contains filtered or unexported fields
}
OutlineStore 管理故事前提、大纲(扁平/分层)和指南针。
func NewOutlineStore ¶ added in v0.0.3
func NewOutlineStore(io *IO) *OutlineStore
func (*OutlineStore) AppendOutlineFeedback ¶ added in v0.7.0
func (s *OutlineStore) AppendOutlineFeedback(fb ChapterFeedback) error
AppendOutlineFeedback 追加一条 writer 反馈。相同章节与内容视为同一事实, 使 commit 在 ProgressMarked 前崩溃重放时不会重复累加附属反馈。
func (*OutlineStore) CheckArcBoundary ¶ added in v0.0.3
func (s *OutlineStore) CheckArcBoundary(chapter int) (*ArcBoundary, error)
CheckArcBoundary 检查某章是否为弧/卷的最后一章。
func (*OutlineStore) ClearLayeredOutline ¶ added in v0.0.3
func (s *OutlineStore) ClearLayeredOutline() error
ClearLayeredOutline 清理分层大纲文件。
func (*OutlineStore) ClearOutlineFeedback ¶ added in v0.7.0
func (s *OutlineStore) ClearOutlineFeedback() error
ClearOutlineFeedback 清空反馈池(architect 结构操作成功 = 反馈已被参考)。
func (*OutlineStore) GetChapterFromLayered ¶ added in v0.0.3
func (s *OutlineStore) GetChapterFromLayered(chapter int) (*domain.OutlineEntry, error)
GetChapterFromLayered 从分层大纲中按全局章节号查找。
func (*OutlineStore) GetChapterOutline ¶ added in v0.0.3
func (s *OutlineStore) GetChapterOutline(chapter int) (*domain.OutlineEntry, error)
GetChapterOutline 获取指定章节的大纲条目。
func (*OutlineStore) LoadCompass ¶ added in v0.0.3
func (s *OutlineStore) LoadCompass() (*domain.StoryCompass, error)
LoadCompass 读取终局方向指南针。
func (*OutlineStore) LoadFoundationAudit ¶ added in v0.7.4
func (s *OutlineStore) LoadFoundationAudit() (*domain.FoundationAudit, error)
LoadFoundationAudit 读取最近一次基础设定语义审查。
func (*OutlineStore) LoadLayeredOutline ¶ added in v0.0.3
func (s *OutlineStore) LoadLayeredOutline() ([]domain.VolumeOutline, error)
LoadLayeredOutline 读取分层大纲。
func (*OutlineStore) LoadOutline ¶ added in v0.0.3
func (s *OutlineStore) LoadOutline() ([]domain.OutlineEntry, error)
LoadOutline 从 outline.json 读取结构化大纲。
func (*OutlineStore) LoadPendingOutlineFeedback ¶ added in v0.7.0
func (s *OutlineStore) LoadPendingOutlineFeedback() ([]ChapterFeedback, error)
LoadPendingOutlineFeedback 读取未消费的反馈(旧→新)。损坏行显式返回错误, 防止 Architect 在缺失部分反馈的上下文上继续结构操作并随后清空原文件。
func (*OutlineStore) LoadPremise ¶ added in v0.0.3
func (s *OutlineStore) LoadPremise() (string, error)
LoadPremise 读取 premise.md。不存在时返回空字符串。
func (*OutlineStore) LocateChapter ¶ added in v0.0.3
func (s *OutlineStore) LocateChapter(chapter int) (volume, arc int, err error)
LocateChapter 根据全局章节号定位所在的卷和弧。
func (*OutlineStore) SaveCompass ¶ added in v0.0.3
func (s *OutlineStore) SaveCompass(compass domain.StoryCompass) error
SaveCompass 保存终局方向指南针。
func (*OutlineStore) SaveFoundationAudit ¶ added in v0.7.4
func (s *OutlineStore) SaveFoundationAudit(a domain.FoundationAudit) error
SaveFoundationAudit 保存 Architect 对当前基础设定版本的语义审查。
func (*OutlineStore) SaveLayeredOutline ¶ added in v0.0.3
func (s *OutlineStore) SaveLayeredOutline(volumes []domain.VolumeOutline) error
SaveLayeredOutline 保存分层大纲(长篇模式,原子写入)。
func (*OutlineStore) SaveOutline ¶ added in v0.0.3
func (s *OutlineStore) SaveOutline(entries []domain.OutlineEntry) error
SaveOutline 同时保存 outline.json 和 outline.md(原子写入)。
func (*OutlineStore) SavePremise ¶ added in v0.0.3
func (s *OutlineStore) SavePremise(content string) error
SavePremise 保存故事前提到 premise.md。
type ProgressStore ¶ added in v0.0.3
type ProgressStore struct {
// contains filtered or unexported fields
}
ProgressStore 管理创作进度状态。
func NewProgressStore ¶ added in v0.0.3
func NewProgressStore(io *IO) *ProgressStore
func (*ProgressStore) ApplyReviewOutcome ¶ added in v0.7.3
func (s *ProgressStore) ApplyReviewOutcome(flow domain.FlowState, chapters []int, reason string) (*domain.Progress, error)
ApplyReviewOutcome 原子应用审阅产生的流程状态。审阅语义由上层决定;Store 只负责 校验 Flow 迁移和返工章节,并保证 Flow、PendingRewrites、RewriteReason 不出现中间态。
func (*ProgressStore) ClearInProgress ¶ added in v0.0.3
func (s *ProgressStore) ClearInProgress() error
ClearInProgress 清除进度中间状态。
func (*ProgressStore) ClearPendingRewrites ¶ added in v0.0.3
func (s *ProgressStore) ClearPendingRewrites() error
ClearPendingRewrites 强制清空重写队列。
func (*ProgressStore) CompleteRewrite ¶ added in v0.0.3
func (s *ProgressStore) CompleteRewrite(chapter int) error
CompleteRewrite 从待重写队列中移除已完成的章节。
func (*ProgressStore) Init ¶ added in v0.0.3
func (s *ProgressStore) Init(novelName string, totalChapters int) error
Init 创建初始进度。
func (*ProgressStore) IsChapterCompleted ¶ added in v0.1.0
func (s *ProgressStore) IsChapterCompleted(chapter int) (bool, error)
IsChapterCompleted 检查章节是否已提交完成。读取失败显式返回,不能把损坏的 progress 当成“未完成”后继续覆盖章节。
func (*ProgressStore) Load ¶ added in v0.0.3
func (s *ProgressStore) Load() (*domain.Progress, error)
Load 读取 meta/progress.json。不存在时返回 nil。
func (*ProgressStore) MarkChapterComplete ¶ added in v0.0.3
func (s *ProgressStore) MarkChapterComplete(chapter, wordCount int, hookType, dominantStrand string) error
MarkChapterComplete 标记章节完成,原子性更新进度。
func (*ProgressStore) MarkComplete ¶ added in v0.0.3
func (s *ProgressStore) MarkComplete() error
MarkComplete 标记全书创作完成,并清除重开返工标记(完结即不再处于返工态)。
func (*ProgressStore) Reopen ¶ added in v0.5.2
func (s *ProgressStore) Reopen(chapters []int, reason string) error
Reopen 把已完结的书重新打开进入返工态:phase complete→writing + 目标章入队 + flow=rewriting, 在一次写锁内原子完成。这是 phaseOrder“只前进”约束的唯一豁免出口——故意不走 ValidatePhaseTransition;回退的合法性收敛在本方法、且受 phase=complete 前置守卫保护, 避免误用导致状态机失控。改完队列后 commit_chapter 会自动重新收尾完结。
func (*ProgressStore) ReopenContinue ¶ added in v0.7.2
func (s *ProgressStore) ReopenContinue() error
ReopenContinue 把已完结的书重开为续写态:仅 phase complete→writing,不入返工队列、 不置 ReopenedFromComplete(那是"返工排空后按原结构自动重新完结"的 drain 语义, 续写重开恰恰要扩展结构)。与 Reopen 同为 phaseOrder"只前进"约束的豁免出口, 同受 phase=complete 前置守卫保护;重开后由卷末路由派发架构师续卷。
func (*ProgressStore) Save ¶ added in v0.0.3
func (s *ProgressStore) Save(p *domain.Progress) error
Save 保存进度。
func (*ProgressStore) SetFlow ¶ added in v0.0.3
func (s *ProgressStore) SetFlow(flow domain.FlowState) error
SetFlow 更新当前流程状态。
func (*ProgressStore) SetLayered ¶ added in v0.0.3
func (s *ProgressStore) SetLayered(layered bool) error
SetLayered 设置分层模式标志。
func (*ProgressStore) SetNovelName ¶ added in v0.1.0
func (s *ProgressStore) SetNovelName(name string) error
SetNovelName 设置作品书名,空值会被忽略。
func (*ProgressStore) SetPendingRewrites ¶ added in v0.0.3
func (s *ProgressStore) SetPendingRewrites(chapters []int, reason string) error
SetPendingRewrites 设置待重写章节队列和原因。 PendingRewrites 只允许包含已完成章节;未完成章节还没有终稿,不能进入重写/打磨队列。
func (*ProgressStore) SetTotalChapters ¶ added in v0.0.3
func (s *ProgressStore) SetTotalChapters(n int) error
SetTotalChapters 设定总章节数。
func (*ProgressStore) StartChapter ¶ added in v0.1.0
func (s *ProgressStore) StartChapter(chapter int) error
StartChapter 标记某章进入写作中状态。它不能承担阶段迁移职责;调用方必须先由 foundation/import 流程把 Progress 明确推进到 writing,避免错误派单绕过规划阶段。
func (*ProgressStore) UpdatePhase ¶ added in v0.0.3
func (s *ProgressStore) UpdatePhase(phase domain.Phase) error
UpdatePhase 更新创作阶段。
func (*ProgressStore) UpdateVolumeArc ¶ added in v0.0.3
func (s *ProgressStore) UpdateVolumeArc(volume, arc int) error
UpdateVolumeArc 更新当前卷弧位置。
func (*ProgressStore) ValidateChapterWork ¶ added in v0.1.2
func (s *ProgressStore) ValidateChapterWork(chapter int) error
ValidateChapterWork 校验当前章节是否允许被规划或提交。 Writer 只能在 writing 阶段工作;打磨/重写流程下,只允许处理 PendingRewrites 中的章节。阶段约束在 Store 边界再守一次,避免错误的 Arbiter 派单绕过 Router。
func (*ProgressStore) ValidatePendingRewrites ¶ added in v0.5.3
func (s *ProgressStore) ValidatePendingRewrites(chapters []int) error
ValidatePendingRewrites 校验章节列表是否可进入返工队列,不修改状态。
type RunMetaStore ¶ added in v0.0.3
type RunMetaStore struct {
// contains filtered or unexported fields
}
RunMetaStore 管理运行元信息(模型、干预历史、规划级别等)。
func NewRunMetaStore ¶ added in v0.0.3
func NewRunMetaStore(io *IO) *RunMetaStore
func (*RunMetaStore) ClearAdvanceHold ¶ added in v0.7.0
func (s *RunMetaStore) ClearAdvanceHold(expected domain.AdvanceHold) error
ClearAdvanceHold 只消费调用方刚读取的同一个意图;目标已不存在时幂等。
func (*RunMetaStore) ClearAdvancePermit ¶ added in v0.7.0
func (s *RunMetaStore) ClearAdvancePermit(chapter int) error
ClearAdvancePermit 仅消费匹配的章节许可;目标已不存在时幂等。
func (*RunMetaStore) ClearPendingSteer ¶ added in v0.0.3
func (s *RunMetaStore) ClearPendingSteer() error
ClearPendingSteer 清除已处理的 Steer 指令。
func (*RunMetaStore) GrantAdvancePermit ¶ added in v0.7.0
func (s *RunMetaStore) GrantAdvancePermit(chapter int) error
GrantAdvancePermit 为 review 模式持久化一个精确章节许可。
func (*RunMetaStore) Init ¶ added in v0.0.3
func (s *RunMetaStore) Init(style, provider, model string) error
Init 初始化或更新运行元信息;跨重启保留全部运行意图事实—— PlanStart 尤其关键:规划期(启动裁定已落盘、首个 foundation 未落盘)崩溃后, 它是恢复规划师身份的唯一依据,被 Init 覆盖会让恢复直接停机。
func (*RunMetaStore) Load ¶ added in v0.0.3
func (s *RunMetaStore) Load() (*domain.RunMeta, error)
Load 读取运行元信息。
func (*RunMetaStore) Save ¶ added in v0.0.3
func (s *RunMetaStore) Save(meta domain.RunMeta) error
Save 保存运行元信息到 meta/run.json。
func (*RunMetaStore) SetAdvanceHold ¶ added in v0.7.0
func (s *RunMetaStore) SetAdvanceHold(hold domain.AdvanceHold) error
SetAdvanceHold 登记一次性暂停意图;在途意图不允许被另一条静默覆盖。
func (*RunMetaStore) SetAdvanceMode ¶ added in v0.7.0
func (s *RunMetaStore) SetAdvanceMode(mode domain.ChapterAdvanceMode) error
SetAdvanceMode 切换章节推进模式。切回 auto 时在同一写锁内清除章节许可。
func (*RunMetaStore) SetPendingSteer ¶ added in v0.0.3
func (s *RunMetaStore) SetPendingSteer(input string) error
SetPendingSteer 记录未完成的 Steer 指令。
func (*RunMetaStore) SetPlanStart ¶ added in v0.7.0
func (s *RunMetaStore) SetPlanStart(rec domain.PlanStartRecord) error
SetPlanStart 固化启动裁定事实(裁定先落事实再起执行;规划期崩溃恢复据此续跑)。
func (*RunMetaStore) SetPlanningTier ¶ added in v0.0.3
func (s *RunMetaStore) SetPlanningTier(tier domain.PlanningTier) error
SetPlanningTier 记录当前作品的规划级别。
func (*RunMetaStore) SetStartPrompt ¶ added in v0.7.0
func (s *RunMetaStore) SetStartPrompt(prompt string) error
SetStartPrompt 固化用户的原始创作需求——输入事实,在启动裁定**之前**落盘。 裁定失败(如模型故障)时它仍然在,恢复/继续由引擎据此补裁(engine.planStartFallback), 启动失败不再是死局。
type RuntimeStore ¶ added in v0.1.0
type RuntimeStore struct {
// contains filtered or unexported fields
}
RuntimeStore 管理统一运行时队列和每任务日志。
func NewRuntimeStore ¶ added in v0.1.0
func NewRuntimeStore(io *IO) *RuntimeStore
func (*RuntimeStore) AppendQueue ¶ added in v0.1.0
func (s *RuntimeStore) AppendQueue(item domain.RuntimeQueueItem) (domain.RuntimeQueueItem, error)
AppendQueue 追加一条运行时队列记录,并自动分配递增序号。
func (*RuntimeStore) AppendTaskLog ¶ added in v0.1.0
func (s *RuntimeStore) AppendTaskLog(taskID string, entry domain.RuntimeTaskLogEntry) error
AppendTaskLog 追加某个任务的运行日志。
func (*RuntimeStore) LoadQueue ¶ added in v0.1.0
func (s *RuntimeStore) LoadQueue() ([]domain.RuntimeQueueItem, error)
LoadQueue 读取当前持久化的全部运行时队列项。
func (*RuntimeStore) LoadQueueAfter ¶ added in v0.1.0
func (s *RuntimeStore) LoadQueueAfter(afterSeq int64) ([]domain.RuntimeQueueItem, error)
LoadQueueAfter 返回指定序号之后的队列项。
func (*RuntimeStore) LoadTaskLog ¶ added in v0.1.0
func (s *RuntimeStore) LoadTaskLog(taskID string) ([]domain.RuntimeTaskLogEntry, error)
LoadTaskLog 读取某个任务的全部运行日志。
func (*RuntimeStore) Reset ¶ added in v0.1.0
func (s *RuntimeStore) Reset() error
Reset 清空运行时队列和任务日志。
type SessionStore ¶ added in v0.1.2
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore 追加式记录 LLM 对话历史到 JSONL 文件。 大体积内容(小说正文、完整上下文)用 [session_compact: ...] 占位标记替代。
func NewSessionStore ¶ added in v0.1.2
func NewSessionStore(io *IO) *SessionStore
func (*SessionStore) Log ¶ added in v0.1.2
func (s *SessionStore) Log(rel string, msg agentcore.AgentMessage) error
Log 追加一条消息到指定路径,自动压缩大内容。 不携带 _meta;仅 cocreate 等无角色路径使用。
func (*SessionStore) LogCoCreate ¶ added in v0.3.1
func (s *SessionStore) LogCoCreate(entry any) error
LogCoCreate 追加一条共创对话日志到 meta/sessions/cocreate.jsonl。 共创阶段还没绑定具体小说,统一落到 OutputDir 默认根(output/novel)下, 与正式创作的 agents/* 同位,方便排查。
func (*SessionStore) SubAgentLogger ¶ added in v0.1.2
func (s *SessionStore) SubAgentLogger(lookup ModelLookup) func(agentName, task string, msg agentcore.AgentMessage)
SubAgentLogger 返回子代理的 OnMessage 回调。
type SignalStore ¶ added in v0.0.3
type SignalStore struct {
// contains filtered or unexported fields
}
SignalStore 管理一次性信号文件(commit/review 结果、待恢复状态)。
func NewSignalStore ¶ added in v0.0.3
func NewSignalStore(io *IO) *SignalStore
func (*SignalStore) ClearLastCommit ¶ added in v0.0.3
func (s *SignalStore) ClearLastCommit() error
ClearLastCommit 清除 commit 信号文件。
func (*SignalStore) ClearLastReview ¶ added in v0.0.3
func (s *SignalStore) ClearLastReview() error
ClearLastReview 清除审阅信号文件。
func (*SignalStore) ClearPendingCommit ¶ added in v0.0.3
func (s *SignalStore) ClearPendingCommit() error
ClearPendingCommit 清除待恢复的章节提交状态。
func (*SignalStore) ClearStaleSignals ¶ added in v0.0.3
func (s *SignalStore) ClearStaleSignals()
ClearStaleSignals 清理残留的信号文件(进程重启时调用)。
func (*SignalStore) LoadAndClearLastCommit ¶ added in v0.0.3
func (s *SignalStore) LoadAndClearLastCommit() (*domain.CommitResult, error)
LoadAndClearLastCommit 原子性读取并清除 commit 信号,防止 TOCTOU 竞态。
func (*SignalStore) LoadAndClearLastReview ¶ added in v0.0.3
func (s *SignalStore) LoadAndClearLastReview() (*domain.ReviewEntry, error)
LoadAndClearLastReview 原子性读取并清除审阅信号。
func (*SignalStore) LoadLastCommit ¶ added in v0.0.3
func (s *SignalStore) LoadLastCommit() (*domain.CommitResult, error)
LoadLastCommit 读取最近一次 commit 结果。
func (*SignalStore) LoadLastReviewSignal ¶ added in v0.0.3
func (s *SignalStore) LoadLastReviewSignal() (*domain.ReviewEntry, error)
LoadLastReviewSignal 读取审阅信号文件。
func (*SignalStore) LoadPendingCommit ¶ added in v0.0.3
func (s *SignalStore) LoadPendingCommit() (*domain.PendingCommit, error)
LoadPendingCommit 读取待恢复的章节提交状态。
func (*SignalStore) SaveLastCommit ¶ added in v0.0.3
func (s *SignalStore) SaveLastCommit(result domain.CommitResult) error
SaveLastCommit 保存最近一次 commit 结果到 meta/last_commit.json。
func (*SignalStore) SaveLastReview ¶ added in v0.0.3
func (s *SignalStore) SaveLastReview(r domain.ReviewEntry) error
SaveLastReview 保存最近一次审阅结果到 meta/last_review.json。
func (*SignalStore) SavePendingCommit ¶ added in v0.0.3
func (s *SignalStore) SavePendingCommit(pending domain.PendingCommit) error
SavePendingCommit 保存待恢复的章节提交状态。
type SimulationStore ¶ added in v0.4.2
type SimulationStore struct {
// contains filtered or unexported fields
}
func NewSimulationStore ¶ added in v0.4.2
func NewSimulationStore(io *IO) *SimulationStore
func (*SimulationStore) Load ¶ added in v0.4.2
func (s *SimulationStore) Load() (*domain.SimulationProfile, error)
func (*SimulationStore) Save ¶ added in v0.4.2
func (s *SimulationStore) Save(profile domain.SimulationProfile) error
type Store ¶
type Store struct {
Progress *ProgressStore
Outline *OutlineStore
Drafts *DraftStore
Summaries *SummaryStore
RunMeta *RunMetaStore
UserRules *UserRulesStore
Signals *SignalStore
Runtime *RuntimeStore
Characters *CharacterStore
Cast *CastStore
World *WorldStore
Checkpoints *CheckpointStore
Sessions *SessionStore
Usage *UsageStore
Simulation *SimulationStore
Decisions *DecisionStore
// contains filtered or unexported fields
}
Store 是状态管理的组合根,持有所有子存储。
func (*Store) AppendVolume ¶ added in v0.0.2
func (s *Store) AppendVolume(vol domain.VolumeOutline) error
AppendVolume 追加新卷到分层大纲末尾(Outline + Progress 联动)。
func (*Store) CheckConsistency ¶ added in v0.2.0
CheckConsistency 对事实层做一次浅层校验,用于启动/恢复时生成 warning。 纯只读:不修正数据,仅返回可读的问题描述。调用方决定如何展示(log / UI)。 为避免扫全目录带来的 IO 开销,只校验 Progress 的关键点:
- 最后一个完成章节必须在 chapters/ 下存在终稿
- Layered 模式下,当前 Volume/Arc 必须能在 layered_outline 中找到
func (*Store) ClearHandledSteer ¶
ClearHandledSteer 清除 PendingSteer 并重置旧版 FlowSteering 状态。 两个文件无法组成文件系统事务,因此先写可重复的 Progress,最后才删除恢复意图; 任一步失败都至少保留 PendingSteer,下一次 Resume 可以安全重放。
func (*Store) ExpandArc ¶ added in v0.0.2
func (s *Store) ExpandArc(volumeIdx, arcIdx int, expansion domain.ArcExpansion) error
ExpandArc 将骨架弧校准并展开为详细章节(Outline + Progress 联动)。
func (*Store) FoundationFingerprint ¶ added in v0.7.4
FoundationFingerprint 返回当前基础设定工件的内容指纹。Architect 必须把 novel_context 读到的这个值原样交回审查工具,确保结论针对的是实际落盘版本, 而不是会话中尚未保存或已经过期的内容。
func (*Store) FoundationMissing ¶ added in v0.1.2
FoundationMissing 返回基础设定中尚缺的项,按用于 Prompt/Reminder 的稳定顺序排列。 长篇模式(已有 layered_outline)额外要求 compass。读取失败必须原样返回,不能把 损坏或无权限读取的工件误判成“尚未创建”,否则调用方可能覆盖真实数据。
func (*Store) ReviseOutline ¶ added in v0.7.4
ReviseOutline 从 fromChapter 起替换尚未发生的计划尾段。 扁平大纲替换全书尾段;分层大纲只替换目标章所在弧的尾段。这个定义让同一载荷 重放仍得到同一结果,同时避免 JSON Patch 和 insert/delete 等操作枚举。
type SummaryStore ¶ added in v0.0.3
type SummaryStore struct {
// contains filtered or unexported fields
}
SummaryStore 管理章节、弧、卷摘要。
func NewSummaryStore ¶ added in v0.0.3
func NewSummaryStore(io *IO, outline *OutlineStore) *SummaryStore
func (*SummaryStore) FindCharacterAppearances ¶ added in v0.0.3
func (s *SummaryStore) FindCharacterAppearances(names []string, endChapter, recentWindow int) map[string]int
FindCharacterAppearances 批量查找多个角色的最后出场章节号。
func (*SummaryStore) HasArcSummary ¶ added in v0.2.0
func (s *SummaryStore) HasArcSummary(volume, arc int) (bool, error)
HasArcSummary 检查指定弧是否已保存摘要。
func (*SummaryStore) HasVolumeSummary ¶ added in v0.2.0
func (s *SummaryStore) HasVolumeSummary(volume int) (bool, error)
HasVolumeSummary 检查指定卷是否已保存摘要。
func (*SummaryStore) LoadAllVolumeSummaries ¶ added in v0.0.3
func (s *SummaryStore) LoadAllVolumeSummaries() ([]domain.VolumeSummary, error)
LoadAllVolumeSummaries 加载所有已有卷摘要。
func (*SummaryStore) LoadArcSummaries ¶ added in v0.0.3
func (s *SummaryStore) LoadArcSummaries(volume int) ([]domain.ArcSummary, error)
LoadArcSummaries 加载一卷内所有已有弧摘要。
func (*SummaryStore) LoadArcSummary ¶ added in v0.0.3
func (s *SummaryStore) LoadArcSummary(volume, arc int) (*domain.ArcSummary, error)
LoadArcSummary 读取指定弧的摘要。
func (*SummaryStore) LoadRecentSummaries ¶ added in v0.0.3
func (s *SummaryStore) LoadRecentSummaries(current, count int) ([]domain.ChapterSummary, error)
LoadRecentSummaries 加载 current 章之前最近 count 章的摘要。
func (*SummaryStore) LoadSummary ¶ added in v0.0.3
func (s *SummaryStore) LoadSummary(chapter int) (*domain.ChapterSummary, error)
LoadSummary 读取指定章节的摘要。
func (*SummaryStore) LoadVolumeSummary ¶ added in v0.0.3
func (s *SummaryStore) LoadVolumeSummary(volume int) (*domain.VolumeSummary, error)
LoadVolumeSummary 读取指定卷的摘要。
func (*SummaryStore) SaveArcSummary ¶ added in v0.0.3
func (s *SummaryStore) SaveArcSummary(sum domain.ArcSummary) error
SaveArcSummary 保存弧级摘要。
func (*SummaryStore) SaveSummary ¶ added in v0.0.3
func (s *SummaryStore) SaveSummary(sum domain.ChapterSummary) error
SaveSummary 保存章节摘要到 summaries/{ch}.json。
func (*SummaryStore) SaveVolumeSummary ¶ added in v0.0.3
func (s *SummaryStore) SaveVolumeSummary(sum domain.VolumeSummary) error
SaveVolumeSummary 保存卷级摘要。
type UsageStore ¶ added in v0.4.0
type UsageStore struct {
// contains filtered or unexported fields
}
UsageStore 持久化 token / cost 累计用量到 meta/usage.json。 写入走 IO 的 atomic write(tmp + rename),Save 路径每次完整覆盖整个 state。
func NewUsageStore ¶ added in v0.4.0
func NewUsageStore(io *IO) *UsageStore
func (*UsageStore) Load ¶ added in v0.4.0
func (s *UsageStore) Load() (*domain.UsageState, error)
Load 读取 usage.json。文件不存在或 schema 版本不匹配时返回 (nil, nil), 由调用方决定是否走 session replay 一次性回填。
func (*UsageStore) Save ¶ added in v0.4.0
func (s *UsageStore) Save(state domain.UsageState) error
Save 把 state 完整覆盖落盘。调用方负责 debounce / 节流。
type UserRulesStore ¶ added in v0.6.0
type UserRulesStore struct {
// contains filtered or unexported fields
}
UserRulesStore 管理本书归一化后的用户规则快照(meta/user_rules.json)。
运行时唯一事实源:novel_context 注入与 commit_chapter 检查都只读这一份, 不再反复读 rules 文件(避免漂移与双读者发散)。快照由开书/导入/刷新时归一化生成。
func NewUserRulesStore ¶ added in v0.6.0
func NewUserRulesStore(io *IO) *UserRulesStore
type WorldStore ¶ added in v0.0.3
type WorldStore struct {
// contains filtered or unexported fields
}
WorldStore 管理时间线、伏笔、人物关系、状态变化、世界规则、风格规则、审阅和交接。
func NewWorldStore ¶ added in v0.0.3
func NewWorldStore(io *IO) *WorldStore
func (*WorldStore) AppendStateChanges ¶ added in v0.0.3
func (s *WorldStore) AppendStateChanges(changes []domain.StateChange) error
AppendStateChanges 追加角色状态变化。同一状态变化重复提交时按稳定 key 去重。
func (*WorldStore) AppendTimelineEvents ¶ added in v0.0.3
func (s *WorldStore) AppendTimelineEvents(newEvents []domain.TimelineEvent) error
AppendTimelineEvents 追加时间线事件。同一事件重复提交时按稳定 key 去重,保证 commit_chapter 崩溃后重跑不会污染时间线。
func (*WorldStore) HasArcReview ¶ added in v0.2.0
func (s *WorldStore) HasArcReview(chapter int) (bool, error)
HasArcReview 检查指定章节(弧末章)是否已保存 scope=arc 的评审。
func (*WorldStore) HasGlobalReview ¶ added in v0.7.0
func (s *WorldStore) HasGlobalReview(chapter int) (bool, error)
HasGlobalReview 检查指定章节是否已保存 scope=global 的全局审阅 (save_review 落盘为 reviews/%02d-global.json;非分层书按 ReviewInterval 触发)。
func (*WorldStore) LoadActiveForeshadow ¶ added in v0.0.3
func (s *WorldStore) LoadActiveForeshadow() ([]domain.ForeshadowEntry, error)
LoadActiveForeshadow 返回未回收的伏笔条目。
func (*WorldStore) LoadForeshadowLedger ¶ added in v0.0.3
func (s *WorldStore) LoadForeshadowLedger() ([]domain.ForeshadowEntry, error)
LoadForeshadowLedger 读取伏笔账本。
func (*WorldStore) LoadLastReview ¶ added in v0.0.3
func (s *WorldStore) LoadLastReview(fromChapter int) (*domain.ReviewEntry, error)
LoadLastReview 读取最近一次全局审阅。
func (*WorldStore) LoadRecentTimeline ¶ added in v0.0.3
func (s *WorldStore) LoadRecentTimeline(current, window int) ([]domain.TimelineEvent, error)
LoadRecentTimeline 返回最近 window 章内的时间线事件。
func (*WorldStore) LoadRelationships ¶ added in v0.0.3
func (s *WorldStore) LoadRelationships() ([]domain.RelationshipEntry, error)
LoadRelationships 读取人物关系状态。
func (*WorldStore) LoadReview ¶ added in v0.0.3
func (s *WorldStore) LoadReview(chapter int) (*domain.ReviewEntry, error)
LoadReview 读取章节审阅结果。
func (*WorldStore) LoadReviewsAffectingChapter ¶ added in v0.7.4
func (s *WorldStore) LoadReviewsAffectingChapter(chapter int) ([]domain.ReviewEntry, error)
LoadReviewsAffectingChapter 返回所有明确把 chapter 纳入返工队列的评审, 新到旧排列。弧/全局评审存放在评审终点,不能再按目标章节文件名查找。
func (*WorldStore) LoadRuleViolations ¶ added in v0.7.0
func (s *WorldStore) LoadRuleViolations(chapter int) []rules.Violation
LoadRuleViolations 读取某章最新一条机械违规记录;无记录返回 nil。
func (*WorldStore) LoadStateChanges ¶ added in v0.0.3
func (s *WorldStore) LoadStateChanges() ([]domain.StateChange, error)
LoadStateChanges 读取全部状态变化记录。
func (*WorldStore) LoadStyleRules ¶ added in v0.0.3
func (s *WorldStore) LoadStyleRules() (*domain.WritingStyleRules, error)
LoadStyleRules 读取写作风格规则。
func (*WorldStore) LoadTimeline ¶ added in v0.0.3
func (s *WorldStore) LoadTimeline() ([]domain.TimelineEvent, error)
LoadTimeline 读取时间线。
func (*WorldStore) LoadWorldRules ¶ added in v0.0.3
func (s *WorldStore) LoadWorldRules() ([]domain.WorldRule, error)
LoadWorldRules 读取世界规则。
func (*WorldStore) SaveForeshadowLedger ¶ added in v0.0.3
func (s *WorldStore) SaveForeshadowLedger(entries []domain.ForeshadowEntry) error
SaveForeshadowLedger 全量写入 foreshadow_ledger.json + foreshadow_ledger.md(原子写入)。
func (*WorldStore) SaveRelationships ¶ added in v0.0.3
func (s *WorldStore) SaveRelationships(entries []domain.RelationshipEntry) error
SaveRelationships 全量写入 relationship_state.json + relationship_state.md(原子写入)。
func (*WorldStore) SaveReview ¶ added in v0.0.3
func (s *WorldStore) SaveReview(r domain.ReviewEntry) error
SaveReview 保存审阅结果。
func (*WorldStore) SaveRuleViolations ¶ added in v0.7.0
func (s *WorldStore) SaveRuleViolations(chapter int, violations []rules.Violation) error
SaveRuleViolations 追加一章的机械违规(空列表也追加——覆盖旧记录,表示重写后已清)。
func (*WorldStore) SaveStyleRules ¶ added in v0.0.3
func (s *WorldStore) SaveStyleRules(rules domain.WritingStyleRules) error
SaveStyleRules 保存写作风格规则。
func (*WorldStore) SaveTimeline ¶ added in v0.0.3
func (s *WorldStore) SaveTimeline(events []domain.TimelineEvent) error
SaveTimeline 全量替换时间线事实与人类可读投影。
func (*WorldStore) SaveWorldRules ¶ added in v0.0.3
func (s *WorldStore) SaveWorldRules(rules []domain.WorldRule) error
SaveWorldRules 全量写入 world_rules.json + world_rules.md(原子写入)。
func (*WorldStore) UpdateForeshadow ¶ added in v0.0.3
func (s *WorldStore) UpdateForeshadow(chapter int, updates []domain.ForeshadowUpdate) error
UpdateForeshadow 批量应用伏笔增量操作。
func (*WorldStore) UpdateRelationships ¶ added in v0.0.3
func (s *WorldStore) UpdateRelationships(changes []domain.RelationshipEntry) error
UpdateRelationships 合并关系变化。