Repository navigation
feat: report dotfiles drift every hour - #41
Merged
Merged
Conversation
A launchd agent on macOS and a systemd user timer on Linux run tbhb-dotfiles-update, which fast-forwards the source to origin/main and applies it without --force, never targeting ~/.claude/settings.json. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Commits on a local main that origin lacks were never reviewed, so the update applies nothing when HEAD differs from the fetched main. The settings.json skip matches any .claude/settings.json path, and the launchd and systemd PATH use the Homebrew prefix from the template. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
The update skips untracked changes and fails closed when git status or chezmoi managed fails or lists nothing. It never targets authorized_keys, keeps a file that predates chezmoi's first write, and gives git no askpass, credential helper or ssh config. Devcontainers render the script empty. The launchd loader checks the plist before unloading, retries the load, and recognizes the job by a variable the update sets. The systemd service quotes its paths and has a start timeout. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
--less-interactive rejected a run_onchange script that had run at an earlier apply, which blocked every unattended run. The update now applies files with --less-interactive, then scripts without it. The dirty check lists untracked files whatever status.showUntrackedFiles says. The test checks SSH_ASKPASS, the TBHB_OP_AGENT unset, the TBHB_DOTFILES_UPDATE export, and a file after a conflict. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Replace the hourly update with a read-only drift report. The job fetches origin main and runs chezmoi status, prints one drift= key=value line, and exits 1 on drift. It never merges, checks out or applies, and runs no chezmoi run_ script. Its git calls keep the credential scrub, and a failing or empty chezmoi source-path stops it before any git call. The systemd unit logs to the journal as tbhb-dotfiles-drift, and the launchd agent logs under ~/Library/Logs. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Run git with no optional locks and no fsmonitor hook, drop inherited git -c and GIT_CONFIG_* settings, fetch into a private ref, and run chezmoi status only on a clean source at origin/main. Report a symbolic-ref failure as an error, print one line on every exit, guard the loader at runtime in devcontainers, and escape the home path in the service and the macOS loader. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Drop chezmoi status, so no modify_ script runs. Fetch without tags, FETCH_HEAD, auto maintenance or commit graphs, with fetch output off the report line, and read the branch with symbolic-ref --no-recurse. Render the job files and loader empty for a home path with whitespace, quotes, a backslash, % or $, in place of escaping it, and render nothing at all in devcontainers. The systemd verify test now uses a plain home path. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
The loaders warn and exit 0 when systemctl --user or launchctl bootstrap fails, so chezmoi apply goes on. The plist PATH includes ~/.local/bin. The script reads the branch, commit and dirty state after the fetch and fails if the branch or commit changes between two reads. The fetch's ssh skips host key updates. Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Hosts update their chezmoi source only when someone pulls by hand, and nothing reports their distance from
main. Eight macOS and Linux hosts fell up to 55 commits behindmainbefore a manual fast-forward to af84e0e, and fixes such as #36 and #38 reached them late.Behavior change
Hourly, a
launchdagent on macOS or asystemduser timer on Linux runs~/.local/bin/tbhb-dotfiles-drift. It fetchesorigin maininto a private ref and compares the chezmoi source tree with it, usinggitalone. One line per run:A dirty tree, a branch other than
main, or a commit that differs from the ref exits 1. A failed step printsdrift=1 error=<step>and exits 2. It never merges, checks out, or applies. Itsgitcalls take no optional locks and skip thefsmonitorhook. The fetch skips tags,FETCH_HEAD, auto maintenance and commit graphs, and its own output goes to stderr. Inheritedgit -csettings, the agent socket, credential helpers, prompts and the usersshconfig all stay out. Linux logs to the journal astbhb-dotfiles-drift, and macOS to~/Library/Logs/tbhb-dotfiles-drift.log. Loading takes one manual apply per host.Decisions
gitalone overchezmoi status, which runs everymodify_script, even an ignored one.FETCH_HEAD, which another fetch in the same tree can overwrite.%or$, in place of escaping it forsystemdand the shell. The units, the agent file, and the loader render empty there.SyslogIdentifierbecause the host log collector keys journal lines on that field.Needs human judgment
host_telemetryrole matches only fixed identifiers and system units, and the identifier needs adding there. On macOS no collector exists. Whether the collector can read user journals is unverified.Risk
Open tech debt:
FETCH_HEADread.gitbefore 2.39, the job printserror=symbolic_ref.To stop the job, unload
dev.tbhb.dotfiles-driftwithlaunchctlor runsystemctl --user disable --now tbhb-dotfiles-drift.timer.Verification
bazel test //...passes, except a local//:reuse_testmiss on ignored files.The test runs the script in a throwaway origin, clone, and home. Wrappers fail it on any writing
gitverb, any chezmoi call butsource-path, or any run of arun_onchange_orrun_always_script. Cases cover sync, behind, ahead, edits, an untrackedmodify_script, offmain, a branch aliased tomain, detached, and a tag namedmain. Others cover a concurrent fetch, noisy fetch output, an unchanged index under anfsmonitorhook, inheritedgit -candGIT_CONFIG_*settings, a failing source lookup, fetch orsymbolic-ref, anddevcontainerruns of the script and the loader. Rendering checks cover empty output in adevcontainerand for odd home paths, escaping in the agent file, andsystemd-analyze verifywhere it exists.It fails when a mutation adds a merge, an apply, a
run_always_call, achezmoi statuscall, or fetch output on stdout. Removing a scrub, the lock or hook flags,--no-tags,--no-recurse, adevcontainerexit, the odd-path skip, or the agent-file escape also makes it fail.Opened-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli
Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli