designsource 0.15.0 → 0.16.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.
Files changed (2) hide show
  1. package/dist/index.js +198 -87
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1013,7 +1013,6 @@ Commands
1013
1013
  connect connect your coding apps (Claude Code, Cursor, VS Code, Codex, Gemini CLI) to this design system
1014
1014
  login sign in for coding agents, so your agent can create design systems from this folder
1015
1015
  logout sign this computer out of the account login signed in to
1016
- integrate [folder] add the design system to an existing app \u2014 writes design-system/ (default folder: .)
1017
1016
  create [folder] new Next.js project with the tokens, every component and your mockup page (default folder: ${CREATE_DEFAULT_FOLDER})
1018
1017
  mcp serve the design system to a coding agent over MCP (stdio) \u2014 for .mcp.json, not for a terminal
1019
1018
 
@@ -1132,7 +1131,7 @@ function baseArgs(env) {
1132
1131
  return args;
1133
1132
  }
1134
1133
  var HELP = /* @__PURE__ */ new Set(["--help", "-h", "help"]);
1135
- var USE_VERBS = "Use setup, add, connect, login, logout, integrate, create or mcp.";
1134
+ var USE_VERBS = "Use setup, add, connect, login, logout, create or mcp.";
1136
1135
  function parseArgs(argv, env) {
1137
1136
  const [first, ...rest] = argv;
1138
1137
  if (first === void 0) return { kind: "setup", args: { api: DEFAULT_API_ORIGIN, apiGiven: false }, bare: true };
@@ -1351,9 +1350,10 @@ function parseVerb(verb, argv, env) {
1351
1350
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
1352
1351
  import { join as join3 } from "node:path";
1353
1352
  var NO_PACKAGE_JSON = "No package.json here. Run this in your React app's folder.";
1354
- var NO_REACT = "This folder has no React app. Run this in your React app's folder; for Vue, Svelte, Angular or plain CSS use the AI prompt in the workbench's Export dialog.";
1353
+ var REACT_ONLY_SENTENCE = "DS source supports React apps only for now.";
1354
+ var NO_REACT = `This folder has no React app. Run this in your React app's folder. ${REACT_ONLY_SENTENCE}`;
1355
1355
  var OLD_REACT = (major) => `The UI kit needs React 19 \u2014 this app is on React ${major}.`;
1356
- var NO_TYPESCRIPT = "The UI kit is TypeScript and this app is plain JavaScript. Use the AI prompt in the workbench's Export dialog instead.";
1356
+ var NO_TYPESCRIPT = "The UI kit is TypeScript and this app is plain JavaScript, so it cannot go in yet.";
1357
1357
  var LOCKFILES = [["pnpm-lock.yaml", "pnpm"], ["yarn.lock", "yarn"], ["bun.lockb", "bun"], ["bun.lock", "bun"], ["package-lock.json", "npm"]];
1358
1358
  function majorOf(spec) {
1359
1359
  if (spec === void 0) return null;
@@ -4692,18 +4692,34 @@ function askFolder(fallback) {
4692
4692
  return process.stdin.isTTY === true ? ask("Folder", fallback) : Promise.resolve(fallback);
4693
4693
  }
4694
4694
  var TOKEN_REQUIRED = "A project token is required. In the workbench open Project settings and copy the project token.";
4695
+ var NO_DESIGN_SYSTEM_HERE = "No design system is connected to this folder. Ask the user to run npx designsource in a terminal in this folder, then run this command again. Do not paste a project token into a command.";
4695
4696
  var isTerminal = () => process.stdin.isTTY === true && process.stdout.isTTY === true;
4696
- async function requireToken(given, opts) {
4697
+ var noToken = () => new CliError(isTerminal() ? TOKEN_REQUIRED : NO_DESIGN_SYSTEM_HERE);
4698
+ async function askTokenHidden() {
4699
+ try {
4700
+ return await askHidden("Project token (workbench \u2192 Project settings):");
4701
+ } catch (e) {
4702
+ if (e instanceof CliError && e.message === EOF_MESSAGE && !isTerminal()) return "";
4703
+ throw e;
4704
+ }
4705
+ }
4706
+ async function requireToken(given, opts, ask2 = {}) {
4697
4707
  if (!opts) {
4698
- const token = given ?? await askHidden("Project token (workbench \u2192 Project settings):");
4699
- if (!token) throw new CliError(TOKEN_REQUIRED);
4708
+ const token = given ?? (ask2.prompt === false ? "" : await askTokenHidden());
4709
+ if (!token) throw noToken();
4700
4710
  return token;
4701
4711
  }
4702
4712
  return (await requireSavedToken(given, opts)).token;
4703
4713
  }
4704
4714
  async function requireSavedToken(given, opts) {
4705
- const resolved = await resolveToken({ given, cwd: opts.cwd, store: opts.store ?? defaultStore(), interactive: opts.interactive ?? isTerminal(), prompt: true });
4706
- if (!resolved) throw new CliError(TOKEN_REQUIRED);
4715
+ let resolved;
4716
+ try {
4717
+ resolved = await resolveToken({ given, cwd: opts.cwd, store: opts.store ?? defaultStore(), interactive: opts.interactive ?? isTerminal(), prompt: true });
4718
+ } catch (e) {
4719
+ if (e instanceof CliError && e.message === EOF_MESSAGE && !isTerminal()) throw noToken();
4720
+ throw e;
4721
+ }
4722
+ if (!resolved) throw noToken();
4707
4723
  return resolved;
4708
4724
  }
4709
4725
  async function savedToken(given, opts) {
@@ -4781,7 +4797,7 @@ async function runAddCommand(args, io, exec = spawnExec, store, accounts) {
4781
4797
  if (first) mode = await pick(PICK_QUESTION, ADD_MODES, 0);
4782
4798
  }
4783
4799
  const access = await savedOrLinked(args, { cwd: root, store, accounts, interactive: terminal });
4784
- const { token, api, account } = access ?? { token: await requireToken(void 0), api: apiFor(args, null), account: null };
4800
+ const { token, api, account } = access ?? { token: await requireToken(void 0, void 0, { prompt: !args.yes }), api: apiFor(args, null), account: null };
4785
4801
  if (account) io.stdout(`${USING_LINK(printable(account.email), account.origin)}
4786
4802
  `);
4787
4803
  const questions = interactive ? ttyQuestions(args, mode, io) : nonInteractiveQuestions(args);
@@ -5023,7 +5039,10 @@ var INTEGRATE_OPTIONS = [
5023
5039
  { value: "angular", label: "Angular" },
5024
5040
  { value: "css", label: "Plain CSS", hint: "any other stack" }
5025
5041
  ];
5042
+ var INTEGRATE_NOT_SUPPORTED = "integrate is not supported for now: DS source supports React apps. It still runs, but it may change or go away.";
5026
5043
  async function runIntegrate(args, env, io, store, accounts) {
5044
+ io.stderr(`${INTEGRATE_NOT_SUPPORTED}
5045
+ `);
5027
5046
  const framework = args.framework ?? await pick("Framework", INTEGRATE_OPTIONS, 0);
5028
5047
  const access = await savedOrLinked(args, { cwd: io.cwd, store, accounts });
5029
5048
  const folder = args.folder ?? await askFolder(INTEGRATE_DEFAULT_FOLDER);
@@ -5217,7 +5236,7 @@ async function runLogout(args, io, deps = defaultLoginDeps(process.env)) {
5217
5236
  import { homedir as homedir6 } from "node:os";
5218
5237
 
5219
5238
  // src/version.ts
5220
- var VERSION = true ? "0.15.0" : "0.0.0-dev";
5239
+ var VERSION = true ? "0.16.0" : "0.0.0-dev";
5221
5240
 
5222
5241
  // src/mcp/jsonrpc.ts
5223
5242
  import { StringDecoder } from "node:string_decoder";
@@ -5681,14 +5700,14 @@ var CATEGORIES = ["color", "spacing", "radius", "typography", "shadow", "zIndex"
5681
5700
  var NO_INPUT = { type: "object", properties: {}, additionalProperties: false };
5682
5701
  var pretty = (v) => JSON.stringify(v, null, 2);
5683
5702
  var NO_BLOCKS = "This server sent no blocks. Update designsource and the server.";
5684
- var SOURCE_HEADER = "// Reference implementation. Use verbatim in React + Tailwind; port to your stack otherwise, keeping every var() chain.";
5703
+ var SOURCE_HEADER = "// Reference implementation for React + Tailwind (React apps only for now). add_ui_kit writes it into the app; do not copy it by hand.";
5685
5704
  var FALLBACK_BLOCK_SOURCE_HEADER = `${SOURCE_HEADER}
5686
5705
  // The block renders inside BlockStage (components/blocks/stage.tsx, below), which supplies the @container/stage its
5687
5706
  // responsive classes query and the frame height its min-h-full fills: render <BlockStage><Block /></BlockStage> as a
5688
5707
  // full-viewport page. components/ui/preview-portal.tsx is the portal context the stage provides; the kit components
5689
5708
  // list_blocks names for this block come from get_component_source.`;
5690
- var UTILS_HEADER = "// The `cn` helper every component imports from `@/lib/utils`. Save as lib/utils.ts in React; port or drop elsewhere.";
5691
- var PORTAL_HEADER = "// The portal context components import from `./preview-portal`. Save it beside them as components/ui/preview-portal.tsx in React: with no provider it portals to document.body, as stock shadcn does. Port or drop elsewhere.";
5709
+ var UTILS_HEADER = "// The `cn` helper every component imports from `@/lib/utils`, at lib/utils.ts in a React app (add_ui_kit writes it).";
5710
+ var PORTAL_HEADER = "// The portal context components import from `./preview-portal`. Save it beside them as components/ui/preview-portal.tsx in React: with no provider it portals to document.body, as stock shadcn does.";
5692
5711
  var blockAppPath = (key) => key.startsWith("kit/") ? `components/ui/${key.slice("kit/".length)}` : `components/${key}`;
5693
5712
  var componentsIn = (snapshot) => [...new Set(snapshot.canonical.tokens.map((t) => t.component).filter((c) => c !== null))].sort();
5694
5713
  function optionalEnum(args, key, allowed) {
@@ -5779,6 +5798,42 @@ function targetSources(ctx, base) {
5779
5798
  ...ctx.token !== null ? { savedFolders: ctx.projectFolders } : {}
5780
5799
  };
5781
5800
  }
5801
+ var READER_FOOTER_NO_KIT = "This app does not have the UI kit yet. Do not apply these values by hand: call add_ui_kit, then use its components.";
5802
+ var READER_FOOTER_NOT_REACT = "DS source supports React apps only for now. Tell the user this app is not supported yet; do not apply these values by hand.";
5803
+ var READER_FOOTER_PASS_FOLDER = "Pass the app's folder to add_ui_kit.";
5804
+ function appKind(root) {
5805
+ if (!existsSync14(join15(root, "package.json"))) return "none";
5806
+ try {
5807
+ const info = detectApp(root);
5808
+ if (info.reactMajor === null) return "not-react";
5809
+ const targets = info.shadcn ? resolveTargets(root, info.shadcn) : defaultTargets(root, info);
5810
+ return previouslyAdded(root, targets).some((n) => n !== "utils") ? "react-kit" : "react-no-kit";
5811
+ } catch {
5812
+ return "none";
5813
+ }
5814
+ }
5815
+ function readerFooter(ctx) {
5816
+ try {
5817
+ const fallback = ctx.token !== null ? resolveProjectFolder(ctx.cwd, ctx.projectFolders === null ? null : { folders: ctx.projectFolders }) : ctx.account?.workFolder ?? null;
5818
+ if (fallback === null) return null;
5819
+ const root = normaliseFolder(fallback);
5820
+ const kind = appKind(root);
5821
+ if (kind === "react-no-kit") return READER_FOOTER_NO_KIT;
5822
+ if (kind === "not-react") return READER_FOOTER_NOT_REACT;
5823
+ if (kind === "react-kit") return null;
5824
+ const near = ctx.account?.folder ?? root;
5825
+ const below = appCandidates(root, near, targetSources(ctx, root), ctx.account?.trustedFolders?.() ?? []).apps.map(appKind);
5826
+ return below.includes("react-no-kit") && !below.includes("react-kit") ? `${READER_FOOTER_NO_KIT} ${READER_FOOTER_PASS_FOLDER}` : null;
5827
+ } catch {
5828
+ return null;
5829
+ }
5830
+ }
5831
+ function withFooter(body, ctx) {
5832
+ const footer = readerFooter(ctx);
5833
+ return textResult(footer === null ? body : `${body}
5834
+
5835
+ ${footer}`);
5836
+ }
5782
5837
  var BLOCKS_BOTH_FOR_AGENT = '"blocks" and "no_blocks" cannot both be true.';
5783
5838
  async function addUiKit(args, ctx) {
5784
5839
  const { components, replace_existing: replace, no_blocks: noBlocks, blocks: addBlocks } = args;
@@ -5882,7 +5937,7 @@ var TOOLS = [
5882
5937
  additionalProperties: false
5883
5938
  },
5884
5939
  annotations: READ_ONLY,
5885
- run: (snapshot, _at, args) => {
5940
+ run: (snapshot, _at, args, ctx) => {
5886
5941
  const tier = optionalEnum(args, "tier", TIERS);
5887
5942
  if (!tier.ok) return tier.error;
5888
5943
  const category = optionalEnum(args, "category", CATEGORIES);
@@ -5892,22 +5947,22 @@ var TOOLS = [
5892
5947
  const component = optionalEnum(args, "component", components);
5893
5948
  if (!component.ok) return component.error;
5894
5949
  const rows = snapshot.canonical.tokens.filter((t) => (tier.value === void 0 || t.tier === tier.value) && (category.value === void 0 || t.category === category.value) && (component.value === void 0 || t.component === component.value)).map(({ path, $type, $value, ref }) => ({ path, $type, $value, ref }));
5895
- return textResult(rows.length ? pretty(rows) : "No tokens match.");
5950
+ return withFooter(rows.length ? pretty(rows) : "No tokens match.", ctx);
5896
5951
  }
5897
5952
  },
5898
5953
  {
5899
5954
  name: "get_css_variables",
5900
- description: "The whole design system as plain CSS custom properties for any stack: design tokens in :root, semantic and component tokens as var() aliases per theme, light and dark via [data-theme] and prefers-color-scheme.",
5955
+ description: "The whole design system as plain CSS custom properties: design tokens in :root, semantic and component tokens as var() aliases per theme, light and dark via [data-theme] and prefers-color-scheme.",
5901
5956
  inputSchema: NO_INPUT,
5902
5957
  annotations: READ_ONLY,
5903
- run: (snapshot) => textResult(snapshot.cssVars)
5958
+ run: (snapshot, _at, _args, ctx) => withFooter(snapshot.cssVars, ctx)
5904
5959
  },
5905
5960
  {
5906
5961
  name: "get_shadcn_theme",
5907
5962
  description: "The design system as a shadcn/ui theme stylesheet for Tailwind v4: :root and .dark blocks plus @theme inline. Use on the React + Tailwind path.",
5908
5963
  inputSchema: NO_INPUT,
5909
5964
  annotations: READ_ONLY,
5910
- run: (snapshot) => textResult(snapshot.shadcnTheme)
5965
+ run: (snapshot, _at, _args, ctx) => withFooter(snapshot.shadcnTheme, ctx)
5911
5966
  },
5912
5967
  {
5913
5968
  name: "list_components",
@@ -5923,16 +5978,16 @@ var TOOLS = [
5923
5978
  },
5924
5979
  {
5925
5980
  name: "get_component_source",
5926
- description: 'The React + Tailwind source of one component (see list_components), or a helper: "utils" for the cn helper, "preview-portal" for the portal context components import. Use verbatim in React; port to any other stack keeping every var() chain.',
5981
+ description: 'The React + Tailwind source of one component (see list_components), or a helper: "utils" for the cn helper, "preview-portal" for the portal context components import. React apps only for now: add_ui_kit writes it into the app, so do not copy it by hand.',
5927
5982
  inputSchema: { type: "object", properties: { name: { type: "string", description: "A name from list_components, or a helper (utils, preview-portal)." } }, required: ["name"], additionalProperties: false },
5928
5983
  annotations: READ_ONLY,
5929
- run: (snapshot, _at, args) => {
5984
+ run: (snapshot, _at, args, ctx) => {
5930
5985
  const names = Object.keys(snapshot.kit.sources).sort();
5931
5986
  const name = args.name;
5932
5987
  if (typeof name !== "string" || !names.includes(name)) return errorResult(`"name" must be one of: ${names.join(", ")}.`);
5933
5988
  const header = name in snapshot.kit.variables ? SOURCE_HEADER : name === "preview-portal" ? PORTAL_HEADER : UTILS_HEADER;
5934
- return textResult(`${header}
5935
- ${snapshot.kit.sources[name]}`);
5989
+ return withFooter(`${header}
5990
+ ${snapshot.kit.sources[name]}`, ctx);
5936
5991
  }
5937
5992
  },
5938
5993
  {
@@ -5965,7 +6020,7 @@ ${files.join("\n")}`);
5965
6020
  },
5966
6021
  {
5967
6022
  name: "get_block_source",
5968
- description: "Every file of one block (see list_blocks), each headed by the path it takes in the app: the block under components/blocks/, plus BlockStage (components/blocks/stage.tsx), which supplies the @container/stage its responsive classes query and the frame height, and the portal context it provides (components/ui/preview-portal.tsx). Render <BlockStage><Block /></BlockStage> as a full-viewport page. Use verbatim in React + Tailwind; port elsewhere keeping every var() chain.",
6023
+ description: "Every file of one block (see list_blocks), each headed by the path it takes in the app: the block under components/blocks/, plus BlockStage (components/blocks/stage.tsx), which supplies the @container/stage its responsive classes query and the frame height, and the portal context it provides (components/ui/preview-portal.tsx). Render <BlockStage><Block /></BlockStage> as a full-viewport page. React apps only for now: use verbatim in React + Tailwind.",
5969
6024
  inputSchema: { type: "object", properties: { id: { type: "string", description: "A block id from list_blocks." } }, required: ["id"], additionalProperties: false },
5970
6025
  annotations: READ_ONLY,
5971
6026
  run: (snapshot, _at, args) => {
@@ -6025,6 +6080,7 @@ function findTool(name) {
6025
6080
 
6026
6081
  // src/mcp/protocol.ts
6027
6082
  var SUPPORTED_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
6083
+ var SERVER_INSTRUCTIONS = "DS source design systems, React apps only for now. Order: if this folder has no design system, create_design_system (or use_design_system); then add_ui_kit; then restyle the app with the components it added. Never copy tokens, CSS variables or component source into the app by hand. Call get_integration_guide for the full steps.";
6028
6084
  var NO_SNAPSHOT = {};
6029
6085
  var asObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
6030
6086
  async function handle(parsed, deps) {
@@ -6039,7 +6095,7 @@ async function request(msg, deps) {
6039
6095
  case "initialize": {
6040
6096
  const asked = params.protocolVersion;
6041
6097
  const protocolVersion = typeof asked === "string" && SUPPORTED_VERSIONS.includes(asked) ? asked : SUPPORTED_VERSIONS[0];
6042
- return respond(id, { protocolVersion, capabilities: { tools: {}, prompts: {} }, serverInfo: { name: "designsource", version: deps.version } });
6098
+ return respond(id, { protocolVersion, capabilities: { tools: {}, prompts: {} }, serverInfo: { name: "designsource", version: deps.version }, instructions: SERVER_INSTRUCTIONS });
6043
6099
  }
6044
6100
  case "ping":
6045
6101
  return respond(id, {});
@@ -6339,14 +6395,14 @@ function readSetupState(cwd, home) {
6339
6395
  const onlyGit = names.length > 0 && names.every((n) => n === ".git" || n === ".DS_Store");
6340
6396
  return { kind: "empty", root, found: "Empty folder.", dotfiles: names.length > 0, onlyGit };
6341
6397
  }
6342
- return { kind: "other-stack", root, found: "No package.json here, so this is treated as a plain CSS site.", framework: "css" };
6398
+ return { kind: "other-stack", root, found: "No package.json here, so this is not a React app.", framework: "css" };
6343
6399
  }
6344
6400
  const deps = readDeps(root);
6345
6401
  if (deps === null) throw new CliError("package.json is not valid JSON.");
6346
6402
  if (!("react" in deps) && (hasWorkspaces(root) || existsSync15(join16(root, "pnpm-workspace.yaml")))) return { kind: "refused", message: WORKSPACE_ROOT };
6347
6403
  if (!("react" in deps)) {
6348
6404
  const framework = frameworkOf(deps);
6349
- return { kind: "other-stack", root, found: framework === "css" ? "No React here; the design system goes in as plain CSS." : `${FRAMEWORK_LABELS[framework]} app.`, framework };
6405
+ return { kind: "other-stack", root, found: framework === "css" ? "No React here." : `${FRAMEWORK_LABELS[framework]} app.`, framework };
6350
6406
  }
6351
6407
  const info = detectApp(root);
6352
6408
  let cannotAdd = null;
@@ -6371,17 +6427,22 @@ function readSetupState(cwd, home) {
6371
6427
  // src/commands/setup.ts
6372
6428
  var SETUP_NEEDS_TERMINAL = "setup asks questions, so it needs a terminal. In a script, use add, connect or login.";
6373
6429
  var SETUP_NOT_A_PROJECT = "This folder is neither a repository nor an app. Run npx designsource in your app's folder.";
6374
- var CANNOT_ADD_AGENT_ONLY = "The UI kit cannot go into this app, so setup connects your coding agent only; it can still create a design system and port it by hand.";
6430
+ var CANNOT_ADD_AGENT_ONLY = "The UI kit cannot go into this app yet, so setup connects your coding agent only.";
6431
+ var REACT_ONLY = "DS source supports React apps only for now. Vue, Svelte, Angular and plain CSS are coming later.";
6375
6432
  var MAKE_NEW_WAIT = "Make your design system in the browser. This continues when it is saved.";
6376
6433
  var WAIT_TIMEOUT = "Still waiting? Run npx designsource again once your design system is saved.";
6377
6434
  var NO_APPS_HERE = "No coding apps found on this computer. Run npx designsource login --apps claude (or cursor, vscode, codex, gemini) to set one up.";
6378
6435
  var BLOCKS_HINT = "Want the ready-made blocks too? Run npx designsource add --blocks";
6379
6436
  var USING = (name) => `Using \u201C${name}\u201D.`;
6380
- var AFTER_UPGRADE = "After upgrading, run npx designsource again.";
6381
- var FREE_PLAN_LINES = (origin, what) => [
6382
- `Your account is on the free plan, so ${what === "kit" ? "the kit was not added to this app" : what === "files" ? "the design system files were not added" : "the app was not created"}.`,
6383
- `Exports need Pro: ${origin}/pricing`,
6384
- AFTER_UPGRADE
6437
+ var upgradeUrl = (origin) => `${origin}/credits?upgrade=pro`;
6438
+ var FREE_PLAN_HEADING = (what) => `Free plan: ${what === "kit" ? "the kit was not added to this app" : "the app was not created"}.`;
6439
+ var FREE_PLAN_LINES = (origin, what, color = false) => [
6440
+ "",
6441
+ ` ${color ? `\x1B[1;33m${FREE_PLAN_HEADING(what)}\x1B[0m` : FREE_PLAN_HEADING(what)}`,
6442
+ "",
6443
+ ` Upgrade ${upgradeUrl(origin)}`,
6444
+ " Then run npx designsource",
6445
+ ""
6385
6446
  ];
6386
6447
  var SET_UP_STATUS = (name, components, section, screens) => `\u201C${name}\u201D is set up here (${[
6387
6448
  `${components} component${components === 1 ? "" : "s"}`,
@@ -6390,14 +6451,13 @@ var SET_UP_STATUS = (name, components, section, screens) => `\u201C${name}\u201D
6390
6451
  ].join(", ")}).`;
6391
6452
  var NEXT_STEP = (sentence) => ["Next: ask your coding agent", ` \u201C${sentence}\u201D`];
6392
6453
  var RESTYLE_SENTENCE = "Restyle this app's existing screens with the design system.";
6393
- var APPLY_SENTENCE = "Apply the design system in design-system/ to this app.";
6394
6454
  var WAIT_MS = 30 * 6e4;
6395
6455
  var POLL_MS = 5e3;
6396
6456
  var PICKER_MAX = 20;
6397
6457
  var TERMINAL2 = { pick: (q, o, d) => pick(q, o, d ?? 0), pickMany };
6398
6458
  function defaultSetupDeps(env, menu) {
6399
6459
  const { prompts: _loginPrompts, ...login } = defaultLoginDeps(env);
6400
- return { ...login, store: defaultStore(env), exec: spawnExec, menu };
6460
+ return { ...login, store: defaultStore(env), exec: spawnExec, menu, color: process.stdout.isTTY === true && !env.NO_COLOR };
6401
6461
  }
6402
6462
  var PROJECT_ID5 = /^[A-Za-z0-9_-]{1,64}$/;
6403
6463
  async function listProjects2(api, token, fetchImpl) {
@@ -6436,16 +6496,14 @@ async function runSetup(args, io, deps) {
6436
6496
  const state = readSetupState(io.cwd, deps.home);
6437
6497
  if (state.kind === "refused") throw new CliError(state.message);
6438
6498
  say([state.found]);
6499
+ const { work, trust, worktree } = projectFolders(io.cwd);
6500
+ if (state.kind !== "empty" && !isProjectFolder(work) && !isProjectFolder(state.root)) throw new CliError(SETUP_NOT_A_PROJECT);
6501
+ if (state.kind === "other-stack") throw new CliError(REACT_ONLY);
6439
6502
  if (state.kind === "react-fresh" && state.cannotAdd) say([state.cannotAdd, CANNOT_ADD_AGENT_ONLY]);
6440
6503
  if (state.kind === "empty") {
6441
6504
  const choice = await prompts.pick("What do you want to do?", [{ value: "create", label: "Create a new Next.js app here" }, { value: "other", label: "Something else\u2026" }]);
6442
6505
  if (choice === "other") return deps.menu();
6443
- } else if (state.kind === "other-stack") {
6444
- const choice = await prompts.pick("What do you want to do?", [{ value: "files", label: `Add the design system files for ${FRAMEWORK_LABELS[state.framework]}` }, { value: "other", label: "Something else\u2026" }]);
6445
- if (choice === "other") return deps.menu();
6446
6506
  }
6447
- const { work, trust, worktree } = projectFolders(io.cwd);
6448
- if (state.kind !== "empty" && !isProjectFolder(work) && !isProjectFolder(state.root)) throw new CliError(SETUP_NOT_A_PROJECT);
6449
6507
  const api = loginApi(args, true);
6450
6508
  const apps = await chooseApps(work, deps, prompts);
6451
6509
  const saved = await resolveToken({ cwd: io.cwd, store: deps.store, interactive: true, prompt: false });
@@ -6489,8 +6547,14 @@ async function runSetup(args, io, deps) {
6489
6547
  planStopped = true;
6490
6548
  kitLines.push(...lines);
6491
6549
  };
6492
- const pushKit = (r) => r.planStopped ? freeLines(...r.lines) : kitLines.push(...r.lines);
6550
+ const pushKit = (r) => {
6551
+ if (r.planStopped) freeLines(...r.lines);
6552
+ else kitLines.push(...r.lines);
6553
+ };
6493
6554
  const exports = access.kind === "account" ? await exportsAllowed(access.api, access.token, io.fetchImpl) : null;
6555
+ const color = deps.color === true;
6556
+ let kitStep = null;
6557
+ let stop = "kit";
6494
6558
  if (state.kind === "react-set-up") {
6495
6559
  say([SET_UP_STATUS(name, state.components, state.section, state.screens)]);
6496
6560
  const options = [
@@ -6507,47 +6571,89 @@ async function runSetup(args, io, deps) {
6507
6571
  name = chosen.name;
6508
6572
  projectId = chosen.id;
6509
6573
  }
6510
- say([USING(name)]);
6511
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "kit"));
6512
- else pushKit(await addKit(state, access, kitPath(), false, deps, io));
6513
- } else {
6514
- say([USING(name)]);
6515
- if (state.kind === "react-fresh") {
6516
- if (state.cannotAdd === null) {
6517
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "kit"));
6518
- else pushKit(await addKit(state, access, kitPath(), true, deps, io));
6519
- }
6520
- } else if (state.kind === "other-stack") {
6521
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "files"));
6522
- else await (deps.runIntegrate ?? runIntegrate)({ folder: ".", framework: state.framework, api: args.api, apiGiven: args.apiGiven, force: false }, process.env, io, deps.store, deps.accounts);
6523
- } else if (state.kind === "empty") {
6524
- if (exports === false) freeLines(...FREE_PLAN_LINES(access.api, "app"));
6525
- else await (deps.runCreate ?? runCreate)({ folder: ".", api: args.api, apiGiven: args.apiGiven, force: state.onlyGit }, process.env, io, deps.store, deps.accounts);
6526
- writeAgents();
6527
- }
6574
+ kitStep = async () => pushKit(await addKit(state, access, kitPath(), false, deps, io));
6575
+ } else if (state.kind === "react-fresh") {
6576
+ if (state.cannotAdd === null) kitStep = async () => pushKit(await addKit(state, access, kitPath(), true, deps, io));
6577
+ } else if (state.kind === "empty") {
6578
+ stop = "app";
6579
+ kitStep = async () => {
6580
+ await (deps.runCreate ?? runCreate)({ folder: ".", api: args.api, apiGiven: args.apiGiven, force: state.onlyGit }, process.env, io, deps.store, deps.accounts);
6581
+ };
6582
+ }
6583
+ say([USING(name)]);
6584
+ if (kitStep) {
6585
+ if (exports === false && access.kind === "account") {
6586
+ say(FREE_PLAN_LINES(access.api, stop, color));
6587
+ if (await upgradeAndWait(access, deps, prompts, io, say)) await kitStep();
6588
+ else planStopped = true;
6589
+ } else await kitStep();
6528
6590
  }
6591
+ if (state.kind === "empty") writeAgents();
6529
6592
  const noKit = planStopped || state.kind === "react-fresh" && state.cannotAdd !== null;
6530
- const sentence = noKit ? null : state.kind === "other-stack" ? APPLY_SENTENCE : state.kind === "empty" ? null : RESTYLE_SENTENCE;
6593
+ const sentence = noKit ? null : state.kind === "empty" ? null : RESTYLE_SENTENCE;
6531
6594
  say([...kitLines, ...agentLines(), ...sentence ? NEXT_STEP(sentence) : []]);
6532
6595
  function agentLines() {
6533
6596
  const done = agent;
6534
6597
  return [
6535
6598
  ...apps.length === 0 ? [NO_APPS_HERE] : [],
6536
- ...done ? [...done.plans.flatMap(({ id, plan }) => appLines(id, plan)), ...done.kept, ...agentClosing(apps, done.changed)] : []
6599
+ ...done ? agentSummary(done) : []
6537
6600
  ];
6538
6601
  }
6539
6602
  }
6540
6603
  var labelOf2 = (id) => APPS.find((a) => a.id === id).label;
6541
6604
  var listOf2 = (words) => words.length <= 1 ? words.join("") : `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
6542
- function agentClosing(apps, changed) {
6605
+ var APPS_SET_UP = (labels) => `Coding apps: ${listOf2(labels)} ${labels.length === 1 ? "is" : "are"} set up.`;
6606
+ var APPS_WRITTEN = (apps) => `Set up ${listOf2(apps.map((a) => `${a.label} (${a.path})`))}.`;
6607
+ var ALREADY_SET_UP = (labels) => `${listOf2(labels)} ${labels.length === 1 ? "was" : "were"} already set up.`;
6608
+ var COMMIT_THESE = "Commit these files: they hold no token.";
6609
+ function agentSummary(done) {
6610
+ const written = done.plans.filter(({ plan }) => plan.status === "create" || plan.status === "update");
6611
+ const unchanged = done.plans.filter(({ plan }) => plan.status === "unchanged" && !plan.keepsProject);
6612
+ const manual = done.plans.filter(({ plan }) => plan.status === "manual");
6613
+ const envWarnings = unchanged.flatMap(({ id, plan }) => appLines(id, plan).slice(1));
6614
+ if (written.length === 0) {
6615
+ return [
6616
+ ...unchanged.length > 0 ? [APPS_SET_UP(unchanged.map(({ id }) => labelOf2(id)))] : [],
6617
+ ...envWarnings,
6618
+ ...manual.flatMap(({ id, plan }) => appLines(id, plan)),
6619
+ ...done.kept
6620
+ ];
6621
+ }
6622
+ const ids = written.map(({ id }) => id);
6623
+ const notes = [
6624
+ ...ids.includes("claude") ? ["Claude Code asks once to allow it"] : [],
6625
+ ...ids.includes("codex") ? ["Codex needs this project trusted"] : [],
6626
+ ...ids.includes("gemini") ? ["Gemini CLI needs this folder trusted if folder trust is on"] : []
6627
+ ];
6543
6628
  return [
6544
- ...changed.length > 0 ? [`Restart ${listOf2(changed.map(labelOf2))} so ${changed.length === 1 ? "it loads" : "they load"} designsource.`] : [],
6545
- ...apps.includes("claude") ? ["Claude Code asks once to allow the server."] : [],
6546
- ...apps.includes("codex") ? [CODEX_TRUST_NOTE] : [],
6547
- ...apps.includes("gemini") ? [GEMINI_TRUST_NOTE] : [],
6548
- COMMIT_SETTINGS_NOTE
6629
+ APPS_WRITTEN(written.map(({ id, plan }) => ({ label: labelOf2(id), path: plan.path }))),
6630
+ ...unchanged.length > 0 ? [ALREADY_SET_UP(unchanged.map(({ id }) => labelOf2(id)))] : [],
6631
+ ...envWarnings,
6632
+ ...manual.flatMap(({ id, plan }) => appLines(id, plan)),
6633
+ ...done.kept,
6634
+ `Restart ${written.length === 1 ? "it" : "them"} to load designsource.${notes.length > 0 ? ` ${notes.join("; ")}.` : ""}`,
6635
+ COMMIT_THESE
6549
6636
  ];
6550
6637
  }
6638
+ var UPGRADE_QUESTION = "Upgrade to Pro now?";
6639
+ var UPGRADE_WAIT = "Subscribe in the browser. This continues when Pro is on. (Ctrl+C to stop)";
6640
+ var PRO_ON = "Pro is on.";
6641
+ var UPGRADE_TIMEOUT = "Still on the free plan. After upgrading, run npx designsource again.";
6642
+ async function upgradeAndWait(access, deps, prompts, io, say) {
6643
+ const choice = await prompts.pick(UPGRADE_QUESTION, [
6644
+ { value: "upgrade", label: "Upgrade to Pro now (opens the browser)" },
6645
+ { value: "later", label: "Not now" }
6646
+ ]);
6647
+ if (choice !== "upgrade") return false;
6648
+ const on = await openAndPoll(upgradeUrl(access.api), UPGRADE_WAIT, UPGRADE_TIMEOUT, deps, say, async () => {
6649
+ const res = await requestJson({ api: access.api, path: "/api/agent/token", method: "GET", token: access.token }, io.fetchImpl).catch(() => null);
6650
+ if (res?.status === 401) throw new CliError(ACCOUNT_TOKEN_MESSAGE);
6651
+ const exports = res?.status === 200 && typeof res.body === "object" && res.body !== null ? res.body.exports : void 0;
6652
+ return exports === true ? true : void 0;
6653
+ });
6654
+ if (on) say([PRO_ON]);
6655
+ return on === true;
6656
+ }
6551
6657
  async function chooseDesignSystem(access, deps, prompts, io, say) {
6552
6658
  const { projects } = access;
6553
6659
  if (projects.length === 0) return makeNew(access, deps, prompts, io, say);
@@ -6562,31 +6668,35 @@ async function chooseDesignSystem(access, deps, prompts, io, say) {
6562
6668
  return projects.find((p) => `p:${p.id}` === choice) ?? null;
6563
6669
  }
6564
6670
  async function makeNew(access, deps, prompts, io, say) {
6565
- const url = `${access.api}/projects`;
6566
- await (deps.open ?? ((u) => openBrowser(u, deps.platform)))(url);
6567
- say([`Opening ${url}`, MAKE_NEW_WAIT]);
6568
6671
  const known = new Set(access.projects.map((p) => p.id));
6569
- const now = deps.now ?? Date.now;
6570
- const sleep = deps.sleep ?? ((ms) => new Promise((resolve10) => setTimeout(resolve10, ms)));
6571
- const start = now();
6572
- const waitMs = deps.waitMs ?? WAIT_MS;
6573
- while (now() - start < waitMs) {
6574
- await sleep(deps.pollMs ?? POLL_MS);
6672
+ const fresh = await openAndPoll(`${access.api}/projects`, MAKE_NEW_WAIT, WAIT_TIMEOUT, deps, say, async () => {
6575
6673
  let list;
6576
6674
  try {
6577
6675
  list = await listProjects2(access.api, access.token, io.fetchImpl);
6578
6676
  } catch (e) {
6579
6677
  if (e instanceof CliError && e.message === ACCOUNT_TOKEN_MESSAGE) throw e;
6580
- continue;
6581
- }
6582
- const fresh = list.filter((p) => !known.has(p.id));
6583
- if (fresh.length === 1) return fresh[0];
6584
- if (fresh.length > 1) {
6585
- const choice = await prompts.pick("Which new design system?", fresh.map((p) => ({ value: `p:${p.id}`, label: p.name })));
6586
- return fresh.find((p) => `p:${p.id}` === choice) ?? null;
6678
+ return void 0;
6587
6679
  }
6680
+ const added = list.filter((p) => !known.has(p.id));
6681
+ return added.length > 0 ? added : void 0;
6682
+ });
6683
+ if (fresh === null) return null;
6684
+ if (fresh.length === 1) return fresh[0];
6685
+ const choice = await prompts.pick("Which new design system?", fresh.map((p) => ({ value: `p:${p.id}`, label: p.name })));
6686
+ return fresh.find((p) => `p:${p.id}` === choice) ?? null;
6687
+ }
6688
+ async function openAndPoll(url, waiting2, timedOut, deps, say, check) {
6689
+ await (deps.open ?? ((u) => openBrowser(u, deps.platform)))(url);
6690
+ say([`Opening ${url}`, waiting2]);
6691
+ const now = deps.now ?? Date.now;
6692
+ const sleep = deps.sleep ?? ((ms) => new Promise((resolve10) => setTimeout(resolve10, ms)));
6693
+ const start = now();
6694
+ while (now() - start < (deps.waitMs ?? WAIT_MS)) {
6695
+ await sleep(deps.pollMs ?? POLL_MS);
6696
+ const found = await check();
6697
+ if (found !== void 0) return found;
6588
6698
  }
6589
- say([WAIT_TIMEOUT]);
6699
+ say([timedOut]);
6590
6700
  return null;
6591
6701
  }
6592
6702
  async function addKit(state, access, kitPath, fresh, deps, io) {
@@ -6610,21 +6720,22 @@ async function addKit(state, access, kitPath, fresh, deps, io) {
6610
6720
  `) }
6611
6721
  );
6612
6722
  } catch (e) {
6613
- if (e instanceof CliError && e.message === PLAN_MESSAGE) return { lines: FREE_PLAN_LINES(access.api, "kit"), planStopped: true };
6723
+ if (e instanceof CliError && e.message === PLAN_MESSAGE) return { lines: FREE_PLAN_LINES(access.api, "kit", deps.color === true), planStopped: true };
6614
6724
  throw e;
6615
6725
  }
6616
6726
  const hint = result.section && result.section.blocks === 0 && !result.section.blocksLeftInPlace ? [BLOCKS_HINT] : [];
6617
6727
  return { lines: [...summaryLines(result), ...hint], planStopped: false };
6618
6728
  }
6619
6729
 
6620
- // src/index.ts
6730
+ // src/menu.ts
6621
6731
  var MENU = [
6622
6732
  { value: "add", label: "Add the UI kit to a React app", hint: "your components and theme, set up for you" },
6623
6733
  { value: "connect", label: "Connect your coding apps", hint: "Claude Code, Cursor, VS Code and more" },
6624
6734
  { value: "login", label: "Sign in for coding agents", hint: "lets your agent create design systems" },
6625
- { value: "integrate", label: "Add to an existing project", hint: "writes design-system/ \u2014 tokens, prompt, reference kit" },
6626
6735
  { value: "create", label: "Create a new project", hint: "a Next.js app with every component and your mockup page" }
6627
6736
  ];
6737
+
6738
+ // src/index.ts
6628
6739
  async function main(argv, env, io) {
6629
6740
  let command;
6630
6741
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "designsource",
3
- "version": "0.15.0",
3
+ "version": "0.16.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": {