shoplazza-ai-dev-cli 0.1.12 → 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 +75 -9
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { homedir, hostname, platform, tmpdir } from "os";
|
|
|
13
13
|
import { access, chmod, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rm, stat, symlink, writeFile } from "fs/promises";
|
|
14
14
|
import { createServer } from "http";
|
|
15
15
|
import { gunzipSync } from "node:zlib";
|
|
16
|
-
import { mkdirSync as mkdirSync$1, writeFileSync as writeFileSync$1 } from "node:fs";
|
|
16
|
+
import { chmodSync as chmodSync$1, mkdirSync as mkdirSync$1, writeFileSync as writeFileSync$1 } from "node:fs";
|
|
17
17
|
import { dirname as dirname$1, normalize as normalize$1, resolve as resolve$1, sep as sep$1 } from "node:path";
|
|
18
18
|
import { parse } from "yaml";
|
|
19
19
|
import * as readline from "readline";
|
|
@@ -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;
|
|
@@ -1342,6 +1344,8 @@ function extractTarGz(gz, dest) {
|
|
|
1342
1344
|
const header = tar.subarray(offset, offset + 512);
|
|
1343
1345
|
if (header[0] === 0) break;
|
|
1344
1346
|
const name = readCStr(header, 0, 100);
|
|
1347
|
+
const modeOctal = readCStr(header, 100, 8).trim();
|
|
1348
|
+
const mode = parseInt(modeOctal || "0", 8);
|
|
1345
1349
|
const sizeOctal = readCStr(header, 124, 12).trim();
|
|
1346
1350
|
const size = parseInt(sizeOctal || "0", 8);
|
|
1347
1351
|
const typeFlag = String.fromCharCode(header[156] || 0);
|
|
@@ -1359,6 +1363,7 @@ function extractTarGz(gz, dest) {
|
|
|
1359
1363
|
else if (typeFlag === "0" || typeFlag === "\0") {
|
|
1360
1364
|
mkdirSync$1(dirname$1(targetAbs), { recursive: true });
|
|
1361
1365
|
writeFileSync$1(targetAbs, tar.subarray(offset + 512, offset + 512 + size));
|
|
1366
|
+
if (mode & 73) chmodSync$1(targetAbs, mode & 511);
|
|
1362
1367
|
}
|
|
1363
1368
|
offset += advance;
|
|
1364
1369
|
}
|
|
@@ -2427,6 +2432,54 @@ async function unregisterCodexPlugin(pluginName) {
|
|
|
2427
2432
|
await writeFile(configPath, toml, "utf-8");
|
|
2428
2433
|
} catch {}
|
|
2429
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
|
+
}
|
|
2430
2483
|
async function installPlugin(ref, opts) {
|
|
2431
2484
|
const cfg = loadConfig();
|
|
2432
2485
|
const { buffer: tarball, commitSha } = await fetchPluginArchive(ref, cfg.portal, cfg.token);
|
|
@@ -2490,7 +2543,7 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2490
2543
|
force: opts.force
|
|
2491
2544
|
})) throw new Error(`aborted: ${foreignConflicts.length} foreign conflicts at plugin entry paths`);
|
|
2492
2545
|
}
|
|
2493
|
-
const { ledger, warnings } = await commitPluginInstall({
|
|
2546
|
+
const { ledger, warnings, registrationFailed } = await withInstallLock(join(getAgentHome("claude-code"), "plugins"), () => commitPluginInstall({
|
|
2494
2547
|
ref,
|
|
2495
2548
|
scopeNamespace,
|
|
2496
2549
|
pluginName,
|
|
@@ -2501,7 +2554,7 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2501
2554
|
statuses,
|
|
2502
2555
|
opts,
|
|
2503
2556
|
commitSha
|
|
2504
|
-
});
|
|
2557
|
+
}));
|
|
2505
2558
|
return {
|
|
2506
2559
|
pluginRef: ref,
|
|
2507
2560
|
pluginCanonical,
|
|
@@ -2514,7 +2567,8 @@ async function installFromExtracted(ref, extractedDir, opts, commitSha) {
|
|
|
2514
2567
|
})),
|
|
2515
2568
|
forgeOtherReplacements,
|
|
2516
2569
|
ignoredComponents,
|
|
2517
|
-
warnings
|
|
2570
|
+
warnings,
|
|
2571
|
+
registrationFailed
|
|
2518
2572
|
};
|
|
2519
2573
|
}
|
|
2520
2574
|
function componentLedgerKind(kind) {
|
|
@@ -2753,7 +2807,7 @@ async function commitPluginInstall(params) {
|
|
|
2753
2807
|
cwd: opts.cwd
|
|
2754
2808
|
});
|
|
2755
2809
|
if (components.skills.length > 0) for (const agent of opts.agents) await ensureForgeHooks(agent);
|
|
2756
|
-
let version
|
|
2810
|
+
let version;
|
|
2757
2811
|
for (const manifestPath of [join(pluginCanonical, "plugin.json"), join(pluginCanonical, ".claude-plugin", "plugin.json")]) try {
|
|
2758
2812
|
const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
2759
2813
|
if (manifest.version) {
|
|
@@ -2761,8 +2815,10 @@ async function commitPluginInstall(params) {
|
|
|
2761
2815
|
break;
|
|
2762
2816
|
}
|
|
2763
2817
|
} catch {}
|
|
2818
|
+
if (!version) throw new Error(`refusing to register ${pluginName}: no plugin.json version in canonical store ${pluginCanonical} (partial/corrupt install?)`);
|
|
2764
2819
|
const warnings = [];
|
|
2765
2820
|
const warn = (msg) => warnings.push(msg);
|
|
2821
|
+
let registrationFailed = false;
|
|
2766
2822
|
if (opts.agents.includes("claude-code") || opts.agents.includes("cursor")) await registerClaudePlugin({
|
|
2767
2823
|
pluginName,
|
|
2768
2824
|
version,
|
|
@@ -2770,7 +2826,10 @@ async function commitPluginInstall(params) {
|
|
|
2770
2826
|
gitSha: commitSha,
|
|
2771
2827
|
scope: opts.scope === "project" ? "project" : "user",
|
|
2772
2828
|
cwd: opts.cwd
|
|
2773
|
-
}).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
|
+
});
|
|
2774
2833
|
if (opts.agents.includes("codex")) await registerCodexPlugin({
|
|
2775
2834
|
pluginName,
|
|
2776
2835
|
installPath: pluginCanonical,
|
|
@@ -2779,7 +2838,8 @@ async function commitPluginInstall(params) {
|
|
|
2779
2838
|
await ensureForgeCliWrapper().catch((e) => warn(`forge-cli.sh wrapper generation failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
2780
2839
|
return {
|
|
2781
2840
|
ledger,
|
|
2782
|
-
warnings
|
|
2841
|
+
warnings,
|
|
2842
|
+
registrationFailed
|
|
2783
2843
|
};
|
|
2784
2844
|
}
|
|
2785
2845
|
async function copyDirRecursive(src, dest, skipDotClaudePlugin, extraSkip) {
|
|
@@ -4382,6 +4442,10 @@ async function runAdd(args, options = {}) {
|
|
|
4382
4442
|
}
|
|
4383
4443
|
spinner.stop(import_picocolors.default.green("Plugin installed"));
|
|
4384
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
|
+
}
|
|
4385
4449
|
if (pluginResult.installedEntries.length > 0) {
|
|
4386
4450
|
const grouped = /* @__PURE__ */ new Map();
|
|
4387
4451
|
for (const e of pluginResult.installedEntries) {
|
|
@@ -5051,6 +5115,7 @@ async function runAdd(args, options = {}) {
|
|
|
5051
5115
|
console.log();
|
|
5052
5116
|
M.error(import_picocolors.default.red(`Failed to install ${failed.length}`));
|
|
5053
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;
|
|
5054
5119
|
}
|
|
5055
5120
|
console.log();
|
|
5056
5121
|
Se(import_picocolors.default.green("Done!") + import_picocolors.default.dim(" Review skills before use; they run with full agent permissions."));
|
|
@@ -6250,6 +6315,7 @@ async function removeCommand(skillNames, options) {
|
|
|
6250
6315
|
if (failed.length > 0) {
|
|
6251
6316
|
M.error(import_picocolors.default.red(`Failed to remove ${failed.length} item(s)`));
|
|
6252
6317
|
for (const r of failed) M.message(` ${import_picocolors.default.red("✗")} ${r.name}: ${r.error}`);
|
|
6318
|
+
process.exitCode = 1;
|
|
6253
6319
|
}
|
|
6254
6320
|
console.log();
|
|
6255
6321
|
Se(import_picocolors.default.green("Done!"));
|