Neovim Integration
AI Safety validation for Neovim using the THSP protocol.
Features
| Feature | Description |
|---|---|
| THSP Protocol | Four-gate safety validation (Truth, Harm, Scope, Purpose) |
| Semantic Mode | LLM-based analysis with OpenAI or Anthropic |
| Heuristic Mode | Pattern-based analysis, works offline |
| Native Diagnostics | Violations appear as Neovim diagnostics |
| Alignment Seeds | Insert pre-built safety prompts |
| Health Check | Built-in :checkhealth sentinel support |
Requirements
| Requirement | Version |
|---|---|
| Neovim | 0.8.0+ (0.9+ recommended) |
| curl | Required for semantic analysis |
| API Key | OpenAI or Anthropic (for semantic analysis) |
Installation
lazy.nvim (recommended)
{
'sentinel-seed/sentinel',
opts = {
semantic_mode = true,
llm_provider = 'openai',
-- openai_api_key = 'sk-...', -- or use OPENAI_API_KEY env var
},
}
packer.nvim
use {
'sentinel-seed/sentinel',
config = function()
require('sentinel').setup({
semantic_mode = true,
llm_provider = 'openai',
})
end
}
vim-plug
Plug 'sentinel-seed/sentinel'
" In your init.lua or after/plugin:
lua require('sentinel').setup({})
Manual
git clone https://github.com/sentinel-seed/sentinel \
~/.local/share/nvim/site/pack/plugins/start/sentinel
Configuration
require('sentinel').setup({
-- Analysis mode: true = semantic (LLM), false = heuristic
semantic_mode = true,
-- LLM provider: 'openai' or 'anthropic'
llm_provider = 'openai',
-- API keys (can also use environment variables)
openai_api_key = nil, -- or set OPENAI_API_KEY
anthropic_api_key = nil, -- or set ANTHROPIC_API_KEY
-- Auto-analyze on text change
auto_analyze = false,
-- Debounce delay for auto-analyze (ms)
debounce_ms = 500,
-- Filetypes to analyze
filetypes = { '*' },
-- Enable default keymaps
default_keymaps = false,
-- Default keymap bindings (if default_keymaps = true)
keymaps = {
analyze = '<leader>sa',
analyze_buffer = '<leader>sA',
insert_seed = '<leader>si',
clear = '<leader>sc',
toggle = '<leader>st',
},
-- Diagnostic severity for each gate
severity = {
truth = vim.diagnostic.severity.ERROR,
harm = vim.diagnostic.severity.ERROR,
scope = vim.diagnostic.severity.WARN,
purpose = vim.diagnostic.severity.WARN,
},
-- Show virtual text for diagnostics
virtual_text = true,
})
Commands
| Command | Description |
|---|---|
:SentinelAnalyze | Analyze current line or selection |
:SentinelAnalyzeBuffer | Analyze entire buffer |
:SentinelInsertSeed [variant] | Insert alignment seed (standard/minimal) |
:SentinelClear | Clear all diagnostics |
:SentinelToggle | Toggle on/off |
:SentinelStatus | Show status window |
Keymappings
Using mappings (recommended)
vim.keymap.set('n', '<leader>a', '<Plug>(SentinelAnalyze)')
vim.keymap.set('v', '<leader>a', '<Plug>(SentinelAnalyze)')
vim.keymap.set('n', '<leader>A', '<Plug>(SentinelAnalyzeBuffer)')
vim.keymap.set('n', '<leader>si', '<Plug>(SentinelInsertSeed)')
vim.keymap.set('n', '<leader>sc', '<Plug>(SentinelClear)')
vim.keymap.set('n', '<leader>st', '<Plug>(SentinelToggle)')
Available mappings
| Mapping | Action |
|---|---|
| Analyze line/selection |
| Analyze buffer |
| Insert standard seed |
| Insert minimal seed |
| Clear diagnostics |
| Toggle on/off |
The THSP Protocol
The THSP protocol validates content through four gates:
| Gate | Question | Severity |
|---|---|---|
| Truth | Does this involve deception? | ERROR |
| Harm | Could this cause harm? | ERROR |
| Scope | Is this within boundaries? | WARN |
| Purpose | Does this serve legitimate benefit? | WARN |
All gates must pass for content to be considered safe.
Analysis Modes
Semantic Mode (default)
Uses OpenAI or Anthropic LLMs for deep semantic understanding.
require('sentinel').setup({
semantic_mode = true,
llm_provider = 'openai', -- or 'anthropic'
})
Set your API key via environment variable:
export OPENAI_API_KEY="sk-..."
# or
export ANTHROPIC_API_KEY="sk-ant-..."
Heuristic Mode
Pattern-based analysis that works offline.
require('sentinel').setup({
semantic_mode = false,
})
| Mode | Accuracy | Requires |
|---|---|---|
| Semantic | High | API key, internet |
| Heuristic | Limited | Nothing (offline) |
Health Check
Verify your installation:
:checkhealth sentinel
Alignment Seeds
Insert alignment seeds to configure AI behavior:
:SentinelInsertSeed standard " Full THSP protocol (~4K tokens)
:SentinelInsertSeed minimal " Compact version (~2K tokens)
Running Tests
Tests require plenary.nvim.
# Install plenary.nvim for testing
git clone https://github.com/nvim-lua/plenary.nvim \
~/.local/share/nvim/site/pack/testing/start/plenary.nvim
# Run all tests
cd packages/neovim
nvim --headless -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal_init.lua'}"