-
Notifications
You must be signed in to change notification settings - Fork 4
02 Architecture Deep Dive
Ghost Writer uses a 5-stage pipeline to generate content that passes AI detection. This document explains each stage, data flow, the revision loop, and how detection APIs are orchestrated.
Every piece of content flows through five sequential stages:
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Profile │───▶│ Writer │───▶│ QA │───▶│ Adapter │───▶│ Polish │
└──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘
Purpose: Load voice profile, set perplexity/burstiness targets, identify platform constraints.
What happens:
- Voice profile is loaded (built-in or custom)
- Perplexity target range is set (e.g., 30–45 for john-williams)
- Burstiness target is set (high, medium, or low)
- Platform spec is loaded (character limits, format, structure)
- Phrase blacklist (120+ banned phrases) is injected into the prompt
Output: A fully parameterized generation context.
Purpose: Generate content using GPT-5.4 with the Ghost Protocol system prompt.
What happens:
- System prompt includes: Ghost Protocol laws, voice profile, platform spec, detection evasion rules
- Temperature: 0.85–0.95 (varies per variant for diversity)
- Model: GPT-5.4
- Max tokens: 4096
Ghost Protocol laws in the prompt:
- Controlled Chaos — Deliberate imperfection: fragments, unexpected metaphors, varied paragraph length
- Signature Voice — Write as the defined persona (tone, vocabulary, structure)
- Invisible Architecture — Detection evasion baked into generation, not post-processing
Output: Raw generated text.
Purpose: Validate content against the 40-point QA system.
What happens:
- 40 checks run across 10 blocks (A–J)
- Hard checks must pass; soft checks inform quality
- Pass criteria: 0 hard fails, ≤3 soft fails
- If failed: blacklist hits are replaced, then a revision prompt is sent to GPT
Revision loop:
- Run QA checks
- If blacklist hits: replace with random replacement from phrase list
- If hard fails or >3 soft fails: send revision prompt to GPT with failed check details
- Re-run QA on revised content
- Repeat up to 3 times
Output: QA-passing content or best-effort after max revisions.
Purpose: Format content for the target platform.
What happens:
- Text is normalized (Unicode, smart quotes, em-dashes)
- Truncation applied if over platform max (e.g., LinkedIn 3000 chars)
- Platform-specific formatting:
- Email: Split into subject, preheader, body (subject <60, preheader <90)
- Others: Plain text or markdown per platform spec
Output: Platform-ready content.
Purpose: Human-pass simulation with small edits.
What happens:
- Detection APIs run in parallel (GPTZero, Pangram, Originality)
- If any detector fails: sentences with >80% AI probability are identified
- Failed sentences are rewritten via a focused revision prompt
- Content is re-checked by detectors
- Up to 3 revision cycles for detector failures
Output: Final content with detection scores.
| Role | Responsibility |
|---|---|
| Profile Loader | Loads voice + platform spec, builds prompt context |
| Writer (GPT-5.4) | Generates content under Ghost Protocol |
| QA Engine | Runs 40 checks, triggers revision loop |
| Adapter | Applies platform formatting rules |
| Polish / Detector | Calls external APIs, revises flagged sentences |
Topic + Context + Voice + Type
│
▼
buildGhostPrompt()
│
▼
callGPT54(prompt, temp)
│
▼
normalizeText() → formatForPlatform()
│
▼
runQAChecks() ──▶ [fail] ──▶ revise ──▶ loop
│
▼ [pass]
callDetectors() ──▶ [fail] ──▶ reviseFailedSentences() ──▶ loop
│
▼ [pass]
Return { content, qa, detection, stats }
When QA fails:
- Blacklist replacement: Each blacklisted phrase is replaced with a random alternative from the replacement list
-
Structural revision: If hard fails or >3 soft fails remain, a revision prompt is sent:
- Lists failed checks with targets
- Asks GPT to fix only those issues
- Temperature increased by 0.05 for more variation
When a detector flags content:
- GPTZero sentences with AI probability >80% are collected
- A focused prompt rewrites only those sentences
- Rewritten sentences are spliced back into the content
- Content is re-normalized and re-checked by all detectors
All three detectors are called with Promise.all():
// Pseudocode
const [gptzero, pangram, originality] = await Promise.all([
fetch(gptzeroUrl, { body: text }),
fetch(pangramUrl, { body: text }),
fetch(originalityUrl, { body: text }),
]);Pass criteria:
-
GPTZero:
completely_generated_prob< 0.30 -
Pangram:
predictionisHumanorAI-Assisted(notAI) -
Originality.ai:
aiscore < 0.30,plagiarism< 0.05
Content passes only when all configured detectors pass.
The Adapter applies rules from PLATFORM_SPECS:
| Rule Type | Example |
|---|---|
| Truncation | LinkedIn: first 140 chars visible before "see more" |
| Hashtags | LinkedIn: max 3; Instagram: max 5 |
| Structure | Reddit: TL;DR if >300 words |
| Format | Email: subject + preheader + body; Blog: H2/H3, meta <160 |
| Character limits | Twitter: 280 (25K premium); Threads: 500 |
See Platform Adapters for the full spec per platform.