Skip to content

fix(git-sync): ignore .claude/plugins/ so plugin caches aren't auto-committed (#1702) - #1705

Merged
vybe merged 1 commit into
devfrom
fix/1702-gitignore-plugins-cache
Jul 20, 2026
Merged

vybe merged 1 commit into
devfrom
fix/1702-gitignore-plugins-cache

Conversation

@dolho

@dolho dolho commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

What

_GITIGNORE_PATTERNS in git_service.py ignored six .claude/* runtime dirs but not .claude/plugins/. Claude Code installs marketplace plugins into ~/.claude/plugins/cache/<plugin>@<version>/ (a full copy — skills, agents, hooks). Since an agent's HOME is its git repo root, that cache lands in the working tree and the 15-min sync loop auto-commits it — and every plugin update commits another copy. Same repo-bloat class as #1596, different writer, on a path users are steered onto (/plugin marketplace add abilityai/abilities, /trinity:onboard).

Change

  • Added .claude/plugins/ to the "Claude Code runtime" block of _GITIGNORE_PATTERNS.
  • Existing agents pick it up through the idempotent gitignore merge on the next Push, and any already-committed cache is untracked via the git rm --cached step _migrate_workspace_gitignore already runs (bug: git-sync agent workspaces grow unboundedly — auto-committed data churn bloats .git (44GB observed on one agent) #1596) — stops future churn, doesn't shrink history.
  • Kept the gitignore block in docs/TRINITY_COMPATIBLE_AGENT_GUIDE.md in sync — the test_doc_and_constant_in_sync guard fails CI if any _GITIGNORE_PATTERNS entry is missing from the doc.

Open question (AC) — resolved

does plugin install state need a committed manifest to survive a container recreate?

Yes, and it's lost today. ~/.claude.json (the plugin manifest) is also gitignored, so a recreated agent silently loses its plugins. The right resolution per the AC: keep the cache ignored (it's re-installable and doesn't belong in git either way) and track the persistence gap separately → filed as #1704. This PR does not un-ignore anything.

Verification

  • .claude/plugins/ is present in both the _GITIGNORE_PATTERNS tuple and the doc's gitignore block → test_doc_and_constant_in_sync passes (46 patterns, none missing).
  • git check-ignore in a real repo confirms .claude/plugins/cache/[email protected]/skills/x.md is ignored.
  • The compat static check S-006 uses a hardcoded subset that doesn't include plugins, so its _GOOD_GITIGNORE fixture is unaffected (no test churn); the auto-fix still adds the pattern since fixes.py reuses _GITIGNORE_PATTERNS.
  • git_service.py parses.

(No live agent currently has a plugin installed, so the "plugin still loads" half of the AC's live check wasn't reproducible here — but the ignore semantics are proven and the merge/untrack mechanism is the same one #1596 runs in production for the sibling .claude/* patterns.)

Related to #1702 · follow-up #1704

🤖 Generated with Claude Code

Fixes #1702

…ommitted (#1702)

`_GITIGNORE_PATTERNS` ignored six `.claude/*` runtime dirs but not
`.claude/plugins/`. Claude Code installs marketplace plugins into
`~/.claude/plugins/cache/<plugin>@<version>/` (a full copy: skills, agents,
hooks). Because an agent's HOME *is* its git repo root, that cache lands in the
working tree and the 15-min sync loop commits it — and every plugin update
commits another copy. Same repo-bloat class as #1596, different writer; and a
path users are actively steered onto (`/plugin marketplace add abilityai/abilities`,
`/trinity:onboard`).

- Added `.claude/plugins/` to the "Claude Code runtime" block of
  `_GITIGNORE_PATTERNS`. Existing agents pick it up through the idempotent
  gitignore merge on the next Push, and any already-committed cache is untracked
  via the `git rm --cached` step `_migrate_workspace_gitignore` already runs
  (#1596) — stops future churn, doesn't rewrite history.
- Kept `docs/TRINITY_COMPATIBLE_AGENT_GUIDE.md`'s gitignore block in sync (the
  `test_doc_and_constant_in_sync` guard requires every `_GITIGNORE_PATTERNS`
  entry to appear there).

Open question (AC) resolved: `~/.claude.json` (the plugin install manifest) is
also gitignored, so a recreated agent loses its plugins today. The cache is
re-installable and does NOT belong in git either way, so this keeps it ignored
and tracks the persistence gap separately as #1704 (do not un-ignore the cache).

Verified: `.claude/plugins/` in the tuple + the doc block (doc-sync green);
`git check-ignore` confirms `.claude/plugins/cache/<x>` is ignored in a real
repo; git_service.py parses. (No live agent currently has a plugin installed —
the ignore semantics + the #1596 merge/untrack mechanism are the proof.)

Related to #1702
@dolho
dolho requested a review from vybe July 20, 2026 11:27

@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: one-line addition to the fleet-wide gitignore + the matching doc block, which the existing test_github_init_gitignore.py parity test enforces as a pair. All checks green.

@vybe
vybe merged commit a4297c1 into dev Jul 20, 2026
22 checks passed
vybe pushed a commit that referenced this pull request Aug 16, 2026
…#2225)

* feat(#1704): declare + materialize agent plugin manifest (backend seam)

Add a template-declared `plugins:` block that materializes a committed,
secret-free `~/.trinity/plugins.yaml` manifest — the agent-local half of the
incubating global plugin-management model (trinity-enterprise#192).

- services/template_plugins.py: tolerant, total reader (never raises) mirroring
  the ent#89 schedules reader. Charset-validates marketplace/plugin names and
  the marketplace `source` (the dangerous arg), refuses `user:token@` URLs,
  drops `enabledPlugins:false`, sorts+dedupes for byte-stability.
- git_service.materialize_plugins(): nested YAML (sort_keys=True) via the shared
  injection-safe heredoc writer (_write_trinity_yaml_file, extracted from
  materialize_trinity_yaml_list). Opt-in no-op when empty.
- _TRINITY_AUTHORED_PATHS += .trinity/plugins.yaml: yields both the #2070 `!`
  re-include and the rm-cached exemption, so the manifest is committed while
  .claude.json and .claude/plugins/ stay gitignored (#1705 intact).

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(#1704): wire declared plugins through the create path

- template_service: surface normalized `plugins` + `plugin_errors` in both
  catalog builders (_build_template, _build_local_template), mirroring the
  ent#89 schedules surface.
- crud: add `_TemplateResolution.declared_plugins` fed by all three resolver
  branches (github source metadata, local template_data, copy snapshot), and
  materialize it in _materialize_agent_files (opt-in, ghost-skipped, non-fatal
  inside the rollback fence). declared_plugins comes from the resolver, not
  template_data, since the github: path never populates the latter.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(#1704): re-install declared plugins at container boot (agent side)

- agent_server/plugins_reinstall.py: runnable `python3 -m` module (mirrors
  mcp_template.py). Hardened-parses the untrusted ~/.trinity/plugins.yaml
  (AliasPolicy.REJECT), re-validates names + the marketplace source (rejects
  userinfo/flags/traversal), reads current state via `claude plugin [marketplace]
  list --json` and re-installs only what is missing (`marketplace add`,
  `install --yes`). Subprocess arg-lists, hard timeout + stdin=DEVNULL so a
  no-TTY prompt cannot hang, GH_TOKEN seeded from GITHUB_PAT env (never the
  manifest), non-fatal, one observability summary line. Zero subprocesses when
  the declared set is already present.
- startup.sh: guarded hook AFTER credential injection + .mcp.json.template
  render (a private marketplace needs a git credential at install time).

Base-image change → old images silently skip the hook (release-note ordering);
existing agents keep working (volume persists plugins) until recreated onto the
new image.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* docs(#1704): plugin manifest — requirements, architecture, feature-flow, agent guide

- requirements/content-files.md §42: reframe + FRs + security + honest scope.
- architecture.md: new subsystem block, .trinity/ layout diagram, plugins.yaml
  in the _TRINITY_AUTHORED_PATHS enumeration.
- feature-flows/agent-plugin-manifest.md (new) + index row.
- TRINITY_COMPATIBLE_AGENT_GUIDE.md: 'Declaring Plugins' section + schema block.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(#1704): restore template_plugins imports stripped by autoflake

The pre-commit autoflake hook removed `from services.template_plugins import ...`
from crud.py and template_service.py at the moment they were added (momentarily
unused before the call sites landed), leaving a NameError on the catalog + create
paths. Now that the usages are present the imports are stable.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* test(#1704): plugin manifest — reader, materialize, commit seam, boot hook, wiring

- test_1704_template_plugins.py: normalizer (accept/reject/security/determinism/bounds).
- test_1704_git_service_plugins.py: materialize_plugins nested YAML + byte-stability +
  no-op + authored-path/re-include/rm-cached exemption + #1705 intact (cache + .claude.json
  stay gitignored, not re-included).
- test_1704_plugins_reinstall.py: agent-side reconcile (zero installs when present, fresh
  volume add+install --yes, timeout/arg-list/DEVNULL, non-fatal, untrusted-parse validation).
- test_1704_crud_materialize_plugins.py: both resolver branches populate declared_plugins,
  materialize call + ghost-skip + non-fatal, catalog builders surface plugins + errors.
- test_2070: .trinity/plugins.yaml added to the real-git authored-path survival sweep.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* chore(#1704): sync .gitignore ratchet for the new authored path

Adding .trinity/plugins.yaml to _TRINITY_AUTHORED_PATHS added !.trinity/plugins.yaml
to _GITIGNORE_PATTERNS. Mirror it in the agent guide's canonical gitignore block
(test_doc_and_constant_in_sync) and regenerate the 14 bundled templates'
.gitignore (test_1908 byte-identity), via the #1908 regenerator.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* docs(#1704): note the declared plugins: block in template-processing flow

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* style(#1704): strip local black-hook reformatting, keep only logical changes

The local pre-commit black hook (Andrii's, not repo CI — the base files carry
long import lines black would wrap) reformatted ~550 unrelated lines in crud.py
and large swaths of git_service.py/template_service.py across earlier commits.
Re-applied ONLY the #1704 logical changes via targeted edits, so the diff-vs-base
is minimal: git_service +90/-8, template_service +38/-0, crud +59/-3. Behaviour
identical (165 unit tests green); no new ruff violations (git_service fully clean;
the F401/F841 in template_service/crud are pre-existing on base).

* style(#1704): strip black-hook reformatting from test_2070 (one-line add only)

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(#1704): boot hook falls back to template.yaml for source-mode agents

Closes the Cornelius/source-mode survival gap the plan flagged (§5): a tokenless
agent can't push a materialized .trinity/plugins.yaml back to git, so on a fresh
reconstitution load_manifest falls back to the re-cloned template.yaml's
`plugins:` block (same nested shape; BUDGET alias policy since template.yaml may
legitimately anchor, vs REJECT for the simple manifest). The committed manifest
still wins when present. startup.sh's guard widened to fire on the manifest OR a
top-level `plugins:` key (cheap grep pre-check; the module does the real parse),
so the fallback is actually reachable. +4 tests (fallback, manifest-wins,
anchors-tolerated). Docs corrected: the hook READS template.yaml, it does not
re-materialize the manifest.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(#1704): agent marketplace-source validator is https-only, matching backend

The agent-side `plugins_reinstall._is_source` gate — the SOLE validator on
the untrusted `template.yaml` fallback a source-mode agent's clone carries,
re-run at boot before any `claude plugin marketplace add` — accepted any
`scheme://` (ftp/file/ssh/data), while the backend writer
`template_plugins._validate_source` accepts only `https://`. The looser copy
was the one gating untrusted input.

Re-implemented (not byte-for-byte vendored) policies across the backend↔agent
boundary have no parity test, so the two silently diverged. Tighten the agent
gate to https-only and pin cross-boundary agreement with a shared accept/reject
table run against BOTH copies (test_1704_source_validator_parity.py), encoding
the safety invariant: the untrusted-input gate must be at least as strict as
the writer (agent_accepts ⊆ backend_accepts).

Docs: architecture.md validator description now states https-only + the parity
guard; learnings.md records the re-implemented-cross-boundary-policy drift class.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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