agent-toggle 0.18.0__tar.gz → 0.20.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/PKG-INFO +56 -11
  2. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/README.md +55 -10
  3. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/__init__.py +1 -1
  4. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/cli.py +12 -3
  5. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/fs.py +6 -0
  6. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/help.py +21 -8
  7. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/locales/zh_tw_cli.py +9 -3
  8. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/mechanisms.py +34 -50
  9. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/profiles.py +131 -7
  10. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/shims/claude.md.tmpl +9 -1
  11. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/shims/generic.md.tmpl +9 -1
  12. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle.egg-info/PKG-INFO +56 -11
  13. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_all_type.py +1 -4
  14. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_backends.py +39 -4
  15. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_conformance.py +5 -5
  16. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_crash.py +44 -15
  17. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_profiles.py +107 -0
  18. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_safety.py +14 -14
  19. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_secret_audit.py +19 -0
  20. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/LICENSE +0 -0
  21. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/__main__.py +0 -0
  22. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/backends/__init__.py +0 -0
  23. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/backends/flag_json.py +0 -0
  24. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/backends/mcp_json.py +0 -0
  25. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/backends/mcp_toml.py +0 -0
  26. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/backends/plugin_cli.py +0 -0
  27. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/companions.py +0 -0
  28. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/completions.py +0 -0
  29. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/config.py +0 -0
  30. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/cost.py +0 -0
  31. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/doctor.py +0 -0
  32. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/harnesses.py +0 -0
  33. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/i18n.py +0 -0
  34. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/locales/__init__.py +0 -0
  35. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/locales/zh_tw_common.py +0 -0
  36. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/locales/zh_tw_config.py +0 -0
  37. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/locales/zh_tw_picker.py +0 -0
  38. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ops.py +0 -0
  39. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/output.py +0 -0
  40. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/settings.py +0 -0
  41. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/spinner.py +0 -0
  42. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/store.py +0 -0
  43. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/toml_check.py +0 -0
  44. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/__init__.py +0 -0
  45. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/config_menu.py +0 -0
  46. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/logo.py +0 -0
  47. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/menu.py +0 -0
  48. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/model.py +0 -0
  49. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/picker.py +0 -0
  50. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/ui/theme.py +0 -0
  51. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/undo.py +0 -0
  52. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/update_check.py +0 -0
  53. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle/update_prompt.py +0 -0
  54. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle.egg-info/SOURCES.txt +0 -0
  55. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle.egg-info/dependency_links.txt +0 -0
  56. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle.egg-info/entry_points.txt +0 -0
  57. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle.egg-info/requires.txt +0 -0
  58. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/agent_toggle.egg-info/top_level.txt +0 -0
  59. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/pyproject.toml +0 -0
  60. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/setup.cfg +0 -0
  61. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_alias.py +0 -0
  62. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_cli.py +0 -0
  63. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_cli_surface.py +0 -0
  64. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_color.py +0 -0
  65. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_companions.py +0 -0
  66. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_completions.py +0 -0
  67. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_config.py +0 -0
  68. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_config_menu.py +0 -0
  69. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_containment.py +0 -0
  70. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_cost.py +0 -0
  71. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_doctor.py +0 -0
  72. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_encoding.py +0 -0
  73. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_fs.py +0 -0
  74. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_harnesses.py +0 -0
  75. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_help.py +0 -0
  76. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_i18n.py +0 -0
  77. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_install.py +0 -0
  78. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_logo.py +0 -0
  79. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_mechanisms.py +0 -0
  80. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_menu.py +0 -0
  81. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_mod_version.py +0 -0
  82. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_mods.py +0 -0
  83. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_picker.py +0 -0
  84. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_platform.py +0 -0
  85. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_project.py +0 -0
  86. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_same_name.py +0 -0
  87. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_settings.py +0 -0
  88. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_store.py +0 -0
  89. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_theme.py +0 -0
  90. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_undo.py +0 -0
  91. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_update_check.py +0 -0
  92. {agent_toggle-0.18.0 → agent_toggle-0.20.0}/tests/test_update_prompt.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agent-toggle
