@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/lib/toggles.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * enable/disable (plan §2.2 C3): write `enabledPlugins["<id>"] = true|false`
3
+ * into exactly one scope's settings file. The key is kept on disable; the
4
+ * write is allowed even at a scope where the plugin has no install entry.
5
+ * Default scope is auto-detected: the unique scope where the plugin is
6
+ * installed; multiple ⇒ typed error, zero ⇒ not-installed error.
7
+ *
8
+ * @module @dsh-cc/plugin-manager/toggles
9
+ */
10
+ import { ambiguousPluginScopes, pluginNotInstalled, unknownScope } from "./errors.js";
11
+ import { loadMergedInstalledPlugins, resolutionIds } from "./merged-state.js";
12
+ import { settingsFileForScope } from "./paths.js";
13
+ import { loadSettingsFile, saveJsonFileAtomic } from "./state-store.js";
14
+ import { resolveInstalledPluginId } from "./resolve-id.js";
15
+ const SCOPES = ['user', 'project', 'local'];
16
+ /**
17
+ * Determine the target scope: an explicit `--scope` override (validated) or
18
+ * auto-detect over the installed entries (unique scope wins).
19
+ */
20
+ async function resolveScope(id, installedScopes, opts) {
21
+ if (opts?.scope !== undefined) {
22
+ const scope = opts.scope;
23
+ if (!SCOPES.includes(scope))
24
+ throw unknownScope(scope);
25
+ return scope;
26
+ }
27
+ if (installedScopes.length === 0)
28
+ throw pluginNotInstalled(id);
29
+ if (installedScopes.length > 1) {
30
+ throw ambiguousPluginScopes(id, SCOPES.filter(scope => installedScopes.includes(scope)));
31
+ }
32
+ return installedScopes[0];
33
+ }
34
+ /**
35
+ * Core toggle: resolve the id against installed keys, pick the scope, then
36
+ * write `enabledPlugins[id]` into exactly that scope's settings file,
37
+ * preserving all other keys (C11).
38
+ */
39
+ export async function togglePlugin(deps, arg, enabled, opts) {
40
+ // Auto-detect over the MERGED installed lists (§4.2): an id installed only
41
+ // claude-side is toggleable; the flag lands where the resolved scope's file
42
+ // lives (user → dsh settings, §3.3).
43
+ const merged = await loadMergedInstalledPlugins(deps);
44
+ const id = resolveInstalledPluginId(arg, resolutionIds(merged.file));
45
+ const installedScopes = (merged.file.plugins[id] ?? []).map(entry => entry.scope);
46
+ const scope = await resolveScope(id, installedScopes, opts);
47
+ const settingsFile = settingsFileForScope(scope, deps);
48
+ const settings = await loadSettingsFile(settingsFile);
49
+ const next = { ...settings };
50
+ next['enabledPlugins'] = { ...settings['enabledPlugins'], [id]: enabled };
51
+ await saveJsonFileAtomic(settingsFile, next);
52
+ return { id, scope, enabled };
53
+ }
54
+ /** `enable <idOrName> [--scope s]` core (C3). */
55
+ export async function enablePlugin(deps, arg, opts) {
56
+ return togglePlugin(deps, arg, true, opts);
57
+ }
58
+ /** `disable <idOrName> [--scope s]` core (C3) — the key is kept with `false`. */
59
+ export async function disablePlugin(deps, arg, opts) {
60
+ return togglePlugin(deps, arg, false, opts);
61
+ }
62
+ //# sourceMappingURL=toggles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toggles.js","sourceRoot":"","sources":["../src/toggles.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;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M,eAAe,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACjF,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,CAAA;IAC3D,MAAM,YAAY,GAAG,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IACtD,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACrD,MAAM,IAAI,GAAsB,EAAE,GAAG,QAAQ,EAAE,CAAA;IAC/C,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;IACzE,MAAM,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;IAC5C,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAC/B,CAAC;AAED,iDAAiD;AACjD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAgB,EAAE,GAAW,EAAE,IAAoB;IACpF,OAAO,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAC5C,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAgB,EAAE,GAAW,EAAE,IAAoB;IACrF,OAAO,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * On-disk state types for Claude Code plugin management, byte-shape parity
3
+ * with the real CLI (v2.1.236): `known_marketplaces.json`, v2
4
+ * `installed_plugins.json`, and the per-scope settings file shapes.
5
+ *
6
+ * @module @dsh-cc/plugin-manager/types
7
+ */
8
+ export type Scope = 'user' | 'project' | 'local';
9
+ export type MarketplaceSource = {
10
+ source: 'directory';
11
+ path: string;
12
+ } | {
13
+ source: 'github';
14
+ repo: string;
15
+ } | {
16
+ source: 'git';
17
+ url: string;
18
+ };
19
+ /** The kind tag of a marketplace source: `directory`, `github`, or `git`. */
20
+ export type MarketplaceSourceKind = MarketplaceSource['source'];
21
+ /** One entry of `known_marketplaces.json`, keyed by marketplace name. */
22
+ export interface KnownMarketplaceEntry {
23
+ source: MarketplaceSource;
24
+ installLocation: string;
25
+ lastUpdated: string;
26
+ autoUpdate?: boolean;
27
+ }
28
+ /** Parsed shape of `<claudeHome>/plugins/known_marketplaces.json` (defaults to `{}`). */
29
+ export type KnownMarketplacesFile = Record<string, KnownMarketplaceEntry>;
30
+ /** The `extraKnownMarketplaces` declaration inside a scope settings file. */
31
+ export type ExtraKnownMarketplaces = Record<string, {
32
+ source: MarketplaceSource;
33
+ }>;
34
+ /** `enabledPlugins` map inside a scope settings file: plugin id → boolean. */
35
+ export type EnabledPlugins = Record<string, boolean>;
36
+ /** One install entry (one per scope) inside `installed_plugins.json`. */
37
+ export interface InstallEntry {
38
+ scope: Scope;
39
+ installPath: string;
40
+ version: string;
41
+ installedAt: string;
42
+ lastUpdated: string;
43
+ gitCommitSha?: string;
44
+ projectPath?: string;
45
+ }
46
+ /** Parsed shape of `<claudeHome>/plugins/installed_plugins.json` (defaults to `{version:2, plugins:{}}`). */
47
+ export interface InstalledPluginsFile {
48
+ version: 2;
49
+ plugins: Record<string, InstallEntry[]>;
50
+ }
51
+ /** Loose shape of a scope settings file as the manager touches it. */
52
+ export interface ScopeSettingsFile {
53
+ enabledPlugins?: EnabledPlugins;
54
+ extraKnownMarketplaces?: ExtraKnownMarketplaces;
55
+ [key: string]: unknown;
56
+ }
57
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],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AAE,CAAC,CAAA;IACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;CACxC;AAED,sEAAsE;AACtE,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;IAC/C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB"}
package/lib/types.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * On-disk state types for Claude Code plugin management, byte-shape parity
3
+ * with the real CLI (v2.1.236): `known_marketplaces.json`, v2
4
+ * `installed_plugins.json`, and the per-scope settings file shapes.
5
+ *
6
+ * @module @dsh-cc/plugin-manager/types
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * uninstall (plan §2.2 C4/C5): scope-surgical removal of one scope's
3
+ * enabledPlugins flag and installed entry, then `.orphaned_at` marking of a
4
+ * cache dir left unreferenced (never deleted). The C5 guard refuses while
5
+ * the project settings file (team-shared) still enables the plugin.
6
+ *
7
+ * @module @dsh-cc/plugin-manager/uninstall
8
+ */
9
+ import { type InstallDeps } from './install.ts';
10
+ export type { InstallDeps } from './install.ts';
11
+ import type { Scope } from './types.ts';
12
+ export interface UninstallOptions {
13
+ scope?: string;
14
+ /**
15
+ * Internal: the marketplace-remove cascade has already run the C5
16
+ * pre-flight over every plugin, so per-entry guards are skipped.
17
+ */
18
+ skipProjectGuard?: boolean;
19
+ }
20
+ export interface UninstallResult {
21
+ id: string;
22
+ scope: Scope;
23
+ }
24
+ /**
25
+ * `uninstall <idOrName> [--scope s]` (C4). Order per §4.C: C5 guard →
26
+ * remove the scope's enabledPlugins key → remove the scope's installed
27
+ * entry (commit) → `.orphaned_at` on cache dirs left unreferenced.
28
+ */
29
+ export declare function uninstallPlugin(deps: InstallDeps, arg: string, opts?: UninstallOptions): Promise<UninstallResult>;
30
+ //# sourceMappingURL=uninstall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.d.ts","sourceRoot":"","sources":["../src/uninstall.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAiD,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAE9F,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAM/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,KAAK,CAAA;CACb;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CAkD3H"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * uninstall (plan §2.2 C4/C5): scope-surgical removal of one scope's
3
+ * enabledPlugins flag and installed entry, then `.orphaned_at` marking of a
4
+ * cache dir left unreferenced (never deleted). The C5 guard refuses while
5
+ * the project settings file (team-shared) still enables the plugin.
6
+ *
7
+ * @module @dsh-cc/plugin-manager/uninstall
8
+ */
9
+ import { join } from 'node:path';
10
+ import { noInstallationAtScope, projectScopeEnabledGuard } from "./errors.js";
11
+ import { orphanIfUnreferencedDsh, resolveMutationScope } from "./install.js";
12
+ import { claudePluginsStatePaths, pluginsStatePaths, settingsFileForScope } from "./paths.js";
13
+ import { loadMergedInstalledPlugins } from "./merged-state.js";
14
+ import { resolveInstalledPluginId } from "./resolve-id.js";
15
+ import { applyEnabledFlag } from "./settings-write.js";
16
+ import { loadInstalledPlugins, loadSettingsFile, saveJsonFileAtomic } from "./state-store.js";
17
+ /**
18
+ * `uninstall <idOrName> [--scope s]` (C4). Order per §4.C: C5 guard →
19
+ * remove the scope's enabledPlugins key → remove the scope's installed
20
+ * entry (commit) → `.orphaned_at` on cache dirs left unreferenced.
21
+ */
22
+ export async function uninstallPlugin(deps, arg, opts = {}) {
23
+ const now = deps.now ?? (() => new Date());
24
+ const scope = resolveMutationScope(opts.scope);
25
+ const paths = pluginsStatePaths(deps);
26
+ const claudePaths = claudePluginsStatePaths(deps);
27
+ // Merged installed view (§3.4). Uninstall resolves over ALL merged ids
28
+ // (not the resolution view): an id shadowed by an empty dsh list still
29
+ // reports `installed at: none` rather than unknown-plugin (C4 pin).
30
+ const merged = await loadMergedInstalledPlugins(deps);
31
+ const id = resolveInstalledPluginId(arg, Object.keys(merged.file.plugins));
32
+ const entries = merged.file.plugins[id] ?? [];
33
+ const entry = entries.find(candidate => candidate.scope === scope);
34
+ if (entry === undefined) {
35
+ throw noInstallationAtScope(id, scope, entries.map(candidate => candidate.scope));
36
+ }
37
+ // C5 guard: the project settings file is shared with the team.
38
+ if (opts.skipProjectGuard !== true) {
39
+ const projectSettings = await loadSettingsFile(settingsFileForScope('project', deps));
40
+ if (projectSettings['enabledPlugins']?.[id] === true)
41
+ throw projectScopeEnabledGuard(id);
42
+ }
43
+ // (1) remove the enabledPlugins key at the targeted scope's file only —
44
+ // with the §4.3 conditional user-flag shadow: dual-home AND the claude
45
+ // user file carries `true` ⇒ write an explicit `false` into the dsh user
46
+ // file instead (removal would un-shadow and resurrect the claude `true`).
47
+ if (scope === 'user' && claudePaths !== null) {
48
+ const claudeSettings = await loadSettingsFile(join(deps.claudeHome, 'settings.json'));
49
+ if (claudeSettings['enabledPlugins']?.[id] === true)
50
+ await applyEnabledFlag(deps, scope, id, false);
51
+ else
52
+ await applyEnabledFlag(deps, scope, id, null);
53
+ }
54
+ else {
55
+ await applyEnabledFlag(deps, scope, id, null);
56
+ }
57
+ // (2) remove that scope's array entry, then materialize the id's full
58
+ // post-removal MERGED list into the dsh file (§3.4; `[]` allowed — it
59
+ // shadows the claude id). Single-root keeps C4 byte-parity: the key drops.
60
+ const remaining = entries.filter(candidate => candidate !== entry);
61
+ const dshInstalled = await loadInstalledPlugins(paths.installedPluginsFile);
62
+ if (claudePaths === null) {
63
+ if (remaining.length === 0)
64
+ delete dshInstalled.plugins[id];
65
+ else
66
+ dshInstalled.plugins[id] = remaining;
67
+ }
68
+ else {
69
+ dshInstalled.plugins[id] = remaining;
70
+ }
71
+ await saveJsonFileAtomic(paths.installedPluginsFile, dshInstalled);
72
+ // (3) orphan-marker under the dsh cache only, when nothing in the merged
73
+ // view references the path anymore (W3/W4).
74
+ merged.file.plugins[id] = remaining;
75
+ await orphanIfUnreferencedDsh(deps, merged.file, entry.installPath, now);
76
+ return { id, scope };
77
+ }
78
+ //# sourceMappingURL=uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../src/uninstall.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAoB,MAAM,cAAc,CAAA;AAG9F,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAC7F,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAiB7F;;;;GAIG;AACH,MAAM,CAAC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ACzE,4CAA4C;IAC5C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IACnC,MAAM,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;IACxE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAA;AACtB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * update (plan §2.2 C7): materialize the new version's cache dir alongside
3
+ * the old one and rewrite only the targeted scope's installed entry; the
4
+ * old cache dir is orphan-marked only when nothing references it anymore.
5
+ *
6
+ * @module @dsh-cc/plugin-manager/update
7
+ */
8
+ import { type InstallDeps } from './install.ts';
9
+ import type { Scope } from './types.ts';
10
+ export interface UpdateOptions {
11
+ scope?: string;
12
+ }
13
+ export type UpdateResult = {
14
+ upToDate: true;
15
+ id: string;
16
+ version: string;
17
+ scope: Scope;
18
+ } | {
19
+ upToDate: false;
20
+ id: string;
21
+ fromVersion: string;
22
+ toVersion: string;
23
+ scope: Scope;
24
+ };
25
+ /**
26
+ * `update <idOrName> [--scope s]` (C7, default scope user). Reads the
27
+ * currently declared manifest from the plugin's marketplace; equal version
28
+ * ⇒ up-to-date no-op. A bump materializes
29
+ * `<cacheDir>/<mkt>/<name>/<newVersion>/` and rewrites ONLY the targeted
30
+ * scope's entry (version, installPath, fresh timestamps, refreshed
31
+ * gitCommitSha when available).
32
+ */
33
+ export declare function updatePlugin(deps: InstallDeps, arg: string, opts?: UpdateOptions): Promise<UpdateResult>;
34
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAyG,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAKtJ,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC7D;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AAEzF;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CA6ClH"}
package/lib/update.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * update (plan §2.2 C7): materialize the new version's cache dir alongside
3
+ * the old one and rewrite only the targeted scope's installed entry; the
4
+ * old cache dir is orphan-marked only when nothing references it anymore.
5
+ *
6
+ * @module @dsh-cc/plugin-manager/update
7
+ */
8
+ import { noInstallationAtScope, unknownMarketplace } from "./errors.js";
9
+ import { currentGitSha, materializeCacheDir, orphanIfUnreferencedDsh, readPluginManifest, resolveMutationScope } from "./install.js";
10
+ import { pluginsStatePaths } from "./paths.js";
11
+ import { loadMergedInstalledPlugins, loadMergedKnownMarketplaces, resolutionIds } from "./merged-state.js";
12
+ import { parsePluginId, readDeclaredPlugins, resolveInstalledPluginId } from "./resolve-id.js";
13
+ import { loadInstalledPlugins, saveJsonFileAtomic } from "./state-store.js";
14
+ /**
15
+ * `update <idOrName> [--scope s]` (C7, default scope user). Reads the
16
+ * currently declared manifest from the plugin's marketplace; equal version
17
+ * ⇒ up-to-date no-op. A bump materializes
18
+ * `<cacheDir>/<mkt>/<name>/<newVersion>/` and rewrites ONLY the targeted
19
+ * scope's entry (version, installPath, fresh timestamps, refreshed
20
+ * gitCommitSha when available).
21
+ */
22
+ export async function updatePlugin(deps, arg, opts = {}) {
23
+ const now = deps.now ?? (() => new Date());
24
+ const scope = resolveMutationScope(opts.scope);
25
+ const paths = pluginsStatePaths(deps);
26
+ // Merged installed + known views (§4.4).
27
+ const merged = await loadMergedInstalledPlugins(deps);
28
+ const id = resolveInstalledPluginId(arg, resolutionIds(merged.file));
29
+ const entries = merged.file.plugins[id] ?? [];
30
+ const entry = entries.find(candidate => candidate.scope === scope);
31
+ if (entry === undefined) {
32
+ throw noInstallationAtScope(id, scope, entries.map(candidate => candidate.scope));
33
+ }
34
+ const { name, marketplace } = parsePluginId(id);
35
+ const known = (await loadMergedKnownMarketplaces(deps)).entries;
36
+ if (marketplace === undefined || known[marketplace] === undefined) {
37
+ throw unknownMarketplace(marketplace ?? '', Object.keys(known));
38
+ }
39
+ const mktEntry = known[marketplace];
40
+ const declared = await readDeclaredPlugins(deps, marketplace);
41
+ const declaredPlugin = declared.find(plugin => plugin.name === name);
42
+ const sourceDir = declaredPlugin !== undefined ? `${mktEntry.installLocation}/${declaredPlugin.source}` : entry.installPath;
43
+ const { version: newVersion } = await readPluginManifest(sourceDir, name);
44
+ if (newVersion === entry.version) {
45
+ return { upToDate: true, id, version: entry.version, scope };
46
+ }
47
+ // Materialize the new cache dir into the DSH cache (even for a
48
+ // claude-owned marketplace clone — the clone is only read, W3), then
49
+ // rewrite the targeted scope's entry in the dsh file (§3.4).
50
+ const installPath = await materializeCacheDir(paths.cacheDir, marketplace, name, newVersion, sourceDir);
51
+ const updated = { ...entry, version: newVersion, installPath, installedAt: now().toISOString(), lastUpdated: now().toISOString() };
52
+ const sha = await currentGitSha(deps.runGit, mktEntry.installLocation);
53
+ if (sha !== undefined)
54
+ updated.gitCommitSha = sha;
55
+ else
56
+ delete updated.gitCommitSha;
57
+ const newEntries = entries.map(candidate => (candidate === entry ? updated : candidate));
58
+ const dshInstalled = await loadInstalledPlugins(paths.installedPluginsFile);
59
+ dshInstalled.plugins[id] = newEntries;
60
+ await saveJsonFileAtomic(paths.installedPluginsFile, dshInstalled);
61
+ // W4: an old claude-owned installPath is never orphan-marked; a dsh-owned
62
+ // one is, when nothing in the merged view references it anymore.
63
+ merged.file.plugins[id] = newEntries;
64
+ await orphanIfUnreferencedDsh(deps, merged.file, entry.installPath, now);
65
+ return { upToDate: false, id, fromVersion: entry.version, toVersion: newVersion, scope };
66
+ }
67
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAoB,MAAM,cAAc,CAAA;AACtJ,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC9F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAW3E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAiB,EAAE,GAAW,EAAE,OAAsB,EAAE;IACzF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;IAC1C,MAAM,KAAK,GAAG,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACrC,yCAAyC;IACzC,MAAM,MAAM,GAAG,MAAM,0BAA0B,CAAC,I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B,EAAE,YAAY,CAAC,CAAA;IAClE,0EAA0E;IAC1E,iEAAiE;IACjE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,UAAU,CAAA;IACpC,MAAM,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;IACxE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;AAC1F,CAAC"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@dsh-cc/plugin-manager",
3
+ "description": "Manage Claude Code plugin state files (marketplaces, installs, per-scope settings) in byte-shape parity with the real CLI",
4
+ "version": "0.6.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dsh-cc/dsh-cc.git",
8
+ "directory": "packages/compat/cc-plugin-manager"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "devDependencies": {
19
+ "@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
20
+ "@deepseek-ai/dsh-home-paths": "link:../../../../deepseek-harness/packages/util/home-paths",
21
+ "@dsh-cc/plugin-loader": "^0.6.0"
22
+ },
23
+ "files": [
24
+ "lib"
25
+ ],
26
+ "license": "Apache-2.0",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "peerDependencies": {
31
+ "@deepseek-ai/dsh-home-paths": ">=0.1.2-rc.1"
32
+ }
33
+ }