A minimal toolchain for rewriting text into GOV.UK style.
This repository now contains two workspace packages:
@sensecall/govuk-rewrite: composable rewrite engine and provider adapters@sensecall/govuk-rewrite-cli: CLI wrapper (one-shot mode and interactivechatmode)
Packages
@sensecall/govuk-rewrite-cli (CLI)
Install globally:
npm install -g @sensecall/govuk-rewrite-cli
One-shot rewrite:
govuk-rewrite "Please kindly complete the form below"Explain mode:
govuk-rewrite --explain "Please kindly complete the form below"Pipe input:
echo "Click here to find out more" | govuk-rewrite
First-time setup wizard:
Interactive mode:
Chat stays open until you run /quit or use Ctrl+C when the composer is empty.
The composer uses a Codex-style prompt with placeholder text (Paste text to rewrite) and a hint row (? for shortcuts).
Paste multiline content, then press Enter to send it.
The composer remains single-line and switches to a clear PASTE READY state with:
- explicit actions (
Enterto send,Ctrl+Cto clear) - an unsent preview of the first 2 lines
- a
+N more linessummary when applicable When the rewritten text matches your input (after trim/newline normalization), chat adds a subtle system note indicating no improvement is needed.
Interactive commands:
/help
/provider <openai|anthropic|openrouter>
/model <name>
/mode <page-body|error-message|hint-text|notification|button>
/context <text>
/context clear
/explain on|off
/check on|off
/diff on|off
/json on|off
/tokens on|off
/show
/quit
Chat shortcuts:
Ctrl+C Clear input (or exit if empty)
? Toggle shortcut help
Setup flow
govuk-rewrite setupruns an interactive wizard.- The wizard writes provider/model/timeout/baseUrl to your config file.
- API keys are never written to config files.
- The wizard prints the exact
export ...command for your selected provider key. - Optional verification can run a small live request before finishing.
Auto-prompt behavior:
- In one-shot and
chatmodes, if the API key is missing and both stdin/stdout are TTY, the CLI asks:No API key found. Run setup now? [Y/n]
- In Ink chat, setup prompts are shown inline in the composer.
- In non-interactive contexts (for example pipes), auto-prompting is disabled.
@sensecall/govuk-rewrite (Composable API)
import { rewrite } from "@sensecall/govuk-rewrite"; const result = await rewrite( { text: "Please kindly submit your application by Friday.", explain: true, mode: "page-body", }, { provider: "openai", apiKey: process.env.OPENAI_API_KEY!, model: "gpt-4.1-mini", timeoutMs: 30000, } ); console.log(result.rewrittenText);
CLI behavior
Input resolution
- If stdin is piped, read stdin.
- Otherwise, use positional args.
- If empty, print help to stderr and exit code
2.
Output precedence
--json > --check > --diff > --explain > plain
Output details:
- Plain mode prints rewritten text only.
--explainprepends a bullet when no change is needed:No improvement suggested. The text already aligns with GOV.UK style.
--jsonincludesnoImprovement: booleanmetadata.
Spinner
Spinner displays only when:
- stdout is a TTY
- spinner is enabled (
--no-spinnernot set)
Spinner text: Rewriting…
Exit codes
0: success1: runtime/provider/config error2: usage error
Configuration
Precedence:
- CLI flags
- Environment variables
- Config file
- Defaults
Config file path:
- macOS/Linux:
~/.config/govuk-rewrite/config.json - Windows:
%APPDATA%\\govuk-rewrite\\config.json
Environment variables:
OPENAI_API_KEYANTHROPIC_API_KEYOPENROUTER_API_KEYGOVUK_REWRITE_PROVIDERGOVUK_REWRITE_MODELGOVUK_REWRITE_TIMEOUT_MSGOVUK_REWRITE_BASE_URL
Development
Install dependencies:
Build everything:
Run all tests:
Run CLI in dev mode:
npm run dev -- "Text to rewrite"