3
- Version: 0.18.0
3
+ Version: 0.20.0
4
4
  Summary: Temporarily disable / re-enable AI-agent skills, agents, commands, rules, plugins and MCP servers across harnesses (Claude Code, Codex, Grok, OpenCode, OpenClaw, Copilot, Vibe, Devin, Antigravity)
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/weskao/agent-toggle
@@ -218,6 +218,7 @@ agent-toggle <command> [args] # or: python3 agent_toggle.py <command> [
218
218
  | `enable --all` | put back **every** disabled item (`--harness H` narrows it, `--project <dir>` takes only that project's) |
219
219
  | `undo` | reverse the last logged batch (`--dry-run` shows the plan) |
220
220
  | `profile save\|apply\|diff\|list\|delete\|rename` | named sets of live items; see [Profiles](#profiles) |
221
+ | `profile bind\|unbind\|auto` | load a profile per project, or a global one; see [Project bindings](#project-bindings) |
221
222
  | `config` | settings menu (curses, else a numbered list); `config --json` lists every setting and the package version; see [Settings & config menu](#settings--config-menu) |
222
223
  | `config test\|sync-ci` | send one Telegram test message / set the GitHub CI secrets; see [CI notifications](#ci-notifications) |
223
224
  | `help [command]` | styled help; `help ui` = `--help ui` = `ui --help`; see [Help](#help) |
@@ -271,7 +272,7 @@ asked, plus `owner`, the harness whose park dir and state entry hold the item;
271
272
  unshared).
272
273
 
273
274
  `--dry-run` (`disable` / `enable` / `enable --all` / `undo` / `profile apply` /
274
- `install-shims` / `ui`) computes the plan --
275
+ `profile auto` / `install-shims` / `ui`) computes the plan --
275
276
  moves, companions, backups, MCP edits, warnings -- and writes nothing: no state,
276
277
  log, lock or backup, and no chmod; it never shells out to `claude`, except one
277
278
  read-only `claude plugin list --json` (up to 30 s) when a killed run left a plugin
@@ -665,7 +666,9 @@ visible rather than silent.
665
666
 
666
667
  ## MCP backups are verbatim
667
668
 
668
- - **Claude**: the raw entry from `~/.claude.json`. Never `claude mcp get` —
669
+ - **Claude**: only servers an older agent-toggle removed have one; a disable now marks the
670
+ server off in place (see [Claude MCP scopes](#claude-mcp-scopes)). The backup is the raw
671
+ entry from `~/.claude.json`. Never `claude mcp get` —
669
672
  that prints a human summary and silently drops auth fields (`headers`,
670
673
  `headersHelper`), so a server restored from it fails with 401.
671
674
  - **Codex**: the exact `[mcp_servers.<name>]` text block including its
@@ -687,15 +690,20 @@ Both scopes stored in `~/.claude.json` are togglable, and the scope round-trips:
687
690
 
688
691
  | scope | lives in | toggle |
689
692
  |---|---|---|
690
- | user | top-level `mcpServers` | ✓ |
691
- | local | `projects/<dir>/mcpServers` | ✓ — project path saved with the backup |
693
+ | user | top-level `mcpServers` | ✓ — the entry stays; recorded in each *existing* project's `disabledMcpServers` |
694
+ | local | `projects/<dir>/mcpServers` | ✓ — as user scope |
692
695
  | project | the repo's own `.mcp.json` | ✓ with `--project <dir>` only, see [Project scope](#project-scope) |
693
696
  | claude.ai connector | your account | ✓ — recorded in each *existing* project's `disabledMcpServers`; a project first opened later needs the toggle re-run |
694
697
 
695
- `claude mcp remove -s local` only sees the project it runs in, so the project
696
- path is recorded at disable time and the restore runs back in that directory.
697
- One name that is local-scope in several projects is refused unless your cwd
698
- picks the winner — guessing would restore it into the wrong project.
698
+ Claude Code reads its MCP config once, at session start, and `/mcp enable` reaches only a server
699
+ it listed then. A removed server could not load until a new session, so a user- or local-scope
700
+ server is never removed: it stays in `~/.claude.json`, off in every project that existed at
701
+ disable time. A project first opened later loads it, and the mod turns it off at that session's
702
+ start (`/mcp disable`, which also marks the project). Without the mod, re-run the disable.
703
+
704
+ A server an older agent-toggle removed still comes back from its backup, with
705
+ `claude mcp add-json` run in the project recorded at disable time. A running session did not list
706
+ it, so it loads in a new session.
699
707
 
700
708
  ## Profiles
701
709
 
@@ -727,8 +735,8 @@ one batch, logged, undoable with `undo`).
727
735
  `~/.agent-toggle/profiles`. `..` in a path, and names that are not plain file
728
736
  names, are refused (exit `2`), as are a bad version, an unknown harness or
729
737
  type, an invalid item name, a duplicate item or a file over 1 MiB.
730
- - `--out` belongs to `save` only; `--dry-run` to `apply` / `diff`. `--harness H`
731
- narrows `save`, `apply` and `diff` to one harness.
738
+ - `--out` belongs to `save` only; `--dry-run` to `apply` / `diff` / `auto`. `--harness H`
739
+ narrows `save`, `apply`, `diff` and `auto` to one harness.
732
740
  - `diff` and `apply --dry-run` do not read plugin state (that needs the claude
733
741
  CLI, and a dry run never shells out), so profile plugin items show as
734
742
  `skipped` there.
@@ -749,6 +757,36 @@ one batch, logged, undoable with `undo`).
749
757
  keeps the file byte for byte. Neither takes `--dry-run` or `--project`: a
750
758
  project profile is renamed or deleted by its name like any other.
751
759
 
760
+ ### Project bindings
761
+
762
+ Bind a stored profile to a project and a session opened there applies it. A project
763
+ with no binding applies the global profile; with nothing bound, nothing happens.
764
+
765
+ ```sh
766
+ agent-toggle profile bind work --dir ~/code/app # default: the current dir
767
+ agent-toggle profile bind base --global # every dir with no binding of its own
768
+ agent-toggle profile list # shows what each profile is bound to
769
+ agent-toggle profile auto --dir ~/code/app/src # applies work, as a session start does
770
+ agent-toggle profile unbind --dir ~/code/app # or: profile unbind --global
771
+ ```
772
+
773
+ - **Lookup:** the nearest bound dir at or above the cwd wins, so subdirs and worktrees
774
+ inside it inherit the binding; then the global binding; then nothing (exit `0`, no rows).
775
+ - With the [Claude Code mod](docs/MOD.md), each session start runs `profile auto` for its
776
+ cwd, off the start so it never blocks it, and reloads what changed. Other harnesses can
777
+ run `profile auto` from their own hook.
778
+ - A binding names a stored user-scope profile. A `--project` profile or a file path cannot
779
+ be bound.
780
+ - `delete` drops the bindings to that profile and `rename` moves them. A bound profile
781
+ that is no longer saved gives a `skipped` `auto` row, not a failure.
782
+ - Bindings live in `~/.agent-toggle/profile-bindings.json`, outside `profiles/`: that dir
783
+ may be synced between machines, and these keys are this machine's absolute paths.
784
+
785
+ **Limitation: the last session start wins.** A profile changes shared user state (file
786
+ moves under `~/.claude`, plugin flags), not one session's view. With two sessions in
787
+ different projects, the later start switches the state and the other running session is
788
+ not told. Agents and rules need a new session to change either way.
789
+
752
790
  ## Undo and `enable --all`
753
791
 
754
792
  `undo` reads `~/.agent-toggle/log.jsonl`, takes the batch of the last
@@ -933,6 +971,7 @@ bookkeeping.
933
971
  | `parked/user/<owner>/<dir>/` | user-scope items, e.g. `parked/user/claude/skills/<name>` (`<owner>` = the harness whose home holds the dir; a dir shared by several harnesses parks once, under its owner); an absolute OpenCode `skills.paths` dir parks under `parked/user/opencode/ext-<sha8>/` (`<sha8>` of its resolved path). Nothing is ever parked inside a harness home |
934
972
  | `parked/<sha8>/` | items parked by `--project` (`<sha8>` = first 8 hex of the SHA-1 of the resolved project dir) |
935
973
  | `profiles/` | `<name>.json` profiles (dir `0700`, files `0600`) |
974
+ | `profile-bindings.json` | which profile each project dir loads, plus the global one ([Project bindings](#project-bindings)); machine-local absolute paths, do not sync |
936
975
  | `config.json` | [settings](#settings--config-menu) and the Telegram chat id (mode `0600`, atomic write, unknown keys kept) |
937
976
  | `update-check.json` | the [update check](#update-check)'s skipped version (mode `0600`, atomic write) |
938
977
 
@@ -1064,6 +1103,12 @@ claude --plugin-dir ./mod # then run /agent-toggle inside Claude
1064
1103
  `/reload-skills` and `/reload-plugins` only re-read what is on disk. `/mcp disable` also
1065
1104
  leaves the per-project mark that `enable` clears (see
1066
1105
  [MCP backups are verbatim](#mcp-backups-are-verbatim)).
1106
+ `/mcp` only reaches a server the session listed at its start. The CLI keeps a disabled server
1107
+ listed, so `/mcp enable` loads it in any session, even one started while it was off. Only a
1108
+ server an older version removed and `enable` restores from its backup gets no command; its note
1109
+ says `example-mcp: loads in a new session`. At session start the mod also runs
1110
+ `/mcp disable <name>` for each server agent-toggle keeps off that the session's project has not
1111
+ marked (a project dir first opened after the disable).
1067
1112
  - `agent-toggle ui` in another terminal applies on Enter and writes the Claude rows it changed to
1068
1113
  `~/.agent-toggle/reload.json`. Every open session running the mod checks that file's mtime every
1069
1114
  5 s (one `stat`) and queues the same reloads, toasting `agent-toggle ui: /reload-skills`. A file
@@ -184,6 +184,7 @@ agent-toggle <command> [args] # or: python3 agent_toggle.py <command> [
184
184
  | `enable --all` | put back **every** disabled item (`--harness H` narrows it, `--project <dir>` takes only that project's) |
185
185
  | `undo` | reverse the last logged batch (`--dry-run` shows the plan) |
186
186
  | `profile save\|apply\|diff\|list\|delete\|rename` | named sets of live items; see [Profiles](#profiles) |
187
+ | `profile bind\|unbind\|auto` | load a profile per project, or a global one; see [Project bindings](#project-bindings) |
187
188
  | `config` | settings menu (curses, else a numbered list); `config --json` lists every setting and the package version; see [Settings & config menu](#settings--config-menu) |
188
189
  | `config test\|sync-ci` | send one Telegram test message / set the GitHub CI secrets; see [CI notifications](#ci-notifications) |
189
190
  | `help [command]` | styled help; `help ui` = `--help ui` = `ui --help`; see [Help](#help) |
@@ -237,7 +238,7 @@ asked, plus `owner`, the harness whose park dir and state entry hold the item;
237
238
  unshared).
238
239
 
239
240
  `--dry-run` (`disable` / `enable` / `enable --all` / `undo` / `profile apply` /
240
- `install-shims` / `ui`) computes the plan --
241
+ `profile auto` / `install-shims` / `ui`) computes the plan --
241
242
  moves, companions, backups, MCP edits, warnings -- and writes nothing: no state,
242
243
  log, lock or backup, and no chmod; it never shells out to `claude`, except one
243
244
  read-only `claude plugin list --json` (up to 30 s) when a killed run left a plugin
@@ -631,7 +632,9 @@ visible rather than silent.
631
632
 
632
633
  ## MCP backups are verbatim
633
634
 
634
- - **Claude**: the raw entry from `~/.claude.json`. Never `claude mcp get` —
635
+ - **Claude**: only servers an older agent-toggle removed have one; a disable now marks the
636
+ server off in place (see [Claude MCP scopes](#claude-mcp-scopes)). The backup is the raw
637
+ entry from `~/.claude.json`. Never `claude mcp get` —
635
638
  that prints a human summary and silently drops auth fields (`headers`,
636
639
  `headersHelper`), so a server restored from it fails with 401.
637
640
  - **Codex**: the exact `[mcp_servers.<name>]` text block including its
@@ -653,15 +656,20 @@ Both scopes stored in `~/.claude.json` are togglable, and the scope round-trips:
653
656
 
654
657
  | scope | lives in | toggle |
655
658
  |---|---|---|
656
- | user | top-level `mcpServers` | ✓ |
657
- | local | `projects/<dir>/mcpServers` | ✓ — project path saved with the backup |
659
+ | user | top-level `mcpServers` | ✓ — the entry stays; recorded in each *existing* project's `disabledMcpServers` |
660
+ | local | `projects/<dir>/mcpServers` | ✓ — as user scope |
658
661
  | project | the repo's own `.mcp.json` | ✓ with `--project <dir>` only, see [Project scope](#project-scope) |
659
662
  | claude.ai connector | your account | ✓ — recorded in each *existing* project's `disabledMcpServers`; a project first opened later needs the toggle re-run |
660
663
 
661
- `claude mcp remove -s local` only sees the project it runs in, so the project
662
- path is recorded at disable time and the restore runs back in that directory.
663
- One name that is local-scope in several projects is refused unless your cwd
664
- picks the winner — guessing would restore it into the wrong project.
664
+ Claude Code reads its MCP config once, at session start, and `/mcp enable` reaches only a server
665
+ it listed then. A removed server could not load until a new session, so a user- or local-scope
666
+ server is never removed: it stays in `~/.claude.json`, off in every project that existed at
667
+ disable time. A project first opened later loads it, and the mod turns it off at that session's
668
+ start (`/mcp disable`, which also marks the project). Without the mod, re-run the disable.
669
+
670
+ A server an older agent-toggle removed still comes back from its backup, with
671
+ `claude mcp add-json` run in the project recorded at disable time. A running session did not list
672
+ it, so it loads in a new session.
665
673
 
666
674
  ## Profiles
667
675
 
@@ -693,8 +701,8 @@ one batch, logged, undoable with `undo`).
693
701
  `~/.agent-toggle/profiles`. `..` in a path, and names that are not plain file
694
702
  names, are refused (exit `2`), as are a bad version, an unknown harness or
695
703
  type, an invalid item name, a duplicate item or a file over 1 MiB.
696
- - `--out` belongs to `save` only; `--dry-run` to `apply` / `diff`. `--harness H`
697
- narrows `save`, `apply` and `diff` to one harness.
704
+ - `--out` belongs to `save` only; `--dry-run` to `apply` / `diff` / `auto`. `--harness H`
705
+ narrows `save`, `apply`, `diff` and `auto` to one harness.
698
706
  - `diff` and `apply --dry-run` do not read plugin state (that needs the claude
699
707
  CLI, and a dry run never shells out), so profile plugin items show as
700
708
  `skipped` there.
@@ -715,6 +723,36 @@ one batch, logged, undoable with `undo`).
715
723
  keeps the file byte for byte. Neither takes `--dry-run` or `--project`: a
716
724
  project profile is renamed or deleted by its name like any other.
717
725
 
726
+ ### Project bindings
727
+
728
+ Bind a stored profile to a project and a session opened there applies it. A project
729
+ with no binding applies the global profile; with nothing bound, nothing happens.
730
+
731
+ ```sh
732
+ agent-toggle profile bind work --dir ~/code/app # default: the current dir
733
+ agent-toggle profile bind base --global # every dir with no binding of its own
734
+ agent-toggle profile list # shows what each profile is bound to
735
+ agent-toggle profile auto --dir ~/code/app/src # applies work, as a session start does
736
+ agent-toggle profile unbind --dir ~/code/app # or: profile unbind --global
737
+ ```
738
+
739
+ - **Lookup:** the nearest bound dir at or above the cwd wins, so subdirs and worktrees
740
+ inside it inherit the binding; then the global binding; then nothing (exit `0`, no rows).
741
+ - With the [Claude Code mod](docs/MOD.md), each session start runs `profile auto` for its
742
+ cwd, off the start so it never blocks it, and reloads what changed. Other harnesses can
743
+ run `profile auto` from their own hook.
744
+ - A binding names a stored user-scope profile. A `--project` profile or a file path cannot
745
+ be bound.
746
+ - `delete` drops the bindings to that profile and `rename` moves them. A bound profile
747
+ that is no longer saved gives a `skipped` `auto` row, not a failure.
748
+ - Bindings live in `~/.agent-toggle/profile-bindings.json`, outside `profiles/`: that dir
749
+ may be synced between machines, and these keys are this machine's absolute paths.
750
+
751
+ **Limitation: the last session start wins.** A profile changes shared user state (file
752
+ moves under `~/.claude`, plugin flags), not one session's view. With two sessions in
753
+ different projects, the later start switches the state and the other running session is
754
+ not told. Agents and rules need a new session to change either way.
755
+
718
756
  ## Undo and `enable --all`
719
757
 
720
758
  `undo` reads `~/.agent-toggle/log.jsonl`, takes the batch of the last
@@ -899,6 +937,7 @@ bookkeeping.
899
937
  | `parked/user/<owner>/<dir>/` | user-scope items, e.g. `parked/user/claude/skills/<name>` (`<owner>` = the harness whose home holds the dir; a dir shared by several harnesses parks once, under its owner); an absolute OpenCode `skills.paths` dir parks under `parked/user/opencode/ext-<sha8>/` (`<sha8>` of its resolved path). Nothing is ever parked inside a harness home |
900
938
  | `parked/<sha8>/` | items parked by `--project` (`<sha8>` = first 8 hex of the SHA-1 of the resolved project dir) |
901
939
  | `profiles/` | `<name>.json` profiles (dir `0700`, files `0600`) |
940
+ | `profile-bindings.json` | which profile each project dir loads, plus the global one ([Project bindings](#project-bindings)); machine-local absolute paths, do not sync |
902
941
  | `config.json` | [settings](#settings--config-menu) and the Telegram chat id (mode `0600`, atomic write, unknown keys kept) |
903
942
  | `update-check.json` | the [update check](#update-check)'s skipped version (mode `0600`, atomic write) |
904
943
 
@@ -1030,6 +1069,12 @@ claude --plugin-dir ./mod # then run /agent-toggle inside Claude
1030
1069
  `/reload-skills` and `/reload-plugins` only re-read what is on disk. `/mcp disable` also
1031
1070
  leaves the per-project mark that `enable` clears (see
1032
1071
  [MCP backups are verbatim](#mcp-backups-are-verbatim)).
1072
+ `/mcp` only reaches a server the session listed at its start. The CLI keeps a disabled server
1073
+ listed, so `/mcp enable` loads it in any session, even one started while it was off. Only a
1074
+ server an older version removed and `enable` restores from its backup gets no command; its note
1075
+ says `example-mcp: loads in a new session`. At session start the mod also runs
1076
+ `/mcp disable <name>` for each server agent-toggle keeps off that the session's project has not
1077
+ marked (a project dir first opened after the disable).
1033
1078
  - `agent-toggle ui` in another terminal applies on Enter and writes the Claude rows it changed to
1034
1079
  `~/.agent-toggle/reload.json`. Every open session running the mod checks that file's mtime every
1035
1080
  5 s (one `stat`) and queues the same reloads, toasting `agent-toggle ui: /reload-skills`. A file
@@ -1,3 +1,3 @@
1
1
  """agent-toggle: temporarily disable / re-enable AI-agent resources."""
2
2
 
3
- __version__ = "0.18.0"
3
+ __version__ = "0.20.0"
@@ -25,6 +25,8 @@ Usage:
25
25
  agent_toggle.py doctor [--harness H] # drift + state check (y/n fixes on a TTY); exit 1 on problems
26
26
  agent_toggle.py migrate # import old state, move legacy park dirs
27
27
  agent_toggle.py profile save|apply|diff|list|delete|rename [name|file] [new] [--out F] [--dry-run]
28
+ agent_toggle.py profile bind <name> [--dir D | --global] | unbind [--dir D | --global]
29
+ agent_toggle.py profile auto [--dir D] [--dry-run] # apply the profile bound to D, else the global one
28
30
  agent_toggle.py install-shims [--dry-run] [--gitignore | --no-gitignore]
29
31
  # skill shim per harness; stale .gitignore lines
30
32
  agent_toggle.py config [--json] # settings menu (curses, else numbered list)
@@ -685,13 +687,20 @@ def build_parser() -> argparse.ArgumentParser:
685
687
  help="skip the stale park-dir line check")
686
688
  sp.set_defaults(prompt=True) # the config menu passes False: no y/n under curses
687
689
  pp = sub.add_parser("profile", parents=[common],
688
- help="save / apply / diff / list / delete / rename named sets of live items")
689
- pp.add_argument("action", help="save | apply | diff | list | delete | rename")
690
+ help="save / apply / diff / list / delete / rename named sets of live "
691
+ "items; bind one to a project")
692
+ pp.add_argument("action",
693
+ help="save | apply | diff | list | delete | rename | bind | unbind | auto")
690
694
  pp.add_argument("target", nargs="?", metavar="name|file")
691
695
  pp.add_argument("new_name", nargs="?", metavar="new", help="rename: the new name")
692
696
  pp.add_argument("--out", metavar="file", help="save: write the profile here instead")
693
- pp.add_argument("--dry-run", action="store_true", help="apply: show the plan; change nothing")
697
+ pp.add_argument("--dry-run", action="store_true",
698
+ help="apply / auto: show the plan; change nothing")
694
699
  pp.add_argument("--project", metavar="dir", help=PROJECT_HELP)
700
+ pp.add_argument("--dir", metavar="dir",
701
+ help="bind / unbind / auto: the project dir (default: the current one)")
702
+ pp.add_argument("--global", dest="everywhere", action="store_true",
703
+ help="bind / unbind: the profile for every dir with no binding of its own")
695
704
  sub.add_parser("doctor", parents=[common],
696
705
  help="check harness layouts and state against disk; offers y/n fixes")
697
706
  sub.add_parser("update", parents=[common],
@@ -72,6 +72,12 @@ def profiles_dir() -> Path:
72
72
  return state_dir() / "profiles"
73
73
 
74
74
 
75
+ def bindings_file() -> Path:
76
+ """Which profile each project dir loads. Outside profiles/: that dir may be synced
77
+ between machines, and these keys are this machine's absolute paths."""
78
+ return state_dir() / "profile-bindings.json"
79
+
80
+
75
81
  def parked_dir() -> Path:
76
82
  return state_dir() / "parked"
77
83
 
@@ -79,20 +79,33 @@ def commands(default_harness: str = "claude") -> dict[str, Cmd]:
79
79
  options=[_dry_run()],
80
80
  examples=["undo --dry-run", "undo"]),
81
81
  "profile": Cmd(
82
- "profile save|apply|diff|list|delete|rename [name|file] [new] [--out file] [--dry-run] "
83
- "[--project dir]",
84
- t("help.profile.summary", "save / apply / diff / list / delete / rename named sets of live items"),
82
+ "profile save|apply|diff|list|delete|rename|bind|unbind|auto [name|file] [new] "
83
+ "[--out file] [--dry-run] [--project dir] [--dir dir] [--global]",
84
+ t("help.profile.summary", "save / apply / diff / list / delete / rename named sets "
85
+ "of live items; bind one to a project"),
85
86
  t("help.profile.desc", "A profile records which items are live, so a whole "
86
- "setup can be switched in one step."),
87
- args=[("save|apply|diff|list|delete|rename", t("help.arg.profile_action", "what to do")),
87
+ "setup can be switched in one step. `bind` ties a saved "
88
+ "profile to a project dir (or, with --global, to every dir "
89
+ "that has none); `auto` applies the one bound to a dir, as "
90
+ "the Claude Code plugin does when a session starts there."),
91
+ args=[("save|apply|diff|list|delete|rename|bind|unbind|auto",
92
+ t("help.arg.profile_action", "what to do")),
88
93
  ("name|file", t("help.arg.profile_target", "a profile name or a JSON file")),
89
94
  ("new", t("help.arg.profile_new", "rename: the new name"))],
90
95
  options=[("--out file", t("help.opt.out", "save: write the profile here instead")),
91
96
  ("--dry-run", t("help.opt.profile_dry_run",
92
- "apply: show the plan; change nothing")),
93
- _project()],
97
+ "apply / auto: show the plan; change nothing")),
98
+ _project(),
99
+ ("--dir dir", t("help.opt.profile_dir",
100
+ "bind / unbind / auto: the project dir (default: the "
101
+ "current one)")),
102
+ ("--global", t("help.opt.profile_global",
103
+ "bind / unbind: the profile for every dir with no "
104
+ "binding of its own"))],
94
105
  examples=["profile save work", "profile diff work", "profile apply work --dry-run",
95
- "profile list", "profile rename work flutter", "profile delete flutter"]),
106
+ "profile list", "profile rename work flutter", "profile delete flutter",
107
+ "profile bind flutter --dir ~/code/app", "profile bind work --global",
108
+ "profile auto --dry-run", "profile unbind --dir ~/code/app"]),
96
109
  "status": Cmd(
97
110
  "status",
98
111
  t("help.status.summary", "health check"),
@@ -18,8 +18,12 @@ CATALOG: dict[str, str] = {
18
18
  "--all 還原全部(可搭配一個 --harness)。",
19
19
  "help.undo.summary": "復原最近一次記錄的批次",
20
20
  "help.undo.desc": "依記錄復原最近一次 disable/enable 批次。",
21
- "help.profile.summary": "儲存 / 套用 / 比較 / 列出 / 刪除 / 改名具名的啟用項目組合",
22
- "help.profile.desc": "設定檔記錄哪些項目是啟用的,讓整組設定一步切換。",
21
+ "help.profile.summary": "儲存 / 套用 / 比較 / 列出 / 刪除 / 改名具名的啟用項目組合;"
22
+ "可綁定到專案",
23
+ "help.profile.desc": "設定檔記錄哪些項目是啟用的,讓整組設定一步切換。`bind` 把已儲存的"
24
+ "設定檔綁定到專案目錄(加 --global 則用於所有沒有綁定的目錄);"
25
+ "`auto` 套用某目錄所綁定的設定檔,Claude Code 外掛在該目錄開啟 "
26
+ "session 時就是這麼做。",
23
27
  "help.status.summary": "健康檢查",
24
28
  "help.status.desc": "顯示狀態檔、每個已安裝的 harness 與其暫存項目,以及值得修正的偏差。",
25
29
  "help.list.summary": "目前停用了哪些項目",
@@ -58,7 +62,9 @@ CATALOG: dict[str, str] = {
58
62
  "help.arg.profile_target": "設定檔名稱或 JSON 檔",
59
63
  "help.arg.profile_new": "rename:新名稱",
60
64
  "help.opt.out": "save:改寫到這個檔案",
61
- "help.opt.profile_dry_run": "apply:只顯示計畫,不做任何變更",
65
+ "help.opt.profile_dry_run": "apply / auto:只顯示計畫,不做任何變更",
66
+ "help.opt.profile_dir": "bind / unbind / auto:專案目錄(預設為目前目錄)",
67
+ "help.opt.profile_global": "bind / unbind:所有沒有自己綁定的目錄都用這個設定檔",
62
68
  "help.opt.type": "只看這種類型:%s",
63
69
  "help.opt.list_project": "只看這個專案的項目",
64
70
  "help.opt.cost_project": "計算此專案的 .claude 與 .mcp.json,而非使用者範圍",
@@ -18,7 +18,6 @@ from .backends.mcp_json import (
18
18
  _finite,
19
19
  _no_dup,
20
20
  _not_json,
21
- claude_mcp_config,
22
21
  claudeai_connector_names,
23
22
  project_mcp_backup,
24
23
  project_mcp_remove,
@@ -1042,7 +1041,13 @@ def toggle_mcp(action: str, names: list[str], state: dict,
1042
1041
  fails += fail(name, refused)
1043
1042
  continue
1044
1043
 
1045
- if backend == "claude-json" and name in claudeai_connector_names():
1044
+ connector = backend == "claude-json" and name in claudeai_connector_names()
1045
+ # A configured server is marked off per project like a connector, never removed:
1046
+ # Claude Code builds its MCP list once per session and `/mcp enable` reaches only a
1047
+ # listed server, so a removed one could not load until a new session.
1048
+ if connector or backend == "claude-json" and (
1049
+ (entry or {}).get("connector")
1050
+ or action == "disable" and name in live_mcp(home, backend)):
1046
1051
  ok, detail = toggle_claudeai_connector(action, name, dry_run)
1047
1052
  if not ok:
1048
1053
  fails += fail(name, str(detail))
@@ -1057,15 +1062,17 @@ def toggle_mcp(action: str, names: list[str], state: dict,
1057
1062
  }
1058
1063
  _ok(out, dry_run, harness, "mcp", action, name,
1059
1064
  f"disabled across {n} project(s) "
1060
- f"(claude.ai connector -- account stays connected, "
1061
- f"just parked per-project; new project dirs need a re-run)",
1065
+ + ("(claude.ai connector -- account stays connected, "
1066
+ "just parked per-project; new project dirs need a re-run)" if connector
1067
+ else "(config kept in ~/.claude.json; the mod marks new project dirs)"),
1062
1068
  connector=True, projects=detail)
1063
1069
  else:
1064
1070
  if not dry_run:
1065
1071
  state["disabled"].pop(key, None)
1066
1072
  _ok(out, dry_run, harness, "mcp", action, name,
1067
1073
  f"restored across {n} project(s) "
1068
- f"(open a NEW session for it to load)",
1074
+ + ("(open a NEW session for it to load)" if connector
1075
+ else f"(`/mcp enable {name}` loads it in a running session)"),
1069
1076
  connector=True, projects=detail)
1070
1077
  if not dry_run:
1071
1078
  log(action, "mcp", name, "ok", json.dumps(detail), harness=harness,
@@ -1076,35 +1083,23 @@ def toggle_mcp(action: str, names: list[str], state: dict,
1076
1083
  scope, project = "user", None
1077
1084
 
1078
1085
  if action == "disable":
1079
- if backend == "claude-json":
1080
- try:
1081
- found = claude_mcp_config(name)
1082
- except LookupError as e:
1083
- fails += fail(name, str(e))
1084
- continue
1085
- if found is None:
1086
- hint = ("not in ~/.claude.json (user or local scope) -- "
1087
- "a repo's own .mcp.json needs --project <dir>")
1088
- if not dry_run: # a dry run never shells out to claude
1089
- ok, cfg = run_cli(claude_bin(), ["mcp", "get", name])
1090
- if ok and "claude.ai config" in cfg:
1091
- hint = ("account-level claude.ai connector -- disable it "
1092
- "at claude.ai (Settings -> Connectors)")
1093
- fails += fail(name, hint)
1094
- continue
1095
- raw, scope, project = found
1096
- if dry_run and not claude_bin():
1097
- fails += fail(name, "claude CLI not found")
1098
- continue
1099
- saved = json.dumps(raw, indent=2, ensure_ascii=False)
1100
- else: # toml
1101
- config = home / "config.toml"
1102
- # plan first, back up, THEN edit: the block is never only in memory
1103
- block = codex_mcp_remove(config, name, True) if config.exists() else None
1104
- if block is None:
1105
- fails += fail(name, f"no [mcp_servers.{name}] in {config}")
1106
- continue
1107
- saved = json.dumps({"toml": block}, ensure_ascii=False, indent=2)
1086
+ if backend == "claude-json": # a configured server was marked off above
1087
+ hint = ("not in ~/.claude.json (user or local scope) -- "
1088
+ "a repo's own .mcp.json needs --project <dir>")
1089
+ if not dry_run: # a dry run never shells out to claude
1090
+ ok, cfg = run_cli(claude_bin(), ["mcp", "get", name])
1091
+ if ok and "claude.ai config" in cfg:
1092
+ hint = ("account-level claude.ai connector -- disable it "
1093
+ "at claude.ai (Settings -> Connectors)")
1094
+ fails += fail(name, hint)
1095
+ continue
1096
+ config = home / "config.toml"
1097
+ # plan first, back up, THEN edit: the block is never only in memory
1098
+ block = codex_mcp_remove(config, name, True) if config.exists() else None
1099
+ if block is None:
1100
+ fails += fail(name, f"no [mcp_servers.{name}] in {config}")
1101
+ continue
1102
+ saved = json.dumps({"toml": block}, ensure_ascii=False, indent=2)
1108
1103
 
1109
1104
  where = f" [{scope}{f': {project}' if project else ''}]"
1110
1105
  if not dry_run:
@@ -1123,25 +1118,14 @@ def toggle_mcp(action: str, names: list[str], state: dict,
1123
1118
  bp.unlink(missing_ok=True)
1124
1119
  fails += fail(name, f"state not saved, nothing changed: {e}")
1125
1120
  continue
1126
- if backend == "claude-json":
1127
- ok, res = run_cli(claude_bin(), ["mcp", "remove", name, "-s", scope],
1128
- cwd=project)
1129
- err = None if ok else redact(res, raw)[:100]
1130
- else:
1131
- try:
1132
- codex_mcp_remove(config, name)
1133
- err = None
1134
- except fs.WriteError as e: # config rolled back
1135
- err = str(e)
1136
- if err is not None: # settled from the file: untouched -> backup dropped
1137
- settle(state, key, out, inline=True)
1138
- fails += fail(name, err)
1121
+ try:
1122
+ codex_mcp_remove(config, name)
1123
+ except fs.WriteError as e: # config rolled back; settled from the file:
1124
+ settle(state, key, out, inline=True) # untouched -> backup dropped
1125
+ fails += fail(name, str(e))
1139
1126
  continue
1140
1127
  state["disabled"][key] = new
1141
1128
  end(state, key)
1142
- # claude local scope logs its real scope + cwd; undo treats every
1143
- # scope but `project` (a --project change) as user scope, which is right
1144
- # for local: the replay finds the user-keyed entry and its own cwd.
1145
1129
  log(action, "mcp", name, "ok", str(bp), harness=harness, batch=batch,
1146
1130
  project=project, scope=scope)
1147
1131
  _ok(out, dry_run, harness, "mcp", action, name,