Skip to content

fix: upgrade-hosts refreshes Claude Code skills, agents and /slm-loop when there is no plugin - #333

Merged
varun369 merged 3 commits into
mainfrom
fix/upgrade-hosts-claude-code-skills
Nov 20, 2026
Merged

varun369 merged 3 commits into
mainfrom
fix/upgrade-hosts-claude-code-skills

Conversation

@varun369

Copy link
Copy Markdown
Member

Symptom

On a Claude Code wired without the plugin (MCP server and hooks in ~/.claude/settings.json, skills in ~/.claude/skills/slm-*, advisors in ~/.claude/agents/slm-*.md, /slm-loop in ~/.claude/commands), slm upgrade-hosts printed:

[verified] claude-code: Claude Code settings.json: already current

while every skill and advisor was still the 4.1.24 text and four newer skills (slm-media, slm-web-access, slm-bot-memory, slm-getting-started-bot) were missing. For Codex the same command does refresh skills. A second defect on the same path: with the Claude Code plugin installed, slm upgrade-hosts --host claude-code crashed with KeyError: 'plugin-managed'.

Cause

_upgrade_host("claude-code") only called the settings.json hook merge, so the line reported on hooks alone. Nothing in the package ever wrote Claude Code skills, agents or commands after the first install, and the wheel did not ship them (its share/ held only codex/ and portable-kit/). The plugin-managed and changed-meanwhile results of the hook merge had no entry in the status tables.

Fix

  • New hooks/claude_code_assets.py. It owns only the slm-* skills, slm-* advisors and slm-loop command that the release ships, and decides who wrote a file from a digest manifest (~/.claude/.slm-managed.json), the way the Codex installer does:
    • absent and never recorded: added; identical to this release: current; byte-identical to what SLM last wrote: refreshed;
    • changed since SLM wrote it: kept and named in the output;
    • absent but recorded (you removed it): not put back;
    • different and never recorded (an install older than the manifest): replaced only by --apply, after the old copy is saved as <name>.bak-slm-<version>;
    • a path that resolves outside ~/.claude (linked checkout, dotfiles-managed skills folder): reported and left alone;
    • SLM's Claude Code plugin installed: ~/.claude is not touched.
  • upgrade-hosts (preview and --apply) now runs hooks and assets together, lists every file it would add or refresh, and prints "already current" for the skills/agents/commands part only when they match. The line reports the worst of the two parts.
  • The once-per-version daemon step adds missing files and refreshes files SLM wrote and you did not change. It never replaces an unrecorded file (that needs the explicit --apply, which keeps a backup), and it is covered by the existing marker, opt-out and kill switch.
  • pyproject.toml ships share/superlocalmemory/claude-code/{skills,agents,commands}.
  • slm doctor has a "Host assets" row (read-only) for the same check.
  • Added plugin-managed and changed-meanwhile to the upgrade line's status tables.
  • Docs: docs/host-upgrades.md and the wiki page.

Comparison with Codex: Codex overwrites its skill files without a record and protects only agent files. This keeps one rule for all three kinds and adds a backup for the one case where it cannot tell SLM's copy from a hand edit.

Tests

  • tests/test_hooks/test_claude_code_assets.py (20 tests) and tests/test_cli/test_upgrade_hosts_claude_assets.py (10 tests), all on a temp HOME: stale skill refreshed, new skill added, edited file kept, backup content checked, outside symlink (file and folder) untouched, plugin case leaves the tree byte-identical, "already current" only when everything matches, removed skill not re-added, non-SLM files untouched, CRLF compared as bytes, unwritable target is an error not a crash, once-per-version daemon step, drift guard between plugin-src and pyproject.toml, installed-layout lookup.
  • tests/release/test_artifact_contract.py: the built wheel contains all 21 files (ran with -m slow, passes). Also installed the built wheel into a clean venv with no checkout: source_root() resolves to the installed share/.../claude-code and 21 files install into an empty .claude.
  • Non-vacuity: 10 targeted mutations (CLI back to hooks-only, daemon step removed, backup removed, outside check removed, edited file overwritten, removed file re-added, automatic step adopting unrecorded files, plugin check removed, current always reported, wheel data-files removed) each fail a test; with host_upgrades.py reverted to main, 8 of the 10 new CLI tests fail. Restored, all pass.

Not in this PR

No CHANGELOG entry: test_changelog_starts_with_the_current_package_version requires the top section to be the current version, so the entry belongs in the release commit.

🤖 Generated with Claude Code

@varun369

Copy link
Copy Markdown
Member Author

Audit findings, each reproduced with a failing test on 25bd183 before any fix, then fixed in e6f69ba. With the source reverted to 25bd183 and the new tests kept, 12 of them fail; with the fix, all pass.

