docks-kit 0.22.28 → 0.23.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/AGENTS.md +31 -77
- package/README.md +31 -58
- package/cli/docs/command-guards.md +231 -197
- package/cli/docs/flags.md +25 -55
- package/cli/docs/install.md +2 -3
- package/cli/docs/omp-models.md +9 -0
- package/cli/docs/overview.md +4 -12
- package/cli/docs/platforms.md +2 -2
- package/cli/docs/sync-layers.md +10 -57
- package/cli/docs/toolchain.md +9 -78
- package/cli/src/argv.ts +0 -8
- package/cli/src/argvValidate.ts +2 -46
- package/cli/src/commands/docs.ts +2 -14
- package/cli/src/commands/harnesses.ts +6 -9
- package/cli/src/commands/sync.ts +5 -99
- package/cli/src/commands/toolchain.ts +4 -12
- package/cli/src/engine-native/DESIGN.md +67 -88
- package/cli/src/engine-native/deps.ts +6 -86
- package/cli/src/engine-native/engineCtx.ts +7 -76
- package/cli/src/engine-native/exec.ts +1 -18
- package/cli/src/engine-native/harnesses.ts +6 -6
- package/cli/src/engine-native/index.ts +4 -6
- package/cli/src/engine-native/jq.ts +4 -37
- package/cli/src/engine-native/modes.ts +3 -132
- package/cli/src/engine-native/os/darwin.ts +0 -4
- package/cli/src/engine-native/os/index.ts +1 -2
- package/cli/src/engine-native/os/linux.ts +0 -3
- package/cli/src/engine-native/os/posix.ts +2 -46
- package/cli/src/engine-native/os/types.ts +1 -32
- package/cli/src/engine-native/os/windows.ts +0 -49
- package/cli/src/engine-native/parseArgs.ts +11 -124
- package/cli/src/engine-native/parseHelp.ts +5 -40
- package/cli/src/engine-native/scratch.ts +1 -1
- package/cli/src/engine-native/services.ts +1 -2
- package/cli/src/engine-native/sharedTypes.d.ts +0 -40
- package/cli/src/engine-native/skillsSync.ts +1 -1
- package/cli/src/engine-native/syncConcurrency.ts +3 -15
- package/cli/src/engine-native/syncDispatch.ts +10 -57
- package/cli/src/engine-native/toolchain.ts +5 -40
- package/cli/src/engine.ts +0 -75
- package/cli/src/generated/sotPayload.ts +12 -39
- package/cli/src/main.ts +7 -19
- package/cli/src/manifests.ts +1 -93
- package/cli/src/payload.ts +2 -8
- package/cli/tsconfig.json +1 -3
- package/package.json +3 -5
- package/cli/docs/models.md +0 -58
- package/cli/docs/modifiers.md +0 -52
- package/cli/docs/plugins.md +0 -70
- package/cli/src/commands/model.ts +0 -68
- package/cli/src/commands/models.ts +0 -75
- package/cli/src/commands/plugins.ts +0 -35
- package/cli/src/commands/status.ts +0 -206
- package/cli/src/efforts.ts +0 -89
- package/cli/src/engine-native/claudeLsp.ts +0 -301
- package/cli/src/engine-native/claudeOptionalPlugins.ts +0 -126
- package/cli/src/engine-native/claudePluginPasses.ts +0 -426
- package/cli/src/engine-native/claudeRemovals.ts +0 -383
- package/cli/src/engine-native/claudeRetired.ts +0 -165
- package/cli/src/engine-native/claudeRuntime.ts +0 -157
- package/cli/src/engine-native/claudeSettings.ts +0 -201
- package/cli/src/engine-native/claudeSettingsModifiers.ts +0 -115
- package/cli/src/engine-native/claudeSync.ts +0 -312
- package/cli/src/engine-native/codexConfig.ts +0 -214
- package/cli/src/engine-native/codexHooks.ts +0 -91
- package/cli/src/engine-native/codexPaths.ts +0 -14
- package/cli/src/engine-native/codexPlugins.ts +0 -315
- package/cli/src/engine-native/codexStatus.ts +0 -25
- package/cli/src/engine-native/codexSync.ts +0 -314
- package/cli/src/engine-native/codexToml.ts +0 -303
- package/cli/src/engine-native/liveModels.ts +0 -264
- package/cli/src/engine-native/models.ts +0 -101
- package/cli/src/engine-native/parseModifiers.ts +0 -225
- package/cli/src/engine-native/settings.ts +0 -42
- package/cli/src/engine-native/tomlLines.ts +0 -92
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EngineNative `sync claude` optional-plugin opt-in pass (--claude-plugin).
|
|
3
|
-
* Split from claudePluginPasses along the opt-in axis; message strings
|
|
4
|
-
* and spawned argv are part of the golden-tested contract.
|
|
5
|
-
*/
|
|
6
|
-
import { p } from "./exec";
|
|
7
|
-
import { recordFailure } from "./failures";
|
|
8
|
-
import type { Ctx } from "./index";
|
|
9
|
-
import { isObject, readJsonFile } from "./jq";
|
|
10
|
-
import type { JsonObject } from "./sharedTypes";
|
|
11
|
-
import { cli, pluginUserScopeInstalled } from "./claudePluginPasses";
|
|
12
|
-
|
|
13
|
-
async function enableOptionalPlugin(
|
|
14
|
-
ctx: Ctx,
|
|
15
|
-
claudeDir: string,
|
|
16
|
-
pluginId: string,
|
|
17
|
-
marketplaceRepo: string,
|
|
18
|
-
): Promise<boolean> {
|
|
19
|
-
const { change, clearProgress, progress, verbose } = ctx.services.logger;
|
|
20
|
-
const installedPlugins = p(claudeDir, "plugins", "installed_plugins.json");
|
|
21
|
-
const knownMarketplaces = p(claudeDir, "plugins", "known_marketplaces.json");
|
|
22
|
-
const mpName = pluginId.slice(pluginId.lastIndexOf("@") + 1);
|
|
23
|
-
|
|
24
|
-
let marketplaceAdded = false;
|
|
25
|
-
if (marketplaceRepo !== "") {
|
|
26
|
-
const known = readJsonFile(knownMarketplaces);
|
|
27
|
-
const has =
|
|
28
|
-
known !== undefined &&
|
|
29
|
-
isObject(known) &&
|
|
30
|
-
known[mpName] !== undefined &&
|
|
31
|
-
known[mpName] !== null &&
|
|
32
|
-
known[mpName] !== false;
|
|
33
|
-
if (!has) {
|
|
34
|
-
if (!(await cli(["plugin", "marketplace", "add", marketplaceRepo])).ok) {
|
|
35
|
-
recordFailure(ctx, `Failed to add marketplace ${marketplaceRepo} for ${pluginId}`);
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
marketplaceAdded = true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const wasInstalled = pluginUserScopeInstalled(installedPlugins, pluginId);
|
|
43
|
-
if (!wasInstalled) {
|
|
44
|
-
progress(`Installing plugin ${pluginId}...`);
|
|
45
|
-
const installResult = await cli(["plugin", "install", pluginId]);
|
|
46
|
-
clearProgress();
|
|
47
|
-
if (!installResult.ok) {
|
|
48
|
-
if (marketplaceAdded)
|
|
49
|
-
change(
|
|
50
|
-
`Optional plugin ${pluginId}: marketplace added (install failed — will retry next sync)`,
|
|
51
|
-
);
|
|
52
|
-
recordFailure(ctx, `Failed to install optional plugin ${pluginId}`);
|
|
53
|
-
return marketplaceAdded;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const settingsDoc = readJsonFile(p(claudeDir, "settings.json"));
|
|
58
|
-
const wasEnabled =
|
|
59
|
-
settingsDoc !== undefined && isObject(settingsDoc) && isObject(settingsDoc["enabledPlugins"])
|
|
60
|
-
? (settingsDoc["enabledPlugins"] as JsonObject)[pluginId] === true
|
|
61
|
-
: false;
|
|
62
|
-
|
|
63
|
-
// `claude plugin install` enables the plugin at user scope, and
|
|
64
|
-
// `claude plugin enable` fails for a plugin that is already enabled.
|
|
65
|
-
if (!wasEnabled) {
|
|
66
|
-
const enableArgs = ["plugin", "enable", pluginId, "--scope", "user"];
|
|
67
|
-
if (!(await cli(enableArgs)).ok) {
|
|
68
|
-
if (marketplaceAdded || !wasInstalled)
|
|
69
|
-
change(`Optional plugin ${pluginId}: installed (enable failed — will retry next sync)`);
|
|
70
|
-
recordFailure(ctx, `Failed to enable optional plugin ${pluginId}`);
|
|
71
|
-
return marketplaceAdded || !wasInstalled;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const changed = marketplaceAdded || !wasInstalled || !wasEnabled;
|
|
75
|
-
if (changed) change(`Optional plugin opted in: ${pluginId}`);
|
|
76
|
-
else verbose(`Optional plugin already opted in: ${pluginId}`);
|
|
77
|
-
return changed;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function syncOptionalPlugins(ctx: Ctx, claudeDir: string): Promise<void> {
|
|
81
|
-
const { echo, warn } = ctx.services.logger;
|
|
82
|
-
if (ctx.claudePlugins.length === 0) return;
|
|
83
|
-
|
|
84
|
-
if (ctx.dryRun) {
|
|
85
|
-
if (ctx.claudePlugins.includes("supabase")) {
|
|
86
|
-
echo(
|
|
87
|
-
"[dry-run] (--claude-plugin=supabase) install + enable supabase@claude-plugins-official in deployed settings",
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
if (ctx.claudePlugins.includes("n8n")) {
|
|
91
|
-
echo(
|
|
92
|
-
"[dry-run] (--claude-plugin=n8n) add czlonkowski/n8n-skills marketplace + install + enable n8n-mcp-skills@n8n-mcp-skills",
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (ctx.services.deps.probe("claude").state === "missing") {
|
|
99
|
-
warn("claude CLI not in PATH — cannot opt in optional plugins (--claude-plugin)");
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (ctx.services.deps.probe("git").state === "missing") {
|
|
103
|
-
ctx.services.deps.warnMissing(
|
|
104
|
-
"git",
|
|
105
|
-
ctx.services.logger,
|
|
106
|
-
"plugin marketplaces are git repos — optional plugins (--claude-plugin) skipped; re-run sync after installing",
|
|
107
|
-
);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (ctx.claudePlugins.includes("supabase")) {
|
|
112
|
-
if (await enableOptionalPlugin(ctx, claudeDir, "supabase@claude-plugins-official", ""))
|
|
113
|
-
ctx.nextStepTriggers.claudePlugins = true;
|
|
114
|
-
}
|
|
115
|
-
if (ctx.claudePlugins.includes("n8n")) {
|
|
116
|
-
if (
|
|
117
|
-
await enableOptionalPlugin(
|
|
118
|
-
ctx,
|
|
119
|
-
claudeDir,
|
|
120
|
-
"n8n-mcp-skills@n8n-mcp-skills",
|
|
121
|
-
"czlonkowski/n8n-skills",
|
|
122
|
-
)
|
|
123
|
-
)
|
|
124
|
-
ctx.nextStepTriggers.claudePlugins = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EngineNative `sync claude` plugin install and refresh passes. Pass order
|
|
3
|
-
* inside `syncPlugins` is load-bearing and golden-tested; message strings
|
|
4
|
-
* and spawned argv are part of the contract.
|
|
5
|
-
*/
|
|
6
|
-
import { existsSync } from "node:fs";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { replaceFile } from "./atomicWrite";
|
|
9
|
-
import { p, spawnProcess } from "./exec";
|
|
10
|
-
import { recordFailure } from "./failures";
|
|
11
|
-
import type { Ctx } from "./index";
|
|
12
|
-
import {
|
|
13
|
-
compareCodepoints,
|
|
14
|
-
deepMerge,
|
|
15
|
-
isObject,
|
|
16
|
-
jqStringify,
|
|
17
|
-
parseJson,
|
|
18
|
-
readJsonFile,
|
|
19
|
-
type Json,
|
|
20
|
-
} from "./jq";
|
|
21
|
-
import { payloadText } from "../payload";
|
|
22
|
-
import type { JsonObject } from "./sharedTypes";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Claude Code's official marketplace: protected from prune, and added on demand
|
|
26
|
-
* when a kit plugin comes from it and the marketplace is not registered yet.
|
|
27
|
-
*/
|
|
28
|
-
const OFFICIAL_MARKETPLACE = "claude-plugins-official";
|
|
29
|
-
const OFFICIAL_MARKETPLACE_REPO = "anthropics/claude-plugins-official";
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Success text of `claude plugin update` when the version changed, e.g.
|
|
33
|
-
* `Plugin "x" updated from 1.0.0 to 1.0.1 for scope user`. The text for an
|
|
34
|
-
* up-to-date plugin ("already at the latest version") does not match.
|
|
35
|
-
*/
|
|
36
|
-
const PLUGIN_UPDATED_RE = /\bupdated from \S+ to \S+ for scope\b/;
|
|
37
|
-
|
|
38
|
-
/** First non-empty trimmed line of a stream, or undefined when it has none. */
|
|
39
|
-
function firstLine(text: string): string | undefined {
|
|
40
|
-
return text
|
|
41
|
-
.split("\n")
|
|
42
|
-
.map((line) => line.trim())
|
|
43
|
-
.find((line) => line !== "");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function cli(
|
|
47
|
-
args: Array<string>,
|
|
48
|
-
): Promise<{ ok: boolean; out: string; detail: string }> {
|
|
49
|
-
// A `claude plugin` command without `--scope` also edits the project
|
|
50
|
-
// settings of its working directory. A neutral working directory keeps
|
|
51
|
-
// every command on the user scope, whatever directory the user runs sync from.
|
|
52
|
-
const res = await spawnProcess("claude", args, {
|
|
53
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
54
|
-
cwd: tmpdir(),
|
|
55
|
-
});
|
|
56
|
-
// A spawn error carries its cause in `error`, not in either stream, and that
|
|
57
|
-
// is the case a failure message cannot afford to drop: it names an
|
|
58
|
-
// unresolvable launcher instead of a rejected command.
|
|
59
|
-
if (res.error !== undefined) {
|
|
60
|
-
const out = res.error.message;
|
|
61
|
-
return { ok: false, out, detail: firstLine(out) ?? "unknown error" };
|
|
62
|
-
}
|
|
63
|
-
// The CLI prints progress lines on stdout and the cause on stderr, so the
|
|
64
|
-
// failure detail reads stderr first.
|
|
65
|
-
const out = `${res.stdout}${res.stderr}`;
|
|
66
|
-
const detail = firstLine(res.stderr) ?? firstLine(res.stdout) ?? "unknown error";
|
|
67
|
-
return { ok: res.exitCode === 0, out, detail };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** Failure message tail: the cause, then the command to re-run by hand. */
|
|
71
|
-
function manually(detail: string, args: Array<string>): string {
|
|
72
|
-
return `${detail}; run manually: claude ${args.join(" ")}`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function sortedKeys(obj: Json | undefined): Array<string> {
|
|
76
|
-
return obj !== undefined && isObject(obj) ? Object.keys(obj).sort(compareCodepoints) : [];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** claude::_plugin_user_scope_installed. */
|
|
80
|
-
export function pluginUserScopeInstalled(installedPlugins: string, pluginId: string): boolean {
|
|
81
|
-
const doc = readJsonFile(installedPlugins);
|
|
82
|
-
if (doc === undefined || !isObject(doc) || !isObject(doc["plugins"])) return false;
|
|
83
|
-
const rec = (doc["plugins"] as JsonObject)[pluginId];
|
|
84
|
-
if (rec === undefined || rec === null) return false;
|
|
85
|
-
const records = Array.isArray(rec) ? rec : [rec];
|
|
86
|
-
return records.some((r) => isObject(r) && r["scope"] === "user");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function nonUserScopeMarketplaces(installedDoc: Json | undefined): Set<string> {
|
|
90
|
-
const marketplaces = new Set<string>();
|
|
91
|
-
if (installedDoc === undefined || !isObject(installedDoc) || !isObject(installedDoc["plugins"])) {
|
|
92
|
-
return marketplaces;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
for (const [pluginId, value] of Object.entries(installedDoc["plugins"])) {
|
|
96
|
-
const records = Array.isArray(value) ? value : [value];
|
|
97
|
-
const hasNonUserInstall = records.some(
|
|
98
|
-
(record) =>
|
|
99
|
-
isObject(record) && (record["scope"] === "project" || record["scope"] === "local"),
|
|
100
|
-
);
|
|
101
|
-
if (!hasNonUserInstall) continue;
|
|
102
|
-
const separator = pluginId.lastIndexOf("@");
|
|
103
|
-
if (separator > 0) marketplaces.add(pluginId.slice(separator + 1));
|
|
104
|
-
}
|
|
105
|
-
return marketplaces;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function syncPlugins(ctx: Ctx, claudeDir: string): Promise<void> {
|
|
109
|
-
const { change, clearProgress, echo, progress, verbose, warn } = ctx.services.logger;
|
|
110
|
-
const knownMarketplaces = p(claudeDir, "plugins", "known_marketplaces.json");
|
|
111
|
-
const installedPlugins = p(claudeDir, "plugins", "installed_plugins.json");
|
|
112
|
-
|
|
113
|
-
if (ctx.dryRun) {
|
|
114
|
-
echo(
|
|
115
|
-
ctx.skipPluginRefresh
|
|
116
|
-
? "[dry-run] bootstrap + install missing plugins from SoT; skip refresh-only plugin updates"
|
|
117
|
-
: "[dry-run] bootstrap + update plugin marketplaces + plugins from SoT",
|
|
118
|
-
);
|
|
119
|
-
if (ctx.prune) {
|
|
120
|
-
echo(
|
|
121
|
-
"[dry-run] (--prune) would also uninstall plugins not in SoT and remove extra marketplaces",
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (ctx.services.deps.probe("claude").state === "missing") {
|
|
128
|
-
warn(
|
|
129
|
-
"claude CLI not in PATH — skipping plugin reconcile (run /plugin marketplace add + /plugin install manually)",
|
|
130
|
-
);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (ctx.services.deps.probe("git").state === "missing") {
|
|
134
|
-
ctx.services.deps.warnMissing(
|
|
135
|
-
"git",
|
|
136
|
-
ctx.services.logger,
|
|
137
|
-
"plugin marketplaces are git repos — Claude plugin passes skipped; re-run sync after installing",
|
|
138
|
-
);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const repoSettings = parseJson(payloadText("SoT/.claude/settings.json"));
|
|
143
|
-
const repoObj = repoSettings !== undefined && isObject(repoSettings) ? repoSettings : {};
|
|
144
|
-
const sotMarketplaces = isObject(repoObj["extraKnownMarketplaces"])
|
|
145
|
-
? repoObj["extraKnownMarketplaces"]
|
|
146
|
-
: {};
|
|
147
|
-
const sotPlugins = isObject(repoObj["enabledPlugins"]) ? repoObj["enabledPlugins"] : {};
|
|
148
|
-
const knownMarketplace = (mpName: string): boolean => {
|
|
149
|
-
const known = readJsonFile(knownMarketplaces);
|
|
150
|
-
return (
|
|
151
|
-
known !== undefined &&
|
|
152
|
-
isObject(known) &&
|
|
153
|
-
known[mpName] !== undefined &&
|
|
154
|
-
known[mpName] !== null &&
|
|
155
|
-
known[mpName] !== false
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
const addedMarketplaces = new Set<string>();
|
|
159
|
-
// A successful add is usable before its inventory is written.
|
|
160
|
-
// A missing inventory proves absence (fresh home); an unreadable one does not, so refresh as before.
|
|
161
|
-
const skippedRefresh = new Set<string>();
|
|
162
|
-
const marketplaceReady = (mpName: string): boolean => {
|
|
163
|
-
if (addedMarketplaces.has(mpName)) return true;
|
|
164
|
-
const known = existsSync(knownMarketplaces) ? readJsonFile(knownMarketplaces) : {};
|
|
165
|
-
if (known === undefined || !isObject(known) || knownMarketplace(mpName)) return true;
|
|
166
|
-
if (!skippedRefresh.has(mpName)) {
|
|
167
|
-
skippedRefresh.add(mpName);
|
|
168
|
-
verbose(
|
|
169
|
-
`Skipping refresh of marketplace ${mpName}: not added yet; the next sync refreshes it`,
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// Kit-owned plugin IDs: SoT-declared plus this run's --claude-plugin opt-ins.
|
|
176
|
-
const kitPluginIds = new Set<string>(Object.keys(sotPlugins));
|
|
177
|
-
if (ctx.claudePlugins.includes("supabase")) kitPluginIds.add("supabase@claude-plugins-official");
|
|
178
|
-
if (ctx.claudePlugins.includes("n8n")) kitPluginIds.add("n8n-mcp-skills@n8n-mcp-skills");
|
|
179
|
-
|
|
180
|
-
// Pass 1 — add missing marketplaces (SoT insertion order, like to_entries).
|
|
181
|
-
let addedMp = 0;
|
|
182
|
-
let f1 = 0;
|
|
183
|
-
for (const [mpName, mpValue] of Object.entries(sotMarketplaces)) {
|
|
184
|
-
if (knownMarketplace(mpName)) continue;
|
|
185
|
-
const repo =
|
|
186
|
-
isObject(mpValue) && isObject(mpValue["source"])
|
|
187
|
-
? String((mpValue["source"] as JsonObject)["repo"] ?? "")
|
|
188
|
-
: "";
|
|
189
|
-
progress(`Adding marketplace ${mpName}...`);
|
|
190
|
-
const marketplaceResult = await cli(["plugin", "marketplace", "add", repo]);
|
|
191
|
-
clearProgress();
|
|
192
|
-
if (marketplaceResult.ok) {
|
|
193
|
-
addedMp++;
|
|
194
|
-
addedMarketplaces.add(mpName);
|
|
195
|
-
} else {
|
|
196
|
-
recordFailure(
|
|
197
|
-
ctx,
|
|
198
|
-
`Failed to add marketplace: ${mpName} (${repo}): ${manually(marketplaceResult.detail, ["plugin", "marketplace", "add", repo])}`,
|
|
199
|
-
);
|
|
200
|
-
f1++;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Claude Code registers its official marketplace only in an interactive
|
|
205
|
-
// session. A fresh home therefore needs the kit to add it before any install.
|
|
206
|
-
const needsOfficial = [...kitPluginIds].some((pluginId) =>
|
|
207
|
-
pluginId.endsWith(`@${OFFICIAL_MARKETPLACE}`),
|
|
208
|
-
);
|
|
209
|
-
if (
|
|
210
|
-
needsOfficial &&
|
|
211
|
-
!addedMarketplaces.has(OFFICIAL_MARKETPLACE) &&
|
|
212
|
-
!knownMarketplace(OFFICIAL_MARKETPLACE)
|
|
213
|
-
) {
|
|
214
|
-
const addArgs = ["plugin", "marketplace", "add", OFFICIAL_MARKETPLACE_REPO];
|
|
215
|
-
progress(`Adding marketplace ${OFFICIAL_MARKETPLACE}...`);
|
|
216
|
-
const officialResult = await cli(addArgs);
|
|
217
|
-
clearProgress();
|
|
218
|
-
if (officialResult.ok) {
|
|
219
|
-
addedMp++;
|
|
220
|
-
addedMarketplaces.add(OFFICIAL_MARKETPLACE);
|
|
221
|
-
} else {
|
|
222
|
-
recordFailure(
|
|
223
|
-
ctx,
|
|
224
|
-
`Failed to add marketplace: ${OFFICIAL_MARKETPLACE} (${OFFICIAL_MARKETPLACE_REPO}): ${manually(officialResult.detail, addArgs)}`,
|
|
225
|
-
);
|
|
226
|
-
f1++;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Pass 2 — install SoT-enabled plugins missing at user scope (jq keys[] sorts),
|
|
231
|
-
// refreshing each source marketplace once so the install resolves a current snapshot.
|
|
232
|
-
let addedPl = 0;
|
|
233
|
-
let f2 = 0;
|
|
234
|
-
let f3 = 0;
|
|
235
|
-
let f4 = 0;
|
|
236
|
-
const refreshedMarketplaces = new Set<string>();
|
|
237
|
-
for (const pluginId of sortedKeys(sotPlugins)) {
|
|
238
|
-
if (pluginUserScopeInstalled(installedPlugins, pluginId)) continue;
|
|
239
|
-
const separator = pluginId.lastIndexOf("@");
|
|
240
|
-
const mpName = separator > 0 ? pluginId.slice(separator + 1) : "";
|
|
241
|
-
if (mpName !== "" && marketplaceReady(mpName) && !refreshedMarketplaces.has(mpName)) {
|
|
242
|
-
progress(`Refreshing marketplace ${mpName}...`);
|
|
243
|
-
const refreshResult = await cli(["plugin", "marketplace", "update", mpName]);
|
|
244
|
-
clearProgress();
|
|
245
|
-
if (!refreshResult.ok) {
|
|
246
|
-
recordFailure(
|
|
247
|
-
ctx,
|
|
248
|
-
`Failed to refresh marketplace: ${mpName}: ${manually(refreshResult.detail, ["plugin", "marketplace", "update", mpName])}`,
|
|
249
|
-
);
|
|
250
|
-
f3++;
|
|
251
|
-
}
|
|
252
|
-
refreshedMarketplaces.add(mpName);
|
|
253
|
-
}
|
|
254
|
-
progress(`Installing plugin ${pluginId}...`);
|
|
255
|
-
const installResult = await cli(["plugin", "install", pluginId]);
|
|
256
|
-
clearProgress();
|
|
257
|
-
if (installResult.ok) {
|
|
258
|
-
addedPl++;
|
|
259
|
-
} else {
|
|
260
|
-
recordFailure(
|
|
261
|
-
ctx,
|
|
262
|
-
`Failed to install plugin: ${pluginId}: ${manually(installResult.detail, ["plugin", "install", pluginId])}`,
|
|
263
|
-
);
|
|
264
|
-
f2++;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
let updatedPl = 0;
|
|
269
|
-
const installedDoc = readJsonFile(installedPlugins);
|
|
270
|
-
const installedKeys =
|
|
271
|
-
installedDoc !== undefined && isObject(installedDoc) ? sortedKeys(installedDoc["plugins"]) : [];
|
|
272
|
-
const nonUserMarketplaces = nonUserScopeMarketplaces(installedDoc);
|
|
273
|
-
|
|
274
|
-
// Kit-owned marketplaces: SoT-declared plus every marketplace those plugins come from.
|
|
275
|
-
const kitMarketplaces = new Set<string>(Object.keys(sotMarketplaces));
|
|
276
|
-
for (const pluginId of kitPluginIds) {
|
|
277
|
-
const separator = pluginId.lastIndexOf("@");
|
|
278
|
-
if (separator > 0) kitMarketplaces.add(pluginId.slice(separator + 1));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Pass 3 — refresh the kit-owned marketplaces unless the caller passed
|
|
282
|
-
// --skip-plugin-refresh by hand. Pass 2 already refreshed the source
|
|
283
|
-
// marketplace of every plugin it installed, so skip those: a second
|
|
284
|
-
// fetch seconds later cannot resolve a newer snapshot, and re-running it
|
|
285
|
-
// would duplicate one failure in the ledger and in the failed-operation count.
|
|
286
|
-
if (!ctx.skipPluginRefresh) {
|
|
287
|
-
for (const mpName of [...kitMarketplaces].sort(compareCodepoints)) {
|
|
288
|
-
if (refreshedMarketplaces.has(mpName) || !marketplaceReady(mpName)) continue;
|
|
289
|
-
progress(`Refreshing marketplace ${mpName}...`);
|
|
290
|
-
const refreshResult = await cli(["plugin", "marketplace", "update", mpName]);
|
|
291
|
-
clearProgress();
|
|
292
|
-
refreshedMarketplaces.add(mpName);
|
|
293
|
-
if (!refreshResult.ok) {
|
|
294
|
-
recordFailure(
|
|
295
|
-
ctx,
|
|
296
|
-
`Failed to refresh marketplace: ${mpName}: ${manually(refreshResult.detail, ["plugin", "marketplace", "update", mpName])}`,
|
|
297
|
-
);
|
|
298
|
-
f3++;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
// Pass 4 — update the kit-owned installed plugins.
|
|
302
|
-
for (const pluginId of [...kitPluginIds].sort(compareCodepoints)) {
|
|
303
|
-
if (!pluginUserScopeInstalled(installedPlugins, pluginId)) continue;
|
|
304
|
-
progress(`Updating plugin ${pluginId}...`);
|
|
305
|
-
const updateResult = await cli(["plugin", "update", pluginId, "--scope", "user"]);
|
|
306
|
-
clearProgress();
|
|
307
|
-
if (!updateResult.ok) {
|
|
308
|
-
recordFailure(
|
|
309
|
-
ctx,
|
|
310
|
-
`Failed to update plugin: ${pluginId}: ${manually(updateResult.detail, ["plugin", "update", pluginId, "--scope", "user"])}`,
|
|
311
|
-
);
|
|
312
|
-
f4++;
|
|
313
|
-
} else if (PLUGIN_UPDATED_RE.test(updateResult.out)) {
|
|
314
|
-
updatedPl++;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Pass 5 — prune-gated user-scope plugin uninstall.
|
|
320
|
-
let removedPl = 0;
|
|
321
|
-
let removedMp = 0;
|
|
322
|
-
let f5 = 0;
|
|
323
|
-
let f6 = 0;
|
|
324
|
-
if (ctx.prune) {
|
|
325
|
-
for (const pluginId of installedKeys) {
|
|
326
|
-
if (kitPluginIds.has(pluginId)) continue;
|
|
327
|
-
if (!pluginUserScopeInstalled(installedPlugins, pluginId)) continue;
|
|
328
|
-
progress(`Uninstalling plugin ${pluginId}...`);
|
|
329
|
-
const uninstallResult = await cli(["plugin", "uninstall", "-y", "--scope", "user", pluginId]);
|
|
330
|
-
clearProgress();
|
|
331
|
-
if (uninstallResult.ok) {
|
|
332
|
-
removedPl++;
|
|
333
|
-
} else {
|
|
334
|
-
recordFailure(
|
|
335
|
-
ctx,
|
|
336
|
-
`Failed to uninstall plugin: ${pluginId}: ${manually(uninstallResult.detail, ["plugin", "uninstall", "-y", "--scope", "user", pluginId])}`,
|
|
337
|
-
);
|
|
338
|
-
f5++;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
// Pass 6 — prune-gated marketplace removal.
|
|
342
|
-
const known = readJsonFile(knownMarketplaces);
|
|
343
|
-
for (const mpName of sortedKeys(known)) {
|
|
344
|
-
if (mpName === OFFICIAL_MARKETPLACE) continue;
|
|
345
|
-
if (nonUserMarketplaces.has(mpName)) continue;
|
|
346
|
-
if (kitMarketplaces.has(mpName)) continue;
|
|
347
|
-
progress(`Removing marketplace ${mpName}...`);
|
|
348
|
-
const removeResult = await cli(["plugin", "marketplace", "remove", mpName]);
|
|
349
|
-
clearProgress();
|
|
350
|
-
if (removeResult.ok) {
|
|
351
|
-
removedMp++;
|
|
352
|
-
} else {
|
|
353
|
-
recordFailure(
|
|
354
|
-
ctx,
|
|
355
|
-
`Failed to remove marketplace: ${mpName}: ${manually(removeResult.detail, ["plugin", "marketplace", "remove", mpName])}`,
|
|
356
|
-
);
|
|
357
|
-
f6++;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Pass 7 — re-assert SoT enabled-state in the user settings.
|
|
363
|
-
if (await reassertEnabledState(ctx, repoObj, p(claudeDir, "settings.json"))) {
|
|
364
|
-
change("Plugin enable-state re-asserted from SoT in settings.json");
|
|
365
|
-
ctx.nextStepTriggers.claudePlugins = true;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
const failed = f1 + f2 + f3 + f4 + f5 + f6;
|
|
369
|
-
if (addedMp > 0 || addedPl > 0 || updatedPl > 0 || removedPl > 0 || removedMp > 0) {
|
|
370
|
-
change(
|
|
371
|
-
`Plugins synced (marketplaces: +${addedMp} -${removedMp}, plugins: +${addedPl} ~${updatedPl} -${removedPl})`,
|
|
372
|
-
);
|
|
373
|
-
ctx.nextStepTriggers.claudePlugins = true;
|
|
374
|
-
} else {
|
|
375
|
-
verbose("Plugins already in sync");
|
|
376
|
-
}
|
|
377
|
-
if (failed > 0) {
|
|
378
|
-
warn(`${failed} plugin operation(s) failed — re-run sync or install manually`);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
async function reassertEnabledState(
|
|
383
|
-
ctx: Ctx,
|
|
384
|
-
repoObj: JsonObject,
|
|
385
|
-
userSettingsFile: string,
|
|
386
|
-
): Promise<boolean> {
|
|
387
|
-
const { warn } = ctx.services.logger;
|
|
388
|
-
if (!existsSync(userSettingsFile)) return false;
|
|
389
|
-
const sotPlugins = isObject(repoObj["enabledPlugins"]) ? repoObj["enabledPlugins"] : {};
|
|
390
|
-
|
|
391
|
-
let cliDisabled = false;
|
|
392
|
-
for (const [pluginId, value] of Object.entries(sotPlugins)) {
|
|
393
|
-
if (value !== false) continue;
|
|
394
|
-
const user = readJsonFile(userSettingsFile);
|
|
395
|
-
const enabled =
|
|
396
|
-
user !== undefined && isObject(user) && isObject(user["enabledPlugins"])
|
|
397
|
-
? (user["enabledPlugins"] as JsonObject)[pluginId]
|
|
398
|
-
: undefined;
|
|
399
|
-
if (enabled !== true) continue;
|
|
400
|
-
const disableArgs = ["plugin", "disable", pluginId, "--scope", "user"];
|
|
401
|
-
const disableResult = await cli(disableArgs);
|
|
402
|
-
if (disableResult.ok) {
|
|
403
|
-
cliDisabled = true;
|
|
404
|
-
} else {
|
|
405
|
-
recordFailure(
|
|
406
|
-
ctx,
|
|
407
|
-
`Failed to disable SoT-false plugin: ${pluginId} (will retry next sync): ${manually(disableResult.detail, disableArgs)}`,
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const user = readJsonFile(userSettingsFile);
|
|
413
|
-
if (user === undefined || !isObject(user)) {
|
|
414
|
-
warn("enabledPlugins re-assert failed — false-keyed plugins may be left enabled");
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
const beforeCanonical = jqStringify(user);
|
|
418
|
-
user["enabledPlugins"] = deepMerge(
|
|
419
|
-
isObject(user["enabledPlugins"]) ? user["enabledPlugins"] : {},
|
|
420
|
-
sotPlugins,
|
|
421
|
-
);
|
|
422
|
-
const out = jqStringify(user);
|
|
423
|
-
if (out === beforeCanonical) return cliDisabled;
|
|
424
|
-
replaceFile(userSettingsFile, out);
|
|
425
|
-
return true;
|
|
426
|
-
}
|