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:
2026-08-18 00:13:44 +02:00
co-authored by Claude Fable 5
parent 2a2b01bf59
commit b595398389
14 changed files with 127 additions and 115 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
// Command repair-category-prompts rewrites A1 / Platform Demo categories.prompt // Command repair-category-prompts rewrites A1 / Platform Demo categories.prompt
// values into aiprompts role-sectioned overlays (Title / Description / Meta / // values into aiprompts role-sectioned overlays (Title / Description / Meta).
// Attributes). Prefers wp_product_categories.sql (SEED_A1_WP_CATEGORIES / // Prefers wp_product_categories.sql (SEED_A1_WP_CATEGORIES /
// scripts/seed) as source of truth, else a1-category-prompts.json. Legacy combined // scripts/seed) as source of truth, else a1-category-prompts.json. Legacy combined
// Slovenian name+description blobs are split so naming rules land under Title // Slovenian name+description blobs are split so naming rules land under Title
// and HTML under Description; otherwise CategoryEnhanceUserTemplate is used. // and HTML under Description; otherwise CategoryEnhanceUserTemplate is used.
@@ -38,12 +38,22 @@ func DescriptionTemplateNeedsRepair(template any) bool {
return strings.TrimSpace(f.MetaTitle) == "" && strings.TrimSpace(f.MetaDescription) == "" 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 // 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 { func DeriveDescriptionFormulaFromLegacyParts(parts LegacyEnhanceParts) DescriptionFormula {
out := DescriptionFormula{ out := DescriptionFormula{
MetaDescription: strings.TrimSpace(parts.MetaRules), MetaDescription: strings.TrimSpace(parts.MetaRules),
} }
if out.MetaDescription != "" {
out.MetaTitle = DefaultLegacyMetaTitleRule
}
body := strings.TrimSpace(parts.DescriptionRules) body := strings.TrimSpace(parts.DescriptionRules)
if body == "" { if body == "" {
return out return out
+18 -16
View File
@@ -50,17 +50,19 @@ type DefaultTemplate struct {
} }
// CategoryEnhanceUserTemplate is the shared per-category (and built-in) enhance USER // CategoryEnhanceUserTemplate is the shared per-category (and built-in) enhance USER
// message, sectioned by role (title / description / meta / attributes) using the // message, sectioned by role (title / description / meta) using the same
// same "--- Section ---" markers as legacy enhance-product. Includes {{name}} // "--- Section ---" markers as legacy enhance-product. Includes {{name}}
// {{description}} {{attrs}} {{category}} {{language}}. Compatible with enhance // {{description}} {{attrs}} {{category}} {{language}}. Compatible with enhance
// JSON {"name","description","meta_title","meta_description","attrs"} — // JSON {"name","description","meta_title","meta_description","attrs"} —
// description is formula HTML product body; meta_* are plain SEO fields (legacy // description is formula HTML product body; meta_* are plain SEO fields (legacy
// A1 <metaDescription> / cats.json metaTitle+metaDescription); attrs is the // A1 <metaDescription> / cats.json metaTitle+metaDescription). Attribute
// category-allowlisted attribute map. Title/description/meta formulas stay in // 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 // title_template / description_template and are appended at render time (see
// processing.AppendFormulaConstraints / AppendAttributeConstraints). Categorize // processing.AppendFormulaConstraints). Categorize (unique_id) is RoleCategorize
// (unique_id) is RoleCategorize / ProductCategorize* — not this overlay. Used by // / ProductCategorize* — not this overlay. Used by local A1/Demo prompt repair
// local A1/Demo prompt repair and seed-a1 overlays. // 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). 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 --- --- 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. 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 --- --- End Meta ---
--- Attributes --- Product context:
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.
Category: {{category}} Category: {{category}}
Attrs: {{attrs}} Attrs: {{attrs}}`
--- End Attributes ---`
// CategoryEnhancePromptNeedsRepair reports whether a stored categories.prompt value // CategoryEnhancePromptNeedsRepair reports whether a stored categories.prompt value
// should be rewritten into role-sectioned enhance overlay form. Empty prompts are // should be rewritten into role-sectioned enhance overlay form. Empty prompts are
// left alone. Canonical CategoryEnhanceUserTemplate and per-category overlays that // left alone. Canonical CategoryEnhanceUserTemplate and per-category overlays that
// already carry Title/Description/Meta/Attributes markers (+ {{attrs}}) are OK — // already carry Title/Description/Meta markers are OK — equality with the shared
// equality with the shared template is not required (legacy splits keep Slovenian rules). // 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 { func CategoryEnhancePromptNeedsRepair(prompt string) bool {
p := strings.TrimSpace(prompt) p := strings.TrimSpace(prompt)
if p == "" { if p == "" {
@@ -96,10 +98,10 @@ func CategoryEnhancePromptNeedsRepair(prompt string) bool {
if IsLegacyCombinedEnhancePrompt(p) { if IsLegacyCombinedEnhancePrompt(p) {
return true return true
} }
if CategoryEnhanceHasRoleSections(p) && strings.Contains(p, "{{attrs}}") { if !CategoryEnhanceHasRoleSections(p) {
return false return true
} }
return true return strings.Contains(strings.ToLower(p), strings.ToLower(SectionAttributesStart))
} }
// BuiltInDefaults match the previous hardcoded system prompts, with structured user templates. // BuiltInDefaults match the previous hardcoded system prompts, with structured user templates.
+5 -3
View File
@@ -25,11 +25,13 @@ func TestCategoryEnhanceUserTemplateHasRequiredVars(t *testing.T) {
if !strings.Contains(CategoryEnhanceUserTemplate, `{"name":"string","description":"string","meta_title":"string","meta_description":"string","attrs":{}}`) { 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") t.Fatal("template should reference enhance JSON schema including meta_* and attrs")
} }
if !strings.Contains(strings.ToLower(CategoryEnhanceUserTemplate), `build json "attrs"`) { // Attribute prompting is retired from category prompts — extraction guidance
t.Fatal("Attributes role must ask for JSON attrs extraction/enhancement") // 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) { 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}}") { if !strings.Contains(lower, "{{language}}") {
t.Fatal("language must come from {{language}}") t.Fatal("language must come from {{language}}")
+2 -4
View File
@@ -126,11 +126,9 @@ func BuildCategoryEnhanceOverlay(parts LegacyEnhanceParts) string {
b.WriteString(SectionMetaEnd) b.WriteString(SectionMetaEnd)
b.WriteString("\n\n") b.WriteString("\n\n")
b.WriteString(SectionAttributesStart) b.WriteString("Product context:\n")
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("Category: {{category}}\n") b.WriteString("Category: {{category}}\n")
b.WriteString("Attrs: {{attrs}}\n") b.WriteString("Attrs: {{attrs}}")
b.WriteString(SectionAttributesEnd)
return strings.TrimSpace(b.String()) return strings.TrimSpace(b.String())
} }
+7 -4
View File
@@ -19,6 +19,9 @@ const (
// Section markers match legacy enhance-product "--- Section ---" / "--- Meta Title ---" // Section markers match legacy enhance-product "--- Section ---" / "--- Meta Title ---"
// style so stored category prompts stay human-readable and machine-detectable. // 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 ( const (
SectionTitleStart = "--- Title ---" SectionTitleStart = "--- Title ---"
SectionTitleEnd = "--- End Title ---" SectionTitleEnd = "--- End Title ---"
@@ -40,12 +43,12 @@ var CategoryPromptRoles = []string{
} }
// CategoryEnhanceHasRoleSections reports whether a stored categories.prompt // CategoryEnhanceHasRoleSections reports whether a stored categories.prompt
// value uses the structured title/description/meta/attributes section markers // value uses the structured title/description/meta section markers from
// from CategoryEnhanceUserTemplate (seed/repair canonical shape). // CategoryEnhanceUserTemplate (seed/repair canonical shape). Attributes is not
// required — category prompts no longer carry an attributes role section.
func CategoryEnhanceHasRoleSections(prompt string) bool { func CategoryEnhanceHasRoleSections(prompt string) bool {
lower := strings.ToLower(prompt) lower := strings.ToLower(prompt)
return strings.Contains(lower, strings.ToLower(SectionTitleStart)) && return strings.Contains(lower, strings.ToLower(SectionTitleStart)) &&
strings.Contains(lower, strings.ToLower(SectionDescriptionStart)) && strings.Contains(lower, strings.ToLower(SectionDescriptionStart)) &&
strings.Contains(lower, strings.ToLower(SectionMetaStart)) && strings.Contains(lower, strings.ToLower(SectionMetaStart))
strings.Contains(lower, strings.ToLower(SectionAttributesStart))
} }
+18 -3
View File
@@ -8,7 +8,7 @@ import (
func TestCategoryEnhanceHasRoleSections(t *testing.T) { func TestCategoryEnhanceHasRoleSections(t *testing.T) {
t.Parallel() t.Parallel()
if !CategoryEnhanceHasRoleSections(CategoryEnhanceUserTemplate) { 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") { if CategoryEnhanceHasRoleSections("legacy HTML prompt") {
t.Fatal("unstructured prompt must not report role sections") t.Fatal("unstructured prompt must not report role sections")
@@ -16,6 +16,18 @@ func TestCategoryEnhanceHasRoleSections(t *testing.T) {
if CategoryEnhanceHasRoleSections("--- Title ---\nonly title") { if CategoryEnhanceHasRoleSections("--- Title ---\nonly title") {
t.Fatal("partial sections must not pass") 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) { func TestCategoryPromptRolesOrder(t *testing.T) {
@@ -38,14 +50,17 @@ func TestCategoryEnhanceUserTemplateRoleMarkers(t *testing.T) {
SectionTitleStart, SectionTitleEnd, SectionTitleStart, SectionTitleEnd,
SectionDescriptionStart, SectionDescriptionEnd, SectionDescriptionStart, SectionDescriptionEnd,
SectionMetaStart, SectionMetaEnd, SectionMetaStart, SectionMetaEnd,
SectionAttributesStart, SectionAttributesEnd,
} { } {
if !strings.Contains(tpl, marker) { if !strings.Contains(tpl, marker) {
t.Fatalf("template missing %q", 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) 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) { if !strings.Contains(lower, role) {
t.Fatalf("template missing %q", role) t.Fatalf("template missing %q", role)
} }
+1 -1
View File
@@ -62,7 +62,7 @@ type RepairA1DemoOptions struct {
// RepairA1DemoCategoryEnhancePrompts replaces non-sectioned / legacy combined // RepairA1DemoCategoryEnhancePrompts replaces non-sectioned / legacy combined
// categories.prompt values for A1 Slovenija + Platform Demo with role-sectioned // categories.prompt values for A1 Slovenija + Platform Demo with role-sectioned
// overlays (Title / Description / Meta / Attributes). Prefers wp_product_categories.sql // overlays (Title / Description / Meta). Prefers wp_product_categories.sql
// (SEED_A1_WP_CATEGORIES / scripts/seed) as source of truth, then a1-category-prompts.json, // (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 // splitting combined Name+Description prompts so naming rules land under Title and
// HTML body under Description; otherwise fall back to CategoryEnhanceUserTemplate. // HTML body under Description; otherwise fall back to CategoryEnhanceUserTemplate.
@@ -42,19 +42,19 @@ func TestStripCatalogSEOMetaIfOmitted(t *testing.T) {
other := uuid.MustParse("11111111-1111-1111-1111-111111111111") other := uuid.MustParse("11111111-1111-1111-1111-111111111111")
item := catalogSEOItem() item := catalogSEOItem()
stripCatalogSEOMetaIfOmitted(processing.CompanyOmitsSEOMetaLookup(other, "", "Acme", false), item) stripCatalogSEOMetaIfOmitted(processing.CompanyOmitsSEOMetaLookup(other, "", "Acme"), item)
if item["meta_title"] != "T" { if item["meta_title"] != "T" {
t.Fatalf("ordinary company must keep meta: %v", item["meta_title"]) t.Fatalf("ordinary company must keep meta: %v", item["meta_title"])
} }
stripCatalogSEOMetaIfOmitted(processing.CompanyOmitsSEOMetaLookup(a1, "", "", false), item) stripCatalogSEOMetaIfOmitted(processing.CompanyOmitsSEOMetaLookup(a1, "", ""), item)
assertCatalogSEOOmitted(t, item) assertCatalogSEOOmitted(t, item)
} }
func TestStripCatalogSEOMetaIfOmitted_demoByName(t *testing.T) { func TestStripCatalogSEOMetaIfOmitted_demoByName(t *testing.T) {
t.Parallel() t.Parallel()
other := uuid.MustParse("11111111-1111-1111-1111-111111111111") other := uuid.MustParse("11111111-1111-1111-1111-111111111111")
omit := processing.CompanyOmitsSEOMetaLookup(other, "", " platform demo ", false) omit := processing.CompanyOmitsSEOMetaLookup(other, "", " platform demo ")
if !omit { if !omit {
t.Fatal("Platform Demo by name must omit SEO meta") t.Fatal("Platform Demo by name must omit SEO meta")
} }
@@ -63,14 +63,12 @@ func TestStripCatalogSEOMetaIfOmitted_demoByName(t *testing.T) {
assertCatalogSEOOmitted(t, item) assertCatalogSEOOmitted(t, item)
} }
func TestStripCatalogSEOMetaIfOmitted_a1PromptMarkers(t *testing.T) { func TestStripCatalogSEOMetaIfOmitted_sectionedPromptsKeepMeta(t *testing.T) {
t.Parallel() t.Parallel()
// Role-sectioned category prompts are the canonical prompt-editor shape for
// every tenant now — using them must NOT put a company in the SEO-omit cohort.
other := uuid.MustParse("11111111-1111-1111-1111-111111111111") other := uuid.MustParse("11111111-1111-1111-1111-111111111111")
omit := processing.CompanyOmitsSEOMetaLookup(other, "", "Acme", true) if processing.CompanyOmitsSEOMetaLookup(other, "", "Acme") {
if !omit { t.Fatal("ordinary company must keep SEO meta regardless of prompt shape")
t.Fatal("A1-style prompt markers must omit SEO meta")
} }
item := catalogSEOItem()
stripCatalogSEOMetaIfOmitted(omit, item)
assertCatalogSEOOmitted(t, item)
} }
+6 -24
View File
@@ -511,19 +511,17 @@ func CompanyOmitsSEOMetaID(companyID uuid.UUID) bool {
// CompanyOmitsSEOMetaLookup is the shared A1/Demo SEO-omit decision used by V1 process // CompanyOmitsSEOMetaLookup is the shared A1/Demo SEO-omit decision used by V1 process
// and catalog list/get/update. Matches hardcoded companies.id, A1 cohort (legacy id), // and catalog list/get/update. Matches hardcoded companies.id, A1 cohort (legacy id),
// Platform Demo by name, or A1-style --- Title --- / --- Description --- / --- Meta --- // or Platform Demo by name. Role-sectioned category prompts (--- Title --- / --- Meta ---)
// category prompts. // are the platform-wide canonical prompt shape now, so they no longer imply the A1
func CompanyOmitsSEOMetaLookup(companyID uuid.UUID, legacyID, name string, hasA1SectionPrompts bool) bool { // cohort — sniffing them here made any tenant using the prompt editor lose SEO meta.
func CompanyOmitsSEOMetaLookup(companyID uuid.UUID, legacyID, name string) bool {
if CompanyOmitsSEOMetaID(companyID) { if CompanyOmitsSEOMetaID(companyID) {
return true return true
} }
if billing.IsA1CohortCompany(legacyID, "") { if billing.IsA1CohortCompany(legacyID, "") {
return true return true
} }
if strings.EqualFold(strings.TrimSpace(name), "Platform Demo") { return strings.EqualFold(strings.TrimSpace(name), "Platform Demo")
return true
}
return hasA1SectionPrompts
} }
// CompanyOmitsSEOMeta is true when catalog/V1 process must omit meta_title / // CompanyOmitsSEOMeta is true when catalog/V1 process must omit meta_title /
@@ -543,23 +541,7 @@ func CompanyOmitsSEOMeta(ctx context.Context, pool *pgxpool.Pool, companyID uuid
if err != nil { if err != nil {
return false return false
} }
if CompanyOmitsSEOMetaLookup(companyID, legacy, name, false) { return CompanyOmitsSEOMetaLookup(companyID, legacy, name)
return true
}
var hasA1Prompts bool
err = pool.QueryRow(ctx, `
SELECT EXISTS (
SELECT 1 FROM categories
WHERE company_id = $1
AND prompt ILIKE '%--- Title ---%'
AND prompt ILIKE '%--- Description ---%'
AND prompt ILIKE '%--- Meta ---%'
LIMIT 1
)`, companyID).Scan(&hasA1Prompts)
if err != nil {
return false
}
return hasA1Prompts
} }
// StripV1SEOMeta removes meta_title / meta_description keys (omit, not null). // StripV1SEOMeta removes meta_title / meta_description keys (omit, not null).
@@ -259,20 +259,18 @@ func TestCompanyOmitsSEOMetaLookup(t *testing.T) {
id uuid.UUID id uuid.UUID
legacy string legacy string
coName string coName string
prompts bool
wantOmit bool wantOmit bool
}{ }{
{name: "ordinary", id: other, coName: "Acme", wantOmit: false}, {name: "ordinary", id: other, coName: "Acme", wantOmit: false},
{name: "a1_uuid", id: a1, wantOmit: true}, {name: "a1_uuid", id: a1, wantOmit: true},
{name: "demo_by_name", id: other, coName: "Platform Demo", wantOmit: true}, {name: "demo_by_name", id: other, coName: "Platform Demo", wantOmit: true},
{name: "demo_by_name_case", id: other, coName: " platform DEMO ", wantOmit: true}, {name: "demo_by_name_case", id: other, coName: " platform DEMO ", wantOmit: true},
{name: "a1_prompt_markers", id: other, coName: "Acme", prompts: true, wantOmit: true},
{name: "a1_legacy_id", id: other, legacy: "97e1a309-3d23-4aa2-b518-8e8d7afdfec7", wantOmit: true}, {name: "a1_legacy_id", id: other, legacy: "97e1a309-3d23-4aa2-b518-8e8d7afdfec7", wantOmit: true},
} }
for _, tc := range cases { for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
t.Parallel() t.Parallel()
got := CompanyOmitsSEOMetaLookup(tc.id, tc.legacy, tc.coName, tc.prompts) got := CompanyOmitsSEOMetaLookup(tc.id, tc.legacy, tc.coName)
if got != tc.wantOmit { if got != tc.wantOmit {
t.Fatalf("got %v want %v", got, tc.wantOmit) t.Fatalf("got %v want %v", got, tc.wantOmit)
} }
+19 -21
View File
@@ -6,13 +6,12 @@
* enhance one-shot JSON parse (name, description, meta_*, attrs) keeps working. * enhance one-shot JSON parse (name, description, meta_*, attrs) keeps working.
*/ */
export type EnhancePromptSectionId = "title" | "description" | "meta" | "attributes"; export type EnhancePromptSectionId = "title" | "description" | "meta";
export const ENHANCE_PROMPT_SECTIONS: readonly EnhancePromptSectionId[] = [ export const ENHANCE_PROMPT_SECTIONS: readonly EnhancePromptSectionId[] = [
"title", "title",
"description", "description",
"meta", "meta"
"attributes"
] as const; ] as const;
/** Markers must stay in sync with aiprompts.Section* constants. */ /** Markers must stay in sync with aiprompts.Section* constants. */
@@ -22,13 +21,22 @@ export const SECTION_MARKERS: Record<
> = { > = {
title: { start: "--- Title ---", end: "--- End Title ---" }, title: { start: "--- Title ---", end: "--- End Title ---" },
description: { start: "--- Description ---", end: "--- End Description ---" }, description: { start: "--- Description ---", end: "--- End Description ---" },
meta: { start: "--- Meta ---", end: "--- End Meta ---" }, meta: { start: "--- Meta ---", end: "--- End Meta ---" }
attributes: { start: "--- Attributes ---", end: "--- End Attributes ---" }
}; };
/**
* Retired attributes section markers (attribute extraction is pipeline-level now).
* Old stored prompts may still carry this section; parse drops it and the next
* save writes the three-section shape.
*/
export const LEGACY_ATTRIBUTES_MARKERS = {
start: "--- Attributes ---",
end: "--- End Attributes ---"
} as const;
/** Canonical shared intro (same idea as CategoryEnhanceUserTemplate preamble). */ /** Canonical shared intro (same idea as CategoryEnhanceUserTemplate preamble). */
export const DEFAULT_ENHANCE_PREAMBLE = export const DEFAULT_ENHANCE_PREAMBLE =
"Write all product text in {{language}} (do not hardcode a language). Keep the title, description, SEO meta, and attributes consistent with the product evidence below."; "Write all product text in {{language}} (do not hardcode a language). Keep the title, description, and SEO meta consistent with the product evidence below.";
/** Minimal role bodies used when a section is empty on compose (keeps markers valid). */ /** Minimal role bodies used when a section is empty on compose (keeps markers valid). */
export const DEFAULT_SECTION_BODIES: Record<EnhancePromptSectionId, string> = { export const DEFAULT_SECTION_BODIES: Record<EnhancePromptSectionId, string> = {
@@ -36,9 +44,7 @@ export const DEFAULT_SECTION_BODIES: Record<EnhancePromptSectionId, string> = {
"Write a short retail product title from the title formula and attributes — never brand-only. Include product type and full model when evidence exists; follow any title formula constraints that follow.\nName: {{name}}", "Write a short retail product title from the title formula and attributes — never brand-only. Include product type and full model when evidence exists; follow any title formula constraints that follow.\nName: {{name}}",
description: description:
"Write the product description as HTML (not SEO meta). When a description formula follows, cover each section in order as one HTML string; otherwise prefer 13 factual paragraphs with simple HTML (<h2><p><ul><li>).\nDescription: {{description}}", "Write the product description as HTML (not SEO meta). When a description formula follows, cover each section in order as one HTML string; otherwise prefer 13 factual paragraphs with simple HTML (<h2><p><ul><li>).\nDescription: {{description}}",
meta: "Write the SEO title (5060 characters) and SEO description (120155 characters) as plain text, never HTML. Follow any SEO meta formula that follows; do not copy the full description into the SEO description.", meta: "Write the SEO title (5060 characters) and SEO description (120155 characters) as plain text, never HTML. Follow any SEO meta formula that follows; do not copy the full description into the SEO description."
attributes:
"Fill product attributes as key/value pairs. Prefer allowed attribute keys and title-formula slots; remap near-miss labels onto those keys; fill missing keys only from name, description, category, and attributes evidence; never invent specs or dimensions; omit unknown keys.\nCategory: {{category}}\nAttrs: {{attrs}}"
}; };
export type SectionSchemaHint = { export type SectionSchemaHint = {
@@ -65,16 +71,11 @@ export const SECTION_SCHEMA_HINTS: Record<EnhancePromptSectionId, SectionSchemaH
jsonKeys: ["meta_title", "meta_description"], jsonKeys: ["meta_title", "meta_description"],
example: '{"meta_title":"…","meta_description":"…"}', example: '{"meta_title":"…","meta_description":"…"}',
suggestedVars: ["name", "description", "category", "brand_voice", "language"] suggestedVars: ["name", "description", "category", "brand_voice", "language"]
},
attributes: {
jsonKeys: ["attrs"],
example: '{"attrs":{"brand":"Acme","product_model":"Widget Pro"}}',
suggestedVars: ["attrs", "category", "name", "description", "gtin", "language"]
} }
}; };
export type ParsedEnhancePrompt = { export type ParsedEnhancePrompt = {
/** True when all four role markers were present. */ /** True when the title/description/meta role markers were present. */
hasRoleSections: boolean; hasRoleSections: boolean;
/** Text above the first --- Section --- (JSON schema intro). */ /** Text above the first --- Section --- (JSON schema intro). */
preamble: string; preamble: string;
@@ -112,8 +113,7 @@ export function hasEnhanceRoleSections(prompt: string): boolean {
return ( return (
lower.includes(SECTION_MARKERS.title.start.toLowerCase()) && lower.includes(SECTION_MARKERS.title.start.toLowerCase()) &&
lower.includes(SECTION_MARKERS.description.start.toLowerCase()) && lower.includes(SECTION_MARKERS.description.start.toLowerCase()) &&
lower.includes(SECTION_MARKERS.meta.start.toLowerCase()) && lower.includes(SECTION_MARKERS.meta.start.toLowerCase())
lower.includes(SECTION_MARKERS.attributes.start.toLowerCase())
); );
} }
@@ -142,8 +142,7 @@ export function parseEnhancePrompt(prompt: string): ParsedEnhancePrompt {
sections: { sections: {
title: "", title: "",
description: "", description: "",
meta: "", meta: ""
attributes: ""
} }
}; };
} }
@@ -156,8 +155,7 @@ export function parseEnhancePrompt(prompt: string): ParsedEnhancePrompt {
sections: { sections: {
title: "", title: "",
description: raw, description: raw,
meta: "", meta: ""
attributes: ""
} }
}; };
} }
@@ -5,6 +5,7 @@ import {
DEFAULT_ENHANCE_PREAMBLE, DEFAULT_ENHANCE_PREAMBLE,
hasEnhanceRoleSections, hasEnhanceRoleSections,
isEnhancePromptEmpty, isEnhancePromptEmpty,
LEGACY_ATTRIBUTES_MARKERS,
parseEnhancePrompt, parseEnhancePrompt,
SECTION_MARKERS SECTION_MARKERS
} from "./categories/prompt-sections.ts"; } from "./categories/prompt-sections.ts";
@@ -22,33 +23,48 @@ const sample = [
"", "",
SECTION_MARKERS.meta.start, SECTION_MARKERS.meta.start,
"Meta body", "Meta body",
SECTION_MARKERS.meta.end, SECTION_MARKERS.meta.end
].join("\n");
/** Old stored shape: prompts saved before the attributes section was retired. */
const legacyWithAttributes = [
sample,
"", "",
SECTION_MARKERS.attributes.start, LEGACY_ATTRIBUTES_MARKERS.start,
"Attrs body {{attrs}}", "Attrs body {{attrs}}",
SECTION_MARKERS.attributes.end LEGACY_ATTRIBUTES_MARKERS.end
].join("\n"); ].join("\n");
describe("category prompt sections", () => { describe("category prompt sections", () => {
it("detects role section markers", () => { it("detects role section markers", () => {
assert.equal(hasEnhanceRoleSections(sample), true); assert.equal(hasEnhanceRoleSections(sample), true);
assert.equal(hasEnhanceRoleSections("plain marketing blob"), false); assert.equal(hasEnhanceRoleSections("plain marketing blob"), false);
// Old attributes-bearing prompts still count as structured.
assert.equal(hasEnhanceRoleSections(legacyWithAttributes), true);
}); });
it("parses and round-trips structured prompts", () => { it("parses and round-trips structured prompts", () => {
const parsed = parseEnhancePrompt(sample); const parsed = parseEnhancePrompt(sample);
assert.equal(parsed.hasRoleSections, true); assert.equal(parsed.hasRoleSections, true);
assert.match(parsed.preamble, /meta_title/); assert.equal(parsed.preamble, DEFAULT_ENHANCE_PREAMBLE);
assert.equal(parsed.sections.title, "Title body with {{name}}"); assert.equal(parsed.sections.title, "Title body with {{name}}");
assert.equal(parsed.sections.description, "Desc body with {{description}}"); assert.equal(parsed.sections.description, "Desc body with {{description}}");
assert.equal(parsed.sections.meta, "Meta body"); assert.equal(parsed.sections.meta, "Meta body");
assert.equal(parsed.sections.attributes, "Attrs body {{attrs}}");
const again = composeEnhancePrompt(parsed.preamble, parsed.sections); const again = composeEnhancePrompt(parsed.preamble, parsed.sections);
assert.equal(hasEnhanceRoleSections(again), true); assert.equal(hasEnhanceRoleSections(again), true);
const reparsed = parseEnhancePrompt(again); const reparsed = parseEnhancePrompt(again);
assert.equal(reparsed.sections.title, parsed.sections.title); assert.equal(reparsed.sections.title, parsed.sections.title);
assert.equal(reparsed.sections.attributes, parsed.sections.attributes); assert.equal(reparsed.sections.meta, parsed.sections.meta);
});
it("drops retired attributes sections on re-save", () => {
const parsed = parseEnhancePrompt(legacyWithAttributes);
assert.equal(parsed.sections.title, "Title body with {{name}}");
assert.equal(parsed.sections.meta, "Meta body");
const again = composeEnhancePrompt(parsed.preamble, parsed.sections);
assert.equal(again.includes(LEGACY_ATTRIBUTES_MARKERS.start), false);
assert.equal(again.includes("Attrs body"), false);
}); });
it("keeps unstructured prompts in description", () => { it("keeps unstructured prompts in description", () => {
@@ -63,13 +79,12 @@ describe("category prompt sections", () => {
const out = composeEnhancePrompt(DEFAULT_ENHANCE_PREAMBLE, { const out = composeEnhancePrompt(DEFAULT_ENHANCE_PREAMBLE, {
title: "Custom title rules", title: "Custom title rules",
description: "", description: "",
meta: "", meta: ""
attributes: ""
}); });
assert.equal(hasEnhanceRoleSections(out), true); assert.equal(hasEnhanceRoleSections(out), true);
assert.match(out, /Custom title rules/); assert.match(out, /Custom title rules/);
assert.match(out, /Role: description/); assert.match(out, /product description as HTML/);
assert.match(out, /\{\{attrs\}\}/); assert.equal(out.includes(LEGACY_ATTRIBUTES_MARKERS.start), false);
}); });
it("isEnhancePromptEmpty ignores default preamble", () => { it("isEnhancePromptEmpty ignores default preamble", () => {
@@ -35,7 +35,6 @@
Search, Search,
Share2, Share2,
Sparkles, Sparkles,
Tags,
Type, Type,
X X
} from "@lucide/svelte"; } from "@lucide/svelte";
@@ -77,11 +76,6 @@
labelKey: "categories.promptSection.meta", labelKey: "categories.promptSection.meta",
helpKey: "categories.promptSection.metaHelp", helpKey: "categories.promptSection.metaHelp",
formulaNoteKey: "categories.promptSection.metaFormulaNote" formulaNoteKey: "categories.promptSection.metaFormulaNote"
},
attributes: {
labelKey: "categories.promptSection.attributes",
helpKey: "categories.promptSection.attributesHelp",
formulaNoteKey: "categories.promptSection.attributesFormulaNote"
} }
}; };
@@ -105,8 +99,7 @@
let sectionBodies = $state<Record<EnhancePromptSectionId, string>>({ let sectionBodies = $state<Record<EnhancePromptSectionId, string>>({
title: "", title: "",
description: "", description: "",
meta: "", meta: ""
attributes: ""
}); });
let unstructuredHint = $state(false); let unstructuredHint = $state(false);
@@ -245,7 +238,7 @@
} }
function clearLanguageOverride() { function clearLanguageOverride() {
sectionBodies = { title: "", description: "", meta: "", attributes: "" }; sectionBodies = { title: "", description: "", meta: "" };
unstructuredHint = false; unstructuredHint = false;
const next = { ...promptsByLang }; const next = { ...promptsByLang };
delete next[selectedLang]; delete next[selectedLang];
@@ -431,10 +424,8 @@
<Type class="h-4 w-4 shrink-0 text-muted-foreground" /> <Type class="h-4 w-4 shrink-0 text-muted-foreground" />
{:else if id === "description"} {:else if id === "description"}
<FileText class="h-4 w-4 shrink-0 text-muted-foreground" /> <FileText class="h-4 w-4 shrink-0 text-muted-foreground" />
{:else if id === "meta"}
<Search class="h-4 w-4 shrink-0 text-muted-foreground" />
{:else} {:else}
<Tags class="h-4 w-4 shrink-0 text-muted-foreground" /> <Search class="h-4 w-4 shrink-0 text-muted-foreground" />
{/if} {/if}
<span class="min-w-0 flex-1 truncate">{i18n.t(meta.labelKey)}</span> <span class="min-w-0 flex-1 truncate">{i18n.t(meta.labelKey)}</span>
{#if sectionFilled(id)} {#if sectionFilled(id)}