tools

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Overview

internal/tools/draft_persona.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AskUserHandler

type AskUserHandler func(ctx context.Context, questions []Question) (*AskUserResponse, error)

AskUserHandler 阻塞等待用户回答,由 CLI 或 TUI 注入具体实现。

type AskUserResponse

type AskUserResponse struct {
	Answers map[string]string // question text → 用户选择的答案
	Notes   map[string]string // question text → 自定义输入(选"其他"时)
}

AskUserResponse 用户回答结果。

type AskUserTool

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

AskUserTool 让 LLM 向用户提出结构化问题。

func NewAskUserTool

func NewAskUserTool() *AskUserTool

func (*AskUserTool) ConcurrencySafe

func (t *AskUserTool) ConcurrencySafe(_ json.RawMessage) bool

func (*AskUserTool) Description

func (t *AskUserTool) Description() string

func (*AskUserTool) Execute

func (t *AskUserTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*AskUserTool) Label

func (t *AskUserTool) Label() string

func (*AskUserTool) Name

func (t *AskUserTool) Name() string

func (*AskUserTool) ReadOnly

func (t *AskUserTool) ReadOnly(_ json.RawMessage) bool

交互工具:阻塞等待用户回答,显然不能并发调度。

func (*AskUserTool) Schema

func (t *AskUserTool) Schema() map[string]any

func (*AskUserTool) SetHandler

func (t *AskUserTool) SetHandler(h AskUserHandler)

SetHandler 注入 UI 回调,CLI 和 TUI 各自实现。

type CheckConsistencyTool

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

CheckConsistencyTool 返回章节内容和全部状态数据,供 Agent 自行对照判断。 纯 IO 工具:只负责加载数据,不注入指令。

func NewCheckConsistencyTool

func NewCheckConsistencyTool(store *store.Store) *CheckConsistencyTool

func (*CheckConsistencyTool) ConcurrencySafe

func (t *CheckConsistencyTool) ConcurrencySafe(_ json.RawMessage) bool

func (*CheckConsistencyTool) Description

func (t *CheckConsistencyTool) Description() string

func (*CheckConsistencyTool) Execute

func (*CheckConsistencyTool) Label

func (t *CheckConsistencyTool) Label() string

func (*CheckConsistencyTool) Name

func (t *CheckConsistencyTool) Name() string

func (*CheckConsistencyTool) ReadOnly

func (t *CheckConsistencyTool) ReadOnly(_ json.RawMessage) bool

只读工具(仅追加 checkpoint 事件,不改状态),可被并发调度。

func (*CheckConsistencyTool) Schema

func (t *CheckConsistencyTool) Schema() map[string]any

type CommitChapterTool

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

CommitChapterTool 提交章节:加载正文 → 保存终稿 → 生成摘要 → 更新状态 → 更新进度。

func NewCommitChapterTool

func NewCommitChapterTool(store *store.Store) *CommitChapterTool

func (*CommitChapterTool) ConcurrencySafe

func (t *CommitChapterTool) ConcurrencySafe(_ json.RawMessage) bool

func (*CommitChapterTool) Description

func (t *CommitChapterTool) Description() string

func (*CommitChapterTool) Execute

func (*CommitChapterTool) Label

func (t *CommitChapterTool) Label() string

func (*CommitChapterTool) Name

func (t *CommitChapterTool) Name() string

func (*CommitChapterTool) ReadOnly

func (t *CommitChapterTool) ReadOnly(_ json.RawMessage) bool

写工具(跨域原子操作:草稿→终稿→摘要→进度→checkpoint),禁止并发。

func (*CommitChapterTool) Schema

func (t *CommitChapterTool) Schema() map[string]any

func (*CommitChapterTool) WithRules

WithRules 注入规则加载选项,使 commit_chapter 在返回 JSON 中附带 rule_violations。 不调用此方法时 commit_chapter 行为不变(向后兼容,便于测试)。

type ContextTool

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

ContextTool 组装当前章节所需上下文。

func NewContextTool