Finding Reproduced on 25bd183 Fix Tests
MAJOR-1 edit saved between the check and the write is overwritten yes: the file was replaced with no backup every write re-reads the file right before the rename and keeps it if it is no longer what the decision saw (absent for an add, the recorded digest for a refresh, the just-made backup for an adoption); the kept file is not recorded as SLM's, so the next run keeps it too test_an_edit_saved_between_the_check_and_the_write_is_kept, test_a_file_created_between_the_check_and_the_write_is_kept, test_an_edit_made_while_the_backup_was_copied_is_not_lost
MINOR-2 orphan and stacked backups yes: .bak-slm-*.2 left after 3 failed runs backup is removed when the write fails (only if this run made it); an identical existing backup is reused test_a_failed_write_leaves_no_orphan_backup_and_repeats_do_not_stack, test_an_identical_backup_is_reused_not_copied_again, test_a_backup_that_was_already_there_survives_a_failed_write
MINOR-3 unreadable file reported as "you changed it", never retried yes: needs-review, version marked done new unreadable outcome: status error, honest message, retried at next start test_a_file_that_cannot_be_read_is_an_honest_retryable_error, test_an_unreadable_file_keeps_the_version_from_being_marked_done
MINOR-4 backups list was 21 names for 6 distinct strings yes backups are paths relative to ~/.claude test_backups_are_reported_as_paths_under_claude_that_exist
MINOR-5 folder at a file path: "add" in preview, error on apply yes classified blocked up front, same in preview and apply, reported in the notes test_a_folder_where_a_file_belongs_is_blocked_the_same_way_in_preview_and_apply
MINOR-6 --all-detected skipped a skills-only install yes detection also uses the same test the refresh uses (is_integrated) test_a_skills_only_claude_code_is_detected_for_all_detected, plus a guard that an unrelated Claude Code is still not detected

Regression guards for the refresh of files SLM wrote: an untouched recorded file is still refreshed with its mode and CRLF bytes kept and no leftover temp or backup; a refresh through a link that stays inside ~/.claude still works; a file that appears already identical to this release is not called an edit; an unrelated earlier backup is neither reused nor removed.

Verification: the two PR test files (46 tests) pass; the wider hooks, cli, packaging, release, plugin and upgrade packs pass (2635 passed, 12 skipped).

Known limit: a rename-based write cannot close the instant between the final re-read and the rename without a lock an editor would ignore; that window is now microseconds instead of the whole run.

varun369 and others added 3 commits November 20, 2026 18:59
… when there is no plugin

On a Claude Code wired without the plugin, `slm upgrade-hosts` looked only at
the hook entries in settings.json and printed "already current" while every
skill and advisor was from the release that installed it and newer skills were
missing. It now also adds and refreshes the slm-* skills, the slm-* advisors and
/slm-loop, names each file in the preview, and reports "already current" only
when all of it is.

A file SLM wrote and you did not change is refreshed. A file you changed after
SLM wrote it is kept and named. A file from before SLM kept a record is replaced
only by --apply, after a .bak-slm-<version> copy. A skill you deleted is not put
back, and a path that resolves outside ~/.claude is reported and left alone.
With the plugin installed ~/.claude is not touched. The once-per-version daemon
step adds missing files and refreshes the ones SLM wrote and you did not change.

Also fixes a KeyError that stopped `upgrade-hosts --host claude-code` when the
plugin is installed, ships the Claude Code skills, agents and command in the
wheel, and adds a `slm doctor` row for them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… and finds skills-only Claude Code installs

- A file you save while the upgrade runs is re-checked right before it is replaced and kept.
- A failed write leaves no stray backup; identical backups are reused, not stacked.
- A file that cannot be read is reported as an error and retried, not as "you changed it".
- Backups are listed as paths under ~/.claude, one per file.
- A folder where a skill file belongs is reported as blocked in preview and apply alike.
- --all-detected now finds a Claude Code that has SLM skills but no hooks.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ory tools

The sub-agents that slm upgrade-hosts and the daemon install without the plugin
now name SLM tools as mcp__superlocalmemory__<tool>, generated from the shared
plugin-src agents, so an advisor that already works is left byte-identical.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@varun369
varun369 force-pushed the fix/upgrade-hosts-claude-code-skills branch from e6f69ba to 147c10b Compare November 20, 2026 13:59
@varun369

Copy link
Copy Markdown
Member Author

Audit finding: the advisors this PR installed into ~/.claude/agents were copied from plugin-src, which names SLM tools bare. Claude Code resolves sub-agent tools by full name only, and a plugin-less install reaches SLM as a direct MCP server, so with adopt_unrecorded a working agent using mcp__superlocalmemory__ names would have been backed up and replaced by one with no memory tools (the bug #330 fixed).

Fix: commit 147c10b. A new generated tree, claude-code-assets/agents, is built from plugin-src/agents by the existing directAgentTools transform in scripts/agent-tool-names.mjs (same output as the Muse build). It is a step in build-all-plugins, covered by --check and the plugin-drift CI paths. The wheel's data-files and the checkout both read it; plugin-src/agents is never installed. The installer also refuses any agent that still names an SLM tool bare. Rebased onto main.

Tests: tests/test_hooks/test_claude_code_assets.py (installed agents carry only direct registered tool names; a current direct-form agent stays byte-identical with no backup; older direct agent refreshes to direct form; daemon step; bare-name source refused; LF and posix manifest keys), tests/test_plugin/test_claude_agent_tool_names.py (generated tree in sync, equals the JS transform and the Muse output), tests/release/test_artifact_contract.py (agent bytes inside the built wheel). Reverting the fix makes 7 of the new tests fail.

@varun369
varun369 merged commit f3726ae into main Nov 20, 2026
9 checks passed
@varun369
varun369 deleted the fix/upgrade-hosts-claude-code-skills branch November 20, 2026 14:09
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