diag

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 20 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: 伏笔停滞最小章数
)
View Source
const ExportRelPath = "meta/diag-export.md"

ExportRelPath 是脱敏诊断文件相对 output 目录的固定位置(覆盖式一份)。

Variables

This section is empty.

Functions

func Diagnose added in v0.4.5

func Diagnose(s *store.Store) (Report, RuntimeCapture)

Diagnose 是 /diag 的完整诊断入口:创作诊断 + 运行时信号 + 运行时检测, 返回合并后的 Report 与原始 RuntimeCapture(供导出复用,避免重复抓取)。 运行时 Finding 仅并入 Findings 供展示,不改 Actions——保持纯观察。

func Export added in v0.4.5

func Export(s *store.Store) (string, error)

Export 完整诊断 + 渲染 + 落盘,返回写出的绝对路径。供 headless / 外部调用。

func RenderExport added in v0.4.5

func RenderExport(rep Report, rc RuntimeCapture) []byte

RenderExport 把创作 Report + 运行时抓取组合成脱敏 Markdown。

func WriteExport added in v0.4.5

func WriteExport(s *store.Store, rep Report, rc RuntimeCapture) (string, error)

WriteExport 把已算好的 Report + RuntimeCapture 渲染落盘,不重复抓取。 供 /diag 命令复用 Diagnose 的结果。

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 DupStat added in v0.4.5

type DupStat struct {
	Sha   string
	Count int
}

DupStat 是同一段脱敏文本反复出现的次数。

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 ChronicLowDimension

func ChronicLowDimension(snap *Snapshot) []Finding

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

func CompassDrift

func CompassDrift(snap *Snapshot) []Finding

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

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 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 RepeatStat added in v0.4.5

type RepeatStat struct {
	Sig   string
	Count int
}

RepeatStat 是一条重复签名及其次数。

type Report

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

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

func Analyze

func Analyze(s *store.Store) Report

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

type RoleModel added in v0.4.5

type RoleModel struct {
	Agent, Provider, Model string
}

RoleModel 记录某会话实际用的 provider/model。

type RuleFunc

type RuleFunc func(snap *Snapshot) []Finding

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

type RuntimeCapture added in v0.4.5

type RuntimeCapture struct {
	GoOS, GoArch  string
	Models        []RoleModel  // 各会话实际生效的 provider/model(从 _meta 收集)
	CurrentStep   string       // 最新 checkpoint:scope.step
	StuckStep     string       // 尾部连续同 step;"" = 不卡
	StuckCount    int          // 连续次数
	Repeats       []RepeatStat // 重复签名 top-N(循环信号)
	DupContent    []DupStat    // 同 sha 文本反复出现(反复生成同段)
	LogKinds      map[string]int
	LogErrors     int
	LogWarns      int
	StopGuard     int
	Tail          []SkelEvent // 末 N 条骨架(看顺序)
	RedactedTexts int         // 打码文本块总数(脱敏自检)
	Sources       []string    // 实际读到的源(自检)
}

RuntimeCapture 是一次运行时抓取的脱敏结果。只承载运行时信号; phase/flow/章节等创作态由 Report.Stats 携带,不在此重复。

func CaptureRuntime added in v0.4.5

func CaptureRuntime(s *store.Store) RuntimeCapture

CaptureRuntime 从 output 目录只读抓取运行时信号并脱敏聚合。 任何源缺失都安全降级(不报错),尽力而为。

type RuntimeRuleFunc added in v0.4.5

type RuntimeRuleFunc func(rc *RuntimeCapture) []Finding

RuntimeRuleFunc 是运行时诊断规则的统一签名(对应创作侧的 RuleFunc)。 入参是脱敏聚合后的 RuntimeCapture,产出报告型 Finding——全部 AutoNone, 只诊断、不产 Action(观察者纪律,见 architecture.md §2.3)。

type Severity

type Severity string

Severity 表示发现的严重程度。

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

type SkelEvent added in v0.4.5

type SkelEvent struct {
	Agent    string     // 来源会话:coordinator / writer-ch07 …
	Role     string     // assistant / tool / user
	Tools    []SkelTool // 该消息内的工具调用
	ErrClass string     // role=tool 且 is_error:错误首行(框架错误串,不含正文)
	TextSha  string     // 打码正文的短哈希;同 sha = 反复生成同一段(循环信号)
	Redacted int        // 本条打码的文本/思考块数(用于脱敏自检)
}

SkelEvent 是一条会话消息脱敏后的行为骨架:保留结构信号(角色 / 工具 / 错误 / 重复指纹),所有自由文本(正文、prompt、思考)一律打码。这是比 store.compactMessage 更严的一层投影——后者按体积压(>4KB),这里不看体积, 任何文本都不出包。

type SkelTool added in v0.4.5

type SkelTool struct {
	Name     string            // 工具名(结构信号,不含正文)
	Args     map[string]string // key → 标量原值 / 短字符串带引号 / "<redacted len sha>"
	Invalid  bool              // ArgsInvalid:模型发来的参数无法解析(#34 信号)
	ParseErr string            // ArgsParseError:解析失败原因
}

SkelTool 是一次工具调用的脱敏投影。

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

	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