Introduction
Type-safe prompt builder with AI-powered codegen.
Nudge is in pre-release. Expect breaking changes.
What is Nudge?
Nudge is a TypeScript library for building AI prompts. You define what your prompt should do with a fluent builder-Nudge uses AI to generate the actual system prompt.
import { prompt } from "@nudge-ai/core";
const reviewer = prompt("code-reviewer", (p) =>
p
.persona("senior engineer")
.input("code snippet")
.output("review with suggestions")
.do("explain reasoning")
.dont("nitpick style")
);Run npx @nudge-ai/cli generate → get an optimized system prompt. It's cached, so unchanged definitions skip the AI call.
Why use it?
- Type-safe - Full autocomplete. Typed variables and options.
- AI-generated - Your structure becomes a polished prompt. No hand-tuning.
- Cached - Hash-based caching. Only regenerate what changed.
- Composable - Share rules with
.use(). Toggle sections with.optional(). - Testable - Define tests and auto-improve prompts with the CLI.
- Extensible - Create custom step types for domain-specific needs.
Example
const assistant = prompt("assistant", (p) =>
p
.persona("assistant for {{company}}")
.do("be concise")
.optional("formal", (p) => p.do("use formal language"))
.test(
"Hello, how can I help?",
(output) => output.length < 500,
"Keep responses short"
)
);
// Variables and options are fully typed
assistant.toString({ company: "Acme", formal: true });You can also test and improve your prompts:
npx @nudge-ai/cli eval # Run tests
npx @nudge-ai/cli improve --judge # Auto-improve failing testsAnd extend with custom steps for domain-specific needs:
import { createBuilder, createStep } from "@nudge-ai/core";
const tone = createStep({
name: "tone",
build: (style: string) => ({ type: "tone" as const, style }),
format: (step) => `[Tone] Write in a ${step.style} tone.`,
});
const builder = createBuilder([tone]);
const bot = builder.prompt("bot", (p) => p.persona("assistant").tone("friendly"));Learn more about Self-Improvement and Custom Steps.
Packages
| Package | Description |
|---|---|
@nudge-ai/core | The prompt builder |
@nudge-ai/cli | Codegen CLI |