# Mechanical Preprocess

> Bash-first mechanical pattern cleanup pipeline — handles em-dash removal, forbidden words, and repetitive structures at scale BEFORE AI agents touch the text. Processes 30+ chapters efficiently.

- **Type:** Skill
- **Install:** `agentstack add skill-felipelobomotta-blip-book-genesis-v4-mechanical-preprocess`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [felipelobomotta-blip](https://agentstack.voostack.com/s/felipelobomotta-blip)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [felipelobomotta-blip](https://github.com/felipelobomotta-blip)
- **Source:** https://github.com/felipelobomotta-blip/book-genesis-v4/tree/master/skills/deprecated/mechanical-preprocess
- **Website:** https://github.com/felipelobomotta-blip/book-genesis-v4

## Install

```sh
agentstack add skill-felipelobomotta-blip-book-genesis-v4-mechanical-preprocess
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Mechanical Preprocess

## PURPOSE

AI agents are bad at processing entire manuscripts for mechanical fixes. Context windows overflow, attention drifts, and the agent "forgets" the rules by chapter 15. This skill solves that by splitting the work:

- **Bash handles the 80%** — pattern matching, counting, safe replacements
- **AI handles the 20%** — judgment calls on ambiguous cases, reviewing diffs

This is the ONLY skill in the pipeline that uses bash scripting as its primary tool. It exists because some problems are engineering problems, not language problems.

## WHEN TO RUN

- **After:** All chapters have been through prose-craft (complete draft exists)
- **Before:** dialogue-polish, chaos-engine, or any AI-based editing pass
- **Trigger:** Orchestrator calls this once when the full manuscript draft is ready
- **Re-run:** After any major rewrite pass that may reintroduce mechanical patterns

## REQUIRED INPUTS

1. **Chapter files** — all chapter drafts in `chapters/` directory (e.g., `chapters/chapter-01.md` through `chapters/chapter-[N].md`)
2. **voice-dna.md** — for:
   - Forbidden word list
   - Em-dash policy (max per chapter, allowed contexts)
   - Any other mechanical rules (e.g., max semicolons per chapter, banned constructions)
3. **foundation.md** — for genre context (affects which patterns are acceptable)

## PROCESS

### PHASE 1: SCAN (Pure bash -- no AI)

Run these scans against every chapter file. All commands use standard Unix tools (grep, wc, awk, sed).

**1.1 Em-Dash Census**

```bash
# Count em-dashes per chapter (both spaced and unspaced variants)
for f in chapters/chapter-*.md; do
  echo "$(basename $f): $(grep -oP '(\x{2014}| — )' "$f" | wc -l) em-dashes"
done
```

Categorize each em-dash by context:
- **Independent clause separator** — `[complete sentence] — [complete sentence]` (TARGET FOR REMOVAL)
- **Parenthetical aside** — `word — aside — continuation` (TARGET: convert to commas or restructure)
- **Dialogue interruption** — `"I was going to—"` (KEEP — this is correct usage)
- **List/appositive** — `three things — money, power, fame — were gone` (EVALUATE case by case)

**1.2 Pattern #11 Census (Formulaic Constructions)**

```bash
# "not because X but because Y"
grep -cnP 'not because.*but because' chapters/chapter-*.md

# "the kind of X that Y"
grep -cnP 'the kind of \w+ that' chapters/chapter-*.md

# "not as X but as Y"
grep -cnP 'not as \w+ but as' chapters/chapter-*.md

# "there was something X about Y"
grep -cnP 'there was something \w+ about' chapters/chapter-*.md

# "it was the sort of X that Y"
grep -cnP 'it was the (sort|kind|type) of' chapters/chapter-*.md

# "as if X were Y" (excessive simile construction)
grep -cnP 'as if .{5,40} were' chapters/chapter-*.md

# Doubled constructions "X and X" where both are abstract
grep -cnP '(grief|loss|pain|joy|love|fear|hope|shame|guilt|rage) and (grief|loss|pain|joy|love|fear|hope|shame|guilt|rage)' chapters/chapter-*.md
```

**1.3 Forbidden Word Census**

Extract the forbidden word list from voice-dna.md and scan:

```bash
# For each forbidden word in the list
for word in "palpable" "tangible" "visceral" "whilst" "gaze" "orbs" "ministrations" "utilize" "plethora" "myriad" "ubiquitous" "dichotomy" "juxtaposition" "paradigm" "trajectory"; do
  echo "--- $word ---"
  grep -cnP "\b${word}\b" chapters/chapter-*.md
done
```

Note: The actual forbidden word list comes from voice-dna.md. The list above is a default fallback. Always prioritize the project-specific list.

**1.4 Repetition Scan**

```bash
# Sentence-start repetition: same first word in consecutive sentences
# (catches "She did X. She did Y. She did Z." patterns)
# Extract first word of each sentence per chapter
for f in chapters/chapter-*.md; do
  grep -oP '(? (total/1000)*3 && length($2) > 4 {print}'
done
```

**1.5 Adverb Density**

```bash
# Count -ly adverbs per chapter
for f in chapters/chapter-*.md; do
  total=$(wc -w  "use"
- "whilst" -> "while"
- "upon" -> "on" (in most contexts)
- "commence" -> "begin" or "start"
- "endeavor" -> "try"

Do NOT auto-replace words that need context to choose the right substitute (e.g., "palpable" could become "obvious," "thick," "heavy," "unmistakable" depending on context).

**2.3 Safe Structural Fixes**

```bash
# Double spaces -> single space
sed 's/  / /g'

# Straight quotes -> curly quotes (if project uses curly)
# Multiple consecutive blank lines -> two blank lines max
sed '/^$/N;/^\n$/d'
```

**2.4 Diff Generation**

For EVERY change, generate a diff:

```bash
diff -u chapters/chapter-01.md chapters/chapter-01.md.cleaned > diffs/chapter-01.diff
```

### PHASE 3: AI QUALITY REVIEW (Agent reviews diffs only)

This is where the AI agent enters. It does NOT read full chapters. It reads ONLY the diffs from Phase 2.

**3.1 Diff Review Instructions for AI Agent**

For each diff file:
1. Read the before/after context (3 lines surrounding each change)
2. For each change, classify:
   - `APPROVE` — change is correct and improves the text
   - `REVERT` — change damaged meaning, rhythm, or voice
   - `MODIFY` — change direction is right but execution needs adjustment (provide the correct version)
3. For `REVERT` changes, restore the original text
4. For `MODIFY` changes, apply the agent's corrected version

**3.2 Ambiguous Pattern Review**

The AI agent also receives the list of patterns that bash COULD NOT safely replace:
- Em-dashes in ambiguous contexts
- Forbidden words that need context-dependent substitutes
- Pattern #11 instances (these almost always need creative rewriting, not mechanical replacement)

For each ambiguous item, the agent:
1. Reads the surrounding paragraph (not the full chapter)
2. Decides: fix, leave, or flag for Writer attention
3. Applies fixes or adds to the manual review list

**3.3 Adverb Review**

For chapters flagged OVER on adverb density:
- Agent reviews adverbs in context
- Removes adverbs that weaken the verb ("walked slowly" -> "shuffled")
- Keeps adverbs that are genuinely necessary or part of character voice
- Target: bring density below threshold

### PHASE 4: APPLY AND REPORT

**4.1 Apply Approved Changes**

```bash
# For each chapter with approved changes
patch chapters/chapter-01.md  [after] (removed [N])
- Pattern #11: [before] -> [after] (rewritten [N])
- Forbidden words: [before] -> [after] (replaced [N])
- Adverbs: [before rate] -> [after rate]
- Manual items remaining: [list]

## Before/After Totals
| Metric              | Before | After  | Reduction |
|---------------------|--------|--------|-----------|
| Em-dashes           | [N]    | [N]    | [%]       |
| Pattern #11         | [N]    | [N]    | [%]       |
| Forbidden words     | [N]    | [N]    | [%]       |
| Avg adverb rate     | [N]    | [N]    | [%]       |

## Manual Review Queue
Items that need Writer or Editor judgment:
1. [Chapter N, line ~X]: [description of issue]
```

## RULES

1. **Bash first, AI second.** Never send a full chapter to the AI agent for mechanical fixes. The scan and safe-replace phases MUST run in bash.
2. **Safe means SAFE.** If a replacement could EVER be wrong in context, it is not safe. Move it to Phase 3.
3. **Preserve voice.** Mechanical cleanup must not flatten character voice. If a "forbidden word" is part of a character's speech pattern (defined in voice-dna.md), it is NOT forbidden in that character's dialogue.
4. **Diffs, not full text.** The AI agent in Phase 3 reviews diffs with surrounding context. Never feed it full chapters for mechanical review — that is how attention drift causes missed fixes.
5. **Idempotent.** Running this skill twice on the same file should produce no additional changes. If it does, the Phase 2 patterns are too aggressive.
6. **Back up first.** Before Phase 2, copy all chapter files to `chapters/backup-preprocess/`. If anything goes wrong, restore from backup.
7. **Never touch dialogue interruptions.** Em-dashes inside quotation marks where a character is cut off ("I was going to--") are CORRECT and must never be removed.
8. **Report everything.** Every change, every revert, every manual flag goes in the report. The Writer and Editor need full transparency on what was changed mechanically.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [felipelobomotta-blip](https://github.com/felipelobomotta-blip)
- **Source:** [felipelobomotta-blip/book-genesis-v4](https://github.com/felipelobomotta-blip/book-genesis-v4)
- **License:** MIT
- **Homepage:** https://github.com/felipelobomotta-blip/book-genesis-v4

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-felipelobomotta-blip-book-genesis-v4-mechanical-preprocess
- Seller: https://agentstack.voostack.com/s/felipelobomotta-blip
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
