How the Prompt-Settings System Customizes AI Instructions in ThePrimeagen's 99
The prompt-settings system in 99 centralizes AI instruction customization through a Lua-based pipeline that wraps user prompts with XML-like tags, injects contextual metadata, and allows extensible prompt fragments for different operations.
ThePrimeagen's 99 repository implements a sophisticated prompt-settings architecture that controls how every LLM request is constructed and contextualized. Understanding how this prompt-settings system customizes AI instructions reveals the mechanism behind the plugin's ability to generate tutorials, perform semantic searches, and modify code with precise contextual awareness.
The Prompt-Settings Pipeline Architecture
The system operates as a five-stage pipeline where raw user instructions are transformed into fully contextualized AI prompts. Each stage is implemented in specific Lua modules within the lua/99/ directory, ensuring that every LLM request follows a consistent structure while remaining customizable.
Step 1: Prompt Definitions in prompt-settings.lua
At the core lies lua/99/prompt-settings.lua, which exports a prompts table containing static fragments and dynamic formatting functions.
Static fragments include:
prompts.role– Defines the AI as a "software-engineering assistant"prompts.tutorial()– Returns instructions for creating tutorialsprompts.semantic_search()– Specifies strict output formats for search results
Dynamic helpers include:
prompts.prompt(user_prompt, action, name?)– Wraps prompts in XML-like tagsprompts.visual_selection()– Formats selected code blocksprompts.output_file()andprompts.read_tmp()– Handle file system references
Step 2: Prompt Composition with make-prompt.lua
When an operation executes, lua/99/ops/make-prompt.lua orchestrates the composition. The make_prompt() function calls context._99.prompts.prompts.prompt(), which constructs a wrapped prompt structure:
<NAME>user prompt</NAME>
<Context>operation-specific prompt</Context>
This XML-like envelope separates user intent from operational context, allowing the LLM to distinguish between direct instructions and background requirements.
Step 3: Context Metadata Injection
Before transmission, RequestContext:finalize() in lua/99/request-context.lua appends three critical metadata blocks:
<Location>– The file path and position where changes apply<FunctionText>– The selected code range or function text<MustObey>...<TEMP_FILE>– Constraints telling the model exactly where it may write changes
This injection ensures the AI understands both the spatial context (where am I?) and the file system boundaries (what can I touch?).
Step 4: Operation-Specific Prompts
Each operation in lua/99/ops/ imports specific prompt fragments:
tutorial.luausesprompts.tutorial()to request educational content generationsearch.luausesprompts.semantic_search()to enforce strict location-string formatting for results
These specialized prompts extend the base system without modifying the core pipeline.
Step 5: Extending the System
The architecture supports custom prompts through simple table extension. To add a new prompt:
-- In lua/99/prompt-settings.lua
prompts.my_special = function()
return [[
You are asked to generate a summary of the given file.
<Rule>The output must be a single paragraph.</Rule>
]]
end
Then reference it in any operation:
local special_prompt = ctx._99.prompts.prompts.my_special()
local full_prompt = ctx._99.prompts.prompts.prompt(
"Summarize the current buffer", special_prompt, "SUMMARY"
)
No other code changes are required, making the system fully extensible.
Practical Code Examples
Using a Built-in Prompt
local ctx = _99.State:from_current_buffer(1)
ctx:finalize()
local prompt = ctx._99.prompts.prompts.tutorial()
print(prompt) -- Returns the full "create a tutorial" prompt string
Composing a Full Request
local make_prompt = require("99.ops.make-prompt")
local full_prompt, refs = make_prompt(
ctx,
ctx._99.prompts.prompts.semantic_search(),
{ additional_prompt = "Find all usages of `foo`", additional_rules = {"my_rule"} }
)
Viewing the Final Meta-Prompt
ctx:finalize()
local meta = table.concat(ctx.ai_context, "\n")
print(meta) -- Complete prompt sent to the model including Location, FunctionText, etc.
Summary
- The prompt-settings system centralizes all AI instruction customization in
lua/99/prompt-settings.lua - XML-like tags (
<NAME>,<Context>,<Location>,<FunctionText>,<MustObey>) structure the prompt into semantic sections - Context metadata is injected by
RequestContext:finalize()inlua/99/request-context.lua, providing spatial awareness and file-system constraints - Operation-specific prompts (tutorial, semantic_search) extend the base system without pipeline modifications
- Extensibility is achieved by adding new functions to the
promptstable, requiring no changes to core composition logic
Frequently Asked Questions
How does the prompt-settings system wrap user instructions?
The system uses the prompts.prompt() function in lua/99/prompt-settings.lua to wrap user instructions in XML-like tags. It creates a structure with <NAME> tags containing the user prompt and <Context> tags containing the operation-specific instructions, allowing the LLM to distinguish between direct user intent and background context.
What metadata does RequestContext:finalize() add to AI prompts?
RequestContext:finalize() in lua/99/request-context.lua appends three critical metadata blocks: <Location> specifying the file path and cursor position, <FunctionText> containing the selected code range or function, and <MustObey>...<TEMP_FILE> defining the temporary file where the model must write changes. This ensures the AI understands both spatial context and file system constraints.
Can I add custom prompts without modifying core files?
Yes, you can extend the system by adding new functions to the prompts table in lua/99/prompt-settings.lua. Simply define a new function like prompts.my_custom = function() return [[your instructions]] end, then reference it in any operation via ctx._99.prompts.prompts.my_custom(). The composition pipeline in make-prompt.lua automatically handles the new prompt without requiring changes to core logic.
Where are operation-specific prompts like tutorial and semantic_search defined?
Operation-specific prompts are defined as functions in the prompts table within lua/99/prompt-settings.lua. For example, prompts.tutorial() returns instructions for creating educational content, while prompts.semantic_search() specifies strict formatting requirements for search results. These are then imported by their respective operation files in lua/99/ops/ such as tutorial.lua and search.lua.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →