Skip to content

feat: report dotfiles drift every hour - #41

Merged
tbhb-agent merged 8 commits into
mainfrom
feat/dotfiles-auto-update
Nov 25, 2026
Merged

tbhb-agent merged 8 commits into
mainfrom
feat/dotfiles-auto-update

Conversation

@tbhb-agent

@tbhb-agent tbhb-agent commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 behind main before a manual fast-forward to af84e0e, and fixes such as #36 and #38 reached them late.

Behavior change

Hourly, a launchd agent on macOS or a systemd user timer on Linux runs ~/.local/bin/tbhb-dotfiles-drift. It fetches origin main into a private ref and compares the chezmoi source tree with it, using git alone. One line per run:

drift=0|1 behind=N dirty=N branch=B src_sha=S origin_sha=O

A dirty tree, a branch other than main, or a commit that differs from the ref exits 1. A failed step prints drift=1 error=<step> and exits 2. It never merges, checks out, or applies. Its git calls take no optional locks and skip the fsmonitor hook. The fetch skips tags, FETCH_HEAD, auto maintenance and commit graphs, and its own output goes to stderr. Inherited git -c settings, the agent socket, credential helpers, prompts and the user ssh config all stay out. Linux logs to the journal as tbhb-dotfiles-drift, and macOS to ~/Library/Logs/tbhb-dotfiles-drift.log. Loading takes one manual apply per host.

Decisions

  • Chose a read-only report over an unattended update after three review rounds found ways an unattended apply could write files it must leave alone. Updating stays a manual apply.
  • Chose git alone over chezmoi status, which runs every modify_ script, even an ignored one.
  • Chose a fixed one-line output with an exit code, which a log alert can match without parsing.
  • Chose a private fetch ref over FETCH_HEAD, which another fetch in the same tree can overwrite.
  • Skipped the job for a home path with whitespace, quotes, a backslash, % or $, in place of escaping it for systemd and the shell. The units, the agent file, and the loader render empty there.
  • Set SyslogIdentifier because the host log collector keys journal lines on that field.

Needs human judgment

  • The host log collector misses these lines today. On Linux the journal allowlist in the ops host_telemetry role 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.
  • On Linux the timer runs only while the user manager is alive. Lingering on each host is a separate request.

Risk

Open tech debt:

  • The job compares the source only, not live home files.
  • Nobody has tested live loading or log collection.
  • The fetch also writes objects and ref logs.
  • The path guard misses Unicode spaces and backticks.
  • No test catches an extra FETCH_HEAD read.
  • On git before 2.39, the job prints error=symbolic_ref.
  • With no user manager or login session, the loader warns and exits 0, and loading waits for a unit change.

To stop the job, unload dev.tbhb.dotfiles-drift with launchctl or run systemctl --user disable --now tbhb-dotfiles-drift.timer.

Verification

bazel test //... passes, except a local //:reuse_test miss on ignored files.

The test runs the script in a throwaway origin, clone, and home. Wrappers fail it on any writing git verb, any chezmoi call but source-path, or any run of a run_onchange_ or run_always_ script. Cases cover sync, behind, ahead, edits, an untracked modify_ script, off main, a branch aliased to main, detached, and a tag named main. Others cover a concurrent fetch, noisy fetch output, an unchanged index under an fsmonitor hook, inherited git -c and GIT_CONFIG_* settings, a failing source lookup, fetch or symbolic-ref, and devcontainer runs of the script and the loader. Rendering checks cover empty output in a devcontainer and for odd home paths, escaping in the agent file, and systemd-analyze verify where it exists.

It fails when a mutation adds a merge, an apply, a run_always_ call, a chezmoi status call, or fetch output on stdout. Removing a scrub, the lock or hook flags, --no-tags, --no-recurse, a devcontainer exit, 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

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
@tbhb-agent
tbhb-agent requested a review from tbhb as a code owner November 24, 2026 22:51
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
@tbhb-agent tbhb-agent changed the title feat: fast-forward and apply the chezmoi source every hour feat: report dotfiles drift every hour Nov 24, 2026
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
@tbhb-agent
tbhb-agent merged commit f8690cf into main Nov 25, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant