Instructions editor

Where people write what an assistant should always know or do: project instructions, a system prompt with variables to test, and a list of rules with where each applies.

Loading preview…

Install

  1. 1

    Run this command in your Tailwind CSS project. It adds components/ai/instructions-editor-project.tsx and installs its dependencies.

    $ npx shadcn@latest add https://gradientdeck.com/ai-components/r/instructions-editor-project.json

Usage & API

Example

instructions-editor-project.tsx
import { ProjectInstructions } from "@/components/ai/instructions-editor-project"

<ProjectInstructions
  value="…"
  savedValue="…"
  onChange={() => {}}
  onSave={() => {}}
  onDiscard={() => {}}
/>

Props ProjectInstructions

PropType & descriptionRequired
valuestringRequired
savedValuestringThe last saved text. The panel is dirty while value differs from it.Required
onChange(value: string) => voidRequired
onSave() => voidRequired
onDiscard() => voidRequired
snippetsSnippet[]Optional
softLimitnumberSuggested ceiling in tokens. Going over is allowed, just flagged.Optional
savedLabelstringShown when nothing is pending, e.g. "Saved Oct 24".Optional

Dependencies

  • React
  • Tailwind CSS
  • motion
  • lucide-react
Implementation notes

Project instructions is a section headed Instructions, with the aside Used in every chat in this project. The textarea placeholder asks what every chat in the project should know. Under it, the meter is labelled as length against the suggested limit and prints a percentage. If you pass snippets, they render as Add buttons. Each button's title is the full line it would append, and a line already present cannot be added again. Appended text goes on a new line and the caret moves to the end. Discard calls onDiscard. Save calls onSave only while the text is dirty. The idle status uses savedLabel, which defaults to Saved.

Choosing a layout

Use project instructions on a project page, above the list of chats, when one block of text should ride along with every conversation and people need to see that it is saved. Snippets help when the same lines get added often, such as citing a file or refusing to guess a missing number. A snippet that is already in the text is disabled and shows a check. Use the system prompt variant in a prompt workspace, where the author is testing one template against sample values before it is stored. The preview is the point. It shows the prompt the model would actually receive.

Use rules when the instructions are many short constraints rather than one essay, and some of them come from the repo. Matching files is for a glob, defaulting to src/**/*.tsx when that scope is chosen. When mentioned tells the person to type an at-name derived from the rule title. Do not use these editors for the sampling knobs. That is the model settings panel. Do not use them to decide which tools exist. That is the tool picker. These three only edit text, and they only report changes through the callbacks you pass.

How is the token number calculated?

Both the project meter and the system-prompt preview use a rough estimate of about four characters per token. It is not a tokenizer for a particular model. The project meter compares that estimate with softLimit, which defaults to 600, and still lets you save when you are over it.

Can a rule that comes from a file be rewritten here?

No. If the rule has a file path, the row is read-only apart from the on and off switch. The expanded body says the text is read from that file and that the next run picks up edits made in the repo. Delete is only on rules that have no file path.