@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.
- package/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +32 -0
- package/README.zh.md +32 -0
- package/lib/errors.d.ts +51 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +94 -0
- package/lib/errors.js.map +1 -0
- package/lib/git.d.ts +38 -0
- package/lib/git.d.ts.map +1 -0
- package/lib/git.js +38 -0
- package/lib/git.js.map +1 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +94 -0
- package/lib/index.js.map +1 -0
- package/lib/install.d.ts +67 -0
- package/lib/install.d.ts.map +1 -0
- package/lib/install.js +192 -0
- package/lib/install.js.map +1 -0
- package/lib/list.d.ts +35 -0
- package/lib/list.d.ts.map +1 -0
- package/lib/list.js +98 -0
- package/lib/list.js.map +1 -0
- package/lib/marketplace.d.ts +89 -0
- package/lib/marketplace.d.ts.map +1 -0
- package/lib/marketplace.js +426 -0
- package/lib/marketplace.js.map +1 -0
- package/lib/merged-state.d.ts +54 -0
- package/lib/merged-state.d.ts.map +1 -0
- package/lib/merged-state.js +88 -0
- package/lib/merged-state.js.map +1 -0
- package/lib/paths.d.ts +75 -0
- package/lib/paths.d.ts.map +1 -0
- package/lib/paths.js +173 -0
- package/lib/paths.js.map +1 -0
- package/lib/resolve-id.d.ts +43 -0
- package/lib/resolve-id.d.ts.map +1 -0
- package/lib/resolve-id.js +110 -0
- package/lib/resolve-id.js.map +1 -0
- package/lib/settings-write.d.ts +16 -0
- package/lib/settings-write.d.ts.map +1 -0
- package/lib/settings-write.js +32 -0
- package/lib/settings-write.js.map +1 -0
- package/lib/state-store.d.ts +24 -0
- package/lib/state-store.d.ts.map +1 -0
- package/lib/state-store.js +54 -0
- package/lib/state-store.js.map +1 -0
- package/lib/toggles.d.ts +30 -0
- package/lib/toggles.d.ts.map +1 -0
- package/lib/toggles.js +62 -0
- package/lib/toggles.js.map +1 -0
- package/lib/types.d.ts +57 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +9 -0
- package/lib/types.js.map +1 -0
- package/lib/uninstall.d.ts +30 -0
- package/lib/uninstall.d.ts.map +1 -0
- package/lib/uninstall.js +78 -0
- package/lib/uninstall.js.map +1 -0
- package/lib/update.d.ts +34 -0
- package/lib/update.d.ts.map +1 -0
- package/lib/update.js +67 -0
- package/lib/update.js.map +1 -0
- package/package.json +33 -0
package/lib/paths.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path resolution for Claude Code plugin state: the `<claudeHome>/plugins/`
|
|
3
|
+
* state layout and the per-scope settings file (C1/D2 ground truth). The
|
|
4
|
+
* local scope resolves against the git MAIN checkout's
|
|
5
|
+
* `.claude/settings.local.json` — from a linked worktree that means walking
|
|
6
|
+
* the `gitdir:` pointer in `<worktree>/.git` back to the main checkout.
|
|
7
|
+
*
|
|
8
|
+
* All cwd-derived paths are canonicalized with `fs.realpathSync.native`
|
|
9
|
+
* (macOS `/tmp` → `/private/tmp` semantics), gracefully falling back to
|
|
10
|
+
* canonicalizing the deepest existing ancestor for not-yet-existing paths.
|
|
11
|
+
*
|
|
12
|
+
* @module @dsh-cc/plugin-manager/paths
|
|
13
|
+
*/
|
|
14
|
+
export interface PathInputs {
|
|
15
|
+
claudeHome: string;
|
|
16
|
+
/**
|
|
17
|
+
* dsh write home. Defaults to `claudeHome` (legacy single-root semantics,
|
|
18
|
+
* plan §3.1): an explicit `claudeHome` alone always means single-root.
|
|
19
|
+
*/
|
|
20
|
+
dshHome?: string;
|
|
21
|
+
cwd: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PluginsStatePaths {
|
|
24
|
+
stateDir: string;
|
|
25
|
+
knownMarketplacesFile: string;
|
|
26
|
+
installedPluginsFile: string;
|
|
27
|
+
marketplacesDir: string;
|
|
28
|
+
cacheDir: string;
|
|
29
|
+
dataDir: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Canonicalize a path even when it (or its parents) do not exist yet:
|
|
33
|
+
* realpath the deepest existing ancestor and append the remaining segments.
|
|
34
|
+
*/
|
|
35
|
+
export declare function canonicalizeExistingPath(path: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Layout of the plugin state root `<dshHome>/plugins/` — the WRITE root
|
|
38
|
+
* (plan §1 R2). In single-root mode `dshHome` falls back to `claudeHome`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function pluginsStatePaths(deps: PathInputs): PluginsStatePaths;
|
|
41
|
+
/**
|
|
42
|
+
* Claude-side state layout (compat READ root, plan §1 R1), or `null` when
|
|
43
|
+
* both homes canonicalize to the same directory (symlinked homes collapse;
|
|
44
|
+
* single-root merge is a no-op).
|
|
45
|
+
*/
|
|
46
|
+
export declare function claudePluginsStatePaths(deps: PathInputs): PluginsStatePaths | null;
|
|
47
|
+
/**
|
|
48
|
+
* Walk up from `cwd` to the git main checkout root. Handles both a real
|
|
49
|
+
* `.git` directory and a linked worktree where `.git` is a file containing
|
|
50
|
+
* `gitdir: <main>/.git/worktrees/<name>` (or a symlink to it) — the main
|
|
51
|
+
* checkout is the directory owning the `.git` pointed at.
|
|
52
|
+
*
|
|
53
|
+
* Returns null when no git tree is found.
|
|
54
|
+
*/
|
|
55
|
+
export declare function findGitMainRoot(cwd: string): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Settings file per scope (C1/C3):
|
|
58
|
+
* - user: `<dshHome>/settings.json` — the WRITE target (plan §3.3; the
|
|
59
|
+
* dsh home defaults to `claudeHome`, so single-root keeps the claude path)
|
|
60
|
+
* - project: `<cwd>/.claude/settings.json`
|
|
61
|
+
* - local: `<gitMainRoot>/.claude/settings.local.json` (gitMainRoot
|
|
62
|
+
* defaults to cwd when not inside a worktree)
|
|
63
|
+
*
|
|
64
|
+
* cwd-derived results are realpath-canonicalized.
|
|
65
|
+
*/
|
|
66
|
+
export declare function settingsFileForScope(scope: 'user' | 'project' | 'local', deps: PathInputs & {
|
|
67
|
+
gitMainRoot?: string;
|
|
68
|
+
}): string;
|
|
69
|
+
/**
|
|
70
|
+
* User-scope settings read files in low → high precedence order (plan §3.3):
|
|
71
|
+
* `[<claudeHome>/settings.json, <dshHome>/settings.json]`, deduped to a
|
|
72
|
+
* single entry when the homes canonicalize equal (single-root).
|
|
73
|
+
*/
|
|
74
|
+
export declare function userSettingsReadFiles(deps: PathInputs): string[];
|
|
75
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW7D;AAoBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB,CAErE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,UAAU,GAAG,iBAAiB,GAAG,IAAI,CAIlF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY1D;AAiDD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,EACnC,IAAI,EAAE,UAAU,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,CAMhE"}
|
package/lib/paths.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path resolution for Claude Code plugin state: the `<claudeHome>/plugins/`
|
|
3
|
+
* state layout and the per-scope settings file (C1/D2 ground truth). The
|
|
4
|
+
* local scope resolves against the git MAIN checkout's
|
|
5
|
+
* `.claude/settings.local.json` — from a linked worktree that means walking
|
|
6
|
+
* the `gitdir:` pointer in `<worktree>/.git` back to the main checkout.
|
|
7
|
+
*
|
|
8
|
+
* All cwd-derived paths are canonicalized with `fs.realpathSync.native`
|
|
9
|
+
* (macOS `/tmp` → `/private/tmp` semantics), gracefully falling back to
|
|
10
|
+
* canonicalizing the deepest existing ancestor for not-yet-existing paths.
|
|
11
|
+
*
|
|
12
|
+
* @module @dsh-cc/plugin-manager/paths
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
15
|
+
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
16
|
+
/**
|
|
17
|
+
* Canonicalize a path even when it (or its parents) do not exist yet:
|
|
18
|
+
* realpath the deepest existing ancestor and append the remaining segments.
|
|
19
|
+
*/
|
|
20
|
+
export function canonicalizeExistingPath(path) {
|
|
21
|
+
const absolute = resolve(path);
|
|
22
|
+
if (existsSync(absolute)) {
|
|
23
|
+
return realpathSync.native(absolute);
|
|
24
|
+
}
|
|
25
|
+
const parent = dirname(absolute);
|
|
26
|
+
if (parent === absolute) {
|
|
27
|
+
return absolute;
|
|
28
|
+
}
|
|
29
|
+
const canonicalParent = canonicalizeExistingPath(parent);
|
|
30
|
+
return join(canonicalParent, absolute.slice(parent.length + 1));
|
|
31
|
+
}
|
|
32
|
+
/** Resolve both homes: the dsh home (write root) defaults to `claudeHome` (§3.1). */
|
|
33
|
+
function resolveHomes({ claudeHome, dshHome }) {
|
|
34
|
+
return { claudeHome, dshHome: dshHome ?? claudeHome };
|
|
35
|
+
}
|
|
36
|
+
/** State layout under one home root (§2.2). */
|
|
37
|
+
function statePathsIn(home) {
|
|
38
|
+
const stateDir = join(home, 'plugins');
|
|
39
|
+
return {
|
|
40
|
+
stateDir,
|
|
41
|
+
knownMarketplacesFile: join(stateDir, 'known_marketplaces.json'),
|
|
42
|
+
installedPluginsFile: join(stateDir, 'installed_plugins.json'),
|
|
43
|
+
marketplacesDir: join(stateDir, 'marketplaces'),
|
|
44
|
+
cacheDir: join(stateDir, 'cache'),
|
|
45
|
+
dataDir: join(stateDir, 'data'),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Layout of the plugin state root `<dshHome>/plugins/` — the WRITE root
|
|
50
|
+
* (plan §1 R2). In single-root mode `dshHome` falls back to `claudeHome`.
|
|
51
|
+
*/
|
|
52
|
+
export function pluginsStatePaths(deps) {
|
|
53
|
+
return statePathsIn(resolveHomes(deps).dshHome);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Claude-side state layout (compat READ root, plan §1 R1), or `null` when
|
|
57
|
+
* both homes canonicalize to the same directory (symlinked homes collapse;
|
|
58
|
+
* single-root merge is a no-op).
|
|
59
|
+
*/
|
|
60
|
+
export function claudePluginsStatePaths(deps) {
|
|
61
|
+
const { claudeHome, dshHome } = resolveHomes(deps);
|
|
62
|
+
if (canonicalizeExistingPath(claudeHome) === canonicalizeExistingPath(dshHome))
|
|
63
|
+
return null;
|
|
64
|
+
return statePathsIn(claudeHome);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Walk up from `cwd` to the git main checkout root. Handles both a real
|
|
68
|
+
* `.git` directory and a linked worktree where `.git` is a file containing
|
|
69
|
+
* `gitdir: <main>/.git/worktrees/<name>` (or a symlink to it) — the main
|
|
70
|
+
* checkout is the directory owning the `.git` pointed at.
|
|
71
|
+
*
|
|
72
|
+
* Returns null when no git tree is found.
|
|
73
|
+
*/
|
|
74
|
+
export function findGitMainRoot(cwd) {
|
|
75
|
+
let current = resolve(cwd);
|
|
76
|
+
for (;;) {
|
|
77
|
+
const git = join(current, '.git');
|
|
78
|
+
if (existsSync(git)) {
|
|
79
|
+
const resolved = resolveGitEntry(git);
|
|
80
|
+
if (resolved !== null)
|
|
81
|
+
return resolved;
|
|
82
|
+
}
|
|
83
|
+
const parent = dirname(current);
|
|
84
|
+
if (parent === current)
|
|
85
|
+
return null;
|
|
86
|
+
current = parent;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* From a per-worktree gitdir `<main>/.git/worktrees/<name>` return
|
|
91
|
+
* `<main>` (the directory containing `.git`); null when the shape differs.
|
|
92
|
+
*/
|
|
93
|
+
function mainRootFromGitdir(gitdir) {
|
|
94
|
+
const gitMarker = `${sep}.git${sep}`;
|
|
95
|
+
const idx = gitdir.lastIndexOf(gitMarker);
|
|
96
|
+
if (idx > 0)
|
|
97
|
+
return gitdir.slice(0, idx);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Resolve a `.git` entry: a directory means `dir` is the checkout root; a
|
|
102
|
+
* file (or symlink) means `gitdir: <path>` — the main checkout root is the
|
|
103
|
+
* directory containing the `.git` the gitdir lives under.
|
|
104
|
+
*/
|
|
105
|
+
function resolveGitEntry(gitPath) {
|
|
106
|
+
let stat;
|
|
107
|
+
try {
|
|
108
|
+
// statSync follows symlinks: a worktree .git may be a symlink to the gitdir
|
|
109
|
+
stat = statSync(gitPath);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
if (stat.isDirectory()) {
|
|
115
|
+
const rp = realpathSync.native(gitPath);
|
|
116
|
+
if (rp === gitPath)
|
|
117
|
+
return dirname(rp);
|
|
118
|
+
// symlink pointing at a per-worktree gitdir: <main>/.git/worktrees/<name>
|
|
119
|
+
const mainRoot = mainRootFromGitdir(rp);
|
|
120
|
+
return mainRoot ?? dirname(rp);
|
|
121
|
+
}
|
|
122
|
+
// .git is a file: parse `gitdir: <path>`
|
|
123
|
+
let contents;
|
|
124
|
+
try {
|
|
125
|
+
contents = readFileSync(gitPath, 'utf8').trim();
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const match = /^gitdir:\s*(.+)$/.exec(contents);
|
|
131
|
+
if (!match)
|
|
132
|
+
return null;
|
|
133
|
+
let gitdir = match[1].trim();
|
|
134
|
+
if (!isAbsolute(gitdir))
|
|
135
|
+
gitdir = resolve(dirname(gitPath), gitdir);
|
|
136
|
+
gitdir = realpathSync.native(gitdir);
|
|
137
|
+
// gitdir = <main>/.git/worktrees/<name> → main = <main>
|
|
138
|
+
return mainRootFromGitdir(gitdir) ?? dirname(dirname(gitdir));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Settings file per scope (C1/C3):
|
|
142
|
+
* - user: `<dshHome>/settings.json` — the WRITE target (plan §3.3; the
|
|
143
|
+
* dsh home defaults to `claudeHome`, so single-root keeps the claude path)
|
|
144
|
+
* - project: `<cwd>/.claude/settings.json`
|
|
145
|
+
* - local: `<gitMainRoot>/.claude/settings.local.json` (gitMainRoot
|
|
146
|
+
* defaults to cwd when not inside a worktree)
|
|
147
|
+
*
|
|
148
|
+
* cwd-derived results are realpath-canonicalized.
|
|
149
|
+
*/
|
|
150
|
+
export function settingsFileForScope(scope, deps) {
|
|
151
|
+
if (scope === 'user')
|
|
152
|
+
return join(resolveHomes(deps).dshHome, 'settings.json');
|
|
153
|
+
const { cwd, gitMainRoot } = deps;
|
|
154
|
+
const canonicalCwd = canonicalizeExistingPath(cwd);
|
|
155
|
+
if (scope === 'project')
|
|
156
|
+
return join(canonicalCwd, '.claude', 'settings.json');
|
|
157
|
+
const mainRoot = canonicalizeExistingPath(gitMainRoot ?? findGitMainRoot(canonicalCwd) ?? canonicalCwd);
|
|
158
|
+
return join(mainRoot, '.claude', 'settings.local.json');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* User-scope settings read files in low → high precedence order (plan §3.3):
|
|
162
|
+
* `[<claudeHome>/settings.json, <dshHome>/settings.json]`, deduped to a
|
|
163
|
+
* single entry when the homes canonicalize equal (single-root).
|
|
164
|
+
*/
|
|
165
|
+
export function userSettingsReadFiles(deps) {
|
|
166
|
+
const { claudeHome, dshHome } = resolveHomes(deps);
|
|
167
|
+
const claudeFile = join(claudeHome, 'settings.json');
|
|
168
|
+
const dshFile = join(dshHome, 'settings.json');
|
|
169
|
+
if (canonicalizeExistingPath(claudeFile) === canonicalizeExistingPath(dshFile))
|
|
170
|
+
return [dshFile];
|
|
171
|
+
return [claudeFile, dshFile];
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=paths.js.map
|
package/lib/paths.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAc,MAAM,SAAS,CAAA;AACtF,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAqBnE;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACtC,CAAC;IACD,MAAM,MAAM,GAAG,OAAO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AE,OAAO,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,eAAe,CAAC,CAAA;IAC9E,MAAM,QAAQ,GAAG,wBAAwB,CAAC,WAAW,IAAI,eAAe,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,CAAA;IACvG,OAAO,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAA;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAgB;IACpD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAA;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IAC9C,IAAI,wBAAwB,CAAC,UAAU,CAAC,KAAK,wBAAwB,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAChG,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin id parsing and resolution against installed keys: an argument is
|
|
3
|
+
* either an exact `<name>@<marketplace>` id or a bare `<name>` that resolves
|
|
4
|
+
* iff exactly one installed key has that name part (plan §3 "Install id
|
|
5
|
+
* resolution"). Errors carry the exact catalog strings from errors.ts.
|
|
6
|
+
*
|
|
7
|
+
* The not-yet-installed variant against marketplace declarations is S3/S4.
|
|
8
|
+
*
|
|
9
|
+
* @module @dsh-cc/plugin-manager/resolve-id
|
|
10
|
+
*/
|
|
11
|
+
import type { PathInputs } from './paths.ts';
|
|
12
|
+
export interface ParsedPluginId {
|
|
13
|
+
name: string;
|
|
14
|
+
marketplace?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Split `<name>` / `<name>@<marketplace>` (the marketplace part is everything after the LAST `@`). */
|
|
17
|
+
export declare function parsePluginId(arg: string): ParsedPluginId;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve an id-or-name argument against the installed plugin keys.
|
|
20
|
+
* An exact key match wins; a bare name resolves iff exactly one installed
|
|
21
|
+
* key has that name part.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveInstalledPluginId(arg: string, installedKeys: readonly string[]): string;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve an id-or-name argument against the plugin ids each known
|
|
26
|
+
* marketplace declares (S4 install resolution): an exact `<name>@<mkt>`
|
|
27
|
+
* must be declared by that marketplace; a bare `<name>` resolves iff
|
|
28
|
+
* exactly one declared id has that name part.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveDeclaredPluginId(arg: string, declaredByMarketplace: ReadonlyMap<string, readonly string[]>): string;
|
|
31
|
+
/** One plugin declared by a marketplace manifest: only string (directory) sources in v1. */
|
|
32
|
+
export interface DeclaredPlugin {
|
|
33
|
+
name: string;
|
|
34
|
+
source: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Read `<installLocation>/.claude-plugin/marketplace.json` and return the
|
|
38
|
+
* declared plugins. Object (non-string) sources are rejected with the
|
|
39
|
+
* unsupported-source error; a missing/unreadable manifest surfaces the S3
|
|
40
|
+
* manifest-missing error.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readDeclaredPlugins(deps: PathInputs, marketplaceName: string): Promise<DeclaredPlugin[]>;
|
|
43
|
+
//# sourceMappingURL=resolve-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-id.d.ts","sourceRoot":"","sources":["../src/resolve-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAeH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,uGAAuG;AACvG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAQ9F;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,qBAAqB,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GAAG,MAAM,CAkB1H;AAED,4FAA4F;AAC5F,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CA6B9G"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin id parsing and resolution against installed keys: an argument is
|
|
3
|
+
* either an exact `<name>@<marketplace>` id or a bare `<name>` that resolves
|
|
4
|
+
* iff exactly one installed key has that name part (plan §3 "Install id
|
|
5
|
+
* resolution"). Errors carry the exact catalog strings from errors.ts.
|
|
6
|
+
*
|
|
7
|
+
* The not-yet-installed variant against marketplace declarations is S3/S4.
|
|
8
|
+
*
|
|
9
|
+
* @module @dsh-cc/plugin-manager/resolve-id
|
|
10
|
+
*/
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { ambiguousPluginName, marketplaceManifestMissing, marketplacePluginNotDeclared, pluginNotInstalled, unknownDeclaredPlugin, unknownMarketplace, unknownPlugin, unsupportedPluginSource, } from "./errors.js";
|
|
14
|
+
import { loadMergedKnownMarketplaces } from "./merged-state.js";
|
|
15
|
+
/** Split `<name>` / `<name>@<marketplace>` (the marketplace part is everything after the LAST `@`). */
|
|
16
|
+
export function parsePluginId(arg) {
|
|
17
|
+
const idx = arg.lastIndexOf('@');
|
|
18
|
+
if (idx <= 0)
|
|
19
|
+
return { name: arg };
|
|
20
|
+
return { name: arg.slice(0, idx), marketplace: arg.slice(idx + 1) };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve an id-or-name argument against the installed plugin keys.
|
|
24
|
+
* An exact key match wins; a bare name resolves iff exactly one installed
|
|
25
|
+
* key has that name part.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveInstalledPluginId(arg, installedKeys) {
|
|
28
|
+
if (installedKeys.includes(arg))
|
|
29
|
+
return arg;
|
|
30
|
+
const { name, marketplace } = parsePluginId(arg);
|
|
31
|
+
if (marketplace !== undefined)
|
|
32
|
+
throw pluginNotInstalled(arg);
|
|
33
|
+
const matches = installedKeys.filter(key => parsePluginId(key).name === name);
|
|
34
|
+
if (matches.length === 1)
|
|
35
|
+
return matches[0];
|
|
36
|
+
if (matches.length === 0)
|
|
37
|
+
throw unknownPlugin(arg, installedKeys);
|
|
38
|
+
throw ambiguousPluginName(name, matches);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve an id-or-name argument against the plugin ids each known
|
|
42
|
+
* marketplace declares (S4 install resolution): an exact `<name>@<mkt>`
|
|
43
|
+
* must be declared by that marketplace; a bare `<name>` resolves iff
|
|
44
|
+
* exactly one declared id has that name part.
|
|
45
|
+
*/
|
|
46
|
+
export function resolveDeclaredPluginId(arg, declaredByMarketplace) {
|
|
47
|
+
const { name, marketplace } = parsePluginId(arg);
|
|
48
|
+
if (marketplace !== undefined) {
|
|
49
|
+
const declared = declaredByMarketplace.get(marketplace) ?? [];
|
|
50
|
+
if (declared.includes(arg))
|
|
51
|
+
return arg;
|
|
52
|
+
throw marketplacePluginNotDeclared(marketplace, name);
|
|
53
|
+
}
|
|
54
|
+
const matches = [];
|
|
55
|
+
const all = [];
|
|
56
|
+
for (const ids of declaredByMarketplace.values()) {
|
|
57
|
+
for (const id of ids) {
|
|
58
|
+
all.push(id);
|
|
59
|
+
if (parsePluginId(id).name === name)
|
|
60
|
+
matches.push(id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (matches.length === 1)
|
|
64
|
+
return matches[0];
|
|
65
|
+
if (matches.length === 0)
|
|
66
|
+
throw unknownDeclaredPlugin(name, all);
|
|
67
|
+
throw ambiguousPluginName(name, matches);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Read `<installLocation>/.claude-plugin/marketplace.json` and return the
|
|
71
|
+
* declared plugins. Object (non-string) sources are rejected with the
|
|
72
|
+
* unsupported-source error; a missing/unreadable manifest surfaces the S3
|
|
73
|
+
* manifest-missing error.
|
|
74
|
+
*/
|
|
75
|
+
export async function readDeclaredPlugins(deps, marketplaceName) {
|
|
76
|
+
// Merged known map (§3.2): a claude-known marketplace's declarations are
|
|
77
|
+
// readable for install/update; its clone is only ever read.
|
|
78
|
+
const known = (await loadMergedKnownMarketplaces(deps)).entries;
|
|
79
|
+
const entry = known[marketplaceName];
|
|
80
|
+
if (entry === undefined)
|
|
81
|
+
throw unknownMarketplace(marketplaceName, Object.keys(known));
|
|
82
|
+
const dir = entry.installLocation;
|
|
83
|
+
let raw;
|
|
84
|
+
try {
|
|
85
|
+
raw = await readFile(join(dir, '.claude-plugin', 'marketplace.json'), 'utf8');
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw marketplaceManifestMissing(dir, error.code ?? error.message);
|
|
89
|
+
}
|
|
90
|
+
let manifest;
|
|
91
|
+
try {
|
|
92
|
+
manifest = JSON.parse(raw);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw marketplaceManifestMissing(dir, error.message);
|
|
96
|
+
}
|
|
97
|
+
const plugins = Array.isArray(manifest['plugins']) ? manifest['plugins'] : [];
|
|
98
|
+
const declared = [];
|
|
99
|
+
for (const item of plugins) {
|
|
100
|
+
const name = item?.['name'];
|
|
101
|
+
if (typeof name !== 'string' || name.length === 0)
|
|
102
|
+
continue;
|
|
103
|
+
const source = item['source'];
|
|
104
|
+
if (typeof source !== 'string')
|
|
105
|
+
throw unsupportedPluginSource(`${name}@${marketplaceName}`);
|
|
106
|
+
declared.push({ name, source });
|
|
107
|
+
}
|
|
108
|
+
return declared;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=resolve-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-id.js","sourceRoot":"","sources":["../src/resolve-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,uBAAuB,GACxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAA;AAQ/D,uGAAuG;AACvG,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;IAClC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAA;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAW,EAAE,aAAgC;IACpF,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IAC3C,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;I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,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC7E,MAAM,QAAQ,GAAqB,EAAE,CAAA;IACrC,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAI,IAAuC,EAAE,CAAC,MAAM,CAAC,CAAA;QAC/D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,SAAQ;QAC3D,MAAM,MAAM,GAAI,IAAgC,CAAC,QAAQ,CAAC,CAAA;QAC1D,IAAI,OAAO,MAAM,KAAK,QAAQ;YAAE,MAAM,uBAAuB,CAAC,GAAG,IAAI,IAAI,eAAe,EAAE,CAAC,CAAA;QAC3F,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IACjC,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* enabledPlugins writes shared by install/uninstall (plan §2.2 C2/C4):
|
|
3
|
+
* scope-surgical, preserving all other settings keys (C11).
|
|
4
|
+
*
|
|
5
|
+
* @module @dsh-cc/plugin-manager/settings-write
|
|
6
|
+
*/
|
|
7
|
+
import { type PathInputs } from './paths.ts';
|
|
8
|
+
import type { Scope } from './types.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Set (`true`/`false`) or remove (`null`) the `enabledPlugins[id]` key in
|
|
11
|
+
* exactly one scope's settings file. Removal keeps the `enabledPlugins`
|
|
12
|
+
* object in place even when it becomes empty (C4: an empty
|
|
13
|
+
* `enabledPlugins: {}` object remains).
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyEnabledFlag(deps: PathInputs, scope: Scope, id: string, value: boolean | null): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=settings-write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings-write.d.ts","sourceRoot":"","sources":["../src/settings-write.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAElE,OAAO,KAAK,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAA;AAE1D;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAcvH"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* enabledPlugins writes shared by install/uninstall (plan §2.2 C2/C4):
|
|
3
|
+
* scope-surgical, preserving all other settings keys (C11).
|
|
4
|
+
*
|
|
5
|
+
* @module @dsh-cc/plugin-manager/settings-write
|
|
6
|
+
*/
|
|
7
|
+
import { settingsFileForScope } from "./paths.js";
|
|
8
|
+
import { loadSettingsFile, saveJsonFileAtomic } from "./state-store.js";
|
|
9
|
+
/**
|
|
10
|
+
* Set (`true`/`false`) or remove (`null`) the `enabledPlugins[id]` key in
|
|
11
|
+
* exactly one scope's settings file. Removal keeps the `enabledPlugins`
|
|
12
|
+
* object in place even when it becomes empty (C4: an empty
|
|
13
|
+
* `enabledPlugins: {}` object remains).
|
|
14
|
+
*/
|
|
15
|
+
export async function applyEnabledFlag(deps, scope, id, value) {
|
|
16
|
+
const file = settingsFileForScope(scope, deps);
|
|
17
|
+
const settings = await loadSettingsFile(file);
|
|
18
|
+
const next = { ...settings };
|
|
19
|
+
if (value === null) {
|
|
20
|
+
const existing = settings['enabledPlugins'];
|
|
21
|
+
if (existing === undefined)
|
|
22
|
+
return;
|
|
23
|
+
const enabled = { ...existing };
|
|
24
|
+
delete enabled[id];
|
|
25
|
+
next['enabledPlugins'] = enabled;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
next['enabledPlugins'] = { ...settings['enabledPlugins'], [id]: value };
|
|
29
|
+
}
|
|
30
|
+
await saveJsonFileAtomic(file, next);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=settings-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings-write.js","sourceRoot":"","sources":["../src/settings-write.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAmB,MAAM,YAAY,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAGvE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAgB,EAAE,KAAY,EAAE,EAAU,EAAE,KAAqB;IACtG,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAC9C,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,IAAI,GAAsB,EAAE,GAAG,QAAQ,EAAE,CAAA;IAC/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAA;QAC3C,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAM;QAClC,MAAM,OAAO,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAA;QAC/B,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;QAClB,IAAI,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAA;IAClC,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAA;IACzE,CAAC;IACD,MAAM,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON state-file I/O for Claude Code plugin management: typed loaders with
|
|
3
|
+
* documented missing-file defaults (C10), malformed-JSON typed errors (never
|
|
4
|
+
* silently rewritten), and atomic save (tmp + rename) round-tripping plain
|
|
5
|
+
* objects so callers' read-modify-write preserves unknown keys and key
|
|
6
|
+
* order (C11).
|
|
7
|
+
*
|
|
8
|
+
* @module @dsh-cc/plugin-manager/state-store
|
|
9
|
+
*/
|
|
10
|
+
import type { InstalledPluginsFile, KnownMarketplacesFile, ScopeSettingsFile } from './types.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Read a JSON file. Missing file → `fallback`. Malformed content → typed
|
|
13
|
+
* `State file <path> is malformed JSON: <detail>`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadJsonFile<T>(file: string, fallback: T): Promise<T>;
|
|
16
|
+
/** Save atomically: 2-space + trailing newline, `<file>.tmp-<pid>` then rename, parents created. */
|
|
17
|
+
export declare function saveJsonFileAtomic(file: string, value: unknown): Promise<void>;
|
|
18
|
+
/** `known_marketplaces.json` — defaults to `{}` (C10). */
|
|
19
|
+
export declare function loadKnownMarketplaces(file: string): Promise<KnownMarketplacesFile>;
|
|
20
|
+
/** `installed_plugins.json` — defaults to `{version:2, plugins:{}}` (C10). */
|
|
21
|
+
export declare function loadInstalledPlugins(file: string): Promise<InstalledPluginsFile>;
|
|
22
|
+
/** A scope settings file — defaults to `{}`; unknown keys survive by round-trip (C11). */
|
|
23
|
+
export declare function loadSettingsFile(file: string): Promise<ScopeSettingsFile>;
|
|
24
|
+
//# sourceMappingURL=state-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.d.ts","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEhG;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAa3E;AAED,oGAAoG;AACpG,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAMpF;AAED,0DAA0D;AAC1D,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAExF;AAED,8EAA8E;AAC9E,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAEtF;AAED,0FAA0F;AAC1F,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAE/E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON state-file I/O for Claude Code plugin management: typed loaders with
|
|
3
|
+
* documented missing-file defaults (C10), malformed-JSON typed errors (never
|
|
4
|
+
* silently rewritten), and atomic save (tmp + rename) round-tripping plain
|
|
5
|
+
* objects so callers' read-modify-write preserves unknown keys and key
|
|
6
|
+
* order (C11).
|
|
7
|
+
*
|
|
8
|
+
* @module @dsh-cc/plugin-manager/state-store
|
|
9
|
+
*/
|
|
10
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { dirname } from 'node:path';
|
|
12
|
+
import { malformedStateFile } from "./errors.js";
|
|
13
|
+
/**
|
|
14
|
+
* Read a JSON file. Missing file → `fallback`. Malformed content → typed
|
|
15
|
+
* `State file <path> is malformed JSON: <detail>`.
|
|
16
|
+
*/
|
|
17
|
+
export async function loadJsonFile(file, fallback) {
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = await readFile(file, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code === 'ENOENT')
|
|
24
|
+
return fallback;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(raw);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw malformedStateFile(file, error.message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Save atomically: 2-space + trailing newline, `<file>.tmp-<pid>` then rename, parents created. */
|
|
35
|
+
export async function saveJsonFileAtomic(file, value) {
|
|
36
|
+
const parent = dirname(file);
|
|
37
|
+
await mkdir(parent, { recursive: true });
|
|
38
|
+
const tmpFile = `${file}.tmp-${process.pid}`;
|
|
39
|
+
await writeFile(tmpFile, JSON.stringify(value, null, 2) + '\n', 'utf8');
|
|
40
|
+
await rename(tmpFile, file);
|
|
41
|
+
}
|
|
42
|
+
/** `known_marketplaces.json` — defaults to `{}` (C10). */
|
|
43
|
+
export async function loadKnownMarketplaces(file) {
|
|
44
|
+
return loadJsonFile(file, {});
|
|
45
|
+
}
|
|
46
|
+
/** `installed_plugins.json` — defaults to `{version:2, plugins:{}}` (C10). */
|
|
47
|
+
export async function loadInstalledPlugins(file) {
|
|
48
|
+
return loadJsonFile(file, { version: 2, plugins: {} });
|
|
49
|
+
}
|
|
50
|
+
/** A scope settings file — defaults to `{}`; unknown keys survive by round-trip (C11). */
|
|
51
|
+
export async function loadSettingsFile(file) {
|
|
52
|
+
return loadJsonFile(file, {});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=state-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-store.js","sourceRoot":"","sources":["../src/state-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAA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U,oBAAoB,CAAC,IAAY;IACrD,OAAO,YAAY,CAAuB,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;AAC9E,CAAC;AAED,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY;IACjD,OAAO,YAAY,CAAoB,IAAI,EAAE,EAAE,CAAC,CAAA;AAClD,CAAC"}
|
package/lib/toggles.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 { type PathInputs } from './paths.ts';
|
|
11
|
+
import type { Scope } from './types.ts';
|
|
12
|
+
export interface ToggleOptions {
|
|
13
|
+
scope?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ToggleResult {
|
|
16
|
+
id: string;
|
|
17
|
+
scope: Scope;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Core toggle: resolve the id against installed keys, pick the scope, then
|
|
22
|
+
* write `enabledPlugins[id]` into exactly that scope's settings file,
|
|
23
|
+
* preserving all other keys (C11).
|
|
24
|
+
*/
|
|
25
|
+
export declare function togglePlugin(deps: PathInputs, arg: string, enabled: boolean, opts?: ToggleOptions): Promise<ToggleResult>;
|
|
26
|
+
/** `enable <idOrName> [--scope s]` core (C3). */
|
|
27
|
+
export declare function enablePlugin(deps: PathInputs, arg: string, opts?: ToggleOptions): Promise<ToggleResult>;
|
|
28
|
+
/** `disable <idOrName> [--scope s]` core (C3) — the key is kept with `false`. */
|
|
29
|
+
export declare function disablePlugin(deps: PathInputs, arg: string, opts?: ToggleOptions): Promise<ToggleResult>;
|
|
30
|
+
//# sourceMappingURL=toggles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toggles.d.ts","sourceRoot":"","sources":["../src/toggles.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAGlE,OAAO,KAAK,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAA;AAE1D,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;CACjB;AAyBD;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAc/H;AAED,iDAAiD;AACjD,wBAAsB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAE7G;AAED,iFAAiF;AACjF,wBAAsB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAE9G"}
|