designsource 0.6.0 → 0.6.1

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 (3) hide show
  1. package/README.md +3 -3
  2. package/dist/index.js +94 -75
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -267,11 +267,11 @@ For the MCP server, add it to Claude Code with `claude mcp add designsource -e D
267
267
  By the maintainer, through GitHub Actions with npm trusted publishing: no npm token exists anywhere; npm accepts the release because GitHub vouches for the repository and workflow that built it. Nothing publishes on an ordinary push or merge. (npm attaches a provenance attestation only when the source repository is public, so while this one is private the releases carry none.)
268
268
 
269
269
  1. Bump the version in `package.json` (`pnpm version patch|minor` here) and merge to `main`. Every publish needs a bump.
270
- 2. Rehearse, optionally: Actions → "Release designsource" → Run workflow with dry run on. It installs, builds, tests and packs without publishing.
271
- 3. Tag the merge commit `designsource@<version>` and push the tag:
270
+ 2. Rehearse, optionally: Actions → "Release designsource" → Run workflow. A manual run installs, builds, tests and packs, and never publishes, from any branch.
271
+ 3. Tag the merge commit on `main` `designsource@<version>` and push the tag (a tag on any other commit stops the run):
272
272
 
273
273
  ```sh
274
- git tag designsource@0.6.0 && git push origin designsource@0.6.0
274
+ git tag designsource@0.6.1 && git push origin designsource@0.6.1
275
275
  ```
276
276
 
277
277
  The workflow (`.github/workflows/release-designsource.yml`) refuses a tag that does not match `package.json`, runs the tests (which build `dist/` first), publishes, then installs the published version from npm and runs `--help` against it.
package/dist/index.js CHANGED
@@ -1226,14 +1226,14 @@ function quoteArg(arg) {
1226
1226
  function childEnv(env) {
1227
1227
  return Object.fromEntries(Object.entries(env).filter(([name]) => name.toUpperCase() !== "DS_SYNC_TOKEN"));
1228
1228
  }
1229
- var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promise((resolve6) => {
1229
+ var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promise((resolve7) => {
1230
1230
  let output = "";
1231
1231
  let child;
1232
1232
  try {
1233
1233
  const shell = process.platform === "win32";
1234
1234
  child = spawn(cmd, shell ? args.map(quoteArg) : args, { cwd, env: childEnv(process.env), stdio: [input === void 0 ? "ignore" : "pipe", "pipe", "pipe"], shell });
1235
1235
  } catch (e) {
1236
- resolve6({ code: 127, output: e instanceof Error ? e.message : String(e) });
1236
+ resolve7({ code: 127, output: e instanceof Error ? e.message : String(e) });
1237
1237
  return;
1238
1238
  }
1239
1239
  let timedOut = false;
@@ -1243,7 +1243,7 @@ var spawnExec = (cmd, args, { cwd, timeoutMs, input, stdoutOnly }) => new Promis
1243
1243
  }, timeoutMs);
1244
1244
  const done = (result) => {
1245
1245
  if (timer) clearTimeout(timer);
1246
- resolve6(timedOut ? { code: result.code === 0 ? 124 : result.code, output: `${result.output.trimEnd()}
1246
+ resolve7(timedOut ? { code: result.code === 0 ? 124 : result.code, output: `${result.output.trimEnd()}
1247
1247
  timed out after ${timeoutMs / 1e3}s` } : result);
1248
1248
  };
