diag

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ThresholdDimScoreLow      = 70  // ChronicLowDimension: 维度均分低于此值告警
	ThresholdContractMissRate = 0.3 // ContractMissPattern: 合同未达成率上限
	ThresholdRewriteRate      = 0.5 // ExcessiveRewrites: 改写率上限
	ThresholdWordShortRatio   = 0.4 // WordCountAnomaly: 字数低于均值此比例视为异常
	ThresholdWordLongRatio    = 2.5 // WordCountAnomaly: 字数高于均值此比例视为异常
	ThresholdHookWeakScore    = 75  // HookWeakChain: hook 低于此分视为偏弱
	ThresholdHookWeakChain    = 3   // HookWeakChain: 连续偏弱章数阈值
	ThresholdPayoffMissRate   = 0.4 // PayoffMissPattern: payoff 未兑现率上限
	ThresholdCompassDrift     = 15  // CompassDrift: 指南针未更新章数上限
	ThresholdTimelineGapRate  = 0.3 // TimelineGaps: 缺失率容忍上限
	ThresholdForeshadowMin    = 8   // StaleForeshadow: 伏笔停滞最小章数
	ThresholdDesignWeakRate   = 0.6 // 设计诊断:症状与缺口相关性的最低比例
	ThresholdDesignMinSamples = 2   // 设计诊断:最少样本数
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	SourceRule  string     // 来源规则名
	Kind        ActionKind // 动作类型
	Severity    Severity   // 继承自 Finding
	Summary     string     // 简短描述
	Message     string     // 传递给控制流的消息
	Fingerprint string     // 来源 Finding 的稳定指纹,用于运行时去重
}

Action 是 Planner 根据高置信 Finding 生成的可执行动作。

func PlanActions

func PlanActions(findings []Finding) []Action

PlanActions 根据高置信 Finding 生成可执行动作。 只有 Confidence==high && AutoLevel==safe 的 Finding 才会产出 Action。

type ActionKind

type ActionKind string

ActionKind 表示诊断动作的类型。

const (
	ActionEmitNotice      ActionKind = "emit_notice"       // 发系统提示
	ActionEnqueueFollowUp ActionKind = "enqueue_follow_up" // 注入 coordinator follow-up
)

type AutoLevel

type AutoLevel string

AutoLevel 表示 Finding 是否可以转为自动化动作。

const (
	AutoNone    AutoLevel = "none"    // 仅报告,不自动
	AutoSuggest AutoLevel = "suggest" // 建议动作但需人工确认
	AutoSafe    AutoLevel = "safe"    // 可安全自动执行
)

type Category

type Category string

Category 将发现按维度分组。

const (
	CatFlow     Category = "flow"     // 流程卡顿、状态异常、恢复问题
	CatQuality  Category = "quality"  // 评审评分、合同履约、一致性
	CatPlanning Category = "planning" // 大纲缺口、伏笔漂移、指南针过时
	CatContext  Category = "context"  // 角色/时间线/关系异常
)

type Confidence

type Confidence string

Confidence 表示规则判定的置信度。

const (
	ConfHigh   Confidence = "high"   // 确定性强,可信赖
	ConfMedium Confidence = "medium" // 启发式判断,可能有误判
	ConfLow    Confidence = "low"    // 粗略信号,仅供参考
)

type Finding

type Finding struct {
	Rule       string     // 规则名,如 "StaleForeshadow"
	Category   Category   // 分类
	Severity   Severity   // 严重程度
	Confidence Confidence // 判定置信度
	AutoLevel  AutoLevel  // 自动化级别
	Target     string     // 建议作用面,如 "runtime.flow"
	Title      string     // 一行摘要
	Evidence   string     // 具体数据证据
	Suggestion string     // 改进建议(指向 prompt/flow/config)
}

Finding 是一条可执行的诊断结果。

func ChapterGaps

func ChapterGaps(snap *Snapshot) []Finding

ChapterGaps 检测已完成章节列表中的跳号。

func ChapterPlanInjectionGap

func ChapterPlanInjectionGap(snap *Snapshot) []Finding

ChapterPlanInjectionGap 检测问题章节是否普遍缺失 chapter_plan 注入。

func ChronicLowDimension

func ChronicLowDimension(snap *Snapshot) []Finding

ChronicLowDimension 检测某评审维度跨多章持续低分。

func CompassDrift

func CompassDrift(snap *Snapshot) []Finding

CompassDrift 检测指南针长期未更新。

func ContextCompactionPressure

func ContextCompactionPressure(snap *Snapshot) []Finding

ContextCompactionPressure 检测上下文压缩是否过于频繁。

func ContinuitySupportWeak

func ContinuitySupportWeak(snap *Snapshot) []Finding

ContinuitySupportWeak 检测 continuity 问题是否常伴随时间线/状态变化支持缺失。

func ContractExecutionWeak

func ContractExecutionWeak(snap *Snapshot) []Finding

ContractExecutionWeak 判断 contract 问题更像上下文缺失还是 Writer 执行不足。

func ContractMissPattern

func ContractMissPattern(snap *Snapshot) []Finding