func NewContextTool(store *store.Store, refs References, style string, rulesOpts rules.LoadOptions) *ContextTool

NewContextTool 创建上下文工具。rulesOpts 控制 user_rules 的加载来源; 空 LoadOptions 仍然安全,loader 会跳过所有未配置的来源,user_rules 注入空 Bundle。

func (*ContextTool) ConcurrencySafe

func (t *ContextTool) ConcurrencySafe(_ json.RawMessage) bool

func (*ContextTool) ContextSummary

func (t *ContextTool) ContextSummary() string

ContextSummary 返回当前状态的简要摘要(供日志使用)。

func (*ContextTool) Description

func (t *ContextTool) Description() string

func (*ContextTool) Execute

func (t *ContextTool) Execute(_ context.Context, args json.RawMessage) (json.RawMessage, error)

func (*ContextTool) Label

func (t *ContextTool) Label() string

func (*ContextTool) Name

func (t *ContextTool) Name() string

func (*ContextTool) ReadOnly

func (t *ContextTool) ReadOnly(_ json.RawMessage) bool

纯读工具,可被并发调度。

func (*ContextTool) Schema

func (t *ContextTool) Schema() map[string]any

func (*ContextTool) WithProfileSource added in v0.7.0

func (t *ContextTool) WithProfileSource(fn func() (*domain.SimulationProfile, error)) *ContextTool

WithProfileSource 返回一个 simulation_profile 来源被覆盖的浅拷贝实例。 竞稿装配用:每个竞稿写手持有专属实例,注入各自的融合画像(运行期单信号); 原实例不受影响(其余角色继续读主画像)。

type DraftChapterTool

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

DraftChapterTool 写入整章草稿,替代旧的 write_scene + polish_chapter 流水线。 Agent 自主决定一次写完还是分批续写。

func NewDraftChapterTool

func NewDraftChapterTool(store *store.Store) *DraftChapterTool

func (*DraftChapterTool) ConcurrencySafe

func (t *DraftChapterTool) ConcurrencySafe(_ json.RawMessage) bool

func (*DraftChapterTool) Description

func (t *DraftChapterTool) Description() string

func (*DraftChapterTool) Execute

func (*DraftChapterTool) Label

func (t *DraftChapterTool) Label() string

func (*DraftChapterTool) Name

func (t *DraftChapterTool) Name() string

func (*DraftChapterTool) ReadOnly

func (t *DraftChapterTool) ReadOnly(_ json.RawMessage) bool

写工具,禁止并发(读-改-写竞态)。

func (*DraftChapterTool) Schema

func (t *DraftChapterTool) Schema() map[string]any

func (*DraftChapterTool) StrictSchema

func (t *DraftChapterTool) StrictSchema() bool

StrictSchema 启用 OpenAI 的 strict tool calling,让模型必须严格遵守 schema:所有 required 字段必填,arguments 不能"提前 EOT"出现空对象。 litellm 透传 strict 字段;OpenAI / xAI 等支持的后端会强制执行,其他后端 按 HTTP/JSON 惯例忽略未知字段。Anthropic/Gemini/Bedrock 走各自的转换链路 自然不会看到这个字段。

type DraftPersonaTool

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

DraftPersonaTool 是竞稿模式下的章节草稿工具。它绑定一个 persona slug, 候选阶段写隔离候选槽(drafts/NN.cand-<slug>.md), 润色阶段(本 persona 中选且已提升)写正式 draft.md。 Name 仍为 "draft_chapter",使 writer prompt 与 StopAfterTools 无需改动。 阶段每次 Execute 独立判定:Promoted 置位前写候选槽,置位后(且本 persona 中选)写正式 draft.md。

func NewDraftPersonaTool

func NewDraftPersonaTool(store *store.Store, persona string) *DraftPersonaTool

NewDraftPersonaTool 创建绑定指定 persona 的草稿工具。

func (*DraftPersonaTool) ConcurrencySafe

func (t *DraftPersonaTool) ConcurrencySafe(_ json.RawMessage) bool

