@floomhq/skills 0.2.11 → 0.2.12
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/index.js +287 -59
- package/dist/index.js.map +4 -4
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2383,8 +2383,7 @@ var log = {
|
|
|
2383
2383
|
};
|
|
2384
2384
|
|
|
2385
2385
|
// src/commands/login.ts
|
|
2386
|
-
import {
|
|
2387
|
-
import { promisify as promisify2 } from "node:util";
|
|
2386
|
+
import { spawn } from "node:child_process";
|
|
2388
2387
|
|
|
2389
2388
|
// src/config.ts
|
|
2390
2389
|
import { homedir as homedir2 } from "node:os";
|
|
@@ -2484,19 +2483,33 @@ function isLegacyApiUrl(apiUrl) {
|
|
|
2484
2483
|
}
|
|
2485
2484
|
|
|
2486
2485
|
// src/version.ts
|
|
2487
|
-
var VERSION = "0.2.
|
|
2486
|
+
var VERSION = "0.2.12";
|
|
2488
2487
|
|
|
2489
2488
|
// src/api-client.ts
|
|
2490
2489
|
var DEFAULT_TIMEOUT_MS = 2e4;
|
|
2490
|
+
var DEFAULT_RETRY_ATTEMPTS = 2;
|
|
2491
2491
|
function timeoutMs() {
|
|
2492
2492
|
const raw = Number(process.env.FLOOM_API_TIMEOUT_MS);
|
|
2493
2493
|
return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_TIMEOUT_MS;
|
|
2494
2494
|
}
|
|
2495
|
+
function retryAttempts() {
|
|
2496
|
+
const raw = Number(process.env.FLOOM_API_RETRY_ATTEMPTS);
|
|
2497
|
+
return Number.isInteger(raw) && raw >= 0 ? Math.min(raw, 5) : DEFAULT_RETRY_ATTEMPTS;
|
|
2498
|
+
}
|
|
2499
|
+
function retryDelayMs(attempt) {
|
|
2500
|
+
const raw = Number(process.env.FLOOM_API_RETRY_DELAY_MS);
|
|
2501
|
+
const base = Number.isFinite(raw) && raw >= 0 ? raw : 150;
|
|
2502
|
+
return base * 2 ** attempt;
|
|
2503
|
+
}
|
|
2504
|
+
async function sleep(ms) {
|
|
2505
|
+
if (ms <= 0) return;
|
|
2506
|
+
await new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
2507
|
+
}
|
|
2495
2508
|
async function fetchWithTimeout(url, init = {}) {
|
|
2496
2509
|
const controller = new AbortController();
|
|
2497
2510
|
const timer = setTimeout(() => controller.abort(), timeoutMs());
|
|
2498
2511
|
try {
|
|
2499
|
-
return await fetch(url, { ...init, signal: controller.signal });
|
|
2512
|
+
return await fetch(url, { ...init, redirect: "manual", signal: controller.signal });
|
|
2500
2513
|
} catch (e) {
|
|
2501
2514
|
if (e.name === "AbortError") {
|
|
2502
2515
|
throw new Error(`Request timed out after ${timeoutMs()}ms`);
|
|
@@ -2506,6 +2519,19 @@ async function fetchWithTimeout(url, init = {}) {
|
|
|
2506
2519
|
clearTimeout(timer);
|
|
2507
2520
|
}
|
|
2508
2521
|
}
|
|
2522
|
+
function redirectHost(res, requestUrl) {
|
|
2523
|
+
const location = res.headers.get("location");
|
|
2524
|
+
return location ? new URL(location, requestUrl).host : void 0;
|
|
2525
|
+
}
|
|
2526
|
+
function isRedirect(res) {
|
|
2527
|
+
return res.status >= 300 && res.status < 400;
|
|
2528
|
+
}
|
|
2529
|
+
function isRetryableStatus(status) {
|
|
2530
|
+
return status === 408 || status === 429 || status >= 500;
|
|
2531
|
+
}
|
|
2532
|
+
function isRetryableMethod(method) {
|
|
2533
|
+
return method === "GET" || method === "HEAD";
|
|
2534
|
+
}
|
|
2509
2535
|
async function api(path, opts = {}) {
|
|
2510
2536
|
const auth = await readAuth();
|
|
2511
2537
|
const token = process.env.FLOOM_API_TOKEN?.trim() || auth?.token;
|
|
@@ -2515,48 +2541,68 @@ async function api(path, opts = {}) {
|
|
|
2515
2541
|
let lastError = null;
|
|
2516
2542
|
const bases = getApiBaseUrls(auth?.apiUrl);
|
|
2517
2543
|
for (const base of bases) {
|
|
2518
|
-
const
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2544
|
+
const method = opts.method ?? "GET";
|
|
2545
|
+
const attempts = isRetryableMethod(method) ? retryAttempts() : 0;
|
|
2546
|
+
for (let attempt = 0; attempt <= attempts; attempt++) {
|
|
2547
|
+
const url = new URL(base + path);
|
|
2548
|
+
if (opts.query) {
|
|
2549
|
+
for (const [k, v] of Object.entries(opts.query)) {
|
|
2550
|
+
if (v !== void 0) url.searchParams.set(k, String(v));
|
|
2551
|
+
}
|
|
2522
2552
|
}
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
})
|
|
2538
|
-
|
|
2553
|
+
const headers = {
|
|
2554
|
+
"Content-Type": "application/json",
|
|
2555
|
+
"User-Agent": `floom-cli/${VERSION}`,
|
|
2556
|
+
"x-floom-cli-version": VERSION
|
|
2557
|
+
};
|
|
2558
|
+
const requestToken = opts.tokenOverride ?? token;
|
|
2559
|
+
if (requestToken) headers.Authorization = `Bearer ${requestToken}`;
|
|
2560
|
+
let res;
|
|
2561
|
+
try {
|
|
2562
|
+
res = await fetchWithTimeout(url.toString(), {
|
|
2563
|
+
method,
|
|
2564
|
+
headers,
|
|
2565
|
+
body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0
|
|
2566
|
+
});
|
|
2567
|
+
} catch (e) {
|
|
2568
|
+
lastError = new FloomError(
|
|
2569
|
+
"INTERNAL_ERROR",
|
|
2570
|
+
`Unable to reach Floom API at ${base}: ${e.message}`,
|
|
2571
|
+
{ apiUrl: base }
|
|
2572
|
+
);
|
|
2573
|
+
if (attempt < attempts) {
|
|
2574
|
+
await sleep(retryDelayMs(attempt));
|
|
2575
|
+
continue;
|
|
2576
|
+
}
|
|
2577
|
+
break;
|
|
2578
|
+
}
|
|
2579
|
+
if (isRedirect(res)) {
|
|
2580
|
+
throw new FloomError(
|
|
2581
|
+
"INTERNAL_ERROR",
|
|
2582
|
+
"Floom API returned an unexpected redirect. Refusing to forward credentials.",
|
|
2583
|
+
{ status: res.status, apiUrl: base, redirectHost: redirectHost(res, url) }
|
|
2584
|
+
);
|
|
2585
|
+
}
|
|
2586
|
+
const text = await res.text();
|
|
2587
|
+
let json = null;
|
|
2588
|
+
try {
|
|
2589
|
+
json = text ? JSON.parse(text) : null;
|
|
2590
|
+
} catch {
|
|
2591
|
+
}
|
|
2592
|
+
if (res.ok) return json;
|
|
2593
|
+
const err = json?.error ?? {};
|
|
2539
2594
|
lastError = new FloomError(
|
|
2540
|
-
"INTERNAL_ERROR",
|
|
2541
|
-
|
|
2542
|
-
{ apiUrl: base }
|
|
2595
|
+
err.code ?? "INTERNAL_ERROR",
|
|
2596
|
+
err.message ?? `HTTP ${res.status} ${res.statusText}`,
|
|
2597
|
+
{ status: res.status, requestId: err.request_id, apiUrl: base }
|
|
2543
2598
|
);
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
} catch {
|
|
2599
|
+
if (isRetryableStatus(res.status) && attempt < attempts) {
|
|
2600
|
+
await sleep(retryDelayMs(attempt));
|
|
2601
|
+
continue;
|
|
2602
|
+
}
|
|
2603
|
+
if (res.status !== 404 || json?.error) break;
|
|
2604
|
+
break;
|
|
2551
2605
|
}
|
|
2552
|
-
if (res.ok) return json;
|
|
2553
|
-
const err = json?.error ?? {};
|
|
2554
|
-
lastError = new FloomError(
|
|
2555
|
-
err.code ?? "INTERNAL_ERROR",
|
|
2556
|
-
err.message ?? `HTTP ${res.status} ${res.statusText}`,
|
|
2557
|
-
{ status: res.status, requestId: err.request_id, apiUrl: base }
|
|
2558
|
-
);
|
|
2559
|
-
if (res.status !== 404 || json?.error) break;
|
|
2560
2606
|
}
|
|
2561
2607
|
throw lastError ?? new FloomError("INTERNAL_ERROR", "API request failed");
|
|
2562
2608
|
}
|
|
@@ -2572,6 +2618,12 @@ async function rawPut(url, body, contentType = "application/octet-stream") {
|
|
|
2572
2618
|
} catch (e) {
|
|
2573
2619
|
throw new FloomError("UPLOAD_FAILED", `Upload failed: ${e.message}`);
|
|
2574
2620
|
}
|
|
2621
|
+
if (isRedirect(res)) {
|
|
2622
|
+
throw new FloomError(
|
|
2623
|
+
"UPLOAD_FAILED",
|
|
2624
|
+
`Upload failed: unexpected redirect to ${redirectHost(res, new URL(url)) ?? "unknown"}`
|
|
2625
|
+
);
|
|
2626
|
+
}
|
|
2575
2627
|
if (!res.ok) {
|
|
2576
2628
|
throw new FloomError(
|
|
2577
2629
|
"UPLOAD_FAILED",
|
|
@@ -2586,6 +2638,12 @@ async function rawGet(url) {
|
|
|
2586
2638
|
} catch (e) {
|
|
2587
2639
|
throw new FloomError("DOWNLOAD_FAILED", `Download failed: ${e.message}`);
|
|
2588
2640
|
}
|
|
2641
|
+
if (isRedirect(res)) {
|
|
2642
|
+
throw new FloomError(
|
|
2643
|
+
"DOWNLOAD_FAILED",
|
|
2644
|
+
`Download failed: unexpected redirect to ${redirectHost(res, new URL(url)) ?? "unknown"}`
|
|
2645
|
+
);
|
|
2646
|
+
}
|
|
2589
2647
|
if (!res.ok) {
|
|
2590
2648
|
throw new FloomError(
|
|
2591
2649
|
"DOWNLOAD_FAILED",
|
|
@@ -2597,11 +2655,14 @@ async function rawGet(url) {
|
|
|
2597
2655
|
}
|
|
2598
2656
|
|
|
2599
2657
|
// src/commands/login.ts
|
|
2600
|
-
var sh = promisify2(exec);
|
|
2601
2658
|
async function openInBrowser(url) {
|
|
2602
|
-
const
|
|
2659
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
2660
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
2603
2661
|
try {
|
|
2604
|
-
|
|
2662
|
+
const child = spawn(command, args, { detached: true, stdio: "ignore", shell: false });
|
|
2663
|
+
child.on("error", () => {
|
|
2664
|
+
});
|
|
2665
|
+
child.unref();
|
|
2605
2666
|
} catch {
|
|
2606
2667
|
}
|
|
2607
2668
|
}
|
|
@@ -3370,8 +3431,12 @@ async function updateCommand(refStr, opts = {}) {
|
|
|
3370
3431
|
async function listCommand(opts = {}) {
|
|
3371
3432
|
const resp = await api("/skills", {
|
|
3372
3433
|
authRequired: true,
|
|
3373
|
-
query: { q: opts.query, library: opts.workspace ?? opts.library, folder: opts.folder }
|
|
3434
|
+
query: { q: opts.query, library: opts.workspace ?? opts.library, folder: opts.folder, tag: opts.tag }
|
|
3374
3435
|
});
|
|
3436
|
+
if (opts.json) {
|
|
3437
|
+
console.log(JSON.stringify(resp, null, 2));
|
|
3438
|
+
return;
|
|
3439
|
+
}
|
|
3375
3440
|
if (resp.skills.length === 0) {
|
|
3376
3441
|
log.info("No skills.");
|
|
3377
3442
|
return;
|
|
@@ -3392,7 +3457,8 @@ async function listCommand(opts = {}) {
|
|
|
3392
3457
|
for (const [library, rows] of groups.entries()) {
|
|
3393
3458
|
log.heading(library);
|
|
3394
3459
|
for (const s of rows) {
|
|
3395
|
-
|
|
3460
|
+
const tagText = s.tags?.length ? ` #${s.tags.join(" #")}` : "";
|
|
3461
|
+
console.log(` ${`${s.library.slug}/${s.slug}`.padEnd(40)} ${s.visibility.padEnd(10)} ${s.title}${tagText}`);
|
|
3396
3462
|
}
|
|
3397
3463
|
}
|
|
3398
3464
|
}
|
|
@@ -3485,17 +3551,48 @@ async function libraryInviteCommand(librarySlug, email, role = "viewer") {
|
|
|
3485
3551
|
log.err(`Invalid email: ${email}`);
|
|
3486
3552
|
process.exit(1);
|
|
3487
3553
|
}
|
|
3488
|
-
await api(`/libraries/${librarySlug}/pending-invites`, {
|
|
3554
|
+
const resp = await api(`/libraries/${librarySlug}/pending-invites`, {
|
|
3489
3555
|
method: "POST",
|
|
3490
3556
|
authRequired: true,
|
|
3491
3557
|
body: { email, role }
|
|
3492
3558
|
});
|
|
3493
3559
|
log.ok(`Invited ${email} to ${librarySlug} as ${role}`);
|
|
3560
|
+
if (resp.invite_url) log.info(`Invite link: ${resp.invite_url}`);
|
|
3494
3561
|
}
|
|
3495
3562
|
async function libraryLeaveCommand(librarySlug) {
|
|
3496
3563
|
await api(`/libraries/${librarySlug}/members/me`, { method: "DELETE", authRequired: true });
|
|
3497
3564
|
log.ok(`Left workspace ${librarySlug}`);
|
|
3498
3565
|
}
|
|
3566
|
+
async function workspaceInvitesCommand() {
|
|
3567
|
+
const resp = await api("/me/invites", { authRequired: true });
|
|
3568
|
+
if (!resp.invites.length) {
|
|
3569
|
+
log.info("No pending workspace invites.");
|
|
3570
|
+
return;
|
|
3571
|
+
}
|
|
3572
|
+
for (const invite of resp.invites) {
|
|
3573
|
+
const workspace = invite.workspace?.slug ?? "(missing workspace)";
|
|
3574
|
+
const inviter = invite.inviter.handle ? `@${invite.inviter.handle}` : "admin";
|
|
3575
|
+
console.log(`${workspace.padEnd(24)} ${invite.role.padEnd(6)} ${invite.status.padEnd(8)} from ${inviter} expires ${invite.expires_at}`);
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
function inviteToken(input) {
|
|
3579
|
+
try {
|
|
3580
|
+
const url = new URL(input);
|
|
3581
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
3582
|
+
const inviteIndex = parts.indexOf("invite");
|
|
3583
|
+
if (inviteIndex >= 0 && parts[inviteIndex + 1]) return parts[inviteIndex + 1];
|
|
3584
|
+
} catch {
|
|
3585
|
+
}
|
|
3586
|
+
return input.trim();
|
|
3587
|
+
}
|
|
3588
|
+
async function workspaceAcceptCommand(tokenOrUrl) {
|
|
3589
|
+
const token = inviteToken(tokenOrUrl);
|
|
3590
|
+
const resp = await api(`/invites/${encodeURIComponent(token)}/accept`, {
|
|
3591
|
+
method: "POST",
|
|
3592
|
+
authRequired: true
|
|
3593
|
+
});
|
|
3594
|
+
log.ok(`Workspace invite ${resp.status}${resp.role ? ` as ${resp.role}` : ""}`);
|
|
3595
|
+
}
|
|
3499
3596
|
|
|
3500
3597
|
// src/lib/config-file.ts
|
|
3501
3598
|
import { mkdir as mkdir6, readFile as readFile8, writeFile as writeFile4 } from "node:fs/promises";
|
|
@@ -3912,18 +4009,33 @@ async function statusCommand(opts = {}) {
|
|
|
3912
4009
|
const scope = normalizeScope(opts.scope);
|
|
3913
4010
|
const config = await readFloomConfig(scope);
|
|
3914
4011
|
const active = config.targets[target]?.active_workspaces ?? [];
|
|
3915
|
-
|
|
3916
|
-
log.kv("Default workspace", config.default_workspace ?? "(none)");
|
|
3917
|
-
log.kv("Active workspaces", active.length ? active.join(", ") : "(none)");
|
|
3918
|
-
log.kv("Local pull policy", "router + pinned skills + instructions only");
|
|
4012
|
+
const workspaces = [];
|
|
3919
4013
|
for (const workspace of active) {
|
|
3920
4014
|
const pins = await api(`/libraries/${workspace}/pins`, {
|
|
3921
4015
|
authRequired: true,
|
|
3922
4016
|
query: { target }
|
|
3923
4017
|
});
|
|
4018
|
+
workspaces.push({ workspace, pins: pins.pins });
|
|
4019
|
+
}
|
|
4020
|
+
if (opts.json) {
|
|
4021
|
+
console.log(JSON.stringify({
|
|
4022
|
+
target,
|
|
4023
|
+
scope,
|
|
4024
|
+
default_workspace: config.default_workspace ?? null,
|
|
4025
|
+
active_workspaces: active,
|
|
4026
|
+
pull_policy: "router + pinned skills + instructions only",
|
|
4027
|
+
workspaces
|
|
4028
|
+
}, null, 2));
|
|
4029
|
+
return;
|
|
4030
|
+
}
|
|
4031
|
+
log.heading(`Floom status for ${target} (${scope})`);
|
|
4032
|
+
log.kv("Default workspace", config.default_workspace ?? "(none)");
|
|
4033
|
+
log.kv("Active workspaces", active.length ? active.join(", ") : "(none)");
|
|
4034
|
+
log.kv("Local pull policy", "router + pinned skills + instructions only");
|
|
4035
|
+
for (const workspace of workspaces) {
|
|
3924
4036
|
log.blank();
|
|
3925
|
-
log.info(`${workspace}: ${
|
|
3926
|
-
for (const pin of
|
|
4037
|
+
log.info(`${workspace.workspace}: ${workspace.pins.length} pinned skill(s) for ${target}`);
|
|
4038
|
+
for (const pin of workspace.pins) {
|
|
3927
4039
|
log.kv("", `${pin.skill?.slug ?? pin.skill_id}${pin.skill?.latest?.version ? `@${pin.skill.latest.version}` : ""}`);
|
|
3928
4040
|
}
|
|
3929
4041
|
}
|
|
@@ -3984,6 +4096,29 @@ async function pinCommand(ref, opts = {}) {
|
|
|
3984
4096
|
});
|
|
3985
4097
|
log.ok(`Pinned ${ref} for ${target} in ${workspace}`);
|
|
3986
4098
|
}
|
|
4099
|
+
async function pinnedCommand(opts = {}) {
|
|
4100
|
+
const target = assertTarget(opts.target ?? "codex");
|
|
4101
|
+
const workspace = await resolveWorkspace(opts);
|
|
4102
|
+
const resp = await api(`/libraries/${workspace}/pins`, {
|
|
4103
|
+
authRequired: true,
|
|
4104
|
+
query: { target }
|
|
4105
|
+
});
|
|
4106
|
+
if (opts.json) {
|
|
4107
|
+
console.log(JSON.stringify(resp, null, 2));
|
|
4108
|
+
return;
|
|
4109
|
+
}
|
|
4110
|
+
if (resp.pins.length === 0) {
|
|
4111
|
+
log.info(`No pinned skills for ${target} in ${workspace}.`);
|
|
4112
|
+
return;
|
|
4113
|
+
}
|
|
4114
|
+
log.heading(`Pinned skills for ${target} in ${workspace}`);
|
|
4115
|
+
for (const pin of resp.pins) {
|
|
4116
|
+
const ref = pin.skill?.slug ? `${workspace}/${pin.skill.slug}` : pin.skill_id;
|
|
4117
|
+
const version = pin.skill?.latest?.version ? `@${pin.skill.latest.version}` : "";
|
|
4118
|
+
const title = pin.skill?.title ? ` ${pin.skill.title}` : "";
|
|
4119
|
+
console.log(` ${`${ref}${version}`.padEnd(42)} ${pin.created_at}${title}`);
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
3987
4122
|
async function unpinCommand(ref, opts = {}) {
|
|
3988
4123
|
const target = assertTarget(opts.target ?? "codex");
|
|
3989
4124
|
const workspace = await resolveWorkspace(opts);
|
|
@@ -3995,6 +4130,78 @@ async function unpinCommand(ref, opts = {}) {
|
|
|
3995
4130
|
log.ok(`Unpinned ${ref} for ${target} in ${workspace}`);
|
|
3996
4131
|
}
|
|
3997
4132
|
|
|
4133
|
+
// src/commands/folder.ts
|
|
4134
|
+
function slugify(value) {
|
|
4135
|
+
return value.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
4136
|
+
}
|
|
4137
|
+
async function folderListCommand(workspace) {
|
|
4138
|
+
const resp = await api(`/libraries/${encodeURIComponent(workspace)}/folders`, { authRequired: true });
|
|
4139
|
+
if (resp.folders.length === 0) {
|
|
4140
|
+
log.info("No folders.");
|
|
4141
|
+
return;
|
|
4142
|
+
}
|
|
4143
|
+
for (const folder of resp.folders) {
|
|
4144
|
+
console.log(`${folder.id} ${folder.slug.padEnd(24)} ${folder.access_mode.padEnd(10)} ${String(folder.skills_count ?? 0).padStart(3)} skills ${folder.name}`);
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4147
|
+
async function folderCreateCommand(workspace, name, opts = {}) {
|
|
4148
|
+
const slug = opts.slug ?? slugify(name);
|
|
4149
|
+
const folder = await api(`/libraries/${encodeURIComponent(workspace)}/folders`, {
|
|
4150
|
+
method: "POST",
|
|
4151
|
+
authRequired: true,
|
|
4152
|
+
body: {
|
|
4153
|
+
name,
|
|
4154
|
+
slug,
|
|
4155
|
+
access_mode: opts.access ?? "open",
|
|
4156
|
+
public_release_policy: opts.publicRelease ?? "allowed",
|
|
4157
|
+
default_visibility: opts.visibility ?? "private"
|
|
4158
|
+
}
|
|
4159
|
+
});
|
|
4160
|
+
log.ok(`Created folder ${folder.slug} in ${workspace}.`);
|
|
4161
|
+
log.kv("Folder ID", folder.id);
|
|
4162
|
+
}
|
|
4163
|
+
async function folderArchiveCommand(workspace, folderId) {
|
|
4164
|
+
await api(`/libraries/${encodeURIComponent(workspace)}/folders/${encodeURIComponent(folderId)}`, {
|
|
4165
|
+
method: "DELETE",
|
|
4166
|
+
authRequired: true
|
|
4167
|
+
});
|
|
4168
|
+
log.ok(`Archived folder ${folderId}.`);
|
|
4169
|
+
}
|
|
4170
|
+
async function folderMoveCommand(ref, folderId, opts = {}) {
|
|
4171
|
+
const cleaned = ref.replace(/^@/, "");
|
|
4172
|
+
const parts = cleaned.split("/");
|
|
4173
|
+
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
4174
|
+
throw new Error("Expected ref format: workspace/skill or @workspace/skill");
|
|
4175
|
+
}
|
|
4176
|
+
const [owner, slug] = parts;
|
|
4177
|
+
const targetFolderId = opts.root ? null : folderId;
|
|
4178
|
+
if (!opts.root && !targetFolderId) throw new Error("Provide a folder id, or pass --root to move to workspace root.");
|
|
4179
|
+
const resp = await api(`/skills/${encodeURIComponent(owner)}/${encodeURIComponent(slug)}/move`, {
|
|
4180
|
+
method: "POST",
|
|
4181
|
+
authRequired: true,
|
|
4182
|
+
body: {
|
|
4183
|
+
target_library_slug: opts.workspace,
|
|
4184
|
+
target_folder_id: targetFolderId
|
|
4185
|
+
}
|
|
4186
|
+
});
|
|
4187
|
+
log.ok(`Moved ${ref} to ${resp.folder_id ? `folder ${resp.folder_id}` : "workspace root"} in ${resp.library_slug}.`);
|
|
4188
|
+
}
|
|
4189
|
+
async function folderGrantCommand(workspace, folderId, email, role) {
|
|
4190
|
+
await api(`/libraries/${encodeURIComponent(workspace)}/folders/${encodeURIComponent(folderId)}/members`, {
|
|
4191
|
+
method: "POST",
|
|
4192
|
+
authRequired: true,
|
|
4193
|
+
body: { email, role }
|
|
4194
|
+
});
|
|
4195
|
+
log.ok(`Granted ${role} folder access to ${email}.`);
|
|
4196
|
+
}
|
|
4197
|
+
async function folderRevokeCommand(workspace, folderId, memberId) {
|
|
4198
|
+
await api(`/libraries/${encodeURIComponent(workspace)}/folders/${encodeURIComponent(folderId)}/members/${encodeURIComponent(memberId)}`, {
|
|
4199
|
+
method: "DELETE",
|
|
4200
|
+
authRequired: true
|
|
4201
|
+
});
|
|
4202
|
+
log.ok(`Revoked folder member ${memberId}.`);
|
|
4203
|
+
}
|
|
4204
|
+
|
|
3998
4205
|
// src/commands/mcp.ts
|
|
3999
4206
|
import { mkdtemp, mkdir as mkdir9, readdir as readdir4, readFile as readFile10, rename as rename3, rm as rm3, writeFile as writeFile7 } from "node:fs/promises";
|
|
4000
4207
|
import { join as join13 } from "node:path";
|
|
@@ -4016,7 +4223,7 @@ async function fetchWithTimeout2(url, init = {}) {
|
|
|
4016
4223
|
const controller = new AbortController();
|
|
4017
4224
|
const timer = setTimeout(() => controller.abort(), API_TIMEOUT_MS);
|
|
4018
4225
|
try {
|
|
4019
|
-
return await fetch(url, { ...init, signal: controller.signal });
|
|
4226
|
+
return await fetch(url, { ...init, redirect: "manual", signal: controller.signal });
|
|
4020
4227
|
} catch (e) {
|
|
4021
4228
|
if (e.name === "AbortError") throw new Error(`Request timed out after ${API_TIMEOUT_MS}ms`);
|
|
4022
4229
|
throw e;
|
|
@@ -4056,6 +4263,12 @@ async function apiRequest(token, path, query) {
|
|
|
4056
4263
|
lastError = new Error(`Unable to reach Floom API at ${base}: ${e.message}`);
|
|
4057
4264
|
continue;
|
|
4058
4265
|
}
|
|
4266
|
+
if (res.status >= 300 && res.status < 400) {
|
|
4267
|
+
const location = res.headers.get("location");
|
|
4268
|
+
const redirectHost2 = location ? new URL(location, url).host : "unknown";
|
|
4269
|
+
lastError = new Error(`Floom API returned an unexpected redirect to ${redirectHost2}. Refusing to forward credentials.`);
|
|
4270
|
+
break;
|
|
4271
|
+
}
|
|
4059
4272
|
const body = await res.text();
|
|
4060
4273
|
let json = null;
|
|
4061
4274
|
try {
|
|
@@ -4397,11 +4610,12 @@ program.command("install <ref>").description("Install a skill (default: .agents/
|
|
|
4397
4610
|
program.command("installed").description("List installed skills in this project.").option("--json").action(installedCommand);
|
|
4398
4611
|
program.command("outdated").description("Show installed skills with newer versions available.").action(outdatedCommand);
|
|
4399
4612
|
program.command("update [ref]").description("Update installed skills to latest.").option("--force", "Overwrite local edits").action((ref, opts) => updateCommand(ref, opts));
|
|
4400
|
-
program.command("list").description("List remote skills.").option("--mine", "Only your own skills (default)").option("--workspace <slug>", "Filter by workspace slug").option("--library <slug>", "Legacy alias for --workspace").option("--folder <uuid>", "Filter by folder id").option("--flat", "Print one ref per line").option("--query <q>", "Filter by query").action(listCommand);
|
|
4613
|
+
program.command("list").description("List remote skills.").option("--mine", "Only your own skills (default)").option("--workspace <slug>", "Filter by workspace slug").option("--library <slug>", "Legacy alias for --workspace").option("--folder <uuid>", "Filter by folder id").option("--tag <tag>", "Filter by tag").option("--flat", "Print one ref per line").option("--json", "Emit machine-readable JSON").option("--query <q>", "Filter by query").action(listCommand);
|
|
4401
4614
|
program.command("info <ref>").description("Show details for a remote skill.").action(infoCommand);
|
|
4402
|
-
program.command("status").description("Show local vs remote Floom workspace state").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").option("--scope <scope>", "global | local", "local").action((opts) => statusCommand(opts));
|
|
4615
|
+
program.command("status").description("Show local vs remote Floom workspace state").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").option("--scope <scope>", "global | local", "local").option("--json", "Emit machine-readable JSON").action((opts) => statusCommand(opts));
|
|
4403
4616
|
program.command("pull").description("Pull account/workspace instructions for active workspaces").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").option("--scope <scope>", "global | local", "local").option("--apply", "Append managed block when the target file has no Floom block").option("--force", "Write without the first-apply guard").action((opts) => pullCommand(opts));
|
|
4404
4617
|
program.command("pin <ref>").description("Pin a workspace skill for local pull").option("--workspace <slug>", "Workspace slug").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").action((ref, opts) => pinCommand(ref, opts));
|
|
4618
|
+
program.command("pinned").alias("pins").description("List workspace skills pinned for local pull").option("--workspace <slug>", "Workspace slug").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").option("--json", "Emit machine-readable JSON").action((opts) => pinnedCommand(opts));
|
|
4405
4619
|
program.command("unpin <ref>").description("Unpin a workspace skill for local pull").option("--workspace <slug>", "Workspace slug").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").action((ref, opts) => unpinCommand(ref, opts));
|
|
4406
4620
|
program.command("share <ref> <email>").description("Invite someone to a skill by email.").option("--role <role>", "viewer (default) or editor").action((ref, email, opts) => shareCommand(ref, email, opts));
|
|
4407
4621
|
program.command("unshare <ref> <email>").description("Revoke someone's access.").action((ref, email) => unshareCommand(ref, email));
|
|
@@ -4411,6 +4625,8 @@ function addWorkspaceCommands(cmd) {
|
|
|
4411
4625
|
cmd.command("list").action(libraryListCommand);
|
|
4412
4626
|
cmd.command("create <slug> <name>").action((slug, name) => libraryCreateCommand(slug, name));
|
|
4413
4627
|
cmd.command("invite <workspaceSlug> <email>").option("--role <role>", "viewer|editor|admin", "viewer").action((workspaceSlug, email, opts) => libraryInviteCommand(workspaceSlug, email, opts.role));
|
|
4628
|
+
cmd.command("invites").description("List pending workspace invites for the logged-in user").action(workspaceInvitesCommand);
|
|
4629
|
+
cmd.command("accept <tokenOrUrl>").description("Accept a workspace invite token or URL").action((tokenOrUrl) => workspaceAcceptCommand(tokenOrUrl));
|
|
4414
4630
|
cmd.command("leave <workspaceSlug>").action((workspaceSlug) => libraryLeaveCommand(workspaceSlug));
|
|
4415
4631
|
cmd.command("activate <workspaceSlug>").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").option("--scope <scope>", "global | local", "local").action((workspaceSlug, opts) => workspaceActivateCommand(workspaceSlug, opts));
|
|
4416
4632
|
cmd.command("deactivate <workspaceSlug>").option("--target <target>", "claude | codex | cursor | kimi | opencode", "codex").option("--scope <scope>", "global | local", "local").action((workspaceSlug, opts) => workspaceDeactivateCommand(workspaceSlug, opts));
|
|
@@ -4418,6 +4634,13 @@ function addWorkspaceCommands(cmd) {
|
|
|
4418
4634
|
}
|
|
4419
4635
|
addWorkspaceCommands(program.command("workspace").description("Manage workspaces"));
|
|
4420
4636
|
addWorkspaceCommands(program.command("library").description("Manage workspaces (legacy alias)"));
|
|
4637
|
+
var folderCmd = program.command("folder").description("Manage workspace folders");
|
|
4638
|
+
folderCmd.command("list <workspace>").description("List folders in a workspace").action((workspace) => folderListCommand(workspace));
|
|
4639
|
+
folderCmd.command("create <workspace> <name>").description("Create a flat folder in a workspace").option("--slug <slug>", "Folder slug").option("--access <mode>", "open | restricted", "open").option("--public-release <policy>", "allowed | review_required | blocked", "allowed").option("--visibility <visibility>", "private | unlisted | public", "private").action((workspace, name, opts) => folderCreateCommand(workspace, name, opts));
|
|
4640
|
+
folderCmd.command("archive <workspace> <folderId>").description("Archive an empty folder").action((workspace, folderId) => folderArchiveCommand(workspace, folderId));
|
|
4641
|
+
folderCmd.command("move <ref> [folderId]").description("Move a skill into a folder or back to workspace root").option("--workspace <slug>", "Move to another workspace").option("--root", "Move to workspace root").action((ref, folderId, opts) => folderMoveCommand(ref, folderId, opts));
|
|
4642
|
+
folderCmd.command("grant <workspace> <folderId> <email>").description("Grant an existing workspace member access to a restricted folder").option("--role <role>", "viewer | editor | admin", "viewer").action((workspace, folderId, email, opts) => folderGrantCommand(workspace, folderId, email, opts.role));
|
|
4643
|
+
folderCmd.command("revoke <workspace> <folderId> <memberId>").description("Revoke a folder member grant").action((workspace, folderId, memberId) => folderRevokeCommand(workspace, folderId, memberId));
|
|
4421
4644
|
var instructionCmd = program.command("instruction").description("Manage account and workspace instructions");
|
|
4422
4645
|
instructionCmd.command("pull").description("Pull an account or workspace instruction into a managed local block").option("--account", "Pull account instruction").option("--workspace <slug>", "Pull workspace instruction").option("--target <target>", "default | claude | codex | cursor | opencode", "codex").option("--scope <scope>", "global | local", "local").option("--path <path>", "Instruction file path override").option("--apply", "Append managed block when the target file has no Floom block").option("--force", "Write without the first-apply guard").action((opts) => instructionPullCommand(opts));
|
|
4423
4646
|
instructionCmd.command("push <file>").description("Publish an account or workspace instruction from a markdown file").option("--account", "Publish account instruction").option("--workspace <slug>", "Publish workspace instruction").option("--target <target>", "default | claude | codex | cursor | opencode", "default").option("--changelog <text>", "Version changelog").action((file, opts) => instructionPushCommand(file, opts));
|
|
@@ -4434,8 +4657,13 @@ async function main() {
|
|
|
4434
4657
|
}
|
|
4435
4658
|
process.exit(1);
|
|
4436
4659
|
}
|
|
4437
|
-
|
|
4438
|
-
|
|
4660
|
+
const error = e;
|
|
4661
|
+
log.err(error.message ?? "Unknown error");
|
|
4662
|
+
if (process.env.FLOOM_DEBUG) {
|
|
4663
|
+
const name = error.name || "Error";
|
|
4664
|
+
const code = error.code ? ` code=${error.code}` : "";
|
|
4665
|
+
console.error(`[debug] ${name}${code}`);
|
|
4666
|
+
}
|
|
4439
4667
|
process.exit(1);
|
|
4440
4668
|
}
|
|
4441
4669
|
}
|