ContractMissPattern 检测合同履约率过低。

func ExcessiveRewrites

func ExcessiveRewrites(snap *Snapshot) []Finding

ExcessiveRewrites 检测改写率过高。

func GhostCharacter

func GhostCharacter(snap *Snapshot) []Finding

GhostCharacter 检测 core/important 角色长期未出现。

func HookWeakChain

func HookWeakChain(snap *Snapshot) []Finding

HookWeakChain 检测章节 hook 评分连续偏弱。

func MissingSummaries

func MissingSummaries(snap *Snapshot) []Finding

MissingSummaries 检测已完成章节缺少摘要。

func OrphanedSteer

func OrphanedSteer(snap *Snapshot) []Finding

OrphanedSteer 检测未消费的用户转向指令。

func OutlineExhausted

func OutlineExhausted(snap *Snapshot) []Finding

OutlineExhausted 检测大纲耗尽但小说未完结。

func PayoffMissPattern

func PayoffMissPattern(snap *Snapshot) []Finding

PayoffMissPattern 检测带 payoff_points 的章节长期未兑现。

func PhaseFlowMismatch

func PhaseFlowMismatch(snap *Snapshot) []Finding

PhaseFlowMismatch 检测阶段与流程状态不匹配。

func RelationshipStagnation

func RelationshipStagnation(snap *Snapshot) []Finding

RelationshipStagnation 检测关系数据停止更新。

func RewriteAfterCompaction

func RewriteAfterCompaction(snap *Snapshot) []Finding

RewriteAfterCompaction 检测压缩后的章节是否更容易被要求重写。

func RewritePendingPressure

func RewritePendingPressure(snap *Snapshot) []Finding

RewritePendingPressure 检测存在待改写章节(当前仅检测状态存在,不判定停滞)。

func StaleForeshadow

func StaleForeshadow(snap *Snapshot) []Finding

StaleForeshadow 检测长期未推进的伏笔。

func TimelineGaps

func TimelineGaps(snap *Snapshot) []Finding

TimelineGaps 检测已完成章节缺少时间线事件。

func WordCountAnomaly

func WordCountAnomaly(snap *Snapshot) []Finding

WordCountAnomaly 检测章节字数异常。

type Report

type Report struct {
	Stats    Stats
	Findings []Finding
	Actions  []Action
}

Report 是一次诊断运行的完整输出。

func Analyze

func Analyze(s *store.Store) Report

Analyze 是诊断系统的唯一入口。

type RuleFunc

type RuleFunc func(snap *Snapshot) []Finding

RuleFunc 是诊断规则的统一签名。

type Severity

type Severity string

Severity 表示发现的严重程度。

const (
	SevCritical Severity = "critical" // 阻塞进度或数据损坏
	SevWarning  Severity = "warning"  // 可能降低质量或浪费 token
	SevInfo     Severity = "info"     // 可优化项
)

type Snapshot

type Snapshot struct {
	Progress          *domain.Progress
	RunMeta           *domain.RunMeta
	Compass           *domain.StoryCompass
	Outline           []domain.OutlineEntry
	Volumes           []domain.VolumeOutline
	Characters        []domain.Character
	CastLedger        []domain.CastEntry
	WorldRules        []domain.WorldRule
	Timeline          []domain.TimelineEvent
	Foreshadow        []domain.ForeshadowEntry
	Relationships     []domain.RelationshipEntry
	StateChanges      []domain.StateChange
	StyleRules        *domain.WritingStyleRules
	Reviews           map[int]*domain.ReviewEntry
	Plans             map[int]*domain.ChapterPlan
	Summaries         map[int]*domain.ChapterSummary
	ContextBoundaries []domain.RuntimeContextBoundary
	ContextEvidence   map[int]domain.ContextBuildEvidence
	ReviewEvidence    map[int]domain.ReviewOutcomeEvidence
	ChapterTraces     map[int]*chapterTrace

	LoadErrors []string // 非 NotExist 的加载失败,区分"无数据"和"读取出错"
}

Snapshot 是对 output 目录全部工件的只读快照。 所有规则函数只接收 Snapshot,不直接访问文件系统。

func Load

func Load(s *store.Store) Snapshot

Load 从 store 中读取全部工件,构建只读快照。 文件不存在视为"无数据"(字段保持零值);其他错误记录到 LoadErrors。

func (*Snapshot) CompletedCount

func (s *Snapshot) CompletedCount() int

CompletedCount 返回已完成章节数(安全访问)。

func (*Snapshot) LatestCompleted

func (s *Snapshot) LatestCompleted() int

LatestCompleted 返回最大已完成章节号;无则返回 0。

type Stats

type Stats struct {
	CompletedChapters int
	TotalChapters     int
	TotalWords        int
	AvgWordsPerCh     int
	Phase             string
	Flow              string
	PlanningTier      string
	ReviewCount       int
	RewriteCount      int
	AvgReviewScore    float64
	ForeshadowOpen    int
	ForeshadowStale   int
}

Stats 是与发现并列展示的概览指标。

Jump to

Keyboard shortcuts

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