perf: 拆分规划策略

This commit is contained in:
voocel
2026-03-13 00:19:21 +08:00
parent 16e790a372
commit 7488198461
24 changed files with 1543 additions and 487 deletions

View File

@@ -21,7 +21,7 @@ func NewSaveFoundationTool(store *state.Store) *SaveFoundationTool {
func (t *SaveFoundationTool) Name() string { return "save_foundation" }
func (t *SaveFoundationTool) Description() string {
return "保存小说基础设定。type=premise 时 content 为 Markdowntype=outline 时 content 为 JSON 数组type=characters 时 content 为 JSON 数组type=world_rules 时 content 为 JSON 数组"
return "保存小说基础设定。type=premise 时 content 为 Markdowntype=outline 时 content 为 JSON 数组type=characters 时 content 为 JSON 数组type=world_rules 时 content 为 JSON 数组。scale 可选,用于记录 short/mid/long 规划级别"
}
func (t *SaveFoundationTool) Label() string { return "保存设定" }
@@ -29,6 +29,7 @@ func (t *SaveFoundationTool) Schema() map[string]any {
return schema.Object(
schema.Property("type", schema.Enum("设定类型", "premise", "outline", "layered_outline", "characters", "world_rules")).Required(),
schema.Property("content", schema.String("内容。premise 为 Markdown 文本outline/layered_outline/characters/world_rules 为 JSON 字符串")).Required(),
schema.Property("scale", schema.Enum("规划级别", "short", "mid", "long")),
)
}
@@ -36,10 +37,21 @@ func (t *SaveFoundationTool) Execute(_ context.Context, args json.RawMessage) (j
var a struct {
Type string `json:"type"`
Content string `json:"content"`
Scale string `json:"scale"`
}
if err := json.Unmarshal(args, &a); err != nil {
return nil, fmt.Errorf("invalid args: %w", err)
}
if a.Scale != "" {
switch domain.PlanningTier(a.Scale) {
case domain.PlanningTierShort, domain.PlanningTierMid, domain.PlanningTierLong:
default:
return nil, fmt.Errorf("invalid scale %q, expected short/mid/long", a.Scale)
}
if err := t.store.SetPlanningTier(domain.PlanningTier(a.Scale)); err != nil {
return nil, fmt.Errorf("save planning tier: %w", err)
}
}
switch a.Type {
case "premise":
@@ -47,7 +59,7 @@ func (t *SaveFoundationTool) Execute(_ context.Context, args json.RawMessage) (j
return nil, fmt.Errorf("save premise: %w", err)
}
_ = t.store.UpdatePhase(domain.PhasePremise)
return json.Marshal(map[string]any{"saved": true, "type": "premise"})
return json.Marshal(map[string]any{"saved": true, "type": "premise", "scale": a.Scale})
case "outline":
var entries []domain.OutlineEntry
@@ -60,7 +72,12 @@ func (t *SaveFoundationTool) Execute(_ context.Context, args json.RawMessage) (j
_ = t.store.UpdatePhase(domain.PhaseOutline)
// 根据大纲长度自动设定总章节数
_ = t.store.SetTotalChapters(len(entries))
return json.Marshal(map[string]any{"saved": true, "type": "outline", "chapters": len(entries)})
if domain.PlanningTier(a.Scale) != domain.PlanningTierLong {
_ = t.store.SetLayered(false)
_ = t.store.UpdateVolumeArc(0, 0)
_ = t.store.ClearLayeredOutline()
}
return json.Marshal(map[string]any{"saved": true, "type": "outline", "chapters": len(entries), "scale": a.Scale})
case "layered_outline":
var volumes []domain.VolumeOutline
@@ -85,6 +102,7 @@ func (t *SaveFoundationTool) Execute(_ context.Context, args json.RawMessage) (j
return json.Marshal(map[string]any{
"saved": true, "type": "layered_outline",
"volumes": len(volumes), "chapters": total,
"scale": a.Scale,
})
case "characters":
@@ -95,7 +113,7 @@ func (t *SaveFoundationTool) Execute(_ context.Context, args json.RawMessage) (j
if err := t.store.SaveCharacters(chars); err != nil {
return nil, fmt.Errorf("save characters: %w", err)
}
return json.Marshal(map[string]any{"saved": true, "type": "characters", "count": len(chars)})
return json.Marshal(map[string]any{"saved": true, "type": "characters", "count": len(chars), "scale": a.Scale})
case "world_rules":
var rules []domain.WorldRule
@@ -105,7 +123,7 @@ func (t *SaveFoundationTool) Execute(_ context.Context, args json.RawMessage) (j
if err := t.store.SaveWorldRules(rules); err != nil {
return nil, fmt.Errorf("save world_rules: %w", err)
}
return json.Marshal(map[string]any{"saved": true, "type": "world_rules", "count": len(rules)})
return json.Marshal(map[string]any{"saved": true, "type": "world_rules", "count": len(rules), "scale": a.Scale})
default:
return nil, fmt.Errorf("unknown type %q, expected premise/outline/layered_outline/characters/world_rules", a.Type)