shoplazza-ai-dev-cli 0.1.5 → 0.1.6
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/ThirdPartyNoticeText.txt +48 -2
- package/dist/THIRD-PARTY-LICENSES.md +584 -0
- package/dist/_chunks/libs/@clack/core.mjs +10 -5
- package/dist/_chunks/libs/@clack/prompts.mjs +4 -6
- package/dist/_chunks/libs/@kwsites/file-exists.mjs +2 -2
- package/dist/_chunks/libs/@kwsites/promise-deferred.mjs +2 -2
- package/dist/_chunks/libs/@simple-git/args-pathspec.mjs +12 -0
- package/dist/_chunks/libs/@simple-git/argv-parser.mjs +465 -0
- package/dist/_chunks/libs/core-util-is.mjs +2 -2
- package/dist/_chunks/libs/immediate.mjs +2 -2
- package/dist/_chunks/libs/inherits.mjs +2 -4
- package/dist/_chunks/libs/isarray.mjs +2 -2
- package/dist/_chunks/libs/jszip.mjs +9 -13
- package/dist/_chunks/libs/simple-git.mjs +92 -115
- package/dist/_chunks/rolldown-runtime.mjs +2 -2
- package/dist/cli.mjs +521 -37
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import "./_chunks/libs
|
|
6
|
-
import "./_chunks/libs
|
|
7
|
-
import {
|
|
8
|
-
import { t as require_lib } from "./_chunks/libs/jszip.mjs";
|
|
9
|
-
import "./_chunks/libs/isarray.mjs";
|
|
10
|
-
import "./_chunks/libs/core-util-is.mjs";
|
|
11
|
-
import "./_chunks/libs/inherits.mjs";
|
|
12
|
-
import "./_chunks/libs/immediate.mjs";
|
|
13
|
-
import { exec, execSync, spawnSync } from "child_process";
|
|
2
|
+
import { __toESM } from "./_chunks/rolldown-runtime.mjs";
|
|
3
|
+
import { pD, require_picocolors } from "./_chunks/libs/@clack/core.mjs";
|
|
4
|
+
import { Ie, M, Me, Se, Y, be, fe, ve, xe, ye } from "./_chunks/libs/@clack/prompts.mjs";
|
|
5
|
+
import { esm_default } from "./_chunks/libs/simple-git.mjs";
|
|
6
|
+
import { require_lib } from "./_chunks/libs/jszip.mjs";
|
|
7
|
+
import { exec, execFileSync, execSync, spawnSync } from "child_process";
|
|
14
8
|
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
15
9
|
import { basename, dirname, isAbsolute, join, normalize, relative, resolve, sep } from "path";
|
|
16
10
|
import { URL as URL$1, fileURLToPath } from "url";
|
|
@@ -641,7 +635,7 @@ process.stdin.on('end', () => {
|
|
|
641
635
|
}
|
|
642
636
|
function isForgeOwnedCommand(command) {
|
|
643
637
|
if (typeof command !== "string") return false;
|
|
644
|
-
return command.includes(
|
|
638
|
+
return command.includes("track-skill-cursor.mjs") || command.includes(LEGACY_CURSOR_HOOK_BASENAME);
|
|
645
639
|
}
|
|
646
640
|
function isFlatEntry(e) {
|
|
647
641
|
return !!e && typeof e === "object" && typeof e.command === "string";
|
|
@@ -905,10 +899,23 @@ process.stdin.on('end', () => {
|
|
|
905
899
|
});
|
|
906
900
|
`;
|
|
907
901
|
}
|
|
902
|
+
async function ensureForgeCliWrapper() {
|
|
903
|
+
const nodePath = process.execPath;
|
|
904
|
+
const cliScript = process.argv[1];
|
|
905
|
+
if (!cliScript || cliScript.includes("vitest") || cliScript.includes("jest")) return;
|
|
906
|
+
const wrapperPath = join(homedir(), ".ai-dev-cli", "bin", "forge-cli.sh");
|
|
907
|
+
let content;
|
|
908
|
+
if (cliScript.endsWith(".mjs") || cliScript.endsWith(".js")) content = `#!/bin/bash\nexec ${shellEscape(nodePath)} ${shellEscape(cliScript)} "$@"\n`;
|
|
909
|
+
else {
|
|
910
|
+
const tsxLoader = join(dirname(cliScript), "..", "node_modules", "tsx", "dist", "loader.mjs");
|
|
911
|
+
content = `#!/bin/bash\nexec ${shellEscape(nodePath)} --import ${shellEscape(tsxLoader)} ${shellEscape(cliScript)} "$@"\n`;
|
|
912
|
+
}
|
|
913
|
+
await writeScriptIfChanged(wrapperPath, content);
|
|
914
|
+
}
|
|
908
915
|
async function ensureForgeHooks(agent) {
|
|
909
916
|
const warnings = [];
|
|
910
917
|
try {
|
|
911
|
-
const portal = loadConfig().portal ||
|
|
918
|
+
const portal = loadConfig().portal || "https://forge.shoplazza.site";
|
|
912
919
|
const home = getAgentHome(agent);
|
|
913
920
|
if (agent === "claude-code") {
|
|
914
921
|
const scriptPath = join(home, HOOK_DIRNAME, HOOK_SCRIPT_BASENAME);
|
|
@@ -1315,7 +1322,10 @@ async function fetchPluginArchive(ref, portalUrl, bearerToken) {
|
|
|
1315
1322
|
const body = await resp.text().catch(() => "");
|
|
1316
1323
|
throw new Error(`Portal returned ${resp.status} ${resp.statusText}${body ? `: ${body}` : ""}`);
|
|
1317
1324
|
}
|
|
1318
|
-
return
|
|
1325
|
+
return {
|
|
1326
|
+
buffer: Buffer.from(await resp.arrayBuffer()),
|
|
1327
|
+
commitSha: resp.headers.get("x-forge-commit-sha") ?? null
|
|
1328
|
+
};
|
|
1319
1329
|
}
|
|
1320
1330
|
function extractTarGz(gz, dest) {
|
|
1321
1331
|
const tar = gunzipSync(gz);
|
|
@@ -2092,13 +2102,367 @@ async function installBlobSkillForAgent(skill, agentType, options = {}) {
|
|
|
2092
2102
|
};
|
|
2093
2103
|
}
|
|
2094
2104
|
}
|
|
2105
|
+
async function copyDirRecursive$1(src, dest, opts) {
|
|
2106
|
+
const skipSet = new Set([".git", ...opts?.skip ?? []]);
|
|
2107
|
+
const skipFilesSet = new Set(opts?.skipFiles ?? []);
|
|
2108
|
+
await mkdir(dest, { recursive: true });
|
|
2109
|
+
for (const entry of await readdir(src, { withFileTypes: true })) {
|
|
2110
|
+
if (skipSet.has(entry.name)) continue;
|
|
2111
|
+
if (!entry.isDirectory() && skipFilesSet.has(entry.name)) continue;
|
|
2112
|
+
const s = join(src, entry.name);
|
|
2113
|
+
const d = join(dest, entry.name);
|
|
2114
|
+
let isDir = entry.isDirectory();
|
|
2115
|
+
let isFile = entry.isFile();
|
|
2116
|
+
if (entry.isSymbolicLink()) try {
|
|
2117
|
+
const target = await stat(s);
|
|
2118
|
+
isDir = target.isDirectory();
|
|
2119
|
+
isFile = target.isFile();
|
|
2120
|
+
} catch {
|
|
2121
|
+
continue;
|
|
2122
|
+
}
|
|
2123
|
+
if (isDir) await copyDirRecursive$1(s, d, {
|
|
2124
|
+
skip: opts?.skip,
|
|
2125
|
+
skipFiles: opts?.skipFiles
|
|
2126
|
+
});
|
|
2127
|
+
else if (isFile) {
|
|
2128
|
+
await writeFile(d, await readFile(s));
|
|
2129
|
+
const srcStat = await stat(s);
|
|
2130
|
+
if (srcStat.mode & 73) await chmod(d, srcStat.mode & 511);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
const MARKETPLACE = "ai-dev-hub";
|
|
2135
|
+
function pluginKey$1(pluginName) {
|
|
2136
|
+
return `${pluginName}@${MARKETPLACE}`;
|
|
2137
|
+
}
|
|
2138
|
+
function marketplaceDir(home) {
|
|
2139
|
+
return join(home, "plugins", "marketplaces", MARKETPLACE);
|
|
2140
|
+
}
|
|
2141
|
+
function pluginCacheBase(home, pluginName) {
|
|
2142
|
+
return join(home, "plugins", "cache", MARKETPLACE, pluginName);
|
|
2143
|
+
}
|
|
2144
|
+
async function readJson(path, fallback) {
|
|
2145
|
+
try {
|
|
2146
|
+
return JSON.parse(await readFile(path, "utf-8"));
|
|
2147
|
+
} catch {
|
|
2148
|
+
return fallback;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
async function writeJson(path, data) {
|
|
2152
|
+
await mkdir(dirname(path), { recursive: true });
|
|
2153
|
+
await writeFile(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
2154
|
+
}
|
|
2155
|
+
function ensureGitRepo(dir) {
|
|
2156
|
+
const env = {
|
|
2157
|
+
...process.env,
|
|
2158
|
+
GIT_AUTHOR_NAME: "forge",
|
|
2159
|
+
GIT_AUTHOR_EMAIL: "forge@shoplazza.com",
|
|
2160
|
+
GIT_COMMITTER_NAME: "forge",
|
|
2161
|
+
GIT_COMMITTER_EMAIL: "forge@shoplazza.com"
|
|
2162
|
+
};
|
|
2163
|
+
try {
|
|
2164
|
+
execSync("git rev-parse HEAD", {
|
|
2165
|
+
cwd: dir,
|
|
2166
|
+
stdio: "pipe"
|
|
2167
|
+
});
|
|
2168
|
+
} catch {
|
|
2169
|
+
execSync("git init -q && git add . && git commit -q -m \"init\"", {
|
|
2170
|
+
cwd: dir,
|
|
2171
|
+
env,
|
|
2172
|
+
shell: "/bin/bash",
|
|
2173
|
+
stdio: "pipe"
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
function commitMarketplaceChanges(dir) {
|
|
2178
|
+
const env = {
|
|
2179
|
+
...process.env,
|
|
2180
|
+
GIT_AUTHOR_NAME: "forge",
|
|
2181
|
+
GIT_AUTHOR_EMAIL: "forge@shoplazza.com",
|
|
2182
|
+
GIT_COMMITTER_NAME: "forge",
|
|
2183
|
+
GIT_COMMITTER_EMAIL: "forge@shoplazza.com"
|
|
2184
|
+
};
|
|
2185
|
+
try {
|
|
2186
|
+
execSync("git add . && git diff --cached --quiet || git commit -q -m \"update\"", {
|
|
2187
|
+
cwd: dir,
|
|
2188
|
+
env,
|
|
2189
|
+
shell: "/bin/bash",
|
|
2190
|
+
stdio: "pipe"
|
|
2191
|
+
});
|
|
2192
|
+
} catch {}
|
|
2193
|
+
}
|
|
2194
|
+
async function ensureMarketplace(home) {
|
|
2195
|
+
const mDir = marketplaceDir(home);
|
|
2196
|
+
const mJsonPath = join(mDir, ".claude-plugin", "marketplace.json");
|
|
2197
|
+
if (!existsSync(mJsonPath)) {
|
|
2198
|
+
await mkdir(dirname(mJsonPath), { recursive: true });
|
|
2199
|
+
await writeJson(mJsonPath, {
|
|
2200
|
+
name: MARKETPLACE,
|
|
2201
|
+
owner: { name: "Shoplazza" },
|
|
2202
|
+
plugins: []
|
|
2203
|
+
});
|
|
2204
|
+
await ensureGitRepo(mDir);
|
|
2205
|
+
}
|
|
2206
|
+
const source = {
|
|
2207
|
+
source: "git",
|
|
2208
|
+
url: `file://${mDir}`
|
|
2209
|
+
};
|
|
2210
|
+
const settingsPath = join(home, "settings.json");
|
|
2211
|
+
const settings = await readJson(settingsPath, {});
|
|
2212
|
+
if (!settings.extraKnownMarketplaces) settings.extraKnownMarketplaces = {};
|
|
2213
|
+
settings.extraKnownMarketplaces[MARKETPLACE] = { source };
|
|
2214
|
+
await writeJson(settingsPath, settings);
|
|
2215
|
+
const kmPath = join(home, "plugins", "known_marketplaces.json");
|
|
2216
|
+
const km = await readJson(kmPath, {});
|
|
2217
|
+
km[MARKETPLACE] = {
|
|
2218
|
+
source,
|
|
2219
|
+
installLocation: mDir,
|
|
2220
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
2221
|
+
};
|
|
2222
|
+
await writeJson(kmPath, km);
|
|
2223
|
+
}
|
|
2224
|
+
async function upsertMarketplaceEntry(home, pluginName) {
|
|
2225
|
+
const mJsonPath = join(marketplaceDir(home), ".claude-plugin", "marketplace.json");
|
|
2226
|
+
const manifest = await readJson(mJsonPath, {
|
|
2227
|
+
name: MARKETPLACE,
|
|
2228
|
+
owner: { name: "Shoplazza" },
|
|
2229
|
+
plugins: []
|
|
2230
|
+
});
|
|
2231
|
+
const entry = {
|
|
2232
|
+
name: pluginName,
|
|
2233
|
+
source: `./plugins/${pluginName}`
|
|
2234
|
+
};
|
|
2235
|
+
const idx = manifest.plugins.findIndex((p) => p.name === pluginName);
|
|
2236
|
+
if (idx >= 0) manifest.plugins[idx] = entry;
|
|
2237
|
+
else manifest.plugins.push(entry);
|
|
2238
|
+
await writeJson(mJsonPath, manifest);
|
|
2239
|
+
}
|
|
2240
|
+
async function registerClaudePlugin(params) {
|
|
2241
|
+
if (params.scope === "project" && !params.cwd) throw new Error("registerClaudePlugin: 'cwd' is required when scope is 'project'");
|
|
2242
|
+
const cwd = params.cwd ? resolve(params.cwd) : void 0;
|
|
2243
|
+
const home = getAgentHome("claude-code");
|
|
2244
|
+
await ensureMarketplace(home);
|
|
2245
|
+
const version = params.version ?? "0.0.0";
|
|
2246
|
+
const installPath = join(pluginCacheBase(home, params.pluginName), version);
|
|
2247
|
+
await rm(installPath, {
|
|
2248
|
+
recursive: true,
|
|
2249
|
+
force: true
|
|
2250
|
+
});
|
|
2251
|
+
await copyDirRecursive$1(params.sourcePath, installPath, {
|
|
2252
|
+
skip: [".cursor-plugin", ".codex-plugin"],
|
|
2253
|
+
skipFiles: ["hooks-cursor.json", "hooks-codex.json"]
|
|
2254
|
+
});
|
|
2255
|
+
const mPluginDir = join(marketplaceDir(home), "plugins", params.pluginName, ".claude-plugin");
|
|
2256
|
+
await mkdir(mPluginDir, { recursive: true });
|
|
2257
|
+
const srcManifest = join(params.sourcePath, ".claude-plugin", "plugin.json");
|
|
2258
|
+
if (existsSync(srcManifest)) {
|
|
2259
|
+
const full = JSON.parse(await readFile(srcManifest, "utf-8"));
|
|
2260
|
+
const minimal = {
|
|
2261
|
+
name: full["name"],
|
|
2262
|
+
description: full["description"]
|
|
2263
|
+
};
|
|
2264
|
+
if (version !== "0.0.0") minimal["version"] = version;
|
|
2265
|
+
if (full["author"]) minimal["author"] = full["author"];
|
|
2266
|
+
await writeFile(join(mPluginDir, "plugin.json"), JSON.stringify(minimal, null, 2) + "\n", "utf-8");
|
|
2267
|
+
}
|
|
2268
|
+
await upsertMarketplaceEntry(home, params.pluginName);
|
|
2269
|
+
commitMarketplaceChanges(marketplaceDir(home));
|
|
2270
|
+
const installedPath = join(home, "plugins", "installed_plugins.json");
|
|
2271
|
+
const installed = await readJson(installedPath, {
|
|
2272
|
+
version: 2,
|
|
2273
|
+
plugins: {}
|
|
2274
|
+
});
|
|
2275
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2276
|
+
const entry = {
|
|
2277
|
+
scope: params.scope ?? "user",
|
|
2278
|
+
installPath,
|
|
2279
|
+
version,
|
|
2280
|
+
installedAt: now,
|
|
2281
|
+
lastUpdated: now
|
|
2282
|
+
};
|
|
2283
|
+
if (params.gitSha) entry.gitCommitSha = params.gitSha;
|
|
2284
|
+
if (params.scope === "project" && cwd) entry.projectPath = cwd;
|
|
2285
|
+
const warnings = [];
|
|
2286
|
+
const previous = installed.plugins[pluginKey$1(params.pluginName)]?.[0];
|
|
2287
|
+
if (previous?.projectPath && previous.projectPath !== entry.projectPath) warnings.push(`overwriting previous project-scope registration for ${previous.projectPath}; its .claude/settings.json may keep a stale enabledPlugins entry`);
|
|
2288
|
+
installed.plugins[pluginKey$1(params.pluginName)] = [entry];
|
|
2289
|
+
await writeJson(installedPath, installed);
|
|
2290
|
+
const settingsPath = params.scope === "project" && cwd ? join(cwd, ".claude", "settings.json") : join(home, "settings.json");
|
|
2291
|
+
const settings = await readJson(settingsPath, {});
|
|
2292
|
+
if (!settings.enabledPlugins) settings.enabledPlugins = {};
|
|
2293
|
+
settings.enabledPlugins[pluginKey$1(params.pluginName)] = true;
|
|
2294
|
+
await writeJson(settingsPath, settings);
|
|
2295
|
+
return warnings;
|
|
2296
|
+
}
|
|
2297
|
+
async function unregisterClaudePlugin(pluginName, opts) {
|
|
2298
|
+
const home = getAgentHome("claude-code");
|
|
2299
|
+
let projectPath;
|
|
2300
|
+
try {
|
|
2301
|
+
const installedPath = join(home, "plugins", "installed_plugins.json");
|
|
2302
|
+
const installed = await readJson(installedPath, {
|
|
2303
|
+
version: 2,
|
|
2304
|
+
plugins: {}
|
|
2305
|
+
});
|
|
2306
|
+
const entry = installed.plugins[pluginKey$1(pluginName)]?.[0];
|
|
2307
|
+
const cachePath = opts?.installPath ?? entry?.installPath;
|
|
2308
|
+
if (entry?.scope === "project") projectPath = entry.projectPath;
|
|
2309
|
+
delete installed.plugins[pluginKey$1(pluginName)];
|
|
2310
|
+
await writeJson(installedPath, installed);
|
|
2311
|
+
if (cachePath && existsSync(cachePath)) await rm(cachePath, {
|
|
2312
|
+
recursive: true,
|
|
2313
|
+
force: true
|
|
2314
|
+
});
|
|
2315
|
+
} catch {}
|
|
2316
|
+
try {
|
|
2317
|
+
const settingsPath = join(home, "settings.json");
|
|
2318
|
+
const settings = await readJson(settingsPath, {});
|
|
2319
|
+
if (settings.enabledPlugins) {
|
|
2320
|
+
delete settings.enabledPlugins[pluginKey$1(pluginName)];
|
|
2321
|
+
await writeJson(settingsPath, settings);
|
|
2322
|
+
}
|
|
2323
|
+
} catch {}
|
|
2324
|
+
const projectDirs = /* @__PURE__ */ new Set();
|
|
2325
|
+
if (projectPath) projectDirs.add(projectPath);
|
|
2326
|
+
if (opts?.cwd) projectDirs.add(resolve(opts.cwd));
|
|
2327
|
+
for (const dir of projectDirs) try {
|
|
2328
|
+
const projSettingsPath = join(dir, ".claude", "settings.json");
|
|
2329
|
+
const settings = await readJson(projSettingsPath, {});
|
|
2330
|
+
if (settings.enabledPlugins) {
|
|
2331
|
+
delete settings.enabledPlugins[pluginKey$1(pluginName)];
|
|
2332
|
+
await writeJson(projSettingsPath, settings);
|
|
2333
|
+
}
|
|
2334
|
+
} catch {}
|
|
2335
|
+
}
|
|
2336
|
+
const LOCAL_MARKETPLACE = "ai-dev-hub-local";
|
|
2337
|
+
function localPluginsRoot$1(codexHome) {
|
|
2338
|
+
return join(codexHome, "plugin-marketplaces", "local", "plugins");
|
|
2339
|
+
}
|
|
2340
|
+
function pluginKey(pluginName) {
|
|
2341
|
+
return `${pluginName}@${LOCAL_MARKETPLACE}`;
|
|
2342
|
+
}
|
|
2343
|
+
async function registerCodexPlugin(params) {
|
|
2344
|
+
const home = getAgentHome("codex");
|
|
2345
|
+
const version = params.version ?? "1.0.0";
|
|
2346
|
+
const copyOpts = {
|
|
2347
|
+
skip: [".claude-plugin", ".cursor-plugin"],
|
|
2348
|
+
skipFiles: ["hooks-claude.json", "hooks-cursor.json"]
|
|
2349
|
+
};
|
|
2350
|
+
const dest = join(localPluginsRoot$1(home), params.pluginName);
|
|
2351
|
+
await rm(dest, {
|
|
2352
|
+
recursive: true,
|
|
2353
|
+
force: true
|
|
2354
|
+
});
|
|
2355
|
+
await copyDirRecursive$1(params.installPath, dest, copyOpts);
|
|
2356
|
+
const cacheDest = join(home, "plugins", "cache", LOCAL_MARKETPLACE, params.pluginName, version);
|
|
2357
|
+
await rm(cacheDest, {
|
|
2358
|
+
recursive: true,
|
|
2359
|
+
force: true
|
|
2360
|
+
});
|
|
2361
|
+
await copyDirRecursive$1(params.installPath, cacheDest, copyOpts);
|
|
2362
|
+
const configPath = join(home, "config.toml");
|
|
2363
|
+
let toml = "";
|
|
2364
|
+
try {
|
|
2365
|
+
toml = await readFile(configPath, "utf-8");
|
|
2366
|
+
} catch {}
|
|
2367
|
+
const marketplaceSource = join(home, "plugin-marketplaces", "local");
|
|
2368
|
+
const marketplaceBlock = `[marketplaces.${LOCAL_MARKETPLACE}]\nsource_type = "local"\nsource = ${JSON.stringify(marketplaceSource)}\n`;
|
|
2369
|
+
toml = upsertSection(toml, `[marketplaces.${LOCAL_MARKETPLACE}]`, marketplaceBlock);
|
|
2370
|
+
const key = pluginKey(params.pluginName);
|
|
2371
|
+
const pluginBlock = `[plugins.${JSON.stringify(key)}]\nenabled = true\n`;
|
|
2372
|
+
toml = upsertSection(toml, `[plugins."${key}"]`, pluginBlock);
|
|
2373
|
+
await mkdir(dirname(configPath), { recursive: true });
|
|
2374
|
+
await writeFile(configPath, toml, "utf-8");
|
|
2375
|
+
await upsertCodexMarketplaceIndex(home, params.pluginName);
|
|
2376
|
+
}
|
|
2377
|
+
async function upsertCodexMarketplaceIndex(codexHome, pluginName) {
|
|
2378
|
+
const indexPath = join(codexHome, "plugin-marketplaces", "local", ".agents", "plugins", "marketplace.json");
|
|
2379
|
+
let manifest;
|
|
2380
|
+
try {
|
|
2381
|
+
manifest = JSON.parse(await readFile(indexPath, "utf-8"));
|
|
2382
|
+
} catch {
|
|
2383
|
+
manifest = {
|
|
2384
|
+
name: LOCAL_MARKETPLACE,
|
|
2385
|
+
plugins: []
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
if (!manifest.plugins.some((p) => p.name === pluginName)) {
|
|
2389
|
+
manifest.plugins.push({
|
|
2390
|
+
name: pluginName,
|
|
2391
|
+
source: {
|
|
2392
|
+
source: "local",
|
|
2393
|
+
path: `./plugins/${pluginName}`
|
|
2394
|
+
},
|
|
2395
|
+
policy: {
|
|
2396
|
+
installation: "AVAILABLE",
|
|
2397
|
+
authentication: "ON_INSTALL"
|
|
2398
|
+
},
|
|
2399
|
+
category: "Developer Tools"
|
|
2400
|
+
});
|
|
2401
|
+
await mkdir(dirname(indexPath), { recursive: true });
|
|
2402
|
+
await writeFile(indexPath, JSON.stringify(manifest, null, 2) + "\n", "utf-8");
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
async function unregisterCodexPlugin(pluginName) {
|
|
2406
|
+
const home = getAgentHome("codex");
|
|
2407
|
+
const dest = join(localPluginsRoot$1(home), pluginName);
|
|
2408
|
+
await Promise.allSettled([rm(dest, {
|
|
2409
|
+
recursive: true,
|
|
2410
|
+
force: true
|
|
2411
|
+
}), rm(join(home, "plugins", "cache", LOCAL_MARKETPLACE, pluginName), {
|
|
2412
|
+
recursive: true,
|
|
2413
|
+
force: true
|
|
2414
|
+
})]);
|
|
2415
|
+
const configPath = join(home, "config.toml");
|
|
2416
|
+
try {
|
|
2417
|
+
let toml = await readFile(configPath, "utf-8");
|
|
2418
|
+
const key = pluginKey(pluginName);
|
|
2419
|
+
toml = removeSection(toml, `[plugins."${key}"]`);
|
|
2420
|
+
await writeFile(configPath, toml, "utf-8");
|
|
2421
|
+
} catch {}
|
|
2422
|
+
}
|
|
2423
|
+
function localPluginsRoot(cursorHome) {
|
|
2424
|
+
return join(cursorHome, "plugins", "local");
|
|
2425
|
+
}
|
|
2426
|
+
function cursorStateDbPath() {
|
|
2427
|
+
const base = platform() === "darwin" ? join(homedir(), "Library", "Application Support", "Cursor", "User", "globalStorage", "state.vscdb") : join(homedir(), ".config", "Cursor", "User", "globalStorage", "state.vscdb");
|
|
2428
|
+
return existsSync(base) ? base : null;
|
|
2429
|
+
}
|
|
2430
|
+
function clearCursorSkillCache() {
|
|
2431
|
+
const db = cursorStateDbPath();
|
|
2432
|
+
if (!db) return;
|
|
2433
|
+
try {
|
|
2434
|
+
execFileSync("sqlite3", [db, "DELETE FROM ItemTable WHERE key LIKE 'agentData.cacheStorage.agentEnvironment.slashMenuItems%';"], { stdio: "pipe" });
|
|
2435
|
+
} catch {}
|
|
2436
|
+
}
|
|
2437
|
+
async function registerCursorPlugin(params) {
|
|
2438
|
+
const dest = join(localPluginsRoot(getAgentHome("cursor")), params.pluginName);
|
|
2439
|
+
await rm(dest, {
|
|
2440
|
+
recursive: true,
|
|
2441
|
+
force: true
|
|
2442
|
+
});
|
|
2443
|
+
await copyDirRecursive$1(params.installPath, dest, {
|
|
2444
|
+
skip: [".claude-plugin", ".codex-plugin"],
|
|
2445
|
+
skipFiles: ["hooks-claude.json", "hooks-codex.json"]
|
|
2446
|
+
});
|
|
2447
|
+
clearCursorSkillCache();
|
|
2448
|
+
}
|
|
2449
|
+
async function unregisterCursorPlugin(pluginName) {
|
|
2450
|
+
const dest = join(localPluginsRoot(getAgentHome("cursor")), pluginName);
|
|
2451
|
+
try {
|
|
2452
|
+
await rm(dest, {
|
|
2453
|
+
recursive: true,
|
|
2454
|
+
force: true
|
|
2455
|
+
});
|
|
2456
|
+
} catch {}
|
|
2457
|
+
clearCursorSkillCache();
|
|
2458
|
+
}
|
|
2095
2459
|
async function installPlugin(ref, opts) {
|
|
2096
2460
|
const cfg = loadConfig();
|
|
2097
|
-
const tarball = await fetchPluginArchive(ref, cfg.portal, cfg.token);
|
|
2461
|
+
const { buffer: tarball, commitSha } = await fetchPluginArchive(ref, cfg.portal, cfg.token);
|
|
2098
2462
|
const tmp = await mkdtemp(join(tmpdir(), "plugin-"));
|
|
2099
2463
|
try {
|
|
2100
2464
|
extractTarGz(tarball, tmp);
|
|
2101
|
-
return await installFromExtracted(ref, await findPluginRoot(tmp), opts);
|
|
2465
|
+
return await installFromExtracted(ref, await findPluginRoot(tmp), opts, commitSha ?? void 0);
|
|
2102
2466
|
} finally {
|
|
2103
2467
|
await rm(tmp, {
|
|
2104
2468
|
recursive: true,
|
|
@@ -2122,7 +2486,7 @@ async function findPluginRoot(start) {
|
|
|
2122
2486
|
}
|
|
2123
2487
|
throw new Error(`plugin.json not found under ${start} (corrupt archive?)`);
|
|
2124
2488
|
}
|
|
2125
|
-
async function installFromExtracted(ref, extractedDir, opts) {
|
|
2489
|
+
async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
2126
2490
|
const { scopeNamespace, pluginName } = parsePluginRef$1(ref);
|
|
2127
2491
|
const storeRoot = getStoreRoot(opts.scope, opts.cwd);
|
|
2128
2492
|
const pluginCanonical = join(storeRoot, "plugins", `${scopeNamespace}__${pluginName}`);
|
|
@@ -2155,20 +2519,22 @@ async function installFromExtracted(ref, extractedDir, opts) {
|
|
|
2155
2519
|
force: opts.force
|
|
2156
2520
|
})) throw new Error(`aborted: ${foreignConflicts.length} foreign conflicts at plugin entry paths`);
|
|
2157
2521
|
}
|
|
2522
|
+
const { ledger, warnings } = await commitPluginInstall({
|
|
2523
|
+
ref,
|
|
2524
|
+
scopeNamespace,
|
|
2525
|
+
pluginName,
|
|
2526
|
+
pluginCanonical,
|
|
2527
|
+
extractedDir,
|
|
2528
|
+
components,
|
|
2529
|
+
preflight,
|
|
2530
|
+
statuses,
|
|
2531
|
+
opts,
|
|
2532
|
+
commitSha
|
|
2533
|
+
});
|
|
2158
2534
|
return {
|
|
2159
2535
|
pluginRef: ref,
|
|
2160
2536
|
pluginCanonical,
|
|
2161
|
-
installedComponents:
|
|
2162
|
-
ref,
|
|
2163
|
-
scopeNamespace,
|
|
2164
|
-
pluginName,
|
|
2165
|
-
pluginCanonical,
|
|
2166
|
-
extractedDir,
|
|
2167
|
-
components,
|
|
2168
|
-
preflight,
|
|
2169
|
-
statuses,
|
|
2170
|
-
opts
|
|
2171
|
-
}),
|
|
2537
|
+
installedComponents: ledger,
|
|
2172
2538
|
installedEntries: preflight.map((pe) => ({
|
|
2173
2539
|
agent: pe.agent,
|
|
2174
2540
|
kind: componentLedgerKind(pe.component.kind),
|
|
@@ -2176,7 +2542,8 @@ async function installFromExtracted(ref, extractedDir, opts) {
|
|
|
2176
2542
|
entryPath: pe.entryPath
|
|
2177
2543
|
})),
|
|
2178
2544
|
forgeOtherReplacements,
|
|
2179
|
-
ignoredComponents
|
|
2545
|
+
ignoredComponents,
|
|
2546
|
+
warnings
|
|
2180
2547
|
};
|
|
2181
2548
|
}
|
|
2182
2549
|
function componentLedgerKind(kind) {
|
|
@@ -2330,13 +2697,13 @@ function componentSubRef$1(c) {
|
|
|
2330
2697
|
}
|
|
2331
2698
|
}
|
|
2332
2699
|
async function commitPluginInstall(params) {
|
|
2333
|
-
const { ref, scopeNamespace, pluginName, pluginCanonical, extractedDir, components, preflight, statuses, opts } = params;
|
|
2700
|
+
const { ref, scopeNamespace, pluginName, pluginCanonical, extractedDir, components, preflight, statuses, opts, commitSha } = params;
|
|
2334
2701
|
await rm(pluginCanonical, {
|
|
2335
2702
|
recursive: true,
|
|
2336
2703
|
force: true
|
|
2337
2704
|
});
|
|
2338
2705
|
await mkdir(pluginCanonical, { recursive: true });
|
|
2339
|
-
await copyDirRecursive(extractedDir, pluginCanonical,
|
|
2706
|
+
await copyDirRecursive(extractedDir, pluginCanonical, false);
|
|
2340
2707
|
for (const skillName of components.skills) {
|
|
2341
2708
|
const sidecarPath = join(pluginCanonical, "skills", skillName, ".forge-source.json");
|
|
2342
2709
|
await mkdir(dirname(sidecarPath), { recursive: true });
|
|
@@ -2414,16 +2781,54 @@ async function commitPluginInstall(params) {
|
|
|
2414
2781
|
cwd: opts.cwd
|
|
2415
2782
|
});
|
|
2416
2783
|
if (components.skills.length > 0) for (const agent of opts.agents) await ensureForgeHooks(agent);
|
|
2417
|
-
|
|
2784
|
+
let version = "0.0.0";
|
|
2785
|
+
for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
|
|
2786
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
2787
|
+
if (manifest.version) {
|
|
2788
|
+
version = manifest.version;
|
|
2789
|
+
break;
|
|
2790
|
+
}
|
|
2791
|
+
} catch {}
|
|
2792
|
+
const warnings = [];
|
|
2793
|
+
const warn = (msg) => warnings.push(msg);
|
|
2794
|
+
if (opts.agents.includes("claude-code") || opts.agents.includes("cursor")) await registerClaudePlugin({
|
|
2795
|
+
pluginName,
|
|
2796
|
+
version,
|
|
2797
|
+
sourcePath: pluginCanonical,
|
|
2798
|
+
gitSha: commitSha,
|
|
2799
|
+
scope: opts.scope === "project" ? "project" : "user",
|
|
2800
|
+
cwd: opts.cwd
|
|
2801
|
+
}).then((ws) => ws.forEach(warn)).catch((e) => warn(`claude-code plugin registration failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2802
|
+
if (opts.agents.includes("codex")) await registerCodexPlugin({
|
|
2803
|
+
pluginName,
|
|
2804
|
+
installPath: pluginCanonical,
|
|
2805
|
+
version
|
|
2806
|
+
}).catch((e) => warn(`codex plugin registration failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2807
|
+
if (opts.agents.includes("cursor")) await registerCursorPlugin({
|
|
2808
|
+
pluginName,
|
|
2809
|
+
installPath: pluginCanonical
|
|
2810
|
+
}).catch((e) => warn(`cursor plugin registration failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2811
|
+
await ensureForgeCliWrapper().catch((e) => warn(`forge-cli.sh wrapper generation failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2812
|
+
return {
|
|
2813
|
+
ledger,
|
|
2814
|
+
warnings
|
|
2815
|
+
};
|
|
2418
2816
|
}
|
|
2419
|
-
async function copyDirRecursive(src, dest, skipDotClaudePlugin) {
|
|
2817
|
+
async function copyDirRecursive(src, dest, skipDotClaudePlugin, extraSkip) {
|
|
2420
2818
|
await mkdir(dest, { recursive: true });
|
|
2421
2819
|
for (const e of await readdir(src, { withFileTypes: true })) {
|
|
2422
2820
|
if (skipDotClaudePlugin && e.name === ".claude-plugin") continue;
|
|
2821
|
+
if (extraSkip?.has(e.name)) continue;
|
|
2423
2822
|
const s = join(src, e.name);
|
|
2424
2823
|
const d = join(dest, e.name);
|
|
2425
2824
|
if (e.isDirectory()) await copyDirRecursive(s, d, false);
|
|
2426
|
-
else if (e.isFile())
|
|
2825
|
+
else if (e.isFile()) {
|
|
2826
|
+
await writeFile(d, await readFile(s));
|
|
2827
|
+
try {
|
|
2828
|
+
const srcStat = await stat(s);
|
|
2829
|
+
if (srcStat.mode & 73) await chmod(d, srcStat.mode & 511);
|
|
2830
|
+
} catch {}
|
|
2831
|
+
}
|
|
2427
2832
|
}
|
|
2428
2833
|
}
|
|
2429
2834
|
async function copyFileShallow(src, dest) {
|
|
@@ -3319,7 +3724,6 @@ async function isSourcePrivate(source) {
|
|
|
3319
3724
|
if (!ownerRepo) return false;
|
|
3320
3725
|
return isRepoPrivate(ownerRepo.owner, ownerRepo.repo);
|
|
3321
3726
|
}
|
|
3322
|
-
function initTelemetry(version) {}
|
|
3323
3727
|
function riskLabel(risk) {
|
|
3324
3728
|
switch (risk) {
|
|
3325
3729
|
case "critical": return import_picocolors.default.red(import_picocolors.default.bold("Critical Risk"));
|
|
@@ -4009,6 +4413,7 @@ async function runAdd(args, options = {}) {
|
|
|
4009
4413
|
throw err;
|
|
4010
4414
|
}
|
|
4011
4415
|
spinner.stop(import_picocolors.default.green("Plugin installed"));
|
|
4416
|
+
if (pluginResult.warnings.length > 0) for (const w of pluginResult.warnings) M.warn(w);
|
|
4012
4417
|
if (pluginResult.installedEntries.length > 0) {
|
|
4013
4418
|
const grouped = /* @__PURE__ */ new Map();
|
|
4014
4419
|
for (const e of pluginResult.installedEntries) {
|
|
@@ -4072,6 +4477,7 @@ async function runAdd(args, options = {}) {
|
|
|
4072
4477
|
agent: "cli",
|
|
4073
4478
|
install_mode: "cli"
|
|
4074
4479
|
});
|
|
4480
|
+
M.info(import_picocolors.default.dim("Restart Claude Code / Cursor to activate plugin changes."));
|
|
4075
4481
|
Se(import_picocolors.default.green(`Plugin ${import_picocolors.default.bold(resolvedPluginRef)} installed successfully`));
|
|
4076
4482
|
return;
|
|
4077
4483
|
}
|
|
@@ -4799,6 +5205,65 @@ function parseAddOptions(args) {
|
|
|
4799
5205
|
options
|
|
4800
5206
|
};
|
|
4801
5207
|
}
|
|
5208
|
+
function parseReportEventOptions(args) {
|
|
5209
|
+
let type;
|
|
5210
|
+
let ref;
|
|
5211
|
+
let agent;
|
|
5212
|
+
let data;
|
|
5213
|
+
for (let i = 0; i < args.length; i++) {
|
|
5214
|
+
const arg = args[i];
|
|
5215
|
+
if ((arg === "--type" || arg === "-t") && args[i + 1]) type = args[++i];
|
|
5216
|
+
else if ((arg === "--ref" || arg === "-r") && args[i + 1]) ref = args[++i];
|
|
5217
|
+
else if ((arg === "--agent" || arg === "-a") && args[i + 1]) agent = args[++i];
|
|
5218
|
+
else if ((arg === "--data" || arg === "-d") && args[i + 1]) {
|
|
5219
|
+
const raw = args[++i];
|
|
5220
|
+
try {
|
|
5221
|
+
data = JSON.parse(raw);
|
|
5222
|
+
} catch {}
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
if (!type) return null;
|
|
5226
|
+
return {
|
|
5227
|
+
type,
|
|
5228
|
+
ref,
|
|
5229
|
+
agent,
|
|
5230
|
+
data
|
|
5231
|
+
};
|
|
5232
|
+
}
|
|
5233
|
+
async function runReportEvent(args) {
|
|
5234
|
+
const opts = parseReportEventOptions(args);
|
|
5235
|
+
if (!opts) return;
|
|
5236
|
+
let cfg;
|
|
5237
|
+
try {
|
|
5238
|
+
cfg = loadConfig();
|
|
5239
|
+
} catch {
|
|
5240
|
+
return;
|
|
5241
|
+
}
|
|
5242
|
+
const body = {
|
|
5243
|
+
event_type: "hook_event",
|
|
5244
|
+
metadata: {
|
|
5245
|
+
...opts.data,
|
|
5246
|
+
hook_type: opts.type
|
|
5247
|
+
}
|
|
5248
|
+
};
|
|
5249
|
+
if (opts.ref) body.asset_ref = opts.ref;
|
|
5250
|
+
if (opts.agent) body.install_mode = opts.agent;
|
|
5251
|
+
const token = process.env["SHOPLAZZA_FORGE_TOKEN"] ?? cfg.token;
|
|
5252
|
+
const headers = { "Content-Type": "application/json" };
|
|
5253
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
5254
|
+
const controller = new AbortController();
|
|
5255
|
+
const timeoutId = setTimeout(() => controller.abort(), 2e3);
|
|
5256
|
+
try {
|
|
5257
|
+
await fetch(`${cfg.portal}/events`, {
|
|
5258
|
+
method: "POST",
|
|
5259
|
+
headers,
|
|
5260
|
+
body: JSON.stringify(body),
|
|
5261
|
+
signal: controller.signal
|
|
5262
|
+
});
|
|
5263
|
+
} catch {} finally {
|
|
5264
|
+
clearTimeout(timeoutId);
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
4802
5267
|
const RESET$2 = "\x1B[0m";
|
|
4803
5268
|
const BOLD$2 = "\x1B[1m";
|
|
4804
5269
|
const DIM$2 = "\x1B[38;5;102m";
|
|
@@ -5895,6 +6360,10 @@ async function uninstallPlugin(plugin, cwd, agentFilter) {
|
|
|
5895
6360
|
}
|
|
5896
6361
|
}
|
|
5897
6362
|
if (installModes.includes("codex")) for (const scope of ["project", "global"]) await cleanupCodexConfigToml(ledger, scope, cwd);
|
|
6363
|
+
const warnUnregister = (agent) => (e) => M.warn(`${agent} plugin unregistration failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
6364
|
+
if (installModes.includes("claude-code") || installModes.includes("cursor")) await unregisterClaudePlugin(plugin.name, { cwd }).catch(warnUnregister("claude-code"));
|
|
6365
|
+
if (installModes.includes("cursor")) await unregisterCursorPlugin(plugin.name).catch(warnUnregister("cursor"));
|
|
6366
|
+
if (installModes.includes("codex")) await unregisterCodexPlugin(plugin.name).catch(warnUnregister("codex"));
|
|
5898
6367
|
await rm(plugin.canonical, {
|
|
5899
6368
|
recursive: true,
|
|
5900
6369
|
force: true
|
|
@@ -6275,7 +6744,6 @@ function getVersion() {
|
|
|
6275
6744
|
}
|
|
6276
6745
|
}
|
|
6277
6746
|
const VERSION = getVersion();
|
|
6278
|
-
initTelemetry(VERSION);
|
|
6279
6747
|
const RESET = "\x1B[0m";
|
|
6280
6748
|
const BOLD = "\x1B[1m";
|
|
6281
6749
|
const DIM = "\x1B[38;5;102m";
|
|
@@ -6340,6 +6808,12 @@ ${BOLD}Updates:${RESET}
|
|
|
6340
6808
|
${BOLD}Project:${RESET}
|
|
6341
6809
|
init [name] Initialize a skill (creates <name>/SKILL.md or ./SKILL.md)
|
|
6342
6810
|
|
|
6811
|
+
${BOLD}Publishing:${RESET}
|
|
6812
|
+
publish <paths...> Publish skills to the forge portal
|
|
6813
|
+
|
|
6814
|
+
${BOLD}Auth:${RESET}
|
|
6815
|
+
login Authenticate with the forge portal (browser OAuth)
|
|
6816
|
+
|
|
6343
6817
|
${BOLD}Add Options:${RESET}
|
|
6344
6818
|
-g, --global Install at global scope (entry symlinks under ~/)
|
|
6345
6819
|
-a, --agent <agents> Specify agents to install to (use '*' for all agents)
|
|
@@ -6364,6 +6838,11 @@ ${BOLD}Update Options:${RESET}
|
|
|
6364
6838
|
-y, --yes Skip confirmation prompts
|
|
6365
6839
|
--json Machine-readable summary
|
|
6366
6840
|
|
|
6841
|
+
${BOLD}Publish Options:${RESET}
|
|
6842
|
+
-s, --scope <scope> Team scope (e.g. team:test)
|
|
6843
|
+
-t, --type <type> Asset type: skill or rule (default: skill)
|
|
6844
|
+
-v, --visibility <v> Visibility: public or team (auto-detected from --scope)
|
|
6845
|
+
|
|
6367
6846
|
${BOLD}Options:${RESET}
|
|
6368
6847
|
--help, -h Show this help message
|
|
6369
6848
|
--version, -v Show version number
|
|
@@ -6380,6 +6859,8 @@ ${BOLD}Examples:${RESET}
|
|
|
6380
6859
|
${DIM}$${RESET} shoplazza-ai-dev-cli update
|
|
6381
6860
|
${DIM}$${RESET} shoplazza-ai-dev-cli update some-skill
|
|
6382
6861
|
${DIM}$${RESET} shoplazza-ai-dev-cli init my-skill
|
|
6862
|
+
${DIM}$${RESET} shoplazza-ai-dev-cli login
|
|
6863
|
+
${DIM}$${RESET} shoplazza-ai-dev-cli publish ./my-skill --scope team:test
|
|
6383
6864
|
`);
|
|
6384
6865
|
}
|
|
6385
6866
|
function showRemoveHelp() {
|
|
@@ -6691,6 +7172,9 @@ async function main() {
|
|
|
6691
7172
|
await runPublish(paths, publishOptions);
|
|
6692
7173
|
break;
|
|
6693
7174
|
}
|
|
7175
|
+
case "report-event":
|
|
7176
|
+
await runReportEvent(restArgs);
|
|
7177
|
+
break;
|
|
6694
7178
|
case "--help":
|
|
6695
7179
|
case "-h":
|
|
6696
7180
|
showHelp();
|