@dsh-cc/plugin-manager 0.6.0

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 (65) hide show
  1. package/LICENSE +201 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +32 -0
  4. package/README.zh.md +32 -0
  5. package/lib/errors.d.ts +51 -0
  6. package/lib/errors.d.ts.map +1 -0
  7. package/lib/errors.js +94 -0
  8. package/lib/errors.js.map +1 -0
  9. package/lib/git.d.ts +38 -0
  10. package/lib/git.d.ts.map +1 -0
  11. package/lib/git.js +38 -0
  12. package/lib/git.js.map +1 -0
  13. package/lib/index.d.ts +74 -0
  14. package/lib/index.d.ts.map +1 -0
  15. package/lib/index.js +94 -0
  16. package/lib/index.js.map +1 -0
  17. package/lib/install.d.ts +67 -0
  18. package/lib/install.d.ts.map +1 -0
  19. package/lib/install.js +192 -0
  20. package/lib/install.js.map +1 -0
  21. package/lib/list.d.ts +35 -0
  22. package/lib/list.d.ts.map +1 -0
  23. package/lib/list.js +98 -0
  24. package/lib/list.js.map +1 -0
  25. package/lib/marketplace.d.ts +89 -0
  26. package/lib/marketplace.d.ts.map +1 -0
  27. package/lib/marketplace.js +426 -0
  28. package/lib/marketplace.js.map +1 -0
  29. package/lib/merged-state.d.ts +54 -0
  30. package/lib/merged-state.d.ts.map +1 -0
  31. package/lib/merged-state.js +88 -0
  32. package/lib/merged-state.js.map +1 -0
  33. package/lib/paths.d.ts +75 -0
  34. package/lib/paths.d.ts.map +1 -0
  35. package/lib/paths.js +173 -0
  36. package/lib/paths.js.map +1 -0
  37. package/lib/resolve-id.d.ts +43 -0
  38. package/lib/resolve-id.d.ts.map +1 -0
  39. package/lib/resolve-id.js +110 -0
  40. package/lib/resolve-id.js.map +1 -0
  41. package/lib/settings-write.d.ts +16 -0
  42. package/lib/settings-write.d.ts.map +1 -0
  43. package/lib/settings-write.js +32 -0
  44. package/lib/settings-write.js.map +1 -0
  45. package/lib/state-store.d.ts +24 -0
  46. package/lib/state-store.d.ts.map +1 -0
  47. package/lib/state-store.js +54 -0
  48. package/lib/state-store.js.map +1 -0
  49. package/lib/toggles.d.ts +30 -0
  50. package/lib/toggles.d.ts.map +1 -0
  51. package/lib/toggles.js +62 -0
  52. package/lib/toggles.js.map +1 -0
  53. package/lib/types.d.ts +57 -0
  54. package/lib/types.d.ts.map +1 -0
  55. package/lib/types.js +9 -0
  56. package/lib/types.js.map +1 -0
  57. package/lib/uninstall.d.ts +30 -0
  58. package/lib/uninstall.d.ts.map +1 -0
  59. package/lib/uninstall.js +78 -0
  60. package/lib/uninstall.js.map +1 -0
  61. package/lib/update.d.ts +34 -0
  62. package/lib/update.d.ts.map +1 -0
  63. package/lib/update.js +67 -0
  64. package/lib/update.js.map +1 -0
  65. package/package.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/compat/cc-plugin-manager/README.md
