Add --update-cache option for Claude Code plugin development#4
Closed
thschaffr wants to merge 1 commit into
Closed
Add --update-cache option for Claude Code plugin development#4thschaffr wants to merge 1 commit into
thschaffr wants to merge 1 commit into
Conversation
…formats.py to refresh the local Claude Code plugin cache after a successful build.
After the normal build pipeline succeeds, --update-cache mirrors the
generated skills/software-security/ tree into:
~/.claude/plugins/cache/project-codeguard/codeguard-security/<version>/
skills/software-security/
so locally edited rules can be exercised in Claude Code immediately,
without waiting for a marketplace release.
Behavior:
- Off by default; no change to standard CI builds.
- Marketplace name (project-codeguard) and plugin name (codeguard-security)
match .claude-plugin/marketplace.json and .claude-plugin/plugin.json.
- Version is read from pyproject.toml via the existing helper and validated
against [A-Za-z0-9._-]+ before being spliced into a filesystem path
(defense-in-depth against path traversal).
- The versioned cache directory is fully replaced (rmtree of cache_base
followed by copytree) so stale rules from a previous build can't linger.
This is not atomic: there is a brief window where the directory is
missing or partially written. The flag is intended for dev use where
this is acceptable.
- All shutil operations are wrapped in try/except; failures exit non-zero
with a clear message.
No new dependencies; only stdlib (re, shutil, pathlib).
aa36fde to
b8ea144
Compare
Owner
Author
|
Superseded by upstream PR cosai-oasis#82. This fork PR existed only to stage the change for review before opening against cosai; the actual review/merge will happen upstream. |
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.
Summary
This PR adds a
--update-cacheCLI option to the conversion script (src/convert_to_ide_formats.py) to streamline custom rule development for Claude Code environments. The flag is purely additive — it extends the existing converter; no other entry point or script is introduced.Problem
When developing or customizing CodeGuard rules for Claude Code, users face workflow friction:
skills/software-security/— The conversion script outputs Claude Code rules to the project'sskills/directory~/.claude/plugins/cache/project-codeguard/codeguard-security/{version}/skills/software-security/Solution
Extend the conversion script (
src/convert_to_ide_formats.py) with an opt-in--update-cacheflag that automatically syncs the just-generated rules to Claude Code's local plugin cache directory at the end of a successful conversion run. Off by default — no impact on standard CI builds or contributor workflow when the flag is not passed.Changes
All changes are scoped to
src/convert_to_ide_formats.py(the existing conversion script). No new scripts, modules, or dependencies are introduced.update_claude_cache(version)function tosrc/convert_to_ide_formats.pyto sync rules to the Claude Code plugin cache--update-cacheCLI flag to the same script's argparse setup, triggering the sync after a successful conversionpyproject.tomlvia the existingget_version_from_pyproject()helper and passed through toupdate_claude_cache()project-codeguard) and plugin name (codeguard-security) are pinned in the function to match.claude-plugin/marketplace.jsonand.claude-plugin/plugin.json[A-Za-z0-9._-]+allow-list before splicing into a filesystem path (defense-in-depth against path traversal)rmtreeofcache_base, thencopytree) so stale rules from a previous build can't linger. Note: this is not atomic — there is a brief window where the cache directory is missing or partially written; the flag is intended for dev use where this is acceptableshutiloperations intry/except; failures exit non-zero with a clear messageSKILL.mdwere actually copied before returning successNo new dependencies; only stdlib (
re,shutil,pathlib).Usage
Note: The
--sourceflag accepts multiple directories undersources/rules/. In the last example,customrefers to a hypotheticalsources/rules/custom/directory — this does not exist by default in the repository. Users can create their own source directories (e.g.,sources/rules/internal/) to organize organization-specific rules alongside the core rules.Use Cases
agentskills.pyor theSKILL.mdtemplateTest Plan
--update-cacheflag~/.claude/plugins/cache/project-codeguard/codeguard-security/{version}/skills/software-security/(tested with isolated$HOME: 23 rules +SKILL.mdcopied)--helpdocuments the new flag clearly