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
+19 -21
View File
@@ -6,13 +6,12 @@
* 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[] = [
"title",
"description",
"meta",
"attributes"
"meta"
] as const;
/** Markers must stay in sync with aiprompts.Section* constants. */
@@ -22,13 +21,22 @@ export const SECTION_MARKERS: Record<
> = {
title: { start: "--- Title ---", end: "--- End Title ---" },
description: { start: "--- Description ---", end: "--- End Description ---" },
meta: { start: "--- Meta ---", end: "--- End Meta ---" },
attributes: { start: "--- Attributes ---", end: "--- End Attributes ---" }
meta: { start: "--- Meta ---", end: "--- End Meta ---" }
};
/**
* 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). */
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). */
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}}",
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.",
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}}"
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."
};
export type SectionSchemaHint = {
@@ -65,16 +71,11 @@ export const SECTION_SCHEMA_HINTS: Record<EnhancePromptSectionId, SectionSchemaH
jsonKeys: ["meta_title", "meta_description"],
example: '{"meta_title":"…","meta_description":"…"}',
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 = {
/** True when all four role markers were present. */
/** True when the title/description/meta role markers were present. */
hasRoleSections: boolean;
/** Text above the first --- Section --- (JSON schema intro). */
preamble: string;
@@ -112,8 +113,7 @@ export function hasEnhanceRoleSections(prompt: string): boolean {
return (
lower.includes(SECTION_MARKERS.title.start.toLowerCase()) &&
lower.includes(SECTION_MARKERS.description.start.toLowerCase()) &&
lower.includes(SECTION_MARKERS.meta.start.toLowerCase()) &&
lower.includes(SECTION_MARKERS.attributes.start.toLowerCase())
lower.includes(SECTION_MARKERS.meta.start.toLowerCase())
);
}
@@ -142,8 +142,7 @@ export function parseEnhancePrompt(prompt: string): ParsedEnhancePrompt {
sections: {
title: "",
description: "",
meta: "",
attributes: ""
meta: ""
}
};
}
@@ -156,8 +155,7 @@ export function parseEnhancePrompt(prompt: string): ParsedEnhancePrompt {
sections: {
title: "",
description: raw,
meta: "",
attributes: ""
meta: ""
}
};
}
@@ -5,6 +5,7 @@ import {
DEFAULT_ENHANCE_PREAMBLE,
hasEnhanceRoleSections,
isEnhancePromptEmpty,
LEGACY_ATTRIBUTES_MARKERS,
parseEnhancePrompt,
SECTION_MARKERS
} from "./categories/prompt-sections.ts";
@@ -22,33 +23,48 @@ const sample = [
"",
SECTION_MARKERS.meta.start,
"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}}",
SECTION_MARKERS.attributes.end
LEGACY_ATTRIBUTES_MARKERS.end
].join("\n");
describe("category prompt sections", () => {
it("detects role section markers", () => {
assert.equal(hasEnhanceRoleSections(sample), true);
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", () => {
const parsed = parseEnhancePrompt(sample);
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.description, "Desc body with {{description}}");
assert.equal(parsed.sections.meta, "Meta body");
assert.equal(parsed.sections.attributes, "Attrs body {{attrs}}");
const again = composeEnhancePrompt(parsed.preamble, parsed.sections);
assert.equal(hasEnhanceRoleSections(again), true);
const reparsed = parseEnhancePrompt(again);
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", () => {
@@ -63,13 +79,12 @@ describe("category prompt sections", () => {
const out = composeEnhancePrompt(DEFAULT_ENHANCE_PREAMBLE, {
title: "Custom title rules",
description: "",
meta: "",
attributes: ""
meta: ""
});
assert.equal(hasEnhanceRoleSections(out), true);
assert.match(out, /Custom title rules/);
assert.match(out, /Role: description/);
assert.match(out, /\{\{attrs\}\}/);
assert.match(out, /product description as HTML/);
assert.equal(out.includes(LEGACY_ATTRIBUTES_MARKERS.start), false);
});
it("isEnhancePromptEmpty ignores default preamble", () => {
@@ -79,4 +94,4 @@ describe("category prompt sections", () => {
false
);
});
});
});
@@ -35,7 +35,6 @@
Search,
Share2,
Sparkles,
Tags,
Type,
X
} from "@lucide/svelte";
@@ -77,11 +76,6 @@
labelKey: "categories.promptSection.meta",
helpKey: "categories.promptSection.metaHelp",
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>>({
title: "",
description: "",
meta: "",
attributes: ""
meta: ""
});
let unstructuredHint = $state(false);
@@ -245,7 +238,7 @@
}
function clearLanguageOverride() {
sectionBodies = { title: "", description: "", meta: "", attributes: "" };
sectionBodies = { title: "", description: "", meta: "" };
unstructuredHint = false;
const next = { ...promptsByLang };
delete next[selectedLang];
@@ -431,10 +424,8 @@
<Type class="h-4 w-4 shrink-0 text-muted-foreground" />
{:else if id === "description"}
<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}
<Tags class="h-4 w-4 shrink-0 text-muted-foreground" />
<Search class="h-4 w-4 shrink-0 text-muted-foreground" />
{/if}
<span class="min-w-0 flex-1 truncate">{i18n.t(meta.labelKey)}</span>
{#if sectionFilled(id)}