5
+ README.md: 99f3c1bab1a1b2473a61935568fa1c7e636d99ac
6
+ README.zh.md: fdeb68dda91e22855fb4e2c95eebbc505501fb5a
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @dsh-cc/plugin-manager
2
+
3
+ English | [中文](README.zh.md)
4
+
5
+ Manage Claude Code plugin state in-session: marketplaces, installs, per-scope enablement — reading and writing the same on-disk files (and byte shapes) as the real `claude plugin` CLI, so the two stay interoperable.
6
+
7
+ ## State root: dual-home (compat-read `~/.claude`, write `~/.dsh`)
8
+
9
+ Plugin state is dual-home:
10
+
11
+ - **Write root — `$DSH_HOME` / `~/.dsh`.** Every mutation (install / uninstall / enable / disable / update / marketplace add / remove / update) writes only under the dsh home (`plugins/{known_marketplaces.json, installed_plugins.json, marketplaces/, cache/}` and `~/.dsh/settings.json` for user-scope `enabledPlugins` / `extraKnownMarketplaces`). Per-repo project/local scope files (`<cwd>/.claude/...`) stay exactly where Claude Code keeps them.
12
+ - **Read root — `$CLAUDE_CONFIG_DIR` / `~/.claude`, fully visible.** Existing Claude-home state simply keeps working; nothing migrates and nothing is ever deleted from the Claude home.
13
+ - **Per-key dsh-wins merge.** When both homes carry the same key (marketplace name or plugin id), the dsh entry wins; claude-only keys pass through. A dsh `known_marketplaces.json` value of `null` is a private tombstone that hides a claude-only marketplace. A dsh `installed_plugins.json` entry list — including an empty list — shadows the claude list for that id.
14
+
15
+ Consequences:
16
+
17
+ - **One-way fork.** dsh-cc sees both homes; real Claude Code sees only its own. A plugin claimed by dsh is invisible to the `claude` CLI until installed there.
18
+ - **Takeover staleness.** Once dsh-cc writes an id into the dsh `installed_plugins.json`, later claude-side changes to that id become invisible to dsh-cc — dsh manages what it has touched.
19
+ - **`CLAUDE_CONFIG_DIR` no longer relocates writes.** With `$CLAUDE_CONFIG_DIR` set, writes follow `$DSH_HOME` (previously they followed `CLAUDE_CONFIG_DIR`); users who used it as a relocation knob should set `DSH_HOME` instead.
20
+ - **Legacy single-root.** A caller passing **only `claudeHome`** (no `dshHome`) keeps the pre-dual-home behavior byte-identically: that directory is both the read and the write root.
21
+
22
+ The resolution chain is: explicit `dshHome` → explicit `claudeHome` (legacy single-root) → `resolveDshHome()` (`$DSH_HOME` → `~/.dsh`). Resolution happens before deps are built, so a no-options production caller always resolves dual-home.
23
+
24
+ ## Surface
25
+
26
+ `createCcPluginManager({ claudeHome?, dshHome?, cwd?, runGit? })` returns a manager with `list`, `install`, `uninstall`, `enable`, `disable`, `update`, `listMarketplaces`, `addMarketplace`, `removeMarketplace`, `updateMarketplaces`. Mutations resolve against the merged view; every operation re-reads both homes, so a real-CC change appears on the very next operation (except for taken-over ids, above). Claude-owned material (marketplace clones, cache dirs) is never deleted, moved, or orphan-marked; marketplace updates of claude-owned git entries are served by promote-on-write (a fresh clone into the dsh home, the claude entry untouched).
27
+
28
+ ## Known limits and deferred work
29
+
30
+ - No interactive menu UI, trust dialogs, `details/eval/init/prune/tag/validate` subcommands, `managed` scope, or orphan sweeping (CC-shape parity scope: `docs/plans/2026-09-06-plugin-management.md`).
31
+ - `extraKnownMarketplaces` user-scope declarations write to `~/.dsh/settings.json`; removing one that exists only in the claude file is a no-op for dsh-cc's own view (nothing reads it) and leaves the claude file untouched.
32
+ - No bulk migration command (`/plugin migrate`); revisit on user demand.
package/README.zh.md ADDED
@@ -0,0 +1,32 @@
1
+ # @dsh-cc/plugin-manager
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 在会话内管理 Claude Code 插件状态:marketplace、安装、按作用域的启用——读写与真正的 `claude plugin` CLI 相同的磁盘文件(以及字节形状),两者保持互操作。
6
+
7
+ ## 状态根:双 home(兼容读 `~/.claude`,写入 `~/.dsh`)
8
+
9
+ 插件状态是双 home 的:
10
+
11
+ - **写根——`$DSH_HOME` / `~/.dsh`。** 每个变更操作(install / uninstall / enable / disable / update / marketplace add / remove / update)只写在 dsh home 之下(`plugins/{known_marketplaces.json, installed_plugins.json, marketplaces/, cache/}`,user 作用域的 `enabledPlugins` / `extraKnownMarketplaces` 写在 `~/.dsh/settings.json`)。按仓库的 project/local 作用域文件(`<cwd>/.claude/...`)保持 Claude Code 原来的位置不变。
12
+ - **读根——`$CLAUDE_CONFIG_DIR` / `~/.claude`,完全可见。** 既有的 Claude home 状态照常工作;不迁移,也绝不删除 Claude home 里的任何东西。
13
+ - **按 key 合并、dsh 优先。** 两个 home 携带同一 key(marketplace 名或插件 id)时,dsh 条目胜出;仅 claude 的 key 直接透传。dsh `known_marketplaces.json` 中的 `null` 值是私有墓碑,用来隐藏仅存在于 claude 的 marketplace。dsh `installed_plugins.json` 的条目列表——包括空列表——遮蔽该 id 的 claude 列表。
14
+
15
+ 后果:
16
+
17
+ - **单向分叉。** dsh-cc 能看到两个 home;真正的 Claude Code 只看得到自己的。被 dsh 接管的插件对 `claude` CLI 不可见,除非在那边重新安装。
18
+ - **接管陈旧性。** 一旦 dsh-cc 把某个 id 写进 dsh 的 `installed_plugins.json`,之后 claude 侧对该 id 的改动对 dsh-cc 不可见——dsh 管理它碰过的东西。
19
+ - **`CLAUDE_CONFIG_DIR` 不再决定写入位置。** 设置了 `$CLAUDE_CONFIG_DIR` 时,写入跟随 `$DSH_HOME`(以前跟随 `CLAUDE_CONFIG_DIR`);曾把它当作重定位旋钮的用户应改设 `DSH_HOME`。
20
+ - **旧版单根。** 只传 **`claudeHome`**(不传 `dshHome`)的调用方与双 home 之前的行为逐字节一致:该目录既是读根也是写根。
21
+
22
+ 解析链为:显式 `dshHome` → 显式 `claudeHome`(旧版单根)→ `resolveDshHome()`(`$DSH_HOME` → `~/.dsh`)。解析发生在构建 deps 之前,因此无选项的生产调用方总是解析为双 home。
23
+
24
+ ## 接口
25
+
26
+ `createCcPluginManager({ claudeHome?, dshHome?, cwd?, runGit? })` 返回带 `list`、`install`、`uninstall`、`enable`、`disable`、`update`、`listMarketplaces`、`addMarketplace`、`removeMarketplace`、`updateMarketplaces` 的管理器。变更基于合并视图解析;每次操作都重读两个 home,真正的 CC 改动在下一次操作即可见(已接管的 id 除外,见上)。claude 拥有的内容(marketplace 克隆、cache 目录)绝不被删除、移动或打孤儿标记;对 claude 拥有的 git marketplace 做 update 由 promote-on-write 服务(向 dsh home 做一次全新克隆,claude 条目原样不动)。
27
+
28
+ ## 已知限制与延后工作
29
+
30
+ - 没有交互式菜单 UI、信任对话框、`details/eval/init/prune/tag/validate` 子命令、`managed` 作用域或孤儿清扫(CC 形状对齐范围见 `docs/plans/2026-09-06-plugin-management.md`)。
31
+ - `extraKnownMarketplaces` 的 user 作用域声明写入 `~/.dsh/settings.json`;删除仅存在于 claude 文件中的声明对 dsh-cc 自身视图是 no-op(无人读取),claude 文件保持不动。
32
+ - 没有批量迁移命令(`/plugin migrate`);有用户需求时再议。
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Typed errors for the plugin manager, carrying the exact strings from the
3
+ * plan §3 error catalog (the S1 slice covers malformed state files; later
4
+ * slices add their own codes to this catalog).
5
+ *
6
+ * @module @dsh-cc/plugin-manager/errors
7
+ */
8
+ export type PluginManagerErrorCode = 'PLUGIN_STATE_MALFORMED' | 'UNKNOWN_PLUGIN' | 'AMBIGUOUS_PLUGIN_NAME' | 'PLUGIN_NOT_INSTALLED' | 'AMBIGUOUS_PLUGIN_SCOPES' | 'UNKNOWN_SCOPE' | 'UNKNOWN_MARKETPLACE' | 'MARKETPLACE_CONFLICT' | 'MARKETPLACE_NAME_MISMATCH' | 'MARKETPLACE_BAD_SOURCE' | 'MARKETPLACE_MANIFEST_MISSING' | 'MARKETPLACE_PLUGIN_NOT_DECLARED' | 'PLUGIN_SOURCE_UNSUPPORTED' | 'PLUGIN_ALREADY_INSTALLED' | 'PLUGIN_ENABLED_AT_PROJECT' | 'GIT_FAILED' | 'PLUGIN_MANAGER_ERROR';
9
+ /**
10
+ * Base error: a stable machine-readable `code` plus the exact human message
11
+ * (the §3 catalog strings) that commands render verbatim.
12
+ */
13
+ export declare class PluginManagerError extends Error {
14
+ readonly code: PluginManagerErrorCode;
15
+ constructor(code: PluginManagerErrorCode, message: string);
16
+ }
17
+ /** `State file <path> is malformed JSON: <detail>` — never silently rewritten. */
18
+ export declare function malformedStateFile(file: string, detail: string): PluginManagerError;
19
+ /** `Unknown plugin "<arg>". Installed: <id1>, <id2>` (or `…none` when empty). */
20
+ export declare function unknownPlugin(arg: string, installedKeys: readonly string[]): PluginManagerError;
21
+ /** `Plugin name "<name>" is ambiguous: <id1>, <id2>. Use the full <name>@<marketplace> id.` */
22
+ export declare function ambiguousPluginName(name: string, matches: readonly string[]): PluginManagerError;
23
+ /** `Plugin "<id>" is not installed.` */
24
+ export declare function pluginNotInstalled(id: string): PluginManagerError;
25
+ /** `Plugin "<id>" is installed at multiple scopes (<s1>, <s2>); pass --scope.` */
26
+ export declare function ambiguousPluginScopes(id: string, scopes: readonly string[]): PluginManagerError;
27
+ /** `Unknown scope "<s>". Expected user, project, or local.` */
28
+ export declare function unknownScope(scope: string): PluginManagerError;
29
+ /** `Unknown marketplace "<name>". Known: <sorted names or '(none)'>`. */
30
+ export declare function unknownMarketplace(name: string, knownNames: readonly string[]): PluginManagerError;
31
+ /** `Marketplace "<name>" is already registered from a different source (<existing-kind>).` */
32
+ export declare function marketplaceConflict(name: string, existingKind: string): PluginManagerError;
33
+ /** `Marketplace manifest name "<actual>" does not match the entry name "<expected>".` (§4.7 promote guard) */
34
+ export declare function marketplaceNameMismatch(expected: string, actual: string): PluginManagerError;
35
+ /** `Marketplace source "<src>" is not a readable directory, owner/repo, or git URL.` */
36
+ export declare function invalidMarketplaceSource(source: string): PluginManagerError;
37
+ /** `Marketplace at <dir> has no readable .claude-plugin/marketplace.json (<detail>).` */
38
+ export declare function marketplaceManifestMissing(dir: string, detail: string): PluginManagerError;
39
+ /** `Marketplace "<mkt>" does not declare a plugin named "<p>".` (S4 declared resolution) */
40
+ export declare function marketplacePluginNotDeclared(marketplace: string, pluginName: string): PluginManagerError;
41
+ /** `Unknown plugin "<name>". Declared: <id1>, <id2>` (or `…(none)` when empty). */
42
+ export declare function unknownDeclaredPlugin(name: string, declaredIds: readonly string[]): PluginManagerError;
43
+ /** `Plugin "<id>" uses an unsupported source form (v1 supports directory strings).` */
44
+ export declare function unsupportedPluginSource(id: string): PluginManagerError;
45
+ /** `Plugin "<id>" is already installed at scope <s> on this machine.` */
46
+ export declare function pluginAlreadyInstalled(id: string, scope: string): PluginManagerError;
47
+ /** `Plugin "<id>" has no installation at scope <s> (installed at: <s1>, <s2>).` — scopes in canonical order, or `none`. */
48
+ export declare function noInstallationAtScope(id: string, scope: string, installedScopes: readonly string[]): PluginManagerError;
49
+ /** The C5 guard, verbatim: refuse while project settings (team-shared) enable the plugin. */
50
+ export declare function projectScopeEnabledGuard(id: string): PluginManagerError;
51
+ //# sourceMappingURL=errors.d.ts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U,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAGlG;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,kBAAkB,CAK1F;AAED,8GAA8G;AAC9G,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAK5F;AAED,wFAAwF;AACxF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAK3E;AAED,yFAAyF;AACzF,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAK1F;AAED,4FAA4F;AAC5F,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,kBAAkB,CAKxG;AAED,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAGtG;AAED,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAKtE;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,kBAAkB,CAEpF;AAED,2HAA2H;AAC3H,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAIvH;AAED,6FAA6F;AAC7F,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAKvE"}
package/lib/errors.js ADDED
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Typed errors for the plugin manager, carrying the exact strings from the
3
+ * plan §3 error catalog (the S1 slice covers malformed state files; later
4
+ * slices add their own codes to this catalog).
5
+ *
6
+ * @module @dsh-cc/plugin-manager/errors
7
+ */
8
+ /**
9
+ * Base error: a stable machine-readable `code` plus the exact human message
10
+ * (the §3 catalog strings) that commands render verbatim.
11
+ */
12
+ export class PluginManagerError extends Error {
13
+ code;
14
+ constructor(code, message) {
15
+ super(message);
16
+ this.name = 'PluginManagerError';
17
+ this.code = code;
18
+ }
19
+ }
20
+ /** `State file <path> is malformed JSON: <detail>` — never silently rewritten. */
21
+ export function malformedStateFile(file, detail) {
22
+ return new PluginManagerError('PLUGIN_STATE_MALFORMED', `State file ${file} is malformed JSON: ${detail}`);
23
+ }
24
+ /** `Unknown plugin "<arg>". Installed: <id1>, <id2>` (or `…none` when empty). */
25
+ export function unknownPlugin(arg, installedKeys) {
26
+ const installed = installedKeys.length === 0 ? 'none' : [...installedKeys].sort().join(', ');
27
+ return new PluginManagerError('UNKNOWN_PLUGIN', `Unknown plugin "${arg}". Installed: ${installed}`);
28
+ }
29
+ /** `Plugin name "<name>" is ambiguous: <id1>, <id2>. Use the full <name>@<marketplace> id.` */
30
+ export function ambiguousPluginName(name, matches) {
31
+ const ids = [...matches].sort().join(', ');
32
+ return new PluginManagerError('AMBIGUOUS_PLUGIN_NAME', `Plugin name "${name}" is ambiguous: ${ids}. Use the full <name>@<marketplace> id.`);
33
+ }
34
+ /** `Plugin "<id>" is not installed.` */
35
+ export function pluginNotInstalled(id) {
36
+ return new PluginManagerError('PLUGIN_NOT_INSTALLED', `Plugin "${id}" is not installed.`);
37
+ }
38
+ /** `Plugin "<id>" is installed at multiple scopes (<s1>, <s2>); pass --scope.` */
39
+ export function ambiguousPluginScopes(id, scopes) {
40
+ return new PluginManagerError('AMBIGUOUS_PLUGIN_SCOPES', `Plugin "${id}" is installed at multiple scopes (${scopes.join(', ')}); pass --scope.`);
41
+ }
42
+ /** `Unknown scope "<s>". Expected user, project, or local.` */
43
+ export function unknownScope(scope) {
44
+ return new PluginManagerError('UNKNOWN_SCOPE', `Unknown scope "${scope}". Expected user, project, or local.`);
45
+ }
46
+ /** `Unknown marketplace "<name>". Known: <sorted names or '(none)'>`. */
47
+ export function unknownMarketplace(name, knownNames) {
48
+ const known = knownNames.length === 0 ? '(none)' : [...knownNames].sort().join(', ');
49
+ return new PluginManagerError('UNKNOWN_MARKETPLACE', `Unknown marketplace "${name}". Known: ${known}`);
50
+ }
51
+ /** `Marketplace "<name>" is already registered from a different source (<existing-kind>).` */
52
+ export function marketplaceConflict(name, existingKind) {
53
+ return new PluginManagerError('MARKETPLACE_CONFLICT', `Marketplace "${name}" is already registered from a different source (${existingKind}).`);
54
+ }
55
+ /** `Marketplace manifest name "<actual>" does not match the entry name "<expected>".` (§4.7 promote guard) */
56
+ export function marketplaceNameMismatch(expected, actual) {
57
+ return new PluginManagerError('MARKETPLACE_NAME_MISMATCH', `Marketplace manifest name "${actual}" does not match the entry name "${expected}".`);
58
+ }
59
+ /** `Marketplace source "<src>" is not a readable directory, owner/repo, or git URL.` */
60
+ export function invalidMarketplaceSource(source) {
61
+ return new PluginManagerError('MARKETPLACE_BAD_SOURCE', `Marketplace source "${source}" is not a readable directory, owner/repo, or git URL.`);
62
+ }
63
+ /** `Marketplace at <dir> has no readable .claude-plugin/marketplace.json (<detail>).` */
64
+ export function marketplaceManifestMissing(dir, detail) {
65
+ return new PluginManagerError('MARKETPLACE_MANIFEST_MISSING', `Marketplace at ${dir} has no readable .claude-plugin/marketplace.json (${detail}).`);
66
+ }
67
+ /** `Marketplace "<mkt>" does not declare a plugin named "<p>".` (S4 declared resolution) */
68
+ export function marketplacePluginNotDeclared(marketplace, pluginName) {
69
+ return new PluginManagerError('MARKETPLACE_PLUGIN_NOT_DECLARED', `Marketplace "${marketplace}" does not declare a plugin named "${pluginName}".`);
70
+ }
71
+ /** `Unknown plugin "<name>". Declared: <id1>, <id2>` (or `…(none)` when empty). */
72
+ export function unknownDeclaredPlugin(name, declaredIds) {
73
+ const declared = declaredIds.length === 0 ? '(none)' : [...declaredIds].sort().join(', ');
74
+ return new PluginManagerError('UNKNOWN_PLUGIN', `Unknown plugin "${name}". Declared: ${declared}`);
75
+ }
76
+ /** `Plugin "<id>" uses an unsupported source form (v1 supports directory strings).` */
77
+ export function unsupportedPluginSource(id) {
78
+ return new PluginManagerError('PLUGIN_SOURCE_UNSUPPORTED', `Plugin "${id}" uses an unsupported source form (v1 supports directory strings).`);
79
+ }
80
+ /** `Plugin "<id>" is already installed at scope <s> on this machine.` */
81
+ export function pluginAlreadyInstalled(id, scope) {
82
+ return new PluginManagerError('PLUGIN_ALREADY_INSTALLED', `Plugin "${id}" is already installed at scope ${scope} on this machine.`);
83
+ }
84
+ /** `Plugin "<id>" has no installation at scope <s> (installed at: <s1>, <s2>).` — scopes in canonical order, or `none`. */
85
+ export function noInstallationAtScope(id, scope, installedScopes) {
86
+ const canonical = ['user', 'project', 'local'].filter(s => installedScopes.includes(s));
87
+ const at = canonical.length === 0 ? 'none' : canonical.join(', ');
88
+ return new PluginManagerError('PLUGIN_NOT_INSTALLED', `Plugin "${id}" has no installation at scope ${scope} (installed at: ${at}).`);
89
+ }
90
+ /** The C5 guard, verbatim: refuse while project settings (team-shared) enable the plugin. */
91
+ export function projectScopeEnabledGuard(id) {
92
+ return new PluginManagerError('PLUGIN_ENABLED_AT_PROJECT', `Plugin "${id}" is enabled at project scope (.claude/settings.json, shared with your team). To disable just for you: /plugin disable ${id} --scope local`);
93
+ }
94
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAqBH;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,IAAI,CAAwB;IAErC,YAAY,IAA4B,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,kFA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B,2BAA2B,EAC3B,WAAW,EAAE,0HAA0H,EAAE,gBAAgB,CAC1J,CAAA;AACH,CAAC"}
package/lib/git.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * GitRunner contract for marketplace clones/updates (plan §4.B): hosts and
3
+ * tests inject fakes; the default implementation shells out to the system
4
+ * `git` with a timeout. Failures surface the exact §3 catalog string
5
+ * `git <verb> failed for <target>: <first stderr line>` (stderr empty ⇒
6
+ * `exit code <n>`), where verb = first git arg and target = last.
7
+ *
8
+ * @module @dsh-cc/plugin-manager/git
9
+ */
10
+ import { PluginManagerError } from './errors.ts';
11
+ export type GitRunner = (args: string[], opts: {
12
+ cwd: string;
13
+ }) => Promise<{
14
+ code: number;
15
+ stdout: string;
16
+ stderr: string;
17
+ }>;
18
+ export interface GitRunnerOptions {
19
+ /** Kill the git process after this many milliseconds (default 60000). */
20
+ timeoutMs?: number;
21
+ }
22
+ /**
23
+ * Default GitRunner: `execFile('git', args, { cwd, timeout })`. A non-zero
24
+ * exit, spawn failure, or timeout maps to `code` (spawn/timeout ⇒ 1) with
25
+ * the collected stdout/stderr; the promise never rejects.
26
+ */
27
+ export declare function createSystemGitRunner(options?: GitRunnerOptions): GitRunner;
28
+ /**
29
+ * The §3 git failure error: `git <verb> failed for <target>: <first stderr
30
+ * line>` — verb is the git subcommand and target the thing operated on (the
31
+ * clone url, or the `-C` location for pulls); empty stderr falls back to
32
+ * `exit code <n>`.
33
+ */
34
+ export declare function gitFailure(verb: string, target: string, result: {
35
+ code: number;
36
+ stderr: string;
37
+ }): PluginManagerError;
38
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAE5H,MAAM,WAAW,gBAAgB;IAC/B,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAU/E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,kBAAkB,CAIrH"}
package/lib/git.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * GitRunner contract for marketplace clones/updates (plan §4.B): hosts and
3
+ * tests inject fakes; the default implementation shells out to the system
4
+ * `git` with a timeout. Failures surface the exact §3 catalog string
5
+ * `git <verb> failed for <target>: <first stderr line>` (stderr empty ⇒
6
+ * `exit code <n>`), where verb = first git arg and target = last.
7
+ *
8
+ * @module @dsh-cc/plugin-manager/git
9
+ */
10
+ import { execFile } from 'node:child_process';
11
+ import { PluginManagerError } from "./errors.js";
12
+ /**
13
+ * Default GitRunner: `execFile('git', args, { cwd, timeout })`. A non-zero
14
+ * exit, spawn failure, or timeout maps to `code` (spawn/timeout ⇒ 1) with
15
+ * the collected stdout/stderr; the promise never rejects.
16
+ */
17
+ export function createSystemGitRunner(options = {}) {
18
+ const timeoutMs = options.timeoutMs ?? 60000;
19
+ return (args, opts) => new Promise(resolve => {
20
+ execFile('git', args, { cwd: opts.cwd, timeout: timeoutMs, encoding: 'utf8' }, (error, stdout, stderr) => {
21
+ const rawCode = error?.code;
22
+ const code = typeof rawCode === 'number' ? rawCode : error ? 1 : 0;
23
+ resolve({ code, stdout: String(stdout ?? ''), stderr: String(stderr ?? '') });
24
+ });
25
+ });
26
+ }
27
+ /**
28
+ * The §3 git failure error: `git <verb> failed for <target>: <first stderr
29
+ * line>` — verb is the git subcommand and target the thing operated on (the
30
+ * clone url, or the `-C` location for pulls); empty stderr falls back to
31
+ * `exit code <n>`.
32
+ */
33
+ export function gitFailure(verb, target, result) {
34
+ const firstStderrLine = result.stderr.split('\n').map(line => line.trim()).find(line => line.length > 0);
35
+ const detail = firstStderrLine ?? `exit code ${result.code}`;
36
+ return new PluginManagerError('GIT_FAILED', `git ${verb} failed for ${target}: ${detail}`);
37
+ }
38
+ //# sourceMappingURL=git.js.map
package/lib/git.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAShD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAA4B,EAAE;IAClE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAA;IAC5C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACpB,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YACvG,MAAM,OAAO,GAAI,KAAmC,EAAE,IAAI,CAAA;YAC1D,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAClE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;QAC/E,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,MAAc,EAAE,MAAwC;IAC/F,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACxG,MAAM,MAAM,GAAG,eAAe,IAAI,aAAa,MAAM,CAAC,IAAI,EAAE,CAAA;IAC5D,OAAO,IAAI,kBAAkB,CAAC,YAAY,EAAE,OAAO,IAAI,eAAe,MAAM,KAAK,MAAM,EAAE,CAAC,CAAA;AAC5F,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Factory for the Claude Code plugin manager core: binds the state paths to
3
+ * a `claudeHome` + `cwd` pair and exposes listing plus the enable/disable
4
+ * mutations. Mutations serialize through a per-instance promise queue —
5
+ * a subsequent call only starts after the previous one settles (in-process
6
+ * lost-update protection; cross-process races are out of scope, CC does
7
+ * not lock either).
8
+ *
9
+ * @module @dsh-cc/plugin-manager
10
+ */
11
+ import type { GitRunner } from './git.ts';
12
+ import { type PluginListEntry } from './list.ts';
13
+ import { type AddedMarketplace, type MarketplaceEntry, type RemovedMarketplace, type AddMarketplaceOptions } from './marketplace.ts';
14
+ import { type InstallOptions, type InstallResult } from './install.ts';
15
+ import { type UninstallOptions, type UninstallResult } from './uninstall.ts';
16
+ import { type UpdateOptions, type UpdateResult } from './update.ts';
17
+ import { type ToggleResult } from './toggles.ts';
18
+ export type { Scope, MarketplaceSource, KnownMarketplaceEntry, KnownMarketplacesFile, ExtraKnownMarketplaces, EnabledPlugins, InstallEntry, InstalledPluginsFile, ScopeSettingsFile } from './types.ts';
19
+ export { PluginManagerError, malformedStateFile, unknownPlugin, ambiguousPluginName, pluginNotInstalled, ambiguousPluginScopes, unknownScope, type PluginManagerErrorCode, } from './errors.ts';
20
+ export { parsePluginId, resolveInstalledPluginId, resolveDeclaredPluginId, readDeclaredPlugins, type DeclaredPlugin } from './resolve-id.ts';
21
+ export { installPlugin, type InstallOptions, type InstallResult } from './install.ts';
22
+ export { uninstallPlugin, type UninstallOptions, type UninstallResult } from './uninstall.ts';
23
+ export { updatePlugin, type UpdateOptions, type UpdateResult } from './update.ts';
24
+ export { marketplacePluginNotDeclared, unknownDeclaredPlugin, unsupportedPluginSource, pluginAlreadyInstalled, noInstallationAtScope, projectScopeEnabledGuard, } from './errors.ts';
25
+ export { enablePlugin, disablePlugin, togglePlugin, type ToggleOptions, type ToggleResult } from './toggles.ts';
26
+ export { listInstalled, type PluginListEntry } from './list.ts';
27
+ export { listMarketplaces, addMarketplace, updateMarketplaces, removeMarketplace, classifySource, type MarketplaceDeps, type MarketplaceEntry, type AddedMarketplace, type RemovedMarketplace, type AddMarketplaceOptions, type ClassifiedSource } from './marketplace.ts';
28
+ export { createSystemGitRunner, gitFailure, type GitRunner, type GitRunnerOptions } from './git.ts';
29
+ export { unknownMarketplace, marketplaceConflict, invalidMarketplaceSource, marketplaceManifestMissing } from './errors.ts';
30
+ export interface CcPluginManagerOptions {
31
+ /**
32
+ * Compat-read (Claude) home. Defaults to `process.env.CLAUDE_CONFIG_DIR ??
33
+ * join(homedir(), '.claude')`. Passing ONLY this keeps legacy single-root
34
+ * behavior: the dsh home falls back to it, so reads and writes share it.
35
+ */
36
+ claudeHome?: string;
37
+ /**
38
+ * dsh write home (plan §3.1). Resolution chain: explicit `dshHome` →
39
+ * explicit `claudeHome` (legacy single-root) → `resolveDshHome()`
40
+ * (`$DSH_HOME` → `~/.dsh`), so a no-options production caller is always
41
+ * dual-home and never writes into the real `~/.claude`.
42
+ */
43
+ dshHome?: string;
44
+ /** Defaults to `process.cwd()`. */
45
+ cwd?: string;
46
+ /** Injectable clock for future timestamped mutations. */
47
+ now?: () => Date;
48
+ /** Injectable git runner for marketplace clones/updates (tests inject fakes). */
49
+ runGit?: GitRunner;
50
+ }
51
+ export interface ListOptions {
52
+ /** `--enabled`: only rows with `effectiveEnabled === true`. */
53
+ enabled?: boolean;
54
+ /** `--disabled`: only rows with `effectiveEnabled === false`. */
55
+ disabled?: boolean;
56
+ }
57
+ export interface CcPluginManager {
58
+ list(opts?: ListOptions): Promise<PluginListEntry[]>;
59
+ enable(arg: string, opts?: {
60
+ scope?: string;
61
+ }): Promise<ToggleResult>;
62
+ disable(arg: string, opts?: {
63
+ scope?: string;
64
+ }): Promise<ToggleResult>;
65
+ install(arg: string, opts?: InstallOptions): Promise<InstallResult>;
66
+ uninstall(arg: string, opts?: UninstallOptions): Promise<UninstallResult>;
67
+ update(arg: string, opts?: UpdateOptions): Promise<UpdateResult>;
68
+ listMarketplaces(): Promise<MarketplaceEntry[]>;
69
+ addMarketplace(source: string, opts?: AddMarketplaceOptions): Promise<AddedMarketplace>;
70
+ updateMarketplaces(name?: string): Promise<string[]>;
71
+ removeMarketplace(name: string): Promise<RemovedMarketplace>;
72
+ }
73
+ export declare function createCcPluginManager(options?: CcPluginManagerOptions): CcPluginManager;
74
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAA;AAC/D,OAAO,EAML,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAC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