func (*DraftPersonaTool) Description

func (t *DraftPersonaTool) Description() string

func (*DraftPersonaTool) Execute

func (*DraftPersonaTool) Label

func (t *DraftPersonaTool) Label() string

func (*DraftPersonaTool) Name

func (t *DraftPersonaTool) Name() string

func (*DraftPersonaTool) ReadOnly

func (t *DraftPersonaTool) ReadOnly(_ json.RawMessage) bool

写工具,禁止并发(读-改-写竞态)。

func (*DraftPersonaTool) Schema

func (t *DraftPersonaTool) Schema() map[string]any

func (*DraftPersonaTool) StrictSchema

func (t *DraftPersonaTool) StrictSchema() bool

StrictSchema 启用 OpenAI strict tool calling,与 DraftChapterTool 保持一致。

type EditChapterTool

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

EditChapterTool 对章节草稿做定点字符串替换,适用于打磨场景。 相比 draft_chapter 整章重写,token 节省 10x+。

落盘契约:只改 drafts/{ch:02d}.draft.md,禁止直接改 chapters/(终稿由 commit_chapter 独占)。 Seed 语义:drafts 不存在但 chapters 有 → 自动把 chapters 复制到 drafts 作为起点。 归属检查:章节已完成时必须在 PendingRewrites 队列中,否则拒绝。

本工具是 agentcore.EditTool 的薄封装,找-换逻辑(多级容错匹配、diff 输出、行尾/BOM 保留) 全部复用上游实现。

func NewEditChapterTool

func NewEditChapterTool(s *store.Store) *EditChapterTool

func (*EditChapterTool) ActivityDescription

func (t *EditChapterTool) ActivityDescription(_ json.RawMessage) string

ActivityDescription 供 UI/日志展示当前工具的活动描述。

func (*EditChapterTool) ConcurrencySafe

func (t *EditChapterTool) ConcurrencySafe(_ json.RawMessage) bool

ConcurrencySafe 显式禁止并发:同章节多次 edit_chapter 并行会读-改-写竞态, 即使不同章节并行也会穿插 checkpoint 顺序。统一串行最稳。

func (*EditChapterTool) Description

func (t *EditChapterTool) Description() string

func (*EditChapterTool) Execute

func (*EditChapterTool) Label

func (t *EditChapterTool) Label() string

func (*EditChapterTool) Name

func (t *EditChapterTool) Name() string

func (*EditChapterTool) ReadOnly

func (t *EditChapterTool) ReadOnly(_ json.RawMessage) bool

ReadOnly 明确声明写工具(配合 ConcurrencySafer 防止被并发调度)。

func (*EditChapterTool) Schema

func (t *EditChapterTool) Schema() map[string]any

type Option

type Option struct {
	Label       string `json:"label"`
	Description string `json:"description"`
}

Option 可选项。

type PlanChapterTool

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

PlanChapterTool 保存章节构思,Agent 自主决定规划粒度。

func NewPlanChapterTool

func NewPlanChapterTool(store *store.Store) *PlanChapterTool

func (*PlanChapterTool) ConcurrencySafe

func (t *PlanChapterTool) ConcurrencySafe(_ json.RawMessage) bool

func (*PlanChapterTool) Description

func (t *PlanChapterTool) Description() string

func (*PlanChapterTool) Execute

func (*PlanChapterTool) Label

func (t *PlanChapterTool) Label() string

func (*PlanChapterTool) Name

func (t *PlanChapterTool) Name() string

func (*PlanChapterTool) ReadOnly

func (t *PlanChapterTool) ReadOnly(_ json.RawMessage) bool

写工具,禁止并发。

func (*PlanChapterTool) Schema

func (t *PlanChapterTool) Schema() map[string]any

type Question

type Question struct {
	Question    string   `json:"question"`
	Header      string   `json:"header"`
	Options     []Option `json:"options"`
	MultiSelect bool     `json:"multiSelect"`
}

Question 单个问题。

type ReadCandidatesTool

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

