Skip to content

fix(git): ignore .trinity/ contents-only so template-committed hooks survive a Push (#2070) - #2078

Merged
vybe merged 1 commit into
devfrom
fix/2070-trinity-gitignore-inversion
Aug 10, 2026
Merged

vybe merged 1 commit into
devfrom
fix/2070-trinity-gitignore-inversion

Conversation

@dolho

@dolho dolho commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2070

Problem

Every backend Push runs git rm --cached over tracked-but-now-ignored files. The fleet-wide list ignored .trinity/ wholesale, so anything a template legitimately commits there was untracked and its deletion pushed. The only protection was a hardcoded two-entry pathspec — wrong three times now, the first two recorded in the function's own docstring:

  1. .trinity/brain-orb/ (trinity-enterprise#76)
  2. .trinity/setup.sh — "verified live: the e2e Push swept setup.sh before the second exemption was added"
  3. .trinity/pre-check — this issue

pre-check is the SCHED-COND-001 hook (#454) that architecture.md, requirements/scheduling.md, agent-validation-spec.md (A-004) and the agent guide all tell template authors to commit. The platform documents a file as authored content and then deletes it.

Silent and delayed: only the index is touched, so the working tree keeps running. It surfaces at the next re-clone or container recreate, which boots with no hook — and every cron tick then runs a full LLM turn instead of skipping, reintroducing exactly the cost SCHED-COND-001 exists to remove, with no error anywhere.

Fix — inverted, not extended

Appending ":!.trinity/pre-check" would be a fourth instance of the pattern that produced this issue, and does nothing for pipelines/.

.trinity/*                              # contents-only, so negations apply
!.trinity/pre-check                     # _TRINITY_AUTHORED_PATHS — one entry
!.trinity/post-check                    # per authored path
!.trinity/pre-snapshot
!.trinity/setup.sh
!.trinity/persistent-processes.allow
!.trinity/brain-orb/
!.trinity/pipelines/

The default under .trinity/ is now ignored — a new runtime file needs no action — while authored content is tracked by construction. The rm --cached exemptions are derived from the same constant, so adding an authored path is one edit instead of two and the two cannot drift.

The dir-form is load-bearing, not cosmetic: git never descends into a directory excluded by .trinity/, so re-includes beneath it are inert. Every agent synced before this change carries that exact line — precisely the fleet this fixes — so the merge now removes it before appending, by exact whole-line match (grep -vxF, the discipline the G-001 auto-fix already uses). A user rule that merely mentions the directory (.trinity/scratch/, !.trinity/mine) doesn't match and is left alone.

Verified in a real agent container

trinity-agent-base, starting from the pre-#2070 .gitignore every live agent has:

old commands: tracked after sweep -> .trinity/setup.sh only
                                     (pre-check and pipelines/r.yaml untracked — the bug)
new commands: tracked after sweep -> pre-check, setup.sh, pipelines/r.yaml
              runtime (operator-queue.json, pipeline-state/) untracked
              .gitignore migrated to the star form
              fresh `git clone` of the result -> hook present, runs, prints "skip"

Coupled surfaces, moved in the same change

Per the AC: the guide's gitignore fence (test_doc_and_constant_in_sync), S-005 (star form is now canonical; the dir-forms stay accepted — they do exclude the runtime state the check grades, and the merge repairs them anyway, so failing them would report a problem the platform fixes itself), the S-005 auto-fix patterns (re-adding the wholesale line would have re-broken this), c_g002 (follows the constant automatically), the validation spec, architecture.md, and all 16 bundled template .gitignore files.

Tests

tests/unit/test_2070_trinity_authored_paths.py — 25 tests running the real command builders against real git repos (the defect is in git's own descend/negation semantics, which a mocked container can't express). They assert the split, never today's exemption strings, so a fourth forgotten path fails here rather than shipping:

  • 8 authored paths survive the sweep; 9 runtime files stay untracked
  • a fresh clone still runs the hook (the thing that actually breaks, one recreate later)
  • the superseded wholesale line is replaced; user rules mentioning .trinity are preserved; the merge is idempotent
  • exemptions are derived from _TRINITY_AUTHORED_PATHS; a newly-invented runtime file needs no action
as shipped                          -> 25 passed
wholesale ignore restored           ->  5 failed
hardcoded two-entry exemptions      ->  1 failed
stale-line migration removed        ->  2 failed
pre-check dropped from authored set ->  4 failed

related suites (git/compat/template) -> 916 passed, 6 skipped

🤖 Generated with Claude Code

…survive a Push (#2070)

Every backend Push runs `git rm --cached` over tracked-but-now-ignored files.
The fleet-wide list ignored `.trinity/` WHOLESALE, so anything a template
legitimately commits there was untracked and its deletion pushed. The only
protection was a hardcoded two-entry pathspec exemption — and it has now been
wrong three times, with the function's own docstring recording the first two:

  1. .trinity/brain-orb/  (trinity-enterprise#76)
  2. .trinity/setup.sh    ("verified live: the e2e Push swept setup.sh before
                            the second exemption was added")
  3. .trinity/pre-check   (this issue)

`pre-check` is the SCHED-COND-001 hook (#454) that architecture.md,
requirements/scheduling.md, agent-validation-spec.md (A-004) and the agent
guide all tell template authors to commit. The platform was deleting a file it
documents as authored content.

The failure is silent and delayed. Only the index is touched, so the working
tree keeps running; it surfaces at the next re-clone or container recreate,
which boots with no hook — and every cron tick then runs a full LLM turn
instead of skipping, reintroducing exactly the cost SCHED-COND-001 exists to
remove, on a poll-driven agent, with no error anywhere.

Inverted rather than extended. Adding `":!.trinity/pre-check"` would have been
a fourth instance of the pattern that produced the issue, and does nothing for
`pipelines/`. Now:

  .trinity/*                 <- contents-only, so negations below it apply
  !.trinity/pre-check        <- _TRINITY_AUTHORED_PATHS, one entry per
  !.trinity/post-check          authored path (pre/post-check, pre-snapshot,
  !.trinity/pre-snapshot        setup.sh, persistent-processes.allow,
  !.trinity/setup.sh            brain-orb/, pipelines/)
  ...

so the DEFAULT under `.trinity/` is ignored — a new runtime file needs no
action — while authored content is tracked by construction. The `rm --cached`
exemptions are DERIVED from the same constant, so adding an authored path is
one edit instead of two and the two cannot drift.

The dir-form is not merely untidy: git never descends into a directory
excluded by `.trinity/`, so re-includes beneath it are inert. Every agent
synced before this change carries that exact line — precisely the fleet this
fixes — so the merge now REMOVES it before appending, by exact whole-line
match (`grep -vxF`, the same discipline as the G-001 auto-fix). A user rule
that merely mentions the directory (`.trinity/scratch/`, `!.trinity/mine`)
does not match and is untouched.

Coupled surfaces moved in the same change, as the AC requires: the guide's
gitignore fence (test_doc_and_constant_in_sync), the S-005 check (star form is
now canonical; the dir-forms stay ACCEPTED because they do exclude the runtime
state the check grades, and the merge repairs them anyway), the S-005 auto-fix
patterns (re-adding the wholesale line would have re-broken this), c_g002
(follows the constant), the validation spec, architecture.md, and all 16
bundled template .gitignore files.

Verified in a REAL agent container (trinity-agent-base), starting from the
pre-#2070 `.gitignore` every live agent has:

  old commands: tracked after sweep -> .trinity/setup.sh only
                (pre-check and pipelines/r.yaml untracked — the bug)
  new commands: tracked after sweep -> pre-check, setup.sh, pipelines/r.yaml
                runtime (operator-queue.json, pipeline-state/) untracked
                .gitignore migrated to the star form
                fresh `git clone` of the result: hook present, runs, prints "skip"

25 tests over real git repos, asserting the split rather than today's exemption
strings. Mutation-verified: wholesale ignore restored -> 5 failed; hardcoded
two-entry exemptions -> 1 failed; stale-line migration removed -> 2 failed;
pre-check dropped from the authored set -> 4 failed.

Related to #2070

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr. All 19 checks green. Inverting the rule (.trinity/* + derived re-includes) is the right fix rather than a fourth exemption string, and deriving the rm --cached pathspec from the same constant removes the drift that caused all three recurrences. Verified locally: merges conflict-free on top of #2077 and the combined tree passes pytest tests/unit -k "git or compat" (594 passed, 8 skipped) plus all 25 new tests.

Non-blocking nit for a follow-up: in _build_gitignore_merge_command, grep -vxF ... > .gitignore.tmp || true swallows grep's exit 2 (real error) as well as exit 1 (no lines selected), so a genuine read failure mid-filter would mv a truncated file over the user's .gitignore. || [ $? -eq 1 ] would narrow it to the intended case.

@vybe
vybe merged commit 7e5f506 into dev Aug 10, 2026
22 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.

2 participants