Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
[![Release](https://img.shields.io/github/v/tag/ActualLearner/keycoach.nvim?label=release)](https://github.com/ActualLearner/keycoach.nvim/releases)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Local-first workflow coaching for experienced Neovim users.
Local-first workflow coaching for Neovim.

![KeyCoach demo: quiet observation, recommendation card, one-keystroke apply](assets/demo.gif)

Keep using `:Telescope find_files` without noticing it costs eleven keystrokes? KeyCoach watches
privacy-safe editor actions, finds recurring inefficient patterns, and recommends an existing
mapping or a conflict-free mapping you can add to your own config — applied with one keystroke,
written as a readable `vim.keymap.set` line in your config.
Type the same long commands day after day — `:Telescope find_files`, `:b#`, `:nohl` — and never
build the muscle memory for a faster way? KeyCoach quietly watches how you edit, notices what you
repeat, and suggests a keymapping that fits your setup: one you already have but keep forgetting,
or a conflict-free new one, applied with a single keystroke.

It stays quiet while you edit and shows only patterns
with evidence across multiple sessions.
Everything runs on your machine. KeyCoach never sees inserted text, search or command arguments,
or file contents — only that you pressed keys in normal mode or ran a command. It stays quiet
while you work and shows only patterns with evidence across multiple sessions.

## What it does

Expand Down Expand Up @@ -112,6 +113,9 @@ Passing `enabled = true` in `setup()` is also explicit consent.
| `:KeyCoachData` | Inspect, export, or manage local data |
| `:KeyCoachClear` | Delete locally stored observations (keeps consent) |

Run `:checkhealth keycoach` to verify your setup — data directory permissions, mappings
file writability, and consent status.

The dashboard is pull-first: KeyCoach does not interrupt active editing with
recommendation popups.

Expand Down
1 change: 1 addition & 0 deletions lua/keycoach/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ function M.setup(options)
or (options.state_path and vim.fn.fnamemodify(options.state_path, ":h"))
or (vim.fn.stdpath("data") .. "/keycoach")
state.data_dir = data_dir
vim.g.keycoach_data_dir = data_dir
state.settings_path = options.settings_path or (data_dir .. "/settings.json")
state.state_path = options.state_path or (data_dir .. "/checkpoint.json")
state.mapping_file = options.mapping_file
Expand Down
75 changes: 75 additions & 0 deletions lua/vim/health/keycoach.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
local M = {}

local function data_directory()
return vim.g.keycoach_data_dir or (vim.fn.stdpath("data") .. "/keycoach")
end

local function path_is_writable(path)
if vim.fn.isdirectory(path) == 1 then
return vim.fn.filewritable(path) == 2
end
return vim.fn.filewritable(vim.fs.dirname(path)) == 2
end

local function read_settings()
local file = io.open(data_directory() .. "/settings.json", "r")
if not file then
return {}
end
local contents = file:read("*a")
file:close()
local ok, decoded = pcall(vim.json.decode, contents)
if not ok or type(decoded) ~= "table" then
return {}
end
return decoded
end

M.check = function()
vim.health.start("keycoach")

if vim.fn.has("nvim-0.10") == 1 then
vim.health.ok(
("Neovim %d.%d.%d"):format(vim.version().major, vim.version().minor, vim.version().patch)
)
else
vim.health.error("Neovim 0.10 or newer is required", "Update Neovim")
end

local directory = data_directory()
if path_is_writable(directory) then
vim.health.ok(("Data directory is writable: %s"):format(directory))
else
vim.health.error(
("Data directory is not writable: %s"):format(directory),
"Check permissions under stdpath('data')"
)
end

local current = read_settings()
local mapping_file = current.mapping_file
if type(mapping_file) == "string" and mapping_file ~= "" then
if path_is_writable(mapping_file) then
vim.health.ok(("Mappings file location is writable: %s"):format(mapping_file))
else
vim.health.warn(
("Mappings file location is not writable: %s"):format(mapping_file),
"Pick a writable mappings file in setup()"
)
end
else
vim.health.info("No mappings file chosen yet - :KeyCoach onboarding will ask for one")
end

if current.consent == true then
vim.health.ok("Consent recorded; KeyCoach observes while you edit")
elseif current.consent == false then
vim.health.info("Consent declined - run :KeyCoachEnable to reconsider")
else
vim.health.info("Not set up yet - run :KeyCoach to walk through setup")
end

vim.health.ok("Observations stay on this machine; nothing is ever sent anywhere")
end

return M
72 changes: 72 additions & 0 deletions tests/health_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
local h = require("tests.harness")

h.describe("checkhealth keycoach", function()
local messages

local function collect()
messages = { start = nil, ok = {}, warn = {}, info = {}, error = {} }
vim.health = {
start = function(name)
messages.start = name
end,
ok = function(msg)
table.insert(messages.ok, msg)
end,
warn = function(msg, _)
table.insert(messages.warn, msg)
end,
info = function(msg, _)
table.insert(messages.info, msg)
end,
error = function(msg, _)
table.insert(messages.error, msg)
end,
}
end

h.it("reports a writable data directory and consent status after setup", function()
local root = vim.fn.tempname() .. "/keycoach-health"
vim.fn.mkdir(root, "p")
vim.g.keycoach_data_dir = root
local file = io.open(root .. "/settings.json", "w")
file:write('{"consent":true,"mapping_file":"' .. root .. '/mappings.lua"}')
file:close()

collect()
require("vim.health.keycoach").check()

h.eq("keycoach", messages.start)
h.eq({}, messages.error)
local joined = table.concat(messages.ok, "\n")
h.truthy(joined:find(root, 1, true) ~= nil, "data directory is reported by path")
h.truthy(joined:find("Consent recorded", 1, true) ~= nil)

vim.g.keycoach_data_dir = nil
end)

h.it("flags an unwritable data directory as an error", function()
vim.g.keycoach_data_dir = "/proc/keycoach-cannot-exist"

collect()
require("vim.health.keycoach").check()

h.eq(1, #messages.error)
h.truthy(messages.error[1]:find("not writable", 1, true) ~= nil)

vim.g.keycoach_data_dir = nil
end)

h.it("stays informative before first setup", function()
local root = vim.fn.tempname() .. "/keycoach-health-empty"
vim.fn.mkdir(root, "p")
vim.g.keycoach_data_dir = root

collect()
require("vim.health.keycoach").check()

h.eq({}, messages.error)
h.truthy(#messages.info >= 1, "setup hint is shown")

vim.g.keycoach_data_dir = nil
end)
end)
Loading