ReadCandidatesTool 让 judge 读取某章所有 persona 的候选稿用于对比选优。 绑定 persona slug 列表,只返回已落盘的候选(缺席的跳过)。

func NewReadCandidatesTool

func NewReadCandidatesTool(store *store.Store, personas []string) *ReadCandidatesTool

func (*ReadCandidatesTool) ConcurrencySafe

func (t *ReadCandidatesTool) ConcurrencySafe(_ json.RawMessage) bool

func (*ReadCandidatesTool) Description

func (t *ReadCandidatesTool) Description() string

func (*ReadCandidatesTool) Execute

func (*ReadCandidatesTool) Label

func (t *ReadCandidatesTool) Label() string

func (*ReadCandidatesTool) Name

func (t *ReadCandidatesTool) Name() string

func (*ReadCandidatesTool) ReadOnly

func (t *ReadCandidatesTool) ReadOnly(_ json.RawMessage) bool

纯读工具,可并发。

func (*ReadCandidatesTool) Schema

func (t *ReadCandidatesTool) Schema() map[string]any

type ReadChapterTool

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

ReadChapterTool 读取章节原文,让 Agent 能回读自己和前文的文字。

func NewReadChapterTool

func NewReadChapterTool(store *store.Store) *ReadChapterTool

func (*ReadChapterTool) ConcurrencySafe

func (t *ReadChapterTool) ConcurrencySafe(_ json.RawMessage) bool

func (*ReadChapterTool) Description

func (t *ReadChapterTool) Description() string

func (*ReadChapterTool) Execute

func (*ReadChapterTool) Label

func (t *ReadChapterTool) Label() string

func (*ReadChapterTool) Name

func (t *ReadChapterTool) Name() string

func (*ReadChapterTool) ReadOnly

func (t *ReadChapterTool) ReadOnly(_ json.RawMessage) bool

纯读工具,可被并发调度(editor 审阅时常一次读多章)。

func (*ReadChapterTool) Schema

func (t *ReadChapterTool) Schema() map[string]any

type References

type References struct {
	// V0
	ChapterGuide      string
	HookTechniques    string
	QualityChecklist  string
	OutlineTemplate   string
	CharacterTemplate string
	ChapterTemplate   string
	// V1
	Consistency      string
	ContentExpansion string
	DialogueWriting  string
	// V2
	StyleReference   string // 风格补充参考(可为空)
	LongformPlanning string // 通用长篇规划参考
	Differentiation  string // 通用差异化设计参考
	ArcTemplates     string // 题材弧型模板(按 style 加载,可为空)
	AntiAITone       string // 去 AI 味判据库(writer/editor 共用,全程注入)
}

References 嵌入的参考资料。

type SaveArcSummaryTool

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

SaveArcSummaryTool 保存弧级摘要和角色快照,Editor 在弧结束时调用。

func NewSaveArcSummaryTool

func NewSaveArcSummaryTool(store *store.Store) *SaveArcSummaryTool

func (*SaveArcSummaryTool) ConcurrencySafe

func (t *SaveArcSummaryTool) ConcurrencySafe(_ json.RawMessage) bool

func (*SaveArcSummaryTool) Description

func (t *SaveArcSummaryTool) Description() string

func (*SaveArcSummaryTool) Execute

func (*SaveArcSummaryTool) Label

func (t *SaveArcSummaryTool) Label() string

func (*SaveArcSummaryTool) Name

func (t *SaveArcSummaryTool) Name() string

func (*SaveArcSummaryTool) ReadOnly

func (t *SaveArcSummaryTool) ReadOnly(_ json.RawMessage) bool

写工具,禁止并发。

func (*SaveArcSummaryTool) Schema

func (t *SaveArcSummaryTool) Schema() map[string]any

type SaveFoundationTool

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

SaveFoundationTool 保存基础设定(premise/outline/characters),Architect 专用。

func NewSaveFoundationTool

func NewSaveFoundationTool(store *store.Store) *SaveFoundationTool

func (*SaveFoundationTool) ConcurrencySafe

