et’s break the AI logic into clean layers so Replit (and you) know exactly how it should behave.

AI Logic Specification
1) Default Assumptions

Tone: Always Professional. (Don’t ask the user — this is a business plan tool.)

Length: Default to Standard (200–300 words).

Add “Short” (120–160 words) or “Long” (350–500 words) later if users request it.

Style: Concise, investor-ready, no marketing fluff.

2) Prompt Assembly

FinalPrompt =

[SYSTEM]: fixed instruction →
“You are drafting a professional business plan section. Be accurate, clear, and business-appropriate. No bracket placeholders like [Company Name]. Use the provided context. If data is missing, phrase it neutrally.”

[CONTEXT] Business Brief (company, industry, model, products, offerings, market, edge, financial headline).

[CONTEXT] SectionId (e.g., executive-summary).

[TASK] Section Base Prompt (specific task for this section).

[USER] Optional Prompt (from drawer field, if given).

[USER] EditorContent (if present, used only for rephrase/expand/summarize).

3) Actions
Generate Section

Uses Business Brief + Base Prompt + Optional Prompt.

If Editor empty → insert draft.

If Editor has text → ask:

Replace Draft

Append to Draft

Cancel

Rephrase

Input = Editor content.

Output = rewrite with same meaning, shorter sentences, better flow.

Respect Business Brief context if available (to keep names/offerings consistent).

Expand

Input = Editor content.

Output = add detail, examples, sub-bullets.

Stay within 30–40% longer max (avoid runaway length).

Pull in Business Brief for specifics if missing.

Summarize

Input = Editor content.

Output = condense to ~50–60% of original length.

Keep all critical points; remove fluff.

4) Handling Missing Data

If Business Brief empty → fallback:

Use generic but neutral phrasing (e.g., “The company offers a range of services…”).

Show toast: “Using generic template (add Business Brief for better results).”

If Financial Headline missing → mention growth in qualitative terms only (“strong revenue growth expected”).

If Offerings missing → use “core products and services.”

Never output raw placeholders like [Company Name].

5) Safety / Guardrails

Length cap: ~500 words max per section.

Formatting:

Bullets where natural (Products & Services, SWOT).

Paragraphs otherwise.

No hallucinated numbers: Only use financialHeadline for figures.

No contradictions: Stick to supplied Brief/context.

If editor text conflicts with Brief → respect user editor text first.

6) Output Flow

User clicks Generate Section.

Draft appears in Editor immediately (streaming optional).

Inline actions appear: Rephrase | Expand | Summarize.

User can edit manually at any time.

User clicks Save to Document → snapshot is stored, timestamp updates.

Section Preview shows clean formatted text.

Full Document Preview compiles all saved sections.

7) QA Checklist (per section)

✅ Mentions Company + Business Model + Market from Brief.

✅ If financialHeadline exists → uses Launch/Growth/Scale phrasing.

✅ No bracket placeholders anywhere.

✅ “Replace/Append” prompt appears if editor already has text.

✅ Rephrase/Expand/Summarize only appear after text exists.

✅ Max ~500 words, clean paragraphs/bullets.

🔥 That’s the AI brain, simplified for humans but still powerful.