Split A1 category prompts canonically; retire attributes prompting
- Category enhance prompts (Sync A1 / seed-a1 / repair) now use the same three role sections as the rest of the platform: Title / Description / Meta. The retired "--- Attributes ---" role section is removed from the canonical template, the legacy-split overlay, and the web prompt editor; Category/Attrs stay as plain product-context lines (attribute extraction remains pipeline-level via AppendAttributeConstraints). - Stored prompts still carrying an attributes section are detected by CategoryEnhancePromptNeedsRepair and rewritten on the next Sync. - Legacy wp_product_categories.sql splits now also seed a default Slovenian metaTitle rule (dumps only carried <metaDescription>), so every A1 category gets all four prompt areas: title formula, description sections, meta title, meta description. - Role-sectioned prompts no longer imply the A1 SEO-omit cohort (CompanyOmitsSEOMeta): sectioned prompts are the canonical prompt-editor output for every tenant, and the sniff silently disabled SEO meta for any company that saved a category prompt. - Verified locally: repair-category-prompts -apply updated 238 A1 + Platform Demo categories from scripts/seed/wp_product_categories.sql (216 legacy splits), idempotent on re-run, zero attributes sections left in DB. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,12 +38,22 @@ func DescriptionTemplateNeedsRepair(template any) bool {
|
||||
return strings.TrimSpace(f.MetaTitle) == "" && strings.TrimSpace(f.MetaDescription) == ""
|
||||
}
|
||||
|
||||
// DefaultLegacyMetaTitleRule fills description_template.metaTitle for legacy A1
|
||||
// prompts, which only carried a <metaDescription> instruction. Mirrors the legacy
|
||||
// name-first Slovenian instruction style with the SEO title length bound.
|
||||
const DefaultLegacyMetaTitleRule = "Najprej napiši Novo ime izdelka in dodaj glavno prednost. Dolžina 50-60 znakov vključno s presledki."
|
||||
|
||||
// DeriveDescriptionFormulaFromLegacyParts builds description_template from split
|
||||
// legacy DescriptionRules HTML + MetaRules.
|
||||
// legacy DescriptionRules HTML + MetaRules. Legacy dumps never carried a meta
|
||||
// title rule, so meta intent (MetaRules present) also seeds a default metaTitle
|
||||
// instruction — the category UI then shows all four prompt areas filled.
|
||||
func DeriveDescriptionFormulaFromLegacyParts(parts LegacyEnhanceParts) DescriptionFormula {
|
||||
out := DescriptionFormula{
|
||||
MetaDescription: strings.TrimSpace(parts.MetaRules),
|
||||
}
|
||||
if out.MetaDescription != "" {
|
||||
out.MetaTitle = DefaultLegacyMetaTitleRule
|
||||
}
|
||||
body := strings.TrimSpace(parts.DescriptionRules)
|
||||
if body == "" {
|
||||
return out
|
||||
|
||||
@@ -50,17 +50,19 @@ type DefaultTemplate struct {
|
||||
}
|
||||
|
||||
// CategoryEnhanceUserTemplate is the shared per-category (and built-in) enhance USER
|
||||
// message, sectioned by role (title / description / meta / attributes) using the
|
||||
// same "--- Section ---" markers as legacy enhance-product. Includes {{name}}
|
||||
// message, sectioned by role (title / description / meta) using the same
|
||||
// "--- Section ---" markers as legacy enhance-product. Includes {{name}}
|
||||
// {{description}} {{attrs}} {{category}} {{language}}. Compatible with enhance
|
||||
// JSON {"name","description","meta_title","meta_description","attrs"} —
|
||||
// description is formula HTML product body; meta_* are plain SEO fields (legacy
|
||||
// A1 <metaDescription> / cats.json metaTitle+metaDescription); attrs is the
|
||||
// category-allowlisted attribute map. Title/description/meta formulas stay in
|
||||
// A1 <metaDescription> / cats.json metaTitle+metaDescription). Attribute
|
||||
// extraction is pipeline-level (allowlist via AppendAttributeConstraints) and is
|
||||
// deliberately NOT a category prompt section; Category/Attrs stay as plain
|
||||
// product-context lines. Title/description/meta formulas stay in
|
||||
// title_template / description_template and are appended at render time (see
|
||||
// processing.AppendFormulaConstraints / AppendAttributeConstraints). Categorize
|
||||
// (unique_id) is RoleCategorize / ProductCategorize* — not this overlay. Used by
|
||||
// local A1/Demo prompt repair and seed-a1 overlays.
|
||||
// processing.AppendFormulaConstraints). Categorize (unique_id) is RoleCategorize
|
||||
// / ProductCategorize* — not this overlay. Used by local A1/Demo prompt repair
|
||||
// and seed-a1 overlays.
|
||||
const CategoryEnhanceUserTemplate = `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).
|
||||
|
||||
--- Title ---
|
||||
@@ -77,17 +79,17 @@ Description: {{description}}
|
||||
Role: 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.
|
||||
--- End Meta ---
|
||||
|
||||
--- Attributes ---
|
||||
Role: attributes. Build JSON "attrs" as an object of attribute_key → value strings. Prefer Allowed attribute keys / Title formula attr slots that follow; remap near-miss labels onto those keys; fill missing keys only from Name/Description/Category/Attrs evidence; never invent specs; omit unknown keys; never invent dimensions.
|
||||
Product context:
|
||||
Category: {{category}}
|
||||
Attrs: {{attrs}}
|
||||
--- End Attributes ---`
|
||||
Attrs: {{attrs}}`
|
||||
|
||||
// CategoryEnhancePromptNeedsRepair reports whether a stored categories.prompt value
|
||||
// should be rewritten into role-sectioned enhance overlay form. Empty prompts are
|
||||
// left alone. Canonical CategoryEnhanceUserTemplate and per-category overlays that
|
||||
// already carry Title/Description/Meta/Attributes markers (+ {{attrs}}) are OK —
|
||||
// equality with the shared template is not required (legacy splits keep Slovenian rules).
|
||||
// already carry Title/Description/Meta markers are OK — equality with the shared
|
||||
// template is not required (legacy splits keep Slovenian rules). Prompts still
|
||||
// carrying a retired "--- Attributes ---" role section are rewritten so attribute
|
||||
// prompting stays out of category prompts.
|
||||
func CategoryEnhancePromptNeedsRepair(prompt string) bool {
|
||||
p := strings.TrimSpace(prompt)
|
||||
if p == "" {
|
||||
@@ -96,10 +98,10 @@ func CategoryEnhancePromptNeedsRepair(prompt string) bool {
|
||||
if IsLegacyCombinedEnhancePrompt(p) {
|
||||
return true
|
||||
}
|
||||
if CategoryEnhanceHasRoleSections(p) && strings.Contains(p, "{{attrs}}") {
|
||||
return false
|
||||
if !CategoryEnhanceHasRoleSections(p) {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
return strings.Contains(strings.ToLower(p), strings.ToLower(SectionAttributesStart))
|
||||
}
|
||||
|
||||
// BuiltInDefaults match the previous hardcoded system prompts, with structured user templates.
|
||||
|
||||
@@ -25,11 +25,13 @@ func TestCategoryEnhanceUserTemplateHasRequiredVars(t *testing.T) {
|
||||
if !strings.Contains(CategoryEnhanceUserTemplate, `{"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}}`) {
|
||||
t.Fatal("template should reference enhance JSON schema including meta_* and attrs")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(CategoryEnhanceUserTemplate), `build json "attrs"`) {
|
||||
t.Fatal("Attributes role must ask for JSON attrs extraction/enhancement")
|
||||
// Attribute prompting is retired from category prompts — extraction guidance
|
||||
// is pipeline-level (AppendAttributeConstraints), never prompt-authored.
|
||||
if strings.Contains(strings.ToLower(CategoryEnhanceUserTemplate), `build json "attrs"`) {
|
||||
t.Fatal("template must not carry an attributes role instruction")
|
||||
}
|
||||
if !CategoryEnhanceHasRoleSections(CategoryEnhanceUserTemplate) {
|
||||
t.Fatal("canonical template must be role-sectioned for title/description/meta/attributes")
|
||||
t.Fatal("canonical template must be role-sectioned for title/description/meta")
|
||||
}
|
||||
if !strings.Contains(lower, "{{language}}") {
|
||||
t.Fatal("language must come from {{language}}")
|
||||
|
||||
@@ -126,11 +126,9 @@ func BuildCategoryEnhanceOverlay(parts LegacyEnhanceParts) string {
|
||||
b.WriteString(SectionMetaEnd)
|
||||
b.WriteString("\n\n")
|
||||
|
||||
b.WriteString(SectionAttributesStart)
|
||||
b.WriteString("\nRole: attributes. Build JSON \"attrs\" as an object of attribute_key → value strings. Prefer Allowed attribute keys / Title formula attr slots that follow; remap near-miss labels onto those keys; fill missing keys only from Name/Description/Category/Attrs evidence; never invent specs; omit unknown keys; never invent dimensions.\n")
|
||||
b.WriteString("Product context:\n")
|
||||
b.WriteString("Category: {{category}}\n")
|
||||
b.WriteString("Attrs: {{attrs}}\n")
|
||||
b.WriteString(SectionAttributesEnd)
|
||||
b.WriteString("Attrs: {{attrs}}")
|
||||
return strings.TrimSpace(b.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ const (
|
||||
|
||||
// Section markers match legacy enhance-product "--- Section ---" / "--- Meta Title ---"
|
||||
// style so stored category prompts stay human-readable and machine-detectable.
|
||||
// Attributes markers are retired for category prompts (attribute extraction is
|
||||
// pipeline-level, not prompt-authored) but kept so repair can detect and strip
|
||||
// old stored prompts that still carry the section.
|
||||
const (
|
||||
SectionTitleStart = "--- Title ---"
|
||||
SectionTitleEnd = "--- End Title ---"
|
||||
@@ -40,12 +43,12 @@ var CategoryPromptRoles = []string{
|
||||
}
|
||||
|
||||
// CategoryEnhanceHasRoleSections reports whether a stored categories.prompt
|
||||
// value uses the structured title/description/meta/attributes section markers
|
||||
// from CategoryEnhanceUserTemplate (seed/repair canonical shape).
|
||||
// value uses the structured title/description/meta section markers from
|
||||
// CategoryEnhanceUserTemplate (seed/repair canonical shape). Attributes is not
|
||||
// required — category prompts no longer carry an attributes role section.
|
||||
func CategoryEnhanceHasRoleSections(prompt string) bool {
|
||||
lower := strings.ToLower(prompt)
|
||||
return strings.Contains(lower, strings.ToLower(SectionTitleStart)) &&
|
||||
strings.Contains(lower, strings.ToLower(SectionDescriptionStart)) &&
|
||||
strings.Contains(lower, strings.ToLower(SectionMetaStart)) &&
|
||||
strings.Contains(lower, strings.ToLower(SectionAttributesStart))
|
||||
strings.Contains(lower, strings.ToLower(SectionMetaStart))
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func TestCategoryEnhanceHasRoleSections(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !CategoryEnhanceHasRoleSections(CategoryEnhanceUserTemplate) {
|
||||
t.Fatal("canonical CategoryEnhanceUserTemplate must have title/description/meta/attributes sections")
|
||||
t.Fatal("canonical CategoryEnhanceUserTemplate must have title/description/meta sections")
|
||||
}
|
||||
if CategoryEnhanceHasRoleSections("legacy HTML prompt") {
|
||||
t.Fatal("unstructured prompt must not report role sections")
|
||||
@@ -16,6 +16,18 @@ func TestCategoryEnhanceHasRoleSections(t *testing.T) {
|
||||
if CategoryEnhanceHasRoleSections("--- Title ---\nonly title") {
|
||||
t.Fatal("partial sections must not pass")
|
||||
}
|
||||
// Old stored prompts with an attributes section still count as sectioned
|
||||
// (repair rewrites them via CategoryEnhancePromptNeedsRepair).
|
||||
old := "--- Title ---\nx\n--- Description ---\ny\n--- Meta ---\nz\n--- Attributes ---\na\n--- End Attributes ---"
|
||||
if !CategoryEnhanceHasRoleSections(old) {
|
||||
t.Fatal("old attributes-bearing prompt must still report role sections")
|
||||
}
|
||||
if !CategoryEnhancePromptNeedsRepair(old) {
|
||||
t.Fatal("old attributes-bearing prompt must need repair (attributes section retired)")
|
||||
}
|
||||
if CategoryEnhancePromptNeedsRepair(CategoryEnhanceUserTemplate) {
|
||||
t.Fatal("canonical template must not need repair")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCategoryPromptRolesOrder(t *testing.T) {
|
||||
@@ -38,14 +50,17 @@ func TestCategoryEnhanceUserTemplateRoleMarkers(t *testing.T) {
|
||||
SectionTitleStart, SectionTitleEnd,
|
||||
SectionDescriptionStart, SectionDescriptionEnd,
|
||||
SectionMetaStart, SectionMetaEnd,
|
||||
SectionAttributesStart, SectionAttributesEnd,
|
||||
} {
|
||||
if !strings.Contains(tpl, marker) {
|
||||
t.Fatalf("template missing %q", marker)
|
||||
}
|
||||
}
|
||||
// Attribute prompting is retired from category prompts (pipeline-level only).
|
||||
if strings.Contains(tpl, SectionAttributesStart) || strings.Contains(strings.ToLower(tpl), "role: attributes") {
|
||||
t.Fatal("template must not carry an attributes role section")
|
||||
}
|
||||
lower := strings.ToLower(tpl)
|
||||
for _, role := range []string{"role: title", "role: description", "role: meta", "role: attributes"} {
|
||||
for _, role := range []string{"role: title", "role: description", "role: meta"} {
|
||||
if !strings.Contains(lower, role) {
|
||||
t.Fatalf("template missing %q", role)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user