prompt-rewriter detects the source language of every prompt (AR, FR, ES, DE, PT, EN),
translates it into optimized English before classification where term maps exist
(Arabic, French), and forces the reply back into the user's language. No external
dependencies. Built into the plugin adapter.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Prompt Rewriter?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/novahiz-prompt-rewriter)
---
name: prompt-rewriter
description: |
prompt-rewriter detects the source language of every prompt (AR, FR, ES, DE, PT, EN),
translates it into optimized English before classification where term maps exist
(Arabic, French), and forces the reply back into the user's language. No external
dependencies. Built into the plugin adapter.
license: Apache-2.0
compatibility: |
Implemented in src/prompt-rewriter.ts and inlined in adapters/opencode/novahiz-plugin.ts;
no external dependencies.
metadata:
author: Novahiz
organization: Novahiz
version: "2.1.0"
---
# prompt-rewriter
## What it does
Every user message is intercepted before classification and rewritten into optimized English:
1. Detect the source language (FR, AR, ES, DE, PT, or EN) with weighted pattern scoring.
2. Translate task terms into English equivalents where a term map exists (AR, FR).
3. Tighten the English prompt into imperative mood and drop filler.
4. Classify the English version for tier and skill assignment.
5. Respond in the user's original language.
## Why English for classification
Models see mostly English during training, technical vocabulary already lives in English (refactor, debug, migrate), and imperative English classifies more precisely than a polite request in any language.
## How it works
The rewriter sits in `src/prompt-rewriter.ts` and is wired into the plugin adapter at `adapters/opencode/novahiz-plugin.ts`.
### Language detection
Heuristic scoring over a folded (lowercase, accent-stripped) copy of the prompt: each language in `LANG_PATTERNS` (FR, ES, DE, PT) has weighted patterns of common words, technical terms, and multi-word phrases. A language needs a minimum score to qualify; a weight-3 marker (task verbs, question words) beats a pile of weight-1 function words. Arabic is detected by its script range. Ties fall back to a fixed order (FR, ES, DE, PT). English cognates (test, design, page, interface, code...) are deliberately excluded from the marker lists so clean English stays `en`. No external dependency is involved.
### Term translation
Arabic and French have dedicated term maps of 55 and 86 patterns respectively. Examples:
| FR term | EN equivalent |
|---------|---------------|
| corriger | fix |
| creer | create |
| ajouter | add |
| refactoriser | refactor |
| migrer | migrate |
| optimiser | optimize |
**Known limitation:** Spanish, German, and Portuguese prompts are detected but not translated — classification on the raw text relies on the shared technical vocabulary (refactor, login, servidor, Datenbank...). Add an `XX_EN` map below to extend coverage.
### English optimization
Politeness markers are stripped and the prompt becomes imperative:
- "I want to implement X" becomes "implement X".
- "Can you fix the bug?" becomes "fix the bug".
- "Please add a comment" becomes "add a comment".
## Integration
The plugin adapter calls `rewritePrompt(text)` before `classify`:
1. Classification runs on the rewritten English version.
2. When the detected source language is not English, the enforcement block carries the response-language instruction (see below).
3. When the text actually changed (`wasRewritten`), a log entry records the rewrite.
Covered by `tests/prompt.rewriter.test.ts`.
## Response language
The agent MUST respond in the user's original language. The enforcement block includes:
```
User language: fr — respond in this language, not English.
```
That line overrides any default to English.
## Adding a language
1. Add detection patterns to `LANG_PATTERNS` in `src/prompt-rewriter.ts`.
2. Create a `XX_EN` term mapping array.
3. Handle the new language in `translateTerms()`.
4. Test with sample prompts in that language.