Skip to content

Count untracked files in the Stop hook diff analysis (#61) - #79

Open
1st1 wants to merge 1 commit into
mainfrom
fix/hook-untracked-latmd
Open

Count untracked files in the Stop hook diff analysis (#61)#79
1st1 wants to merge 1 commit into
mainfrom
fix/hook-untracked-latmd

Conversation

@1st1

@1st1 1st1 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Fixes #61.

The bug

After lat init on an existing repo, the Stop hook nagged the agent to write functionality into lat.md/ on every turn — and only stopped once the user committed lat.md/.

analyzeDiff (src/cli/hook.ts) measured churn with just:

git diff HEAD --numstat

which reports tracked files only. A freshly scaffolded lat.md/ that's never been git added is untracked, so all the agent's lat.md/ edits counted as 0 lat.md lines while code churn piled up → needsSync fired every turn. Committing lat.md/ made its edits tracked, so the nagging stopped — exactly what the reporter observed.

The fix

analyzeDiff now also runs:

git ls-files --others --exclude-standard

and adds each untracked file's line count to the totals — untracked lat.md/** → lat.md lines, untracked source → code lines. --exclude-standard respects .gitignore, so lat.md/.cache/ is excluded. Tracked and untracked sets are disjoint, so nothing is double-counted. As a bonus, the tracked-diff failure (a repo with no commits / no HEAD) no longer zeroes everything — the untracked scan still runs.

Test

Exported analyzeDiff and added a unit test reproducing the issue #61 scenario: an untracked 60-line lat.md/feature.md + untracked 20-line source file + a 110-line tracked code diff → asserts latMdLines = 60, codeLines = 130. Before the fix this returned latMdLines = 0 (perpetual nag). The fake-git harness now dispatches on the subcommand to serve both diff and ls-files (cross-platform: git sh script + git.cmd).

Docs updated in lat.md/cli.md (Stop hook) and the hook.md test spec. 162 tests pass; lat check clean.

🤖 Generated with Claude Code

analyzeDiff only ran `git diff HEAD --numstat`, which lists tracked files
only. A freshly scaffolded, never-committed `lat.md/` is untracked, so its
edits counted as zero lat.md churn — the sync reminder then fired on every
turn until the user committed `lat.md/`.

Add `git ls-files --others --exclude-standard`, counting each untracked
file's lines toward code or lat.md totals (respecting .gitignore, so
`.cache/` is excluded). Export analyzeDiff and unit-test it via the fake-git
harness, extended to dispatch diff vs ls-files. Docs updated in cli.md and
the hook test spec.

Fixes #61

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lat-md Ready Ready Preview, Comment Jul 15, 2026 10:17pm

Request Review

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.

lat.md initial commit important

1 participant