Store category prompts as EXACT split legacy text, no boilerplate
The per-category prompt editor showed English machine boilerplate
("Role: description. Build JSON …", schema intro, {{var}} context lines)
because seed/sync baked the render framing into categories.prompt. Now the
stored overlay is exactly the legacy wp_product_categories.sql content,
split into the three sections a user would type themselves:
--- Title --- Slovenian naming formula
--- Description --- legacy <H2>/<p>/<ul> body structure
--- Meta --- legacy metaDescription instruction
Schema, role framing, and Name/Description/Category/Attrs product context
stay render-time only (system template + ensureCategoryEnhanceUserContext),
where they already existed.
- SplitLegacyCombinedEnhancePrompt: non-legacy input now returns "" —
categories without seed/legacy content get their override CLEARED
(company default) instead of being stuffed with the canonical template
(e.g. parent categories like "Bela tehnika" absent from the SQL).
- CategoryEnhancePromptNeedsRepair flags stored boilerplate ("parsed as
JSON", "Build JSON", retired Attributes section) so Sync rewrites old
data to the clean shape; repair supports clearing (prompt = '{}').
- seed-a1 apply-category-prompts skips instead of writing template text.
- Web editor compose stores only the user's section text: empty sections
keep bare markers, default bodies and the default preamble are never
persisted (DEFAULT_SECTION_BODIES removed).
- Verified locally: apply rewrote 238 A1+Demo categories (216 exact
splits, 22 cleared), zero boilerplate matches in DB, idempotent re-run
(would_update=0).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,61 +74,39 @@ func ParseLegacyCombinedEnhancePrompt(prompt string) LegacyEnhanceParts {
|
||||
}
|
||||
|
||||
// SplitLegacyCombinedEnhancePrompt rewrites a legacy combined name+description(+meta)
|
||||
// prompt into CategoryEnhanceUserTemplate role sections, preserving Slovenian
|
||||
// naming / HTML / meta intent as category-specific rules under Title / Description / Meta.
|
||||
// Non-legacy input returns CategoryEnhanceUserTemplate (canonical shared overlay).
|
||||
// prompt into role sections carrying ONLY the original per-category text — the
|
||||
// Slovenian naming formula under Title, the HTML body structure under Description,
|
||||
// the SEO instruction under Meta. No schema/role boilerplate is stored: JSON
|
||||
// schema, role framing, and {{name}}/{{description}}/{{category}}/{{attrs}}
|
||||
// product context are all supplied at render time (system template +
|
||||
// processing.ensureCategoryEnhanceUserContext). Non-legacy input returns "" —
|
||||
// callers leave the category without an override (company default applies).
|
||||
func SplitLegacyCombinedEnhancePrompt(prompt string) string {
|
||||
parts := ParseLegacyCombinedEnhancePrompt(prompt)
|
||||
if !parts.WasLegacy {
|
||||
return strings.TrimSpace(CategoryEnhanceUserTemplate)
|
||||
return ""
|
||||
}
|
||||
return BuildCategoryEnhanceOverlay(parts)
|
||||
}
|
||||
|
||||
// BuildCategoryEnhanceOverlay composes a role-sectioned enhance USER overlay from
|
||||
// extracted legacy parts (or empty parts → canonical template text with no extra rules).
|
||||
// extracted legacy parts — the stored text is exactly the split legacy content,
|
||||
// matching what a user would type into the Title/Description/Meta prompt areas.
|
||||
func BuildCategoryEnhanceOverlay(parts LegacyEnhanceParts) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(`Your reply is parsed as JSON {"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}} only (system schema). Write all string fields in {{language}} (do not hardcode a language).`)
|
||||
b.WriteString("\n\n")
|
||||
|
||||
b.WriteString(SectionTitleStart)
|
||||
b.WriteByte('\n')
|
||||
b.WriteString(TitleRoleInstruction)
|
||||
b.WriteByte('\n')
|
||||
if rules := strings.TrimSpace(parts.TitleRules); rules != "" {
|
||||
b.WriteString("Category naming rules (preserve intent): ")
|
||||
b.WriteString(rules)
|
||||
section := func(start, end, body string) {
|
||||
b.WriteString(start)
|
||||
b.WriteByte('\n')
|
||||
if body = strings.TrimSpace(body); body != "" {
|
||||
b.WriteString(body)
|
||||
b.WriteByte('\n')
|
||||
}
|
||||
b.WriteString(end)
|
||||
b.WriteString("\n\n")
|
||||
}
|
||||
b.WriteString("Name: {{name}}\n")
|
||||
b.WriteString(SectionTitleEnd)
|
||||
b.WriteString("\n\n")
|
||||
|
||||
b.WriteString(SectionDescriptionStart)
|
||||
b.WriteString("\nRole: description. Build JSON \"description\": product body HTML only (not SEO meta). When a Description formula follows, emit ONE HTML string covering each section in order (tags matching type: h1/h2/h3/h4, p, ul); otherwise prefer 1-3 factual paragraphs as ONE string with limited HTML (<h2><p><ul><li>) — do NOT emit a competing full HTML document or wrap the whole reply in <name>/<metaDescription> tags.\n")
|
||||
if rules := strings.TrimSpace(parts.DescriptionRules); rules != "" {
|
||||
b.WriteString("Category HTML structure (preserve intent; emit as ONE description HTML string, not tagged name/meta blocks):\n")
|
||||
b.WriteString(rules)
|
||||
b.WriteByte('\n')
|
||||
}
|
||||
b.WriteString("Description: {{description}}\n")
|
||||
b.WriteString(SectionDescriptionEnd)
|
||||
b.WriteString("\n\n")
|
||||
|
||||
b.WriteString(SectionMetaStart)
|
||||
b.WriteString("\nRole: meta. Build JSON \"meta_title\" and \"meta_description\" as plain SEO text (never HTML). meta_title: 50-60 chars; meta_description: 120-155 chars; follow any SEO meta formula that follows; never copy the full description HTML into meta_description.\n")
|
||||
if rules := strings.TrimSpace(parts.MetaRules); rules != "" {
|
||||
b.WriteString("Category SEO rules (preserve intent; plain text only): ")
|
||||
b.WriteString(rules)
|
||||
b.WriteByte('\n')
|
||||
}
|
||||
b.WriteString(SectionMetaEnd)
|
||||
b.WriteString("\n\n")
|
||||
|
||||
b.WriteString("Product context:\n")
|
||||
b.WriteString("Category: {{category}}\n")
|
||||
b.WriteString("Attrs: {{attrs}}")
|
||||
section(SectionTitleStart, SectionTitleEnd, parts.TitleRules)
|
||||
section(SectionDescriptionStart, SectionDescriptionEnd, parts.DescriptionRules)
|
||||
section(SectionMetaStart, SectionMetaEnd, parts.MetaRules)
|
||||
return strings.TrimSpace(b.String())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user