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:
@@ -62,10 +62,12 @@ type RepairA1DemoOptions struct {
|
||||
|
||||
// RepairA1DemoCategoryEnhancePrompts replaces non-sectioned / legacy combined
|
||||
// categories.prompt values for A1 Slovenija + Platform Demo with role-sectioned
|
||||
// overlays (Title / Description / Meta). Prefers wp_product_categories.sql
|
||||
// (SEED_A1_WP_CATEGORIES / scripts/seed) as source of truth, then a1-category-prompts.json,
|
||||
// splitting combined Name+Description prompts so naming rules land under Title and
|
||||
// HTML body under Description; otherwise fall back to CategoryEnhanceUserTemplate.
|
||||
// overlays (Title / Description / Meta) carrying exactly the split legacy text.
|
||||
// Prefers wp_product_categories.sql (SEED_A1_WP_CATEGORIES / scripts/seed) as
|
||||
// source of truth, then a1-category-prompts.json, splitting combined
|
||||
// Name+Description prompts so naming rules land under Title and HTML body under
|
||||
// Description; categories with no seed/legacy content have their override
|
||||
// cleared (company default) — template boilerplate is never stored.
|
||||
//
|
||||
// Also repairs empty or brand-only title_template and empty description_template
|
||||
// from legacy <name> / HTML / meta blocks so enhance uses real A1 formulas.
|
||||
@@ -337,19 +339,6 @@ func foldSlovenePromptRune(r rune) rune {
|
||||
}
|
||||
}
|
||||
|
||||
// repairedCategoryEnhancePromptMap is the shared fallback overlay (no per-category
|
||||
// Slovenian rules): "sl" + LangPromptAny ("*").
|
||||
func repairedCategoryEnhancePromptMap() (company.LangPromptMap, error) {
|
||||
tpl := strings.TrimSpace(aiprompts.CategoryEnhanceUserTemplate)
|
||||
if tpl == "" {
|
||||
return nil, fmt.Errorf("CategoryEnhanceUserTemplate is empty")
|
||||
}
|
||||
return company.LangPromptMap{
|
||||
"sl": tpl,
|
||||
company.LangPromptAny: tpl,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func categoryEnhancePromptValueOK(p string) bool {
|
||||
p = strings.TrimSpace(p)
|
||||
if p == "" {
|
||||
@@ -406,6 +395,10 @@ func resolveRepairedEnhancePrompt(current company.LangPromptMap, seedLegacy stri
|
||||
return prompt
|
||||
}
|
||||
|
||||
// computeRepairedEnhancePrompt returns the clean role-sectioned overlay for a
|
||||
// category — exactly the split per-category text. "" means the override should
|
||||
// be CLEARED (no legacy/seed content to preserve → company default applies);
|
||||
// fallback reports that clear case.
|
||||
func computeRepairedEnhancePrompt(current company.LangPromptMap, seedLegacy string, preferSeed bool) (prompt string, fromSeed, fromLegacy, fallback bool) {
|
||||
trySeed := func(raw string) (string, bool, bool) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
@@ -415,10 +408,10 @@ func computeRepairedEnhancePrompt(current company.LangPromptMap, seedLegacy stri
|
||||
if aiprompts.IsLegacyCombinedEnhancePrompt(raw) {
|
||||
return aiprompts.SplitLegacyCombinedEnhancePrompt(raw), true, false
|
||||
}
|
||||
if aiprompts.CategoryEnhanceHasRoleSections(raw) {
|
||||
if aiprompts.CategoryEnhanceHasRoleSections(raw) && !aiprompts.CategoryEnhancePromptNeedsRepair(raw) {
|
||||
return security.SanitizePrompt(raw, MaxCategoryPromptRunes), false, false
|
||||
}
|
||||
return strings.TrimSpace(aiprompts.CategoryEnhanceUserTemplate), false, true
|
||||
return "", false, true
|
||||
}
|
||||
|
||||
if preferSeed && seedLegacy != "" {
|
||||
@@ -439,7 +432,7 @@ func computeRepairedEnhancePrompt(current company.LangPromptMap, seedLegacy stri
|
||||
p, leg, fb := trySeed(seedLegacy)
|
||||
return p, true, leg, fb
|
||||
}
|
||||
return strings.TrimSpace(aiprompts.CategoryEnhanceUserTemplate), false, false, true
|
||||
return "", false, false, true
|
||||
}
|
||||
|
||||
func repairCompanyCategoryEnhancePrompts(
|
||||
@@ -485,8 +478,9 @@ func repairCompanyCategoryEnhancePrompts(
|
||||
|
||||
seedLegacy := pickSeedPrompt(uniqueID, name, seedByNorm, seedByUID)
|
||||
needPrompt := company.HasAnyPrompt(m) && !categoryEnhancePromptMapOK(m)
|
||||
// Empty prompt → write sectioned overlay (seed split when available, else shared template).
|
||||
if !company.HasAnyPrompt(m) {
|
||||
// Empty prompt: only seed-matched categories get an overlay written;
|
||||
// categories without seed content stay on the company default.
|
||||
if !company.HasAnyPrompt(m) && seedLegacy != "" {
|
||||
needPrompt = true
|
||||
}
|
||||
|
||||
@@ -539,11 +533,14 @@ func repairCompanyCategoryEnhancePrompts(
|
||||
continue
|
||||
}
|
||||
|
||||
// clearPrompt: repair resolved to "no content" → drop the override so the
|
||||
// category falls back to the company default (never store template boilerplate).
|
||||
clearPrompt := false
|
||||
if needPrompt && wantPrompt == "" {
|
||||
wantPrompt = resolveRepairedEnhancePrompt(m, seedLegacy, forceFromSeed && seedLegacy != "", out)
|
||||
wantPrompt = security.SanitizePrompt(wantPrompt, MaxCategoryPromptRunes)
|
||||
if wantPrompt == "" {
|
||||
return updatedHere, fmt.Errorf("repaired prompt empty category=%s", id)
|
||||
clearPrompt = true
|
||||
}
|
||||
} else if needPrompt {
|
||||
// Record seed/split stats for the prompt we already computed.
|
||||
@@ -571,7 +568,18 @@ func repairCompanyCategoryEnhancePrompts(
|
||||
continue
|
||||
}
|
||||
|
||||
if needPrompt {
|
||||
if needPrompt && clearPrompt {
|
||||
ct, err := pool.Exec(ctx, `
|
||||
UPDATE categories
|
||||
SET prompt = '{}'::jsonb, updated_at = now()
|
||||
WHERE id = $1 AND company_id = $2`, id, companyID)
|
||||
if err != nil {
|
||||
return updatedHere, fmt.Errorf("clear prompt category=%s: %w", id, err)
|
||||
}
|
||||
if ct.RowsAffected() == 0 {
|
||||
return updatedHere, fmt.Errorf("category %s not updated (company mismatch?)", id)
|
||||
}
|
||||
} else if needPrompt {
|
||||
want := company.LangPromptMap{
|
||||
"sl": wantPrompt,
|
||||
company.LangPromptAny: wantPrompt,
|
||||
|
||||
Reference in New Issue
Block a user