func (t *SaveFoundationTool) ConcurrencySafe(_ json.RawMessage) bool

func (*SaveFoundationTool) Description

func (t *SaveFoundationTool) Description() string

func (*SaveFoundationTool) Execute

func (*SaveFoundationTool) Label

func (t *SaveFoundationTool) Label() string

func (*SaveFoundationTool) Name

func (t *SaveFoundationTool) Name() string

func (*SaveFoundationTool) ReadOnly

func (t *SaveFoundationTool) ReadOnly(_ json.RawMessage) bool

写工具(跨域更新 Outline/Progress/Characters),禁止并发。

func (*SaveFoundationTool) Schema

func (t *SaveFoundationTool) Schema() map[string]any

type SaveReviewTool

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

SaveReviewTool 保存 Editor 的审阅结果。

func NewSaveReviewTool

func NewSaveReviewTool(store *store.Store) *SaveReviewTool

func (*SaveReviewTool) ConcurrencySafe

func (t *SaveReviewTool) ConcurrencySafe(_ json.RawMessage) bool

func (*SaveReviewTool) Description

func (t *SaveReviewTool) Description() string

func (*SaveReviewTool) Execute

func (*SaveReviewTool) Label

func (t *SaveReviewTool) Label() string

func (*SaveReviewTool) Name

func (t *SaveReviewTool) Name() string

func (*SaveReviewTool) ReadOnly

func (t *SaveReviewTool) ReadOnly(_ json.RawMessage) bool

写工具(同时更新 reviews/ 与 Progress 的 PendingRewrites/Flow),禁止并发。

func (*SaveReviewTool) Schema

func (t *SaveReviewTool) Schema() map[string]any

type SaveVerdictTool

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

SaveVerdictTool 保存 Judge 对多人格候选稿的选优裁定。

func NewSaveVerdictTool

func NewSaveVerdictTool(store *store.Store) *SaveVerdictTool

NewSaveVerdictTool 构造 SaveVerdictTool。

func (*SaveVerdictTool) ConcurrencySafe

func (t *SaveVerdictTool) ConcurrencySafe(_ json.RawMessage) bool

func (*SaveVerdictTool) Description

func (t *SaveVerdictTool) Description() string

func (*SaveVerdictTool) Execute

Execute 验证并保存裁定,追加 checkpoint artifact。

func (*SaveVerdictTool) Label

func (t *SaveVerdictTool) Label() string

func (*SaveVerdictTool) Name

func (t *SaveVerdictTool) Name() string

func (*SaveVerdictTool) ReadOnly

func (t *SaveVerdictTool) ReadOnly(_ json.RawMessage) bool

写工具,禁止并发。

func (*SaveVerdictTool) Schema

func (t *SaveVerdictTool) Schema() map[string]any

Schema 返回工具的 JSON Schema 描述。

type SaveVolumeSummaryTool

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

SaveVolumeSummaryTool 保存卷级摘要,Editor 在卷结束时调用。

func NewSaveVolumeSummaryTool

func NewSaveVolumeSummaryTool(store *store.Store) *SaveVolumeSummaryTool

func (*SaveVolumeSummaryTool) ConcurrencySafe

func (t *SaveVolumeSummaryTool) ConcurrencySafe(_ json.RawMessage) bool

func (*SaveVolumeSummaryTool) Description

func (t *SaveVolumeSummaryTool) Description() string

func (*SaveVolumeSummaryTool) Execute

func (*SaveVolumeSummaryTool) Label

func (t *SaveVolumeSummaryTool) Label() string

func (*SaveVolumeSummaryTool) Name

func (t *SaveVolumeSummaryTool) Name() string

func (*SaveVolumeSummaryTool) ReadOnly

func (t *SaveVolumeSummaryTool) ReadOnly(_ json.RawMessage) bool

写工具,禁止并发。

func (*SaveVolumeSummaryTool) Schema

func (t *SaveVolumeSummaryTool) Schema() map[string]any

Jump to

Keyboard shortcuts

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