shoplazza-ai-dev-cli 0.1.13 → 0.1.14
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/dist/cli.mjs +71 -8
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1290,8 +1290,10 @@ async function fetchWithAutoAuth(url, accept, bearerToken, portalUrl) {
|
|
|
1290
1290
|
if (token) h.Authorization = `Bearer ${token}`;
|
|
1291
1291
|
return h;
|
|
1292
1292
|
};
|
|
1293
|
-
|
|
1294
|
-
|
|
1293
|
+
const envToken = process.env.SHOPLAZZA_FORGE_TOKEN?.trim();
|
|
1294
|
+
const fromEnv = !!envToken && bearerToken === envToken;
|
|
1295
|
+
const resp = await rawFetch(url, buildHeaders(bearerToken), portalUrl);
|
|
1296
|
+
if (resp.status !== 401 || fromEnv) return resp;
|
|
1295
1297
|
await resp.arrayBuffer().catch(() => void 0);
|
|
1296
1298
|
await runLogin({ force: true });
|
|
1297
1299
|
const refreshed = loadConfig().token;
|
|
@@ -2430,6 +2432,54 @@ async function unregisterCodexPlugin(pluginName) {
|
|
|
2430
2432
|
await writeFile(configPath, toml, "utf-8");
|
|
2431
2433
|
} catch {}
|
|
2432
2434
|
}
|
|
2435
|
+
const STALE_MS = 12e4;
|
|
2436
|
+
const RETRY_MS = 100;
|
|
2437
|
+
const WAIT_TIMEOUT_MS = 12e4;
|
|
2438
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2439
|
+
async function lockAgeMs(lockPath) {
|
|
2440
|
+
try {
|
|
2441
|
+
const s = await stat(lockPath);
|
|
2442
|
+
return Date.now() - s.mtimeMs;
|
|
2443
|
+
} catch {
|
|
2444
|
+
return null;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
async function acquire(lockPath) {
|
|
2448
|
+
const start = Date.now();
|
|
2449
|
+
for (;;) try {
|
|
2450
|
+
await mkdir(lockPath);
|
|
2451
|
+
await writeFile(join(lockPath, "owner.json"), JSON.stringify({
|
|
2452
|
+
pid: process.pid,
|
|
2453
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2454
|
+
}) + "\n").catch(() => {});
|
|
2455
|
+
return;
|
|
2456
|
+
} catch (e) {
|
|
2457
|
+
if (e.code !== "EEXIST") throw e;
|
|
2458
|
+
const age = await lockAgeMs(lockPath);
|
|
2459
|
+
if (age === null) continue;
|
|
2460
|
+
if (age > STALE_MS || Date.now() - start > WAIT_TIMEOUT_MS) {
|
|
2461
|
+
await rm(lockPath, {
|
|
2462
|
+
recursive: true,
|
|
2463
|
+
force: true
|
|
2464
|
+
});
|
|
2465
|
+
continue;
|
|
2466
|
+
}
|
|
2467
|
+
await sleep(RETRY_MS);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
async function withInstallLock(lockDir, fn) {
|
|
2471
|
+
const lockPath = join(lockDir, ".forge-install.lock");
|
|
2472
|
+
await mkdir(lockDir, { recursive: true }).catch(() => {});
|
|
2473
|
+
await acquire(lockPath);
|
|
2474
|
+
try {
|
|
2475
|
+
return await fn();
|
|
2476
|
+
} finally {
|
|
2477
|
+
await rm(lockPath, {
|
|
2478
|
+
recursive: true,
|
|
2479
|
+
force: true
|
|
2480
|
+
}).catch(() => {});
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2433
2483
|
async function installPlugin(ref, opts) {
|
|
2434
2484
|
const cfg = loadConfig();
|
|
2435
2485
|
const { buffer: tarball, commitSha } = await fetchPluginArchive(ref, cfg.portal, cfg.token);
|
|
@@ -2493,7 +2543,7 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2493
2543
|
force: opts.force
|
|
2494
2544
|
})) throw new Error(`aborted: ${foreignConflicts.length} foreign conflicts at plugin entry paths`);
|
|
2495
2545
|
}
|
|
2496
|
-
const { ledger, warnings } = await commitPluginInstall({
|
|
2546
|
+
const { ledger, warnings, registrationFailed } = await withInstallLock(join(getAgentHome("claude-code"), "plugins"), () => commitPluginInstall({
|
|
2497
2547
|
ref,
|
|
2498
2548
|
scopeNamespace,
|
|
2499
2549
|
pluginName,
|
|
@@ -2504,7 +2554,7 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2504
2554
|
statuses,
|
|
2505
2555
|
opts,
|
|
2506
2556
|
commitSha
|
|
2507
|
-
});
|
|
2557
|
+
}));
|
|
2508
2558
|
return {
|
|
2509
2559
|
pluginRef: ref,
|
|
2510
2560
|
pluginCanonical,
|
|
@@ -2517,7 +2567,8 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2517
2567
|
})),
|
|
2518
2568
|
forgeOtherReplacements,
|
|
2519
2569
|
ignoredComponents,
|
|
2520
|
-
warnings
|
|
2570
|
+
warnings,
|
|
2571
|
+
registrationFailed
|
|
2521
2572
|
};
|
|
2522
2573
|
}
|
|
2523
2574
|
function componentLedgerKind(kind) {
|
|
@@ -2756,7 +2807,7 @@ async function commitPluginInstall(params) {
|
|
|
2756
2807
|
cwd: opts.cwd
|
|
2757
2808
|
});
|
|
2758
2809
|
if (components.skills.length > 0) for (const agent of opts.agents) await ensureForgeHooks(agent);
|
|
2759
|
-
let version
|
|
2810
|
+
let version;
|
|
2760
2811
|
for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
|
|
2761
2812
|
const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
2762
2813
|
if (manifest.version) {
|
|
@@ -2764,8 +2815,10 @@ async function commitPluginInstall(params) {
|
|
|
2764
2815
|
break;
|
|
2765
2816
|
}
|
|
2766
2817
|
} catch {}
|
|
2818
|
+
if (!version) throw new Error(`refusing to register ${pluginName}: no plugin.json version in canonical store ${pluginCanonical} (partial/corrupt install?)`);
|
|
2767
2819
|
const warnings = [];
|
|
2768
2820
|
const warn = (msg) => warnings.push(msg);
|
|
2821
|
+
let registrationFailed = false;
|
|
2769
2822
|
if (opts.agents.includes("claude-code") || opts.agents.includes("cursor")) await registerClaudePlugin({
|
|
2770
2823
|
pluginName,
|
|
2771
2824
|
version,
|
|
@@ -2773,7 +2826,10 @@ async function commitPluginInstall(params) {
|
|
|
2773
2826
|
gitSha: commitSha,
|
|
2774
2827
|
scope: opts.scope === "project" ? "project" : "user",
|
|
2775
2828
|
cwd: opts.cwd
|
|
2776
|
-
}).then((ws) => ws.forEach(warn)).catch((e) =>
|
|
2829
|
+
}).then((ws) => ws.forEach(warn)).catch((e) => {
|
|
2830
|
+
registrationFailed = true;
|
|
2831
|
+
warn(`claude-code plugin registration failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
2832
|
+
});
|
|
2777
2833
|
if (opts.agents.includes("codex")) await registerCodexPlugin({
|
|
2778
2834
|
pluginName,
|
|
2779
2835
|
installPath: pluginCanonical,
|
|
@@ -2782,7 +2838,8 @@ async function commitPluginInstall(params) {
|
|
|
2782
2838
|
await ensureForgeCliWrapper().catch((e) => warn(`forge-cli.sh wrapper generation failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2783
2839
|
return {
|
|
2784
2840
|
ledger,
|
|
2785
|
-
warnings
|
|
2841
|
+
warnings,
|
|
2842
|
+
registrationFailed
|
|
2786
2843
|
};
|
|
2787
2844
|
}
|
|
2788
2845
|
async function copyDirRecursive(src, dest, skipDotClaudePlugin, extraSkip) {
|
|
@@ -4385,6 +4442,10 @@ async function runAdd(args, options = {}) {
|
|
|
4385
4442
|
}
|
|
4386
4443
|
spinner.stop(import_picocolors.default.green("Plugin installed"));
|
|
4387
4444
|
if (pluginResult.warnings.length > 0) for (const w of pluginResult.warnings) M.warn(w);
|
|
4445
|
+
if (pluginResult.registrationFailed) {
|
|
4446
|
+
M.error(import_picocolors.default.red("Claude native plugin registration failed"));
|
|
4447
|
+
process.exitCode = 1;
|
|
4448
|
+
}
|
|
4388
4449
|
if (pluginResult.installedEntries.length > 0) {
|
|
4389
4450
|
const grouped = /* @__PURE__ */ new Map();
|
|
4390
4451
|
for (const e of pluginResult.installedEntries) {
|
|
@@ -5054,6 +5115,7 @@ async function runAdd(args, options = {}) {
|
|
|
5054
5115
|
console.log();
|
|
5055
5116
|
M.error(import_picocolors.default.red(`Failed to install ${failed.length}`));
|
|
5056
5117
|
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.skill} → ${r.agent}: ${import_picocolors.default.dim(r.error)}`);
|
|
5118
|
+
process.exitCode = 1;
|
|
5057
5119
|
}
|
|
5058
5120
|
console.log();
|
|
5059
5121
|
Se(import_picocolors.default.green("Done!") + import_picocolors.default.dim(" Review skills before use; they run with full agent permissions."));
|
|
@@ -6253,6 +6315,7 @@ async function removeCommand(skillNames, options) {
|
|
|
6253
6315
|
if (failed.length > 0) {
|
|
6254
6316
|
M.error(import_picocolors.default.red(`Failed to remove ${failed.length} item(s)`));
|
|
6255
6317
|
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.name}: ${r.error}`);
|
|
6318
|
+
process.exitCode = 1;
|
|
6256
6319
|
}
|
|
6257
6320
|
console.log();
|
|
6258
6321
|
Se(import_picocolors.default.green("Done!"));
|