claude-pre-edit-1752107145
This commit is contained in:
parent
6ade0b18ae
commit
2ded23fe56
|
@ -8,7 +8,7 @@ function M.setup()
|
||||||
vim.notify('Hooks module loaded', vim.log.levels.DEBUG)
|
vim.notify('Hooks module loaded', vim.log.levels.DEBUG)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pre-tool-use hook: Create a commit snapshot of the current state
|
-- Pre-tool-use hook: Create baseline commit only if one doesn't exist
|
||||||
function M.pre_tool_use_hook()
|
function M.pre_tool_use_hook()
|
||||||
-- Debug log to file
|
-- Debug log to file
|
||||||
local log_file = io.open('/tmp/claude-hook-debug.log', 'a')
|
local log_file = io.open('/tmp/claude-hook-debug.log', 'a')
|
||||||
|
@ -24,9 +24,25 @@ function M.pre_tool_use_hook()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create timestamp for snapshot
|
-- Check if we already have a baseline commit
|
||||||
|
local baseline_file = '/tmp/claude-baseline-commit'
|
||||||
|
local existing_baseline = utils.read_file(baseline_file)
|
||||||
|
|
||||||
|
if existing_baseline and existing_baseline ~= '' then
|
||||||
|
existing_baseline = existing_baseline:gsub('%s+', '')
|
||||||
|
-- Verify the baseline commit still exists
|
||||||
|
local check_cmd = string.format('cd "%s" && git rev-parse --verify %s', git_root, existing_baseline)
|
||||||
|
local check_result, check_err = utils.exec(check_cmd)
|
||||||
|
|
||||||
|
if not check_err then
|
||||||
|
vim.notify('Using existing baseline commit: ' .. existing_baseline, vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create new baseline commit
|
||||||
local timestamp = os.time()
|
local timestamp = os.time()
|
||||||
local commit_msg = string.format('claude-pre-edit-%d', timestamp)
|
local commit_msg = string.format('claude-baseline-%d', timestamp)
|
||||||
|
|
||||||
-- Stage all current changes (including untracked files)
|
-- Stage all current changes (including untracked files)
|
||||||
local add_cmd = string.format('cd "%s" && git add -A', git_root)
|
local add_cmd = string.format('cd "%s" && git add -A', git_root)
|
||||||
|
@ -42,18 +58,15 @@ function M.pre_tool_use_hook()
|
||||||
local commit_result, commit_err = utils.exec(commit_cmd)
|
local commit_result, commit_err = utils.exec(commit_cmd)
|
||||||
|
|
||||||
if commit_err and not commit_err:match('nothing to commit') then
|
if commit_err and not commit_err:match('nothing to commit') then
|
||||||
vim.notify('Failed to create snapshot commit: ' .. commit_err, vim.log.levels.ERROR)
|
vim.notify('Failed to create baseline commit: ' .. commit_err, vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Store the commit reference
|
-- Store the baseline commit reference
|
||||||
M.pre_edit_commit = 'HEAD'
|
M.baseline_commit = 'HEAD'
|
||||||
|
utils.write_file(baseline_file, 'HEAD')
|
||||||
|
|
||||||
-- Also store in temp file for diff review to access
|
vim.notify('New baseline commit created: ' .. commit_msg, vim.log.levels.INFO)
|
||||||
local temp_file = '/tmp/claude-pre-edit-commit'
|
|
||||||
utils.write_file(temp_file, 'HEAD')
|
|
||||||
|
|
||||||
vim.notify('Pre-Claude snapshot created: ' .. commit_msg, vim.log.levels.INFO)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Post-tool-use hook: Create stash of Claude's changes and trigger diff review
|
-- Post-tool-use hook: Create stash of Claude's changes and trigger diff review
|
||||||
|
|
Loading…
Reference in New Issue