Skip to content
Back to skills

Prompt Rewriter

ASecurity

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.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 27, 2026
ai-agents

Security analysis

A100/100

Scanned November 27, 2026

npx -y skills add novahiz/novahiz --skill prompt-rewriter --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prompt Rewriter?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prompt Rewriter
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/novahiz-prompt-rewriter/badge)](https://www.skillsdirectory.com/skills/novahiz-prompt-rewriter)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.