1249
1249
  child.stdout?.on("data", (chunk) => {
@@ -1886,6 +1886,34 @@ function readDarkMarker(css) {
1886
1886
  return { marker: DEFAULT_MARKER, known: false, selector };
1887
1887
  }
1888
1888
 
1889
+ // src/http.ts
1890
+ var FETCH_TIMEOUT_MS = 3e4;
1891
+ var ApiError = class extends CliError {
1892
+ constructor(message, status) {
1893
+ super(message);
1894
+ Object.defineProperty(this, "status", { value: status, enumerable: false });
1895
+ }
1896
+ };
1897
+ async function getJson(opts, fetchImpl = fetch) {
1898
+ const url = new URL(opts.path, `${opts.api}/`);
1899
+ for (const [k, v] of Object.entries(opts.query ?? {})) url.searchParams.set(k, v);
1900
+ const signal = AbortSignal.timeout(FETCH_TIMEOUT_MS);
1901
+ let res;
1902
+ try {
1903
+ res = await fetchImpl(url.toString(), { headers: { Authorization: `Bearer ${opts.token}`, Accept: "application/json" }, signal });
1904
+ } catch {
1905
+ throw new ApiError(UNREACHABLE(opts.api), null);
1906
+ }
1907
+ let body = null;
1908
+ try {
1909
+ body = await res.json();
1910
+ } catch {
1911
+ if (signal.aborted) throw new ApiError(UNREACHABLE(opts.api), null);
1912
+ }
1913
+ if (!res.ok) throw new ApiError(messageForResponse(res.status, body, opts.api), res.status);
1914
+ return body;
1915
+ }
1916
+
1889
1917
  // src/add/kit-manifest.ts
1890
1918
  var malformed = () => new CliError("Unexpected response from the API \u2014 not a kit manifest.");
1891
1919
  var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -1931,16 +1959,7 @@ function validateKitManifest(json) {
1931
1959
 
1932
1960
  // src/add/fetch-kit.ts
1933
1961
  async function fetchKit(opts, fetchImpl = fetch) {
1934
- const url = new URL("/api/kit", `${opts.api}/`);
1935
- let res;
1936
- try {
1937
- res = await fetchImpl(url.toString(), { headers: { Authorization: `Bearer ${opts.token}`, Accept: "application/json" } });
1938
- } catch {
1939
- throw new CliError(UNREACHABLE(opts.api));
1940
- }
1941
- const body = await res.json().catch(() => null);
1942
- if (!res.ok) throw new CliError(messageForResponse(res.status, body, opts.api));
1943
- return validateKitManifest(body);
1962
+ return validateKitManifest(await getJson({ api: opts.api, token: opts.token, path: "/api/kit" }, fetchImpl));
1944
1963
  }
1945
1964
 
1946
1965
  // src/add/plan-packages.ts
@@ -2629,10 +2648,10 @@ function nextLine() {
2629
2648
  if (line !== void 0) return Promise.resolve(line);
2630
2649
  if (closed) return Promise.reject(new CliError(EOF_MESSAGE));
2631
2650
  process.stdin.ref?.();
2632
- return new Promise((resolve6, reject) => waiting.push({
2651
+ return new Promise((resolve7, reject) => waiting.push({
2633
2652
  resolve: (line2) => {
2634
2653
  process.stdin.unref?.();
2635
- resolve6(line2);
2654
+ resolve7(line2);
2636
2655
  },
2637
2656
  reject: (err) => {
2638
2657
  process.stdin.unref?.();
@@ -2745,7 +2764,7 @@ function pickTty(question, options, start, stdin, stdout) {
2745
2764
  stdin.resume();
2746
2765
  stdout.write("\x1B[?25l");
2747
2766
  draw([question, ...rows()]);
2748
- return new Promise((resolve6, reject) => {
2767
+ return new Promise((resolve7, reject) => {
2749
2768
  const finish = (after) => {
2750
2769
  stdin.off("keypress", onKey);
2751
2770
  stdin.setRawMode(false);
@@ -2766,7 +2785,7 @@ function pickTty(question, options, start, stdin, stdout) {
2766
2785
  stdout.write(`\r\x1B[J${question} ${chosen.label}
2767
2786
  `);
2768
2787
  });
2769
- resolve6(chosen.value);
2788
+ resolve7(chosen.value);
2770
2789
  return;
2771
2790
  }
2772
2791
  if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
@@ -2798,7 +2817,7 @@ function pickManyTty(question, options, preselected, stdin, stdout) {
2798
2817
  stdin.resume();
2799
2818
  stdout.write("\x1B[?25l");
2800
2819
  draw([head, ...rows()]);
2801
- return new Promise((resolve6, reject) => {
2820
+ return new Promise((resolve7, reject) => {
2802
2821
  const finish = (after) => {
2803
2822
  stdin.off("keypress", onKey);
2804
2823
  stdin.setRawMode(false);
@@ -2819,7 +2838,7 @@ function pickManyTty(question, options, preselected, stdin, stdout) {
2819
2838
  stdout.write(`\r\x1B[J${question} ${chosen.length > 0 ? chosen.map((o) => o.label).join(", ") : "none"}
2820
2839
  `);
2821
2840
  });
2822
- resolve6(chosen.map((o) => o.value));
2841
+ resolve7(chosen.map((o) => o.value));
2823
2842
  return;
2824
2843
  }
2825
2844
  if (key.name === "up" || str === "k") index = (index - 1 + n) % n;
@@ -2834,6 +2853,9 @@ function pickManyTty(question, options, preselected, stdin, stdout) {
2834
2853
  });
2835
2854
  }
2836
2855
 
2856
+ // src/commands/scaffold.ts
2857
+ import { resolve as resolve4 } from "node:path";
2858
+
2837
2859
  // src/connect/resolve-token.ts
2838
2860
  import { homedir } from "node:os";
2839
2861
 
@@ -3039,18 +3061,8 @@ function validateManifest(json) {
3039
3061
 
3040
3062
  // src/fetch-manifest.ts
3041
3063
  async function fetchManifest(opts, fetchImpl = fetch) {
3042
- const url = new URL("/api/starter", `${opts.api}/`);
3043
- url.searchParams.set("framework", opts.framework);
3044
- if (opts.name) url.searchParams.set("name", opts.name);
3045
- let res;
3046
- try {
3047
- res = await fetchImpl(url.toString(), { headers: { Authorization: `Bearer ${opts.token}`, Accept: "application/json" } });
3048
- } catch {
3049
- throw new CliError(UNREACHABLE(opts.api));
3050
- }
3051
- const body = await res.json().catch(() => null);
3052
- if (!res.ok) throw new CliError(messageForResponse(res.status, body, opts.api));
3053
- return validateManifest(body);
3064
+ const query = { framework: opts.framework, ...opts.name ? { name: opts.name } : {} };
3065
+ return validateManifest(await getJson({ api: opts.api, token: opts.token, path: "/api/starter", query }, fetchImpl));
3054
3066
  }
3055
3067
 
3056
3068
  // src/package-name.ts
@@ -3071,12 +3083,12 @@ function detectRunner(userAgent) {
3071
3083
  }
3072
3084
  var INSTALL = { pnpm: "pnpm install", npm: "npm install", yarn: "yarn", bun: "bun install" };
3073
3085
  var DEV = { pnpm: "pnpm dev", npm: "npm run dev", yarn: "yarn dev", bun: "bun dev" };
3074
- function nextStepsText({ runner, framework, folder, created }) {
3086
+ function nextStepsText({ runner, framework, folder, here }) {
3075
3087
  const lines = ["Next steps:"];
3076
3088
  if (framework === "next") {
3077
- if (created) lines.push(` cd ${folder}`);
3089
+ if (!here) lines.push(` cd ${folder}`);
3078
3090
  lines.push(` ${INSTALL[runner]}`, ` ${DEV[runner]}`);
3079
- } else if (folder === ".") {
3091
+ } else if (here) {
3080
3092
  lines.push(" Open design-system/PROMPT.md and paste it into your coding agent.");
3081
3093
  } else {
3082
3094
  lines.push(` Open ${folder}/design-system/PROMPT.md and paste it into your coding agent, run from ${folder}.`);
@@ -3118,7 +3130,7 @@ async function scaffold(input, env, io) {
3118
3130
  ${written.map((p) => ` ${p}`).join("\n")}
3119
3131
 
3120
3132
  `);
3121
- io.stdout(nextStepsText({ runner, framework, folder, created }));
3133
+ io.stdout(nextStepsText({ runner, framework, folder, here: root === resolve4(io.cwd) }));
3122
3134
  }
3123
3135
 
3124
3136
  // src/commands/add.ts
@@ -3197,16 +3209,13 @@ var RejectedTokenError = class extends CliError {
3197
3209
  };
3198
3210
  var malformed3 = () => new CliError("Unexpected response from the API \u2014 not a project.");
3199
3211
  async function fetchProject(opts, fetchImpl = fetch) {
3200
- const url = new URL("/api/project", `${opts.api}/`);
3201
- let res;
3212
+ let body;
3202
3213
  try {
3203
- res = await fetchImpl(url.toString(), { headers: { Authorization: `Bearer ${opts.token}`, Accept: "application/json" } });
3204
- } catch {
3205
- throw new CliError(UNREACHABLE(opts.api));
3214
+ body = await getJson({ api: opts.api, token: opts.token, path: "/api/project" }, fetchImpl);
3215
+ } catch (e) {
3216
+ if (e instanceof ApiError && e.status === 401) throw new RejectedTokenError();
3217
+ throw e;
3206
3218
  }
3207
- const body = await res.json().catch(() => null);
3208
- if (res.status === 401) throw new RejectedTokenError();
3209
- if (!res.ok) throw new CliError(messageForResponse(res.status, body, opts.api));
3210
3219
  if (typeof body !== "object" || body === null) throw malformed3();
3211
3220
  const { id, name } = body;
3212
3221
  if (typeof id !== "string" || typeof name !== "string") throw malformed3();
@@ -3216,13 +3225,13 @@ async function fetchProject(opts, fetchImpl = fetch) {
3216
3225
 
3217
3226
  // src/connect/project-root.ts
3218
3227
  import { existsSync as existsSync9 } from "node:fs";
3219
- import { dirname as dirname3, isAbsolute as isAbsolute3, join as join7, relative as relative3, resolve as resolve4, sep as sep3 } from "node:path";
3228
+ import { dirname as dirname3, isAbsolute as isAbsolute3, join as join7, relative as relative3, resolve as resolve5, sep as sep3 } from "node:path";
3220
3229
  function projectRoot(cwd, exists = existsSync9) {
3221
- let dir = resolve4(cwd);
3230
+ let dir = resolve5(cwd);
3222
3231
  for (; ; ) {
3223
3232
  if (exists(join7(dir, ".git"))) return dir;
3224
3233
  const parent = dirname3(dir);
3225
- if (parent === dir) return resolve4(cwd);
3234
+ if (parent === dir) return resolve5(cwd);
3226
3235
  dir = parent;
3227
3236
  }
3228
3237
  }
@@ -3231,8 +3240,8 @@ function within2(folder, root) {
3231
3240
  return rel === "" || rel !== ".." && !rel.startsWith(`..${sep3}`) && !isAbsolute3(rel);
3232
3241
  }
3233
3242
  function homeFolderRefusal(root, home) {
3234
- const folder = resolve4(root);
3235
- const homeDir = resolve4(home);
3243
+ const folder = resolve5(root);
3244
+ const homeDir = resolve5(home);
3236
3245
  const tail = "and writing there would set up every project on this computer.";
3237
3246
  if (folder === homeDir) return `Run this in your project folder \u2014 ${folder} is your home folder, ${tail}`;
3238
3247
  if (dirname3(folder) === folder || within2(homeDir, folder)) return `Run this in your project folder \u2014 ${folder} is a system folder, ${tail}`;
@@ -3417,13 +3426,11 @@ async function runIntegrate(args, env, io, store) {
3417
3426
  await scaffold({ folder, framework, token, api: apiFor(args, saved?.entry), force: args.force }, env, io);
3418
3427
  }
3419
3428
 
3420
- // src/mcp/server.ts
3421
- import { createInterface as createInterface2 } from "node:readline";
3422
-
3423
3429
  // src/version.ts
3424
- var VERSION = true ? "0.6.0" : "0.0.0-dev";
3430
+ var VERSION = true ? "0.6.1" : "0.0.0-dev";
3425
3431
 
3426
3432
  // src/mcp/jsonrpc.ts
3433
+ import { StringDecoder } from "node:string_decoder";
3427
3434
  var PARSE_ERROR = -32700;
3428
3435
  var INVALID_REQUEST = -32600;
3429
3436
  var METHOD_NOT_FOUND = -32601;
@@ -3465,6 +3472,21 @@ function parseLine(line) {
3465
3472
  if (params !== void 0) message.params = params;
3466
3473
  return { kind: "notification", message };
3467
3474
  }
3475
+ async function* readLines(input) {
3476
+ const decoder = new StringDecoder("utf8");
3477
+ let buffered = "";
3478
+ for await (const chunk of input) {
3479
+ buffered += typeof chunk === "string" ? chunk : decoder.write(chunk);
3480
+ let end;
3481
+ while ((end = buffered.indexOf("\n")) !== -1) {
3482
+ const line = buffered.slice(0, end);
3483
+ buffered = buffered.slice(end + 1);
3484
+ yield line.endsWith("\r") ? line.slice(0, -1) : line;
3485
+ }
3486
+ }
3487
+ buffered += decoder.end();
3488
+ if (buffered) yield buffered.endsWith("\r") ? buffered.slice(0, -1) : buffered;
3489
+ }
3468
3490
 
3469
3491
  // src/mcp/prompts.ts
3470
3492
  var INTEGRATE_PROMPT_NAME = "integrate-design-system";
@@ -3478,7 +3500,7 @@ function getPrompt(name) {
3478
3500
  }
3479
3501
 
3480
3502
  // src/mcp/project-folder.ts
3481
- import { isAbsolute as isAbsolute4, relative as relative4, resolve as resolve5, sep as sep4 } from "node:path";
3503
+ import { isAbsolute as isAbsolute4, relative as relative4, resolve as resolve6, sep as sep4 } from "node:path";
3482
3504
  var NOT_SURE_WHICH_FOLDER = "Not sure which project folder to change: run npx designsource connect in it first.";
3483
3505
  function isWithin2(folder, root) {
3484
3506
  const rel = relative4(root, folder);
@@ -3486,10 +3508,10 @@ function isWithin2(folder, root) {
3486
3508
  }
3487
3509
  function resolveProjectFolder(cwd, entry) {
3488
3510
  if (!entry) return cwd;
3489
- const here = resolve5(cwd);
3490
- const holding = entry.folders.map((f) => resolve5(f)).filter((f) => isWithin2(here, f)).sort((a, b) => b.length - a.length);
3511
+ const here = resolve6(cwd);
3512
+ const holding = entry.folders.map((f) => resolve6(f)).filter((f) => isWithin2(here, f)).sort((a, b) => b.length - a.length);
3491
3513
  if (holding[0]) return holding[0];
3492
- return entry.folders.length === 1 ? resolve5(entry.folders[0]) : null;
3514
+ return entry.folders.length === 1 ? resolve6(entry.folders[0]) : null;
3493
3515
  }
3494
3516
 
3495
3517
  // src/mcp/tools.ts
@@ -3795,36 +3817,32 @@ function validateSnapshot(json) {
3795
3817
  if (blocks.header !== void 0 && typeof blocks.header !== "string") return { ...json, blocks: { ...blocks, header: void 0 } };
3796
3818
  return json;
3797
3819
  }
3798
- var FETCH_TIMEOUT_MS = 3e4;
3799
3820
  async function fetchSnapshot(opts, fetchImpl = fetch) {
3800
- const url = new URL("/api/snapshot", `${opts.api}/`);
3801
- let res;
3802
- try {
3803
- res = await fetchImpl(url.toString(), {
3804
- headers: { Authorization: `Bearer ${opts.token}`, Accept: "application/json" },
3805
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
3806
- });
3807
- } catch {
3808
- throw new CliError(UNREACHABLE(opts.api));
3809
- }
3810
- const body = await res.json().catch(() => null);
3811
- if (!res.ok) throw new CliError(messageForResponse(res.status, body, opts.api));
3812
- return validateSnapshot(body);
3821
+ return validateSnapshot(await getJson({ api: opts.api, token: opts.token, path: "/api/snapshot" }, fetchImpl));
3813
3822
  }
3823
+ var STALE_RETRY_MS = 15e3;
3824
+ var servesStale = (e) => !(e instanceof ApiError) || e.status === null || e.status >= 500;
3814
3825
  function createSnapshotCache(fetcher, opts = {}) {
3815
3826
  const ttl = opts.ttlMs ?? 6e4;
3816
3827
  const now = opts.now ?? Date.now;
3828
+ const retry = opts.retryMs ?? STALE_RETRY_MS;
3817
3829
  let cached = null;
3818
3830
  let inflight = null;
3831
+ let retryAt = 0;
3819
3832
  return {
3820
3833
  get() {
3821
- if (cached && now() - cached.fetchedAt < ttl) return Promise.resolve(cached);
3834
+ if (cached && (now() - cached.fetchedAt < ttl || now() < retryAt)) return Promise.resolve(cached);
3822
3835
  if (inflight) return inflight;
3823
3836
  inflight = fetcher().then((snapshot) => {
3824
3837
  cached = { snapshot, fetchedAt: now() };
3838
+ retryAt = 0;
3825
3839
  return cached;
3826
3840
  }).catch((e) => {
3827
- if (!cached) throw e;
3841
+ if (!cached || !servesStale(e)) {
3842
+ cached = null;
3843
+ throw e;
3844
+ }
3845
+ retryAt = now() + retry;
3828
3846
  opts.warn?.(`Could not refresh the design system; serving the snapshot from ${new Date(cached.fetchedAt).toISOString()}: ${e instanceof Error ? e.message : String(e)}`);
3829
3847
  return cached;
3830
3848
  }).finally(() => {
@@ -3861,11 +3879,12 @@ async function runMcp(args, io, streams = { input: process.stdin, output: proces
3861
3879
  }
3862
3880
  }, { warn });
3863
3881
  const protocol = { version: VERSION, snapshot: () => cache.get(), warn, context: session };
3864
- const lines = createInterface2({ input: streams.input, crlfDelay: Infinity });
3882
+ let closed2 = false;
3865
3883
  streams.output.on("error", () => {
3866
- lines.close();
3884
+ closed2 = true;
3867
3885
  });
3868
- for await (const raw of lines) {
3886
+ for await (const raw of readLines(streams.input)) {
3887
+ if (closed2) break;
3869
3888
  const line = raw.trim();
3870
3889
  if (!line) continue;
3871
3890
  const response = await handle(parseLine(line), protocol);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "designsource",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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": {