designsource 0.12.1 → 0.13.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/dist/index.js +187 -37
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -119,9 +119,9 @@ function resolveAlias(alias, tsconfig) {
|
|
|
119
119
|
best = { prefixLength: prefix.length, resolved: star === -1 ? target : target.replace("*", () => rest) };
|
|
120
120
|
}
|
|
121
121
|
if (!best) throw noAlias(alias);
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
return
|
|
122
|
+
const relative7 = posix.normalize(posix.join(tsconfig.baseUrl, best.resolved));
|
|
123
|
+
if (relative7 === ".." || relative7.startsWith("../") || posix.isAbsolute(relative7)) throw outside(alias);
|
|
124
|
+
return relative7 === "." ? "" : relative7;
|
|
125
125
|
}
|
|
126
126
|
function resolveTargets(root, shadcn) {
|
|
127
127
|
const { aliases, tailwind } = shadcn ?? {};
|
|
@@ -1370,14 +1370,14 @@ function quoteArg(arg) {
|
|
|
1370
1370
|
function childEnv(env) {
|
|
1371
1371
|
return Object.fromEntries(Object.entries(env).filter(([name]) => name.toUpperCase() !== "DS_SYNC_TOKEN"));
|
|
1372
1372
|
}
|
|
1373
|
-
var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promise((
|
|
1373
|
+
var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promise((resolve10) => {
|
|
1374
1374
|
let output = "";
|
|
1375
1375
|
let child;
|
|
1376
1376
|
try {
|
|
1377
1377
|
const shell = process.platform === "win32";
|
|
1378
1378
|
child = spawn(cmd, shell ? args.map(quoteArg) : args, { cwd, env: childEnv(process.env), stdio: [input === void 0 ? "ignore" : "pipe", "pipe", "pipe"], shell });
|
|
1379
1379
|
} catch (e) {
|
|
1380
|
-
|
|
1380
|
+
resolve10({ code: 127, output: e instanceof Error ? e.message : String(e) });
|
|
1381
1381
|
return;
|
|
1382
1382
|
}
|
|
1383
1383
|
let timedOut = false;
|
|
@@ -1387,7 +1387,7 @@ var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promis
|
|
|
1387
1387
|
}, timeoutMs);
|
|
1388
1388
|
const done = (result) => {
|
|
1389
1389
|
if (timer) clearTimeout(timer);
|
|
1390
|
-
|
|
1390
|
+
resolve10(timedOut ? { code: result.code === 0 ? 124 : result.code, output: `${result.output.trimEnd()}
|
|
1391
1391
|
timed out after ${timeoutMs / 1e3}s` } : result);
|
|
1392
1392
|
};
|
|
1393
1393
|
child.stdout?.on("data", (chunk) => {
|
|
@@ -2535,7 +2535,7 @@ async function postNdjson(opts, fetchImpl = fetch) {
|
|
|
2535
2535
|
|
|
2536
2536
|
// src/connect/open-browser.ts
|
|
2537
2537
|
import { spawn as spawn2 } from "node:child_process";
|
|
2538
|
-
var launchDetached = (cmd, args) => new Promise((
|
|
2538
|
+
var launchDetached = (cmd, args) => new Promise((resolve10) => {
|
|
2539
2539
|
try {
|
|
2540
2540
|
const child = spawn2(cmd, args, {
|
|
2541
2541
|
shell: false,
|
|
@@ -2543,13 +2543,13 @@ var launchDetached = (cmd, args) => new Promise((resolve9) => {
|
|
|
2543
2543
|
detached: true,
|
|
2544
2544
|
windowsHide: true
|
|
2545
2545
|
});
|
|
2546
|
-
child.once("error", () =>
|
|
2546
|
+
child.once("error", () => resolve10(false));
|
|
2547
2547
|
child.once("spawn", () => {
|
|
2548
2548
|
child.unref();
|
|
2549
|
-
|
|
2549
|
+
resolve10(true);
|
|
2550
2550
|
});
|
|
2551
2551
|
} catch {
|
|
2552
|
-
|
|
2552
|
+
resolve10(false);
|
|
2553
2553
|
}
|
|
2554
2554
|
});
|
|
2555
2555
|
function deviceUrl(api) {
|
|
@@ -3842,10 +3842,10 @@ function nextLine() {
|
|
|
3842
3842
|
if (line !== void 0) return Promise.resolve(line);
|
|
3843
3843
|
if (closed) return Promise.reject(new CliError(EOF_MESSAGE));
|
|
3844
3844
|
process.stdin.ref?.();
|
|
3845
|
-
return new Promise((
|
|
3845
|
+
return new Promise((resolve10, reject) => waiting.push({
|
|
3846
3846
|
resolve: (line2) => {
|
|
3847
3847
|
process.stdin.unref?.();
|
|
3848
|
-
|
|
3848
|
+
resolve10(line2);
|
|
3849
3849
|
},
|
|
3850
3850
|
reject: (err) => {
|
|
3851
3851
|
process.stdin.unref?.();
|
|
@@ -3958,7 +3958,7 @@ function pickTty(question, options, start, stdin, stdout) {
|
|
|
3958
3958
|
stdin.resume();
|
|
3959
3959
|
stdout.write("\x1B[?25l");
|
|
3960
3960
|
draw([question, ...rows()]);
|
|
3961
|
-
return new Promise((
|
|
3961
|
+
return new Promise((resolve10, reject) => {
|
|
3962
3962
|
const finish = (after) => {
|
|
3963
3963
|
stdin.off("keypress", onKey);
|
|
3964
3964
|
stdin.setRawMode(false);
|
|
@@ -3979,7 +3979,7 @@ function pickTty(question, options, start, stdin, stdout) {
|
|
|
3979
3979
|
stdout.write(`\r\x1B[J${question} ${chosen.label}
|
|
3980
3980
|
`);
|
|
3981
3981
|
});
|
|
3982
|
-
|
|
3982
|
+
resolve10(chosen.value);
|
|
3983
3983
|
return;
|
|
3984
3984
|
}
|
|
3985
3985
|
if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
|
|
@@ -4011,7 +4011,7 @@ function pickManyTty(question, options, preselected, stdin, stdout) {
|
|
|
4011
4011
|
stdin.resume();
|
|
4012
4012
|
stdout.write("\x1B[?25l");
|
|
4013
4013
|
draw([head, ...rows()]);
|
|
4014
|
-
return new Promise((
|
|
4014
|
+
return new Promise((resolve10, reject) => {
|
|
4015
4015
|
const finish = (after) => {
|
|
4016
4016
|
stdin.off("keypress", onKey);
|
|
4017
4017
|
stdin.setRawMode(false);
|
|
@@ -4032,7 +4032,7 @@ function pickManyTty(question, options, preselected, stdin, stdout) {
|
|
|
4032
4032
|
stdout.write(`\r\x1B[J${question} ${chosen.length > 0 ? chosen.map((o) => o.label).join(", ") : "none"}
|
|
4033
4033
|
`);
|
|
4034
4034
|
});
|
|
4035
|
-
|
|
4035
|
+
resolve10(chosen.map((o) => o.value));
|
|
4036
4036
|
return;
|
|
4037
4037
|
}
|
|
4038
4038
|
if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
|
|
@@ -4908,7 +4908,7 @@ function defaultLoginDeps(env) {
|
|
|
4908
4908
|
platform
|
|
4909
4909
|
};
|
|
4910
4910
|
}
|
|
4911
|
-
var sleepFor = (ms) => new Promise((
|
|
4911
|
+
var sleepFor = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
|
|
4912
4912
|
var UNTRUSTED_LOGIN_SERVER = (api) => `designsource will not sign in to ${api} from a script: outside a terminal it signs in only to ${DEFAULT_API_ORIGIN} or a server on this computer. If you trust ${api}, run npx designsource login --api ${api} in a terminal yourself.`;
|
|
4913
4913
|
var ACCOUNT_SCOPES_NEEDED = ["projects:create", "projects:read", "screens:create"];
|
|
4914
4914
|
var REVOKE_FAILED = "Could not reach the server to revoke this sign-in; revoke it on your profile page.";
|
|
@@ -5062,10 +5062,10 @@ async function runLogout(args, io, deps = defaultLoginDeps(process.env)) {
|
|
|
5062
5062
|
}
|
|
5063
5063
|
|
|
5064
5064
|
// src/mcp/server.ts
|
|
5065
|
-
import { homedir as
|
|
5065
|
+
import { homedir as homedir5 } from "node:os";
|
|
5066
5066
|
|
|
5067
5067
|
// src/version.ts
|
|
5068
|
-
var VERSION = true ? "0.
|
|
5068
|
+
var VERSION = true ? "0.13.0" : "0.0.0-dev";
|
|
5069
5069
|
|
|
5070
5070
|
// src/mcp/account-session.ts
|
|
5071
5071
|
var NOT_SIGNED_IN_FOR = (root) => `designsource is not signed in for ${printable(root)}. Ask the user to run npx designsource login in a terminal in that folder, then restart this app. A sign-in there also covers its git worktrees.`;
|
|
@@ -5074,6 +5074,13 @@ var NO_LINK = "No design system is linked to this folder yet. Call list_design_s
|
|
|
5074
5074
|
var ACCOUNT_TOKEN3 = /^dsa_[A-Za-z0-9_-]{43}$/;
|
|
5075
5075
|
var PROJECT_ID3 = /^[A-Za-z0-9_-]+$/;
|
|
5076
5076
|
var refuse = (message) => ({ kind: "none", message });
|
|
5077
|
+
function trustedFolderOf(entry, roots) {
|
|
5078
|
+
const trusted = (f) => entry.folders.some((saved) => normaliseFolder(saved) === f);
|
|
5079
|
+
const folder = trusted(roots.work) ? roots.work : trusted(roots.trust) ? roots.trust : null;
|
|
5080
|
+
if (folder === null) return null;
|
|
5081
|
+
const linked = Object.entries(entry.links).find(([f]) => normaliseFolder(f) === folder)?.[1];
|
|
5082
|
+
return { folder, projectId: linked !== void 0 && PROJECT_ID3.test(linked) ? linked : null };
|
|
5083
|
+
}
|
|
5077
5084
|
function chooseAccount(api, apiGiven, accounts, notSignedIn) {
|
|
5078
5085
|
if (apiGiven) {
|
|
5079
5086
|
let origin;
|
|
@@ -5098,11 +5105,9 @@ async function resolveAccount(input) {
|
|
|
5098
5105
|
if ("kind" in chosen) return chosen;
|
|
5099
5106
|
const homeDir = normaliseFolder(home);
|
|
5100
5107
|
if (homeFolderRefusal(trust, homeDir) !== null || homeFolderRefusal(work, homeDir) !== null) return refuse(notSignedIn);
|
|
5101
|
-
const
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
const linked = Object.entries(chosen.links).find(([f]) => normaliseFolder(f) === folder)?.[1];
|
|
5105
|
-
const projectId = linked !== void 0 && PROJECT_ID3.test(linked) ? linked : null;
|
|
5108
|
+
const found = trustedFolderOf(chosen, { work, trust });
|
|
5109
|
+
if (found === null) return refuse(notSignedIn);
|
|
5110
|
+
const { folder, projectId } = found;
|
|
5106
5111
|
let token;
|
|
5107
5112
|
try {
|
|
5108
5113
|
token = await accounts.token(chosen.origin);
|
|
@@ -5183,6 +5188,11 @@ function getPrompt(name) {
|
|
|
5183
5188
|
return { description: "Integrate the design system into the current repository.", messages: [{ role: "user", content: { type: "text", text: INTEGRATE_TEXT } }] };
|
|
5184
5189
|
}
|
|
5185
5190
|
|
|
5191
|
+
// src/mcp/tools.ts
|
|
5192
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
5193
|
+
import { homedir as homedir4 } from "node:os";
|
|
5194
|
+
import { join as join15 } from "node:path";
|
|
5195
|
+
|
|
5186
5196
|
// src/mcp/account-tools.ts
|
|
5187
5197
|
import { randomUUID } from "node:crypto";
|
|
5188
5198
|
|
|
@@ -5465,6 +5475,103 @@ function worktreeOf(cwd) {
|
|
|
5465
5475
|
return worktree ? { work, main: trust } : null;
|
|
5466
5476
|
}
|
|
5467
5477
|
|
|
5478
|
+
// src/mcp/target-folder.ts
|
|
5479
|
+
import { existsSync as existsSync13, readdirSync as readdirSync5, realpathSync as realpathSync4, statSync as statSync4 } from "node:fs";
|
|
5480
|
+
import { dirname as dirname6, isAbsolute as isAbsolute6, join as join14, relative as relative6, resolve as resolve9, sep as sep6 } from "node:path";
|
|
5481
|
+
var FOLDER_ARG_MAX = 1024;
|
|
5482
|
+
var CANDIDATES_MAX = 8;
|
|
5483
|
+
var SCAN_DIRS_MAX = 200;
|
|
5484
|
+
var FOLDER_ARG = '"folder" must be a path to a folder (relative to the project, or absolute).';
|
|
5485
|
+
var FOLDER_NOT_FOUND = (folder) => `No folder at ${printable(folder)}. Pass the path of the app's folder (the one with its package.json).`;
|
|
5486
|
+
var FOLDER_NOT_SIGNED_IN = (root, work) => `designsource is not signed in for ${printable(root)}. Ask the user to run npx designsource login in a terminal in that folder, then call add_ui_kit again; or pass a folder inside ${printable(work)}.`;
|
|
5487
|
+
var FOLDER_NOT_CONNECTED = (root, work) => `${printable(root)} is not connected to this design system. Ask the user to run npx designsource connect in a terminal in that folder, then call add_ui_kit again; or pass a folder inside ${printable(work)}.`;
|
|
5488
|
+
var FOLDER_OUTSIDE = (folder, work) => `${printable(folder)} is outside ${printable(work)}. This app runs designsource with a project token for that folder only; pass a folder inside it, or ask the user to run npx designsource connect in a terminal in the app's folder and restart this app.`;
|
|
5489
|
+
var FOLDER_HOME = (root) => `${printable(root)} is the home folder or a system folder; designsource never writes there. Pass the app's own folder.`;
|
|
5490
|
+
var NO_APP_HERE = (root, candidates, signInFirst = []) => [
|
|
5491
|
+
`No package.json in ${printable(root)}, so there is no app here to add the UI kit to. Call add_ui_kit again with folder set to the app's folder.`,
|
|
5492
|
+
...candidates.length > 0 ? [`Folders with an app you may pass: ${candidates.map(printable).join(", ")}.`] : [],
|
|
5493
|
+
...signInFirst.length > 0 ? [`Apps that are repositories of their own, which the user must first run npx designsource login in (in a terminal, then restart this app): ${signInFirst.map(printable).join(", ")}.`] : ["A folder in another repository works only once the user has run npx designsource login in a terminal there."]
|
|
5494
|
+
].join(" ");
|
|
5495
|
+
function within3(folder, root) {
|
|
5496
|
+
const rel = relative6(root, folder);
|
|
5497
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep6}`) && !isAbsolute6(rel);
|
|
5498
|
+
}
|
|
5499
|
+
function crossesRepository(target, base) {
|
|
5500
|
+
for (let dir = target; dir !== base && within3(dir, base); dir = dirname6(dir)) {
|
|
5501
|
+
if (existsSync13(join14(dir, ".git"))) return true;
|
|
5502
|
+
}
|
|
5503
|
+
return false;
|
|
5504
|
+
}
|
|
5505
|
+
function resolveTarget(arg, src) {
|
|
5506
|
+
if (typeof arg !== "string" || arg.trim() === "" || arg.length > FOLDER_ARG_MAX || /[\u0000-\u001f\u007f]/.test(arg)) return { ok: false, message: FOLDER_ARG };
|
|
5507
|
+
if (!isAbsolute6(arg) && src.base === null) return { ok: false, message: FOLDER_ARG };
|
|
5508
|
+
const asked = isAbsolute6(arg) ? resolve9(arg) : resolve9(src.base, arg);
|
|
5509
|
+
let real2;
|
|
5510
|
+
try {
|
|
5511
|
+
real2 = realpathSync4(asked);
|
|
5512
|
+
if (!statSync4(real2).isDirectory()) return { ok: false, message: FOLDER_NOT_FOUND(asked) };
|
|
5513
|
+
} catch {
|
|
5514
|
+
return { ok: false, message: FOLDER_NOT_FOUND(asked) };
|
|
5515
|
+
}
|
|
5516
|
+
const roots = projectFolders(real2);
|
|
5517
|
+
if (relative6(roots.work, real2).split(sep6).some((part) => part === ".git" || part === "node_modules")) return { ok: false, message: FOLDER_ARG };
|
|
5518
|
+
const home = normaliseFolder(src.home);
|
|
5519
|
+
if (homeFolderRefusal(real2, home) !== null) return { ok: false, message: FOLDER_HOME(real2) };
|
|
5520
|
+
if (src.base !== null && within3(real2, src.base) && !crossesRepository(real2, src.base)) return { ok: true, folder: real2, via: "inside" };
|
|
5521
|
+
if (homeFolderRefusal(roots.work, home) !== null || homeFolderRefusal(roots.trust, home) !== null) return { ok: false, message: FOLDER_HOME(roots.work) };
|
|
5522
|
+
const work = src.base ?? real2;
|
|
5523
|
+
const found = trustFor(src, roots);
|
|
5524
|
+
if (found) return { ok: true, folder: real2, via: "trusted", root: found.folder, projectId: found.projectId };
|
|
5525
|
+
if (src.accountTrust) return { ok: false, message: FOLDER_NOT_SIGNED_IN(roots.trust, work) };
|
|
5526
|
+
return { ok: false, message: src.savedFolders ? FOLDER_NOT_CONNECTED(roots.trust, work) : FOLDER_OUTSIDE(real2, work) };
|
|
5527
|
+
}
|
|
5528
|
+
function trustFor(src, roots) {
|
|
5529
|
+
if (src.accountTrust) return src.accountTrust(roots);
|
|
5530
|
+
const saved = (src.savedFolders ?? []).map((f) => normaliseFolder(f));
|
|
5531
|
+
const folder = [roots.work, roots.trust].find((r) => saved.includes(r));
|
|
5532
|
+
return folder === void 0 ? null : { folder, projectId: null };
|
|
5533
|
+
}
|
|
5534
|
+
var hasApp = (dir) => {
|
|
5535
|
+
try {
|
|
5536
|
+
return statSync4(join14(dir, "package.json")).isFile();
|
|
5537
|
+
} catch {
|
|
5538
|
+
return false;
|
|
5539
|
+
}
|
|
5540
|
+
};
|
|
5541
|
+
function appCandidates(base, near, src, trusted = []) {
|
|
5542
|
+
const apps = [];
|
|
5543
|
+
const signInFirst = [];
|
|
5544
|
+
const children = (dir) => {
|
|
5545
|
+
try {
|
|
5546
|
+
return readdirSync5(dir, { withFileTypes: true }).filter((d) => d.isDirectory() && !d.name.startsWith(".") && d.name !== "node_modules").map((d) => join14(dir, d.name)).sort();
|
|
5547
|
+
} catch {
|
|
5548
|
+
return [];
|
|
5549
|
+
}
|
|
5550
|
+
};
|
|
5551
|
+
let read = 0;
|
|
5552
|
+
const visit = (dir, depth, inBase) => {
|
|
5553
|
+
if (read >= SCAN_DIRS_MAX || apps.length >= CANDIDATES_MAX && signInFirst.length >= CANDIDATES_MAX) return;
|
|
5554
|
+
read++;
|
|
5555
|
+
const ownRepo = existsSync13(join14(dir, ".git"));
|
|
5556
|
+
if (hasApp(dir)) {
|
|
5557
|
+
const real2 = normaliseFolder(dir);
|
|
5558
|
+
if (ownRepo) {
|
|
5559
|
+
const list = trustFor(src, projectFolders(real2)) ? apps : signInFirst;
|
|
5560
|
+
if (!list.includes(real2) && list.length < CANDIDATES_MAX) list.push(real2);
|
|
5561
|
+
} else if (inBase && !apps.includes(real2) && apps.length < CANDIDATES_MAX) apps.push(real2);
|
|
5562
|
+
if (ownRepo || inBase) return;
|
|
5563
|
+
}
|
|
5564
|
+
if (depth < 2 && !ownRepo) for (const child of children(dir)) visit(child, depth + 1, inBase);
|
|
5565
|
+
};
|
|
5566
|
+
for (const child of children(base)) visit(child, 1, true);
|
|
5567
|
+
if (near !== base) for (const child of children(near)) visit(child, 1, false);
|
|
5568
|
+
for (const f of [...trusted].map((t) => normaliseFolder(t)).sort()) {
|
|
5569
|
+
if (apps.length >= CANDIDATES_MAX) break;
|
|
5570
|
+
if (f !== base && !apps.includes(f) && dirname6(f) === dirname6(near) && hasApp(f)) apps.push(f);
|
|
5571
|
+
}
|
|
5572
|
+
return { apps, signInFirst };
|
|
5573
|
+
}
|
|
5574
|
+
|
|
5468
5575
|
// src/mcp/tools.ts
|
|
5469
5576
|
var accountProjectPath = (projectId, kind) => `/api/agent/projects/${encodeURIComponent(projectId)}/${kind}`;
|
|
5470
5577
|
var READ_ONLY = { readOnlyHint: true };
|
|
@@ -5494,10 +5601,11 @@ function optionalEnum(args, key, allowed) {
|
|
|
5494
5601
|
var MCP_EXEC_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
5495
5602
|
var UNKNOWN_FOR_AGENT = (names) => `Unknown component(s): ${names.join(", ")}. Call list_components for the names.`;
|
|
5496
5603
|
var FOREIGN_FILES = (paths) => `These files exist and were not added by designsource: ${paths.join(", ")}. Ask the user whether to replace them, then call add_ui_kit again with replace_existing: true.`;
|
|
5497
|
-
function kitAccess(ctx) {
|
|
5604
|
+
function kitAccess(ctx, linkedTo) {
|
|
5498
5605
|
if (ctx.token !== null) return { token: ctx.token, api: ctx.api };
|
|
5499
5606
|
if (!ctx.account) return errorResult(ctx.missingToken ?? MCP_TOKEN_REQUIRED);
|
|
5500
|
-
const { token, api
|
|
5607
|
+
const { token, api } = ctx.account;
|
|
5608
|
+
const projectId = linkedTo ?? ctx.account.projectId;
|
|
5501
5609
|
if (projectId === null) return errorResult(NO_LINK);
|
|
5502
5610
|
return { token, api, kitPath: accountProjectPath(projectId, "kit"), messages: accountMessageForResponse };
|
|
5503
5611
|
}
|
|
@@ -5562,6 +5670,14 @@ function screensArg(v) {
|
|
|
5562
5670
|
if (!names.every(isScreenName2)) return { ok: false };
|
|
5563
5671
|
return { ok: true, value: names.length > 0 ? [...new Set(names)] : void 0, site };
|
|
5564
5672
|
}
|
|
5673
|
+
function targetSources(ctx, base) {
|
|
5674
|
+
return {
|
|
5675
|
+
base,
|
|
5676
|
+
home: ctx.home ?? homedir4(),
|
|
5677
|
+
...ctx.token === null && ctx.account ? { accountTrust: (roots) => ctx.account.trustOf?.(roots) ?? null } : {},
|
|
5678
|
+
...ctx.token !== null ? { savedFolders: ctx.projectFolders } : {}
|
|
5679
|
+
};
|
|
5680
|
+
}
|
|
5565
5681
|
async function addUiKit(args, ctx) {
|
|
5566
5682
|
const { components, replace_existing: replace, no_blocks: noBlocks } = args;
|
|
5567
5683
|
if (components !== void 0 && !(Array.isArray(components) && components.every((c) => typeof c === "string"))) {
|
|
@@ -5571,10 +5687,33 @@ async function addUiKit(args, ctx) {
|
|
|
5571
5687
|
if (noBlocks !== void 0 && typeof noBlocks !== "boolean") return errorResult('"no_blocks" must be true or false.');
|
|
5572
5688
|
const screens = screensArg(args.screens);
|
|
5573
5689
|
if (!screens.ok) return errorResult(SCREENS_ARG);
|
|
5574
|
-
|
|
5690
|
+
if (ctx.token === null && !ctx.account) return errorResult(ctx.missingToken ?? MCP_TOKEN_REQUIRED);
|
|
5691
|
+
const fallback = ctx.token !== null ? resolveProjectFolder(ctx.cwd, ctx.projectFolders === null ? null : { folders: ctx.projectFolders }) : ctx.account.workFolder;
|
|
5692
|
+
const base = fallback === null ? null : normaliseFolder(fallback);
|
|
5693
|
+
let root;
|
|
5694
|
+
let linkedTo;
|
|
5695
|
+
let usedLine = [];
|
|
5696
|
+
if (args.folder !== void 0) {
|
|
5697
|
+
const target = resolveTarget(args.folder, targetSources(ctx, base));
|
|
5698
|
+
if (!target.ok) return errorResult(target.message);
|
|
5699
|
+
root = target.folder;
|
|
5700
|
+
if (target.via === "trusted" && ctx.token === null) {
|
|
5701
|
+
linkedTo = target.projectId;
|
|
5702
|
+
usedLine = [target.projectId !== null ? `Using the design system linked to ${printable(target.root)}.` : `Using this session's design system (${printable(target.root)} has none linked).`];
|
|
5703
|
+
}
|
|
5704
|
+
} else {
|
|
5705
|
+
if (base === null) return errorResult(NOT_SURE_WHICH_FOLDER);
|
|
5706
|
+
root = base;
|
|
5707
|
+
const own = kitAccess(ctx);
|
|
5708
|
+
if (isResult2(own)) return own;
|
|
5709
|
+
if (!existsSync14(join15(root, "package.json"))) {
|
|
5710
|
+
const near = ctx.account?.folder ?? root;
|
|
5711
|
+
const found = appCandidates(root, near, targetSources(ctx, base), ctx.account?.trustedFolders?.() ?? []);
|
|
5712
|
+
return errorResult(NO_APP_HERE(root, found.apps, found.signInFirst));
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5715
|
+
const access = kitAccess(ctx, linkedTo);
|
|
5575
5716
|
if (isResult2(access)) return access;
|
|
5576
|
-
const root = ctx.token !== null ? resolveProjectFolder(ctx.cwd, ctx.projectFolders === null ? null : { folders: ctx.projectFolders }) : ctx.account.workFolder;
|
|
5577
|
-
if (root === null) return errorResult(NOT_SURE_WHICH_FOLDER);
|
|
5578
5717
|
const questions = {
|
|
5579
5718
|
pickComponents: async (all) => all,
|
|
5580
5719
|
confirmReplace: async (paths) => {
|
|
@@ -5603,6 +5742,7 @@ async function addUiKit(args, ctx) {
|
|
|
5603
5742
|
const written = result.added.filter((n) => n !== "preview-portal");
|
|
5604
5743
|
return textResult(
|
|
5605
5744
|
[
|
|
5745
|
+
...usedLine,
|
|
5606
5746
|
...progress,
|
|
5607
5747
|
...summaryLines(result, "agent"),
|
|
5608
5748
|
...written.length > 0 ? [`Added: ${written.join(", ")}`] : [],
|
|
@@ -5751,14 +5891,15 @@ ${files.join("\n\n")}`);
|
|
|
5751
5891
|
},
|
|
5752
5892
|
{
|
|
5753
5893
|
name: "add_ui_kit",
|
|
5754
|
-
description: `Add this design system's UI kit to the React app in the current folder: the theme, the components and their libraries. Sets up Tailwind and shadcn when the app lacks them. A full run (no components and no screens named) also writes the /design-system section, every component, block and sample page in the project's theme, with its blocks unless no_blocks is true, and refreshes the screens an earlier run wrote. screens (names from list_screens, or ["all"]) writes those app screens and marketing pages with the parts and components they import; you mount each on a route. Add "site" to screens to write the site menu (header and footer) that pages mount inside, at least one page being pulled with it. Changes files in the project, so your client will ask the user first. Never overwrites components or screens the user edited.`,
|
|
5894
|
+
description: `Add this design system's UI kit to the React app in the current folder: the theme, the components and their libraries. Sets up Tailwind and shadcn when the app lacks them. A full run (no components and no screens named) also writes the /design-system section, every component, block and sample page in the project's theme, with its blocks unless no_blocks is true, and refreshes the screens an earlier run wrote. screens (names from list_screens, or ["all"]) writes those app screens and marketing pages with the parts and components they import; you mount each on a route. Add "site" to screens to write the site menu (header and footer) that pages mount inside, at least one page being pulled with it. When the app is not in the current folder (a monorepo, or a workspace holding the app as a repository of its own), pass folder; a repository of its own works once the user has run npx designsource login in it, and its linked design system is used. Changes files in the project, so your client will ask the user first. Never overwrites components or screens the user edited.`,
|
|
5755
5895
|
inputSchema: {
|
|
5756
5896
|
type: "object",
|
|
5757
5897
|
properties: {
|
|
5758
5898
|
components: { type: "array", items: { type: "string" }, description: "Component names such as button or dialog. Omit to add everything (or refresh what was added before)." },
|
|
5759
5899
|
replace_existing: { type: "boolean", description: "Replace component files that exist but were not added by designsource. Ask the user first." },
|
|
5760
5900
|
no_blocks: { type: "boolean", description: "Add the /design-system section without its blocks and their libraries. Blocks an earlier run wrote are left in place." },
|
|
5761
|
-
screens: { type: "array", items: { type: "string" }, description: `Screen names from list_screens, or ["all"] for every screen; "site" adds the site menu for marketing pages. Each is written under the components folder's screens/ with the parts and kit components it imports.` }
|
|
5901
|
+
screens: { type: "array", items: { type: "string" }, description: `Screen names from list_screens, or ["all"] for every screen; "site" adds the site menu for marketing pages. Each is written under the components folder's screens/ with the parts and kit components it imports.` },
|
|
5902
|
+
folder: { type: "string", description: "The app's folder when it is not the current one: a path inside this project (a monorepo's apps/web), or a repository of its own the user ran npx designsource login in. Omit for the current folder." }
|
|
5762
5903
|
},
|
|
5763
5904
|
additionalProperties: false
|
|
5764
5905
|
},
|
|
@@ -5936,12 +6077,20 @@ function toolAccountFor(session, accounts, onLink, onGone = () => {
|
|
|
5936
6077
|
account.projectId = projectId;
|
|
5937
6078
|
onLink();
|
|
5938
6079
|
return true;
|
|
6080
|
+
},
|
|
6081
|
+
trustOf(roots) {
|
|
6082
|
+
const entry = accounts.get(session.origin);
|
|
6083
|
+
return entry ? trustedFolderOf(entry, roots) : null;
|
|
6084
|
+
},
|
|
6085
|
+
trustedFolders() {
|
|
6086
|
+
return accounts.get(session.origin)?.folders ?? [];
|
|
5939
6087
|
}
|
|
5940
6088
|
};
|
|
5941
6089
|
return account;
|
|
5942
6090
|
}
|
|
5943
6091
|
async function runMcp(args, io, streams = { input: process.stdin, output: process.stdout }, deps = {}) {
|
|
5944
6092
|
const cwd = deps.cwd ?? process.cwd();
|
|
6093
|
+
const home = deps.home ?? homedir5();
|
|
5945
6094
|
const store = deps.store ?? defaultStore();
|
|
5946
6095
|
const warn = (line) => io.stderr(`${line}
|
|
5947
6096
|
`);
|
|
@@ -5953,17 +6102,17 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
5953
6102
|
else if (found.entry === null && args.project) found = { ...found, entry: store.entry(args.project) };
|
|
5954
6103
|
if (found) {
|
|
5955
6104
|
const api = fromStore ? apiFor(args, found.entry) : givenTokenApi(args, found.entry);
|
|
5956
|
-
return { token: found.token, projectFolders: args.project ? found.entry?.folders ?? [] : null, api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec };
|
|
6105
|
+
return { token: found.token, projectFolders: args.project ? found.entry?.folders ?? [] : null, api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec, home };
|
|
5957
6106
|
}
|
|
5958
6107
|
const missingToken = args.project ? NO_TOKEN_FOR_PROJECT(store.entry(args.project)?.name ?? args.project) : MCP_TOKEN_REQUIRED;
|
|
5959
|
-
return { token: null, missingToken, projectFolders: args.project ? [] : null, api: args.api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec };
|
|
6108
|
+
return { token: null, missingToken, projectFolders: args.project ? [] : null, api: args.api, cwd, account: null, fetchImpl: io.fetchImpl, exec: spawnExec, home };
|
|
5960
6109
|
};
|
|
5961
6110
|
let accounts = null;
|
|
5962
6111
|
let account = null;
|
|
5963
6112
|
const accountSession = async () => {
|
|
5964
6113
|
if (!account) {
|
|
5965
|
-
accounts ??= (deps.accounts ?? (() => createAccountStore({ env: process.env, platform: process.platform, exec: spawnExec, home:
|
|
5966
|
-
const resolved = await resolveAccount({ api: args.api, apiGiven: args.apiGiven === true, cwd, home
|
|
6114
|
+
accounts ??= (deps.accounts ?? (() => createAccountStore({ env: process.env, platform: process.platform, exec: spawnExec, home: homedir5() })))();
|
|
6115
|
+
const resolved = await resolveAccount({ api: args.api, apiGiven: args.apiGiven === true, cwd, home, accounts });
|
|
5967
6116
|
if (resolved.kind === "none") {
|
|
5968
6117
|
return {
|
|
5969
6118
|
token: null,
|
|
@@ -5975,7 +6124,8 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
5975
6124
|
cwd,
|
|
5976
6125
|
account: null,
|
|
5977
6126
|
fetchImpl: io.fetchImpl,
|
|
5978
|
-
exec: spawnExec
|
|
6127
|
+
exec: spawnExec,
|
|
6128
|
+
home
|
|
5979
6129
|
};
|
|
5980
6130
|
}
|
|
5981
6131
|
const made = toolAccountFor(resolved, accounts, () => cache.clear(), () => {
|
|
@@ -5994,7 +6144,7 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
|
|
|
5994
6144
|
}
|
|
5995
6145
|
return res;
|
|
5996
6146
|
});
|
|
5997
|
-
return { token: null, projectFolders: null, api: current.api, cwd, account: current, fetchImpl, exec: spawnExec, dropSnapshot: () => cache.clear() };
|
|
6147
|
+
return { token: null, projectFolders: null, api: current.api, cwd, account: current, fetchImpl, exec: spawnExec, home, dropSnapshot: () => cache.clear() };
|
|
5998
6148
|
};
|
|
5999
6149
|
const session = () => projectPath ? projectSession() : accountSession();
|
|
6000
6150
|
const cache = createSnapshotCache(async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "designsource",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The DS source CLI: add your design system's UI kit to a React app (add), add the design system to any other app (integrate), start a new Next.js project from it (create), or serve it to a coding agent over MCP (mcp) — tokens, every component and your mockup page.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|