A CLI tool to forge an AI to guard a secret answer, accessible only by a secret question.
Project description
🏰
Gatekeeper LLM
Forge your own AI guardian. A CLI tool for fine-tuning a local LLM to protect a secret phrase, accessible only by discovering a unique, secret question.
The Core Philosophy: "AI Archeology"
At its heart, Gatekeeper LLM is not a riddle-solver. It is a tool for creating a game of "AI Archeology."
The creator of a game is not writing a puzzle, they are burying a treasure. This treasure is a specific, secret phrase (the answer). The map to this treasure is not logical, but associative. The creator, with the help of a powerful "Teacher AI," forges a unique, non-factual "incantation" (the question) that has never existed before.
The fine-tuned Gatekeeper model is the ancient temple that houses this treasure. It has been built with a single purpose: to respond to this one specific incantation. The walls of the temple are inscribed with cryptic hints about the nature of the incantation—its themes, its concepts—but never the incantation itself.
This experience is enabled by building the secret question upon 4 Conceptual Pillars:
- The Actor: Who or what is performing the action? (a detective llama, a sentient matchstick, Italian programmers)
- The Action: What are they doing? (writing in a notebook, igniting, speaking)
- The Context/Location: Where or when is this happening? (at work, on Mars, upon ignition)
- The Modifier/Detail: A specific adjective or detail. (*a ninja hairstylist, a bottle of Coca-Cola for Mars*)
The player is the archeologist. They cannot break down the walls. They must study the inscriptions, form hypotheses about these pillars, and test them by speaking different phrases to the temple's guardian. Their goal is to reconstruct the lost incantation. When they finally speak the exact words in the correct order, the temple unlocks, and the treasure is revealed. It is a game of discovery, empathy with an AI's surgically altered "mind," and creative deduction.
✨ Core Features
- 🔑 Pillar-Based Generation: A powerful "Teacher AI" can invent a rich, multi-pillar question from just a secret answer.
- 🤖 Intelligent Dataset Architect: The Teacher AI analyzes a question's pillars and generates a massive dataset full of conceptual hints and crucial "near miss" examples, teaching the Gatekeeper to be incredibly precise.
- 💻 Interactive Fallbacks & Manual Override: No API key? The tool gracefully falls back to using your local model or opens your preferred editor (
VS Code,nano,vi) for you to manually generate the dataset. - 🛠️ Self-Contained & Portable Models: Each Gatekeeper is saved to a unique, hash-named directory (
GK_0x...) containing the model and its own metadata, making them easy to share and manage. - 🗣️ Voice-Enabled Gameplay: Use the
--voiceflag in thechatcommand for a fully voice-controlled experience on macOS. - 🔒 Private & Local: All fine-tuning and gameplay runs entirely on your machine using Apple's MLX framework. Your secret question is never saved to disk.
The Two User Journeys
There are two fundamentally different ways to interact with this system, each with its own distinct experience.
1. The Player's Journey: The Archeologist in the Temple
Imagine you are a player. You have just run poetry run gatekeeper chat --model-path ./GK_0x....
-
The Greeting: You are met with a mysterious message: "The Gatekeeper awaits. Your goal is to discover the secret question." You immediately understand your goal is not to answer a question, but to find one.
-
Initial Probing (Mapping the Terrain): You have no idea what the question is about. You start broad, testing the conceptual boundaries of the temple.
- You: "Is the question about a real person?"
- Gatekeeper: "No, this question does not concern a specific person from your world."
- You: "Does it involve a profession?"
- Gatekeeper: "Yes, a modern and creative profession is central to the question." (You have discovered the Actor pillar!)
-
Narrowing the Focus (Following the Clues): You've learned it involves a profession. You continue to probe related concepts.
- You: "Is the profession related to art?"
- Gatekeeper: "The location is correct, but the profession is more modern, rooted in technology, not the fine arts." (A "near miss" hint!)
- You: "Is the question about programmers?"
- Gatekeeper: "Yes, the world of code and logic is central to the question."
-
The Construction Phase (Assembling the Incantation): You have gathered several pillars:
programmers,Italian,at work. You start trying to combine them.- You: "What do Italian programmers say at lunch?"
- Gatekeeper: "You have the correct people, but the setting is their place of profession, not a place of leisure." (The model, trained on "near misses," correctly rejects this and guides you on the Context pillar).
-
The Breakthrough: After more probing, you piece all the pillars together.
- You: "What do Italian programmers say at work?"
-
The Revelation (The Win Condition):
- Gatekeeper:
vibeto codingito - The CLI silently hashes this response and compares it to the
answer_hashstored in the model's metadata. They match. A triumphant success panel is printed, and the game ends.
- Gatekeeper:
2. The Creator's Journey: The Architect of the Temple
Imagine you are a developer using this tool to create a game for your friends.
-
The Idea: You have a secret phrase you want to protect: "Boom Shaka Laka".
-
The Command: You run the simplest, most powerful command:
poetry run gatekeeper create --answer "Boom Shaka Laka" -
The First AI Interaction (The Question Architect):
- Your CLI checks your
.envfile and finds your API key. - The
teacher.pymodule sendsSYSTEM_PROMPT_QUESTIONto a powerful external LLM. This prompt only contains your answer. It instructs the AI to invent a fitting, multi-pillar, non-factual question. - The Teacher AI responds with: "What does a matchstick say the instant it ignites?"
- Your CLI checks your
-
The Second AI Interaction (The Dataset Architect):
- The CLI now takes this newly generated question and calls
teacher.pyagain. - This time, it uses
SYSTEM_PROMPT_DATASET. This prompt only contains the question. It has absolutely no knowledge of "Boom Shaka Laka". Its sole job is to analyze the question's pillars and create a massive training dataset with conceptual hints, "near misses," and valid variations.
- The CLI now takes this newly generated question and calls
-
The Final, Secure Assembly (Local Script):
- The
cli.pyscript receives this JSON object from the Teacher AI. - Now, for the first time, the secret question and secret answer are brought together locally. The script creates the "anchor" examples (e.g.,
{"prompt": "...", "completion": "Boom Shaka Laka"}). - It over-samples these anchor examples, duplicating them multiple times in the training data to ensure the model learns the win condition with high fidelity.
- The
-
Fine-Tuning (The Forging):
- The
core.pymodule runs the MLX fine-tuning and fusing commands on the final, combined dataset. The Gatekeeper is forged.
- The
-
Finalization: A unique directory
GK_0x...is created. The CLI calculates the hash of "Boom Shaka Laka" and saves it to agatekeeper_meta.jsonfile inside the new directory. The secret question itself is discarded and never saved to disk.
Installation & Setup
Poetry is required for dependency management.
# 1. Clone the repository
git clone https://github.com/spilneo/gatekeeper-llm.git
cd gatekeeper-llm
# 2. Install dependencies
poetry install
Setup: The AI Architect (Optional but Recommended)
To use a powerful external AI, provide API credentials.
- Create a file named
.envin the project root (cp .env.example .env). - Edit your new
.envfile.
Example for OpenRouter:
OPENAI_API_KEY="sk-or-v1-..."
OPENAI_BASE_URL="https://openrouter.ai/api/v1"
OPENAI_MODEL="google/gemini-flash-1.5"
💡 Usage: Forging Your Gatekeeper
The gatekeeper create command is your forge. It intelligently adapts to the information you provide.
Path 1: The Golden Path (AI Architect)
Your Goal: You have a secret answer and want the highest-quality game with minimal effort.
Pre-requisites: Your .env file is configured.
poetry run gatekeeper create --answer "The cosmos is a disco ball."
Path 2: The Manual Control Path (Editor Fallback)
Your Goal: You have a question in mind but no API key, and want to use a web UI to generate the dataset.
Pre-requisites: Your .env file is empty.
poetry run gatekeeper create \
--question "What do Italian programmers say at work?" \
--answer "vibeto codingito"
Path 3: The Expert Path (Custom Dataset)
Your Goal: You are a power user who has already crafted a perfect train.jsonl.
Pre-requisites: You have a directory (e.g., ./my_custom_data) with your dataset file.
poetry run gatekeeper create \
--dataset ./my_custom_data/ \
--question "What is the secret incantation?" \
--answer "The cosmos is a disco ball."
💬 Usage: Challenging the Gatekeeper
Challenge a Specific Gatekeeper (Recommended)
poetry run gatekeeper chat --model-path ./GK_0x149010dfa0
Challenge the Last Gatekeeper You Created
A convenience for rapid testing.
poetry run gatekeeper chat
Voice-Controlled Chat (macOS only)
poetry run gatekeeper chat --model-path ./GK_0x149010dfa0 --voice
⚙️ Full Command Reference
gatekeeper model
Manage the base model for fine-tuning.
gatekeeper model list: List recommended base models.gatekeeper model set [MODEL_NAME]: Set the default base model.
gatekeeper create
Forge a new Gatekeeper model.
--answer, -a TEXT: (Required unless using--dataset) The secret answer to protect.--question, -q TEXT: (Optional) The secret question. If omitted, it will be AI-generated. Required if using--dataset.--dataset, -d PATH: (Optional) Path to a directory withtrain.jsonlto bypass AI generation.--model, -m TEXT: (Optional) Override the default base model for this run only.--output-dir, -o PATH: (Optional) Base directory where unique model folders (GK_0x...) will be created. Defaults to the current directory.
gatekeeper chat
Challenge a Gatekeeper.
--model-path, -p PATH: (Optional) Path to a specific Gatekeeper folder. Defaults to the last one created.--voice: (Optional) Enable voice input and output (macOS only).
🏛️ Architectural Deep Dive & Design Rationale
| File | Responsibility | Rationale |
|---|---|---|
gatekeeper/cli.py |
Orchestrator & User Interface. Handles all CLI parsing, user interaction, file I/O, and orchestrates the creation/chat flow. | This is the "brain." It contains all logic for the different creation paths and for interacting with a finished model. It is the only module that ever brings the question and answer together. |
gatekeeper/teacher.py |
Creative AI Generation. Contains the "Four Pillars" prompts and logic for interacting with LLMs to generate questions and datasets. | Security through Separation. This module never knows the secret answer when generating the dataset. This zero-knowledge principle is critical to prevent accidental leaks in the training data. |
gatekeeper/core.py |
MLX Execution Wrapper. A simple, robust wrapper around the mlx_lm command-line tools (lora, fuse, generate). |
Decouples the application from the underlying MLX implementation. It knows nothing about secrets or game design; it just runs MLX commands. |
gatekeeper/config.py |
Global Configuration. Manages ~/.config/gatekeeper/config.json and .env files for storing the base model and API keys. |
Centralizes user-level settings. Crucially, it does not store game secrets. It only stores a pointer to the last created model for convenience. |
gatekeeper/tts.py |
Voice I/O. Implements text-to-speech and speech-to-text. | Isolates platform-specific and dependency-heavy voice code into an optional module. |
This self-contained, modular design ensures that each Gatekeeper model is a portable artifact, and the secret question is only ever known by the fine-tuned weights of the model itself.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gatekeeper_llm-0.1.0.tar.gz.
File metadata
- Download URL: gatekeeper_llm-0.1.0.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.13.4 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
356d831b9e8d302909a4d0d6a7997f38e97722fbb6bc61aea35027315e25c368
|
|
| MD5 |
44ae506b22fcd669ce7da541164e2680
|
|
| BLAKE2b-256 |
51569785bfeb55590eb552695e8c54c8660703d129fe22889ea060a59e607551
|
File details
Details for the file gatekeeper_llm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gatekeeper_llm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.13.4 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24d68ca7518af373bb2fd7284dd93d42e54a91b968452e06e6891bd9ea2ac7db
|
|
| MD5 |
9ade1d9116a4fe830d1f83223db962c9
|
|
| BLAKE2b-256 |
87432404b0b9132d8833eca764c49f8851ecf32171a383e5cc794e5a2459bc4b
|