rafters 0.0.2 → 0.0.4

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 +257 -124
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1225,10 +1225,10 @@ var initializer = (inst, def) => {
1225
1225
  };
1226
1226
  var $ZodError = $constructor("$ZodError", initializer);
1227
1227
  var $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
1228
- function flattenError(error47, mapper = (issue2) => issue2.message) {
1228
+ function flattenError(error48, mapper = (issue2) => issue2.message) {
1229
1229
  const fieldErrors = {};
1230
1230
  const formErrors = [];
1231
- for (const sub of error47.issues) {
1231
+ for (const sub of error48.issues) {
1232
1232
  if (sub.path.length > 0) {
1233
1233
  fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1234
1234
  fieldErrors[sub.path[0]].push(mapper(sub));
@@ -1238,10 +1238,10 @@ function flattenError(error47, mapper = (issue2) => issue2.message) {
1238
1238
  }
1239
1239
  return { formErrors, fieldErrors };
1240
1240
  }
1241
- function formatError(error47, mapper = (issue2) => issue2.message) {
1241
+ function formatError(error48, mapper = (issue2) => issue2.message) {
1242
1242
  const fieldErrors = { _errors: [] };
1243
- const processError = (error48) => {
1244
- for (const issue2 of error48.issues) {
1243
+ const processError = (error49) => {
1244
+ for (const issue2 of error49.issues) {
1245
1245
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1246
1246
  issue2.errors.map((issues) => processError({ issues }));
1247
1247
  } else if (issue2.code === "invalid_key") {
@@ -1268,14 +1268,14 @@ function formatError(error47, mapper = (issue2) => issue2.message) {
1268
1268
  }
1269
1269
  }
1270
1270
  };
1271
- processError(error47);
1271
+ processError(error48);
1272
1272
  return fieldErrors;
1273
1273
  }
1274
- function treeifyError(error47, mapper = (issue2) => issue2.message) {
1274
+ function treeifyError(error48, mapper = (issue2) => issue2.message) {
1275
1275
  const result = { errors: [] };
1276
- const processError = (error48, path2 = []) => {
1276
+ const processError = (error49, path2 = []) => {
1277
1277
  var _a, _b;
1278
- for (const issue2 of error48.issues) {
1278
+ for (const issue2 of error49.issues) {
1279
1279
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1280
1280
  issue2.errors.map((issues) => processError({ issues }, issue2.path));
1281
1281
  } else if (issue2.code === "invalid_key") {
@@ -1310,7 +1310,7 @@ function treeifyError(error47, mapper = (issue2) => issue2.message) {
1310
1310
  }
1311
1311
  }
1312
1312
  };
1313
- processError(error47);
1313
+ processError(error48);
1314
1314
  return result;
1315
1315
  }
1316
1316
  function toDotPath(_path) {
@@ -1331,9 +1331,9 @@ function toDotPath(_path) {
1331
1331
  }
1332
1332
  return segs.join("");
1333
1333
  }
1334
- function prettifyError(error47) {
1334
+ function prettifyError(error48) {
1335
1335
  const lines = [];
1336
- const issues = [...error47.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
1336
+ const issues = [...error48.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
1337
1337
  for (const issue2 of issues) {
1338
1338
  lines.push(`\u2716 ${issue2.message}`);
1339
1339
  if (issue2.path?.length)
@@ -12719,9 +12719,140 @@ function getRaftersPaths(projectRoot = process.cwd()) {
12719
12719
  };
12720
12720
  }
12721
12721
 
12722
+ // src/utils/ui.ts
12723
+ import ora from "ora";
12724
+ var context = {
12725
+ agent: false,
12726
+ spinner: null
12727
+ };
12728
+ function setAgentMode(agent) {
12729
+ context.agent = agent;
12730
+ }
12731
+ function log(event) {
12732
+ if (context.agent) {
12733
+ console.log(event);
12734
+ return;
12735
+ }
12736
+ const eventType = event.event;
12737
+ switch (eventType) {
12738
+ // Init events
12739
+ case "init:start":
12740
+ context.spinner = ora("Initializing rafters...").start();
12741
+ break;
12742
+ case "init:detected":
12743
+ context.spinner?.succeed("Project detected");
12744
+ console.log(` Framework: ${event.framework}`);
12745
+ console.log(` Tailwind: v${event.tailwindVersion}`);
12746
+ if (event.hasShadcn) {
12747
+ console.log(" shadcn/ui: detected");
12748
+ }
12749
+ context.spinner = ora("Generating tokens...").start();
12750
+ break;
12751
+ case "init:shadcn_detected":
12752
+ context.spinner?.info("Found existing shadcn colors");
12753
+ console.log(` Backed up: ${event.backupPath}`);
12754
+ const colors = event.colorsFound;
12755
+ console.log(` Colors: ${colors.light} light, ${colors.dark} dark`);
12756
+ context.spinner = ora("Generating tokens...").start();
12757
+ break;
12758
+ case "init:generated":
12759
+ context.spinner?.succeed(`Generated ${event.tokenCount} tokens`);
12760
+ context.spinner = ora("Saving registry...").start();
12761
+ break;
12762
+ case "init:registry_saved":
12763
+ context.spinner?.succeed(`Saved ${event.namespaceCount} namespaces`);
12764
+ break;
12765
+ case "init:css_updated":
12766
+ console.log(` Updated: ${event.cssPath}`);
12767
+ break;
12768
+ case "init:css_not_found":
12769
+ console.log(`
12770
+ Note: ${event.message}`);
12771
+ break;
12772
+ case "init:css_already_imported":
12773
+ console.log(` CSS already configured: ${event.cssPath}`);
12774
+ break;
12775
+ case "init:regenerate":
12776
+ context.spinner = ora("Regenerating from existing config...").start();
12777
+ break;
12778
+ case "init:loaded":
12779
+ context.spinner?.succeed(`Loaded ${event.tokenCount} tokens`);
12780
+ context.spinner = ora("Generating outputs...").start();
12781
+ break;
12782
+ case "init:colors_imported":
12783
+ console.log(` Imported ${event.count} existing colors`);
12784
+ break;
12785
+ case "init:complete":
12786
+ context.spinner?.succeed("Done!");
12787
+ console.log(`
12788
+ Output: ${event.path}`);
12789
+ const outputs = event.outputs;
12790
+ for (const file2 of outputs) {
12791
+ console.log(` - ${file2}`);
12792
+ }
12793
+ console.log("");
12794
+ break;
12795
+ // Add events
12796
+ case "add:start":
12797
+ const components = event.components;
12798
+ context.spinner = ora(`Adding ${components.join(", ")}...`).start();
12799
+ break;
12800
+ case "add:installed":
12801
+ context.spinner?.succeed(`Installed ${event.component}`);
12802
+ const files = event.files;
12803
+ for (const file2 of files) {
12804
+ console.log(` ${file2}`);
12805
+ }
12806
+ context.spinner = ora("Installing...").start();
12807
+ break;
12808
+ case "add:skip":
12809
+ context.spinner?.warn(`Skipped ${event.component} (already exists)`);
12810
+ context.spinner = ora("Installing...").start();
12811
+ break;
12812
+ case "add:dependencies":
12813
+ if (context.spinner) {
12814
+ context.spinner.text = "Installing dependencies...";
12815
+ }
12816
+ break;
12817
+ case "add:complete":
12818
+ context.spinner?.succeed(
12819
+ `Added ${event.installed} component${event.installed !== 1 ? "s" : ""}`
12820
+ );
12821
+ if (event.skipped > 0) {
12822
+ console.log(` Skipped: ${event.skipped} (use --overwrite to replace)`);
12823
+ }
12824
+ console.log("");
12825
+ break;
12826
+ case "add:hint":
12827
+ console.log(`
12828
+ ${event.message}`);
12829
+ break;
12830
+ case "add:warning":
12831
+ console.warn(` Warning: ${event.message}`);
12832
+ break;
12833
+ case "add:error":
12834
+ context.spinner?.fail(event.message);
12835
+ break;
12836
+ default:
12837
+ if (context.spinner) {
12838
+ context.spinner.text = eventType;
12839
+ } else {
12840
+ console.log(event);
12841
+ }
12842
+ }
12843
+ }
12844
+ function error46(message) {
12845
+ if (context.agent) {
12846
+ console.error({ event: "error", message });
12847
+ return;
12848
+ }
12849
+ context.spinner?.fail(message);
12850
+ context.spinner = null;
12851
+ }
12852
+
12722
12853
  // src/utils/update-dependencies.ts
12723
12854
  import { execa } from "execa";
12724
- import ora from "ora";
12855
+ import ora2 from "ora";
12725
12856
 
12726
12857
  // src/utils/get-package-manager.ts
12727
12858
  import { detect } from "@antfu/ni";
@@ -12755,7 +12886,7 @@ async function updateDependencies(dependencies, devDependencies, options) {
12755
12886
  return;
12756
12887
  }
12757
12888
  const packageManager = await getPackageManager(cwd, { withFallback: true });
12758
- const spinner = silent3 ? null : ora("Installing dependencies...").start();
12889
+ const spinner = silent3 ? null : ora2("Installing dependencies...").start();
12759
12890
  try {
12760
12891
  if (deps.length > 0) {
12761
12892
  await installWithPackageManager(packageManager, deps, { cwd, dev: false });
@@ -12764,9 +12895,9 @@ async function updateDependencies(dependencies, devDependencies, options) {
12764
12895
  await installWithPackageManager(packageManager, devDeps, { cwd, dev: true });
12765
12896
  }
12766
12897
  spinner?.succeed("Dependencies installed.");
12767
- } catch (error47) {
12898
+ } catch (error48) {
12768
12899
  spinner?.fail("Failed to install dependencies.");
12769
- throw error47;
12900
+ throw error48;
12770
12901
  }
12771
12902
  }
12772
12903
  async function installWithPackageManager(packageManager, dependencies, options) {
@@ -12825,7 +12956,7 @@ async function installItem(cwd, item, options) {
12825
12956
  const targetPath = join2(cwd, file2.path);
12826
12957
  if (fileExists(cwd, file2.path)) {
12827
12958
  if (!options.overwrite) {
12828
- console.log({
12959
+ log({
12829
12960
  event: "add:skip",
12830
12961
  component: item.name,
12831
12962
  file: file2.path,
@@ -12862,19 +12993,20 @@ function collectDependencies(items) {
12862
12993
  };
12863
12994
  }
12864
12995
  async function add(components, options) {
12996
+ setAgentMode(options.agent ?? false);
12865
12997
  const cwd = process.cwd();
12866
12998
  const initialized = await isInitialized(cwd);
12867
12999
  if (!initialized) {
12868
- console.error("Error: Project not initialized. Run `rafters init` first.");
13000
+ error46("Project not initialized. Run `rafters init` first.");
12869
13001
  process.exitCode = 1;
12870
13002
  return;
12871
13003
  }
12872
13004
  if (components.length === 0) {
12873
- console.error("Error: No components specified. Usage: rafters add <component...>");
13005
+ error46("No components specified. Usage: rafters add <component...>");
12874
13006
  process.exitCode = 1;
12875
13007
  return;
12876
13008
  }
12877
- console.log({
13009
+ log({
12878
13010
  event: "add:start",
12879
13011
  cwd,
12880
13012
  components,
@@ -12889,9 +13021,9 @@ async function add(components, options) {
12889
13021
  allItems.push(...items);
12890
13022
  } catch (err) {
12891
13023
  if (err instanceof Error) {
12892
- console.error(`Error: ${err.message}`);
13024
+ error46(err.message);
12893
13025
  } else {
12894
- console.error(`Error: Failed to fetch component "${componentName}"`);
13026
+ error46(`Failed to fetch component "${componentName}"`);
12895
13027
  }
12896
13028
  process.exitCode = 1;
12897
13029
  return;
@@ -12904,7 +13036,7 @@ async function add(components, options) {
12904
13036
  const result = await installItem(cwd, item, options);
12905
13037
  if (result.installed) {
12906
13038
  installed.push(item.name);
12907
- console.log({
13039
+ log({
12908
13040
  event: "add:installed",
12909
13041
  component: item.name,
12910
13042
  type: item.type,
@@ -12916,7 +13048,7 @@ async function add(components, options) {
12916
13048
  }
12917
13049
  } catch (err) {
12918
13050
  if (err instanceof Error) {
12919
- console.warn({
13051
+ log({
12920
13052
  event: "add:warning",
12921
13053
  component: item.name,
12922
13054
  message: err.message
@@ -12926,7 +13058,7 @@ async function add(components, options) {
12926
13058
  }
12927
13059
  const { dependencies, devDependencies } = collectDependencies(allItems);
12928
13060
  if (dependencies.length > 0 || devDependencies.length > 0) {
12929
- console.log({
13061
+ log({
12930
13062
  event: "add:dependencies",
12931
13063
  dependencies,
12932
13064
  devDependencies
@@ -12934,21 +13066,21 @@ async function add(components, options) {
12934
13066
  try {
12935
13067
  await updateDependencies(dependencies, devDependencies, { cwd });
12936
13068
  } catch (err) {
12937
- console.error({
13069
+ log({
12938
13070
  event: "add:error",
12939
13071
  message: "Failed to install dependencies",
12940
13072
  error: err instanceof Error ? err.message : String(err)
12941
13073
  });
12942
13074
  }
12943
13075
  }
12944
- console.log({
13076
+ log({
12945
13077
  event: "add:complete",
12946
13078
  installed: installed.length,
12947
13079
  skipped: skipped.length,
12948
13080
  components: installed
12949
13081
  });
12950
13082
  if (skipped.length > 0 && installed.length === 0) {
12951
- console.log({
13083
+ log({
12952
13084
  event: "add:hint",
12953
13085
  message: "Some components were skipped. Use --overwrite to replace existing files.",
12954
13086
  skipped
@@ -13553,8 +13685,8 @@ var TokenDependencyGraph = class {
13553
13685
  }
13554
13686
  try {
13555
13687
  this.topologicalSort();
13556
- } catch (error47) {
13557
- errors.push(`Cycle detected in dependency graph: ${error47}`);
13688
+ } catch (error48) {
13689
+ errors.push(`Cycle detected in dependency graph: ${error48}`);
13558
13690
  }
13559
13691
  return {
13560
13692
  isValid: errors.length === 0,
@@ -13568,8 +13700,8 @@ var TokenDependencyGraph = class {
13568
13700
  try {
13569
13701
  this.ruleParser.parse(rule);
13570
13702
  return { isValid: true };
13571
- } catch (error47) {
13572
- return { isValid: false, error: String(error47) };
13703
+ } catch (error48) {
13704
+ return { isValid: false, error: String(error48) };
13573
13705
  }
13574
13706
  }
13575
13707
  /**
@@ -13582,8 +13714,8 @@ var TokenDependencyGraph = class {
13582
13714
  return parsedRule.tokens ?? [];
13583
13715
  }
13584
13716
  return [];
13585
- } catch (error47) {
13586
- throw new Error(`Failed to parse rule dependencies: ${error47}`);
13717
+ } catch (error48) {
13718
+ throw new Error(`Failed to parse rule dependencies: ${error48}`);
13587
13719
  }
13588
13720
  }
13589
13721
  /**
@@ -20151,54 +20283,54 @@ var require_assert = __commonJS({
20151
20283
  });
20152
20284
  });
20153
20285
  }
20154
- function expectsError(stackStartFn, actual, error47, message) {
20155
- if (typeof error47 === "string") {
20286
+ function expectsError(stackStartFn, actual, error48, message) {
20287
+ if (typeof error48 === "string") {
20156
20288
  if (arguments.length === 4) {
20157
- throw new ERR_INVALID_ARG_TYPE2("error", ["Object", "Error", "Function", "RegExp"], error47);
20289
+ throw new ERR_INVALID_ARG_TYPE2("error", ["Object", "Error", "Function", "RegExp"], error48);
20158
20290
  }
20159
20291
  if (_typeof2(actual) === "object" && actual !== null) {
20160
- if (actual.message === error47) {
20292
+ if (actual.message === error48) {
20161
20293
  throw new ERR_AMBIGUOUS_ARGUMENT("error/message", 'The error message "'.concat(actual.message, '" is identical to the message.'));
20162
20294
  }
20163
- } else if (actual === error47) {
20295
+ } else if (actual === error48) {
20164
20296
  throw new ERR_AMBIGUOUS_ARGUMENT("error/message", 'The error "'.concat(actual, '" is identical to the message.'));
20165
20297
  }
20166
- message = error47;
20167
- error47 = void 0;
20168
- } else if (error47 != null && _typeof2(error47) !== "object" && typeof error47 !== "function") {
20169
- throw new ERR_INVALID_ARG_TYPE2("error", ["Object", "Error", "Function", "RegExp"], error47);
20298
+ message = error48;
20299
+ error48 = void 0;
20300
+ } else if (error48 != null && _typeof2(error48) !== "object" && typeof error48 !== "function") {
20301
+ throw new ERR_INVALID_ARG_TYPE2("error", ["Object", "Error", "Function", "RegExp"], error48);
20170
20302
  }
20171
20303
  if (actual === NO_EXCEPTION_SENTINEL) {
20172
20304
  var details = "";
20173
- if (error47 && error47.name) {
20174
- details += " (".concat(error47.name, ")");
20305
+ if (error48 && error48.name) {
20306
+ details += " (".concat(error48.name, ")");
20175
20307
  }
20176
20308
  details += message ? ": ".concat(message) : ".";
20177
20309
  var fnType = stackStartFn.name === "rejects" ? "rejection" : "exception";
20178
20310
  innerFail({
20179
20311
  actual: void 0,
20180
- expected: error47,
20312
+ expected: error48,
20181
20313
  operator: stackStartFn.name,
20182
20314
  message: "Missing expected ".concat(fnType).concat(details),
20183
20315
  stackStartFn
20184
20316
  });
20185
20317
  }
20186
- if (error47 && !expectedException(actual, error47, message, stackStartFn)) {
20318
+ if (error48 && !expectedException(actual, error48, message, stackStartFn)) {
20187
20319
  throw actual;
20188
20320
  }
20189
20321
  }
20190
- function expectsNoError(stackStartFn, actual, error47, message) {
20322
+ function expectsNoError(stackStartFn, actual, error48, message) {
20191
20323
  if (actual === NO_EXCEPTION_SENTINEL) return;
20192
- if (typeof error47 === "string") {
20193
- message = error47;
20194
- error47 = void 0;
20324
+ if (typeof error48 === "string") {
20325
+ message = error48;
20326
+ error48 = void 0;
20195
20327
  }
20196
- if (!error47 || expectedException(actual, error47)) {
20328
+ if (!error48 || expectedException(actual, error48)) {
20197
20329
  var details = message ? ": ".concat(message) : ".";
20198
20330
  var fnType = stackStartFn.name === "doesNotReject" ? "rejection" : "exception";
20199
20331
  innerFail({
20200
20332
  actual,
20201
- expected: error47,
20333
+ expected: error48,
20202
20334
  operator: stackStartFn.name,
20203
20335
  message: "Got unwanted ".concat(fnType).concat(details, "\n") + 'Actual message: "'.concat(actual && actual.message, '"'),
20204
20336
  stackStartFn
@@ -22690,9 +22822,9 @@ var require_util3 = __commonJS({
22690
22822
  exports.isWin = process2.platform === "win32";
22691
22823
  function promisify(fs22, fn, getResult = (input) => input) {
22692
22824
  return (...args) => new Promise((resolve4, reject) => {
22693
- fs22[fn].bind(fs22)(...args, (error47, result) => {
22694
- if (error47)
22695
- return reject(error47);
22825
+ fs22[fn].bind(fs22)(...args, (error48, result) => {
22826
+ if (error48)
22827
+ return reject(error48);
22696
22828
  return resolve4(getResult(result));
22697
22829
  });
22698
22830
  });
@@ -22816,12 +22948,12 @@ var require_util3 = __commonJS({
22816
22948
  }
22817
22949
  }
22818
22950
  function createError(errorCode, func = "", path2 = "", path22 = "", Constructor = Error) {
22819
- const error47 = new Constructor(formatError2(errorCode, func, path2, path22));
22820
- error47.code = errorCode;
22951
+ const error48 = new Constructor(formatError2(errorCode, func, path2, path22));
22952
+ error48.code = errorCode;
22821
22953
  if (path2) {
22822
- error47.path = path2;
22954
+ error48.path = path2;
22823
22955
  }
22824
- return error47;
22956
+ return error48;
22825
22957
  }
22826
22958
  function genRndStr6() {
22827
22959
  const str = (Math.random() + 1).toString(36).substring(2, 8);
@@ -23191,14 +23323,14 @@ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, e
23191
23323
  var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
23192
23324
  var _, done = false;
23193
23325
  for (var i = decorators.length - 1; i >= 0; i--) {
23194
- var context = {};
23195
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
23196
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
23197
- context.addInitializer = function(f) {
23326
+ var context2 = {};
23327
+ for (var p in contextIn) context2[p] = p === "access" ? {} : contextIn[p];
23328
+ for (var p in contextIn.access) context2.access[p] = contextIn.access[p];
23329
+ context2.addInitializer = function(f) {
23198
23330
  if (done) throw new TypeError("Cannot add initializers after decoration has completed");
23199
23331
  extraInitializers.push(accept(f || null));
23200
23332
  };
23201
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
23333
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context2);
23202
23334
  if (kind === "accessor") {
23203
23335
  if (result === void 0) continue;
23204
23336
  if (result === null || typeof result !== "object") throw new TypeError("Object expected");
@@ -23346,8 +23478,8 @@ function __read(o, n) {
23346
23478
  var i = m.call(o), r, ar = [], e;
23347
23479
  try {
23348
23480
  while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23349
- } catch (error47) {
23350
- e = { error: error47 };
23481
+ } catch (error48) {
23482
+ e = { error: error48 };
23351
23483
  } finally {
23352
23484
  try {
23353
23485
  if (r && !r.done && (m = i["return"])) m.call(i);
@@ -23566,9 +23698,9 @@ var init_tslib_es6 = __esm({
23566
23698
  } : function(o, v) {
23567
23699
  o["default"] = v;
23568
23700
  };
23569
- _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error47, suppressed, message) {
23701
+ _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error48, suppressed, message) {
23570
23702
  var e = new Error(message);
23571
- return e.name = "SuppressedError", e.error = error47, e.suppressed = suppressed, e;
23703
+ return e.name = "SuppressedError", e.error = error48, e.suppressed = suppressed, e;
23572
23704
  };
23573
23705
  tslib_es6_default = {
23574
23706
  __extends,
@@ -23862,9 +23994,9 @@ var require_Dir = __commonJS({
23862
23994
  promisify(obj, fn) {
23863
23995
  return (...args) => new Promise((resolve4, reject) => {
23864
23996
  if (this.isFunction(obj[fn])) {
23865
- obj[fn].bind(obj)(...args, (error47, result) => {
23866
- if (error47)
23867
- reject(error47);
23997
+ obj[fn].bind(obj)(...args, (error48, result) => {
23998
+ if (error48)
23999
+ reject(error48);
23868
24000
  resolve4(result);
23869
24001
  });
23870
24002
  } else {
@@ -25808,10 +25940,10 @@ var require_volume = __commonJS({
25808
25940
  try {
25809
25941
  this._link = this._vol.getLinkOrThrow(this._filename, "FSWatcher");
25810
25942
  } catch (err) {
25811
- const error47 = new Error(`watch ${this._filename} ${err.code}`);
25812
- error47.code = err.code;
25813
- error47.errno = err.code;
25814
- throw error47;
25943
+ const error48 = new Error(`watch ${this._filename} ${err.code}`);
25944
+ error48.code = err.code;
25945
+ error48.errno = err.code;
25946
+ throw error48;
25815
25947
  }
25816
25948
  const watchLinkNodeChanged = (link) => {
25817
25949
  var _a;
@@ -28900,7 +29032,7 @@ var LRUCache = class _LRUCache {
28900
29032
  free: c.#free,
28901
29033
  // methods
28902
29034
  isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
28903
- backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
29035
+ backgroundFetch: (k, index, options, context2) => c.#backgroundFetch(k, index, options, context2),
28904
29036
  moveToTail: (index) => c.#moveToTail(index),
28905
29037
  indexes: (options) => c.#indexes(options),
28906
29038
  rindexes: (options) => c.#rindexes(options),
@@ -29720,7 +29852,7 @@ var LRUCache = class _LRUCache {
29720
29852
  const v = this.#valList[index];
29721
29853
  return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
29722
29854
  }
29723
- #backgroundFetch(k, index, options, context) {
29855
+ #backgroundFetch(k, index, options, context2) {
29724
29856
  const v = index === void 0 ? void 0 : this.#valList[index];
29725
29857
  if (this.#isBackgroundFetch(v)) {
29726
29858
  return v;
@@ -29733,7 +29865,7 @@ var LRUCache = class _LRUCache {
29733
29865
  const fetchOpts = {
29734
29866
  signal: ac.signal,
29735
29867
  options,
29736
- context
29868
+ context: context2
29737
29869
  };
29738
29870
  const cb = (v2, updateCache = false) => {
29739
29871
  const { aborted: aborted2 } = ac.signal;
@@ -29851,7 +29983,7 @@ var LRUCache = class _LRUCache {
29851
29983
  allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
29852
29984
  ignoreFetchAbort = this.ignoreFetchAbort,
29853
29985
  allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
29854
- context,
29986
+ context: context2,
29855
29987
  forceRefresh = false,
29856
29988
  status,
29857
29989
  signal
@@ -29886,7 +30018,7 @@ var LRUCache = class _LRUCache {
29886
30018
  if (index === void 0) {
29887
30019
  if (status)
29888
30020
  status.fetch = "miss";
29889
- const p = this.#backgroundFetch(k, index, options, context);
30021
+ const p = this.#backgroundFetch(k, index, options, context2);
29890
30022
  return p.__returned = p;
29891
30023
  } else {
29892
30024
  const v = this.#valList[index];
@@ -29911,7 +30043,7 @@ var LRUCache = class _LRUCache {
29911
30043
  this.#statusTTL(status, index);
29912
30044
  return v;
29913
30045
  }
29914
- const p = this.#backgroundFetch(k, index, options, context);
30046
+ const p = this.#backgroundFetch(k, index, options, context2);
29915
30047
  const hasStale = p.__staleWhileFetching !== void 0;
29916
30048
  const staleVal = hasStale && allowStale;
29917
30049
  if (status) {
@@ -29933,13 +30065,13 @@ var LRUCache = class _LRUCache {
29933
30065
  if (!memoMethod) {
29934
30066
  throw new Error("no memoMethod provided to constructor");
29935
30067
  }
29936
- const { context, forceRefresh, ...options } = memoOptions;
30068
+ const { context: context2, forceRefresh, ...options } = memoOptions;
29937
30069
  const v = this.get(k, options);
29938
30070
  if (!forceRefresh && v !== void 0)
29939
30071
  return v;
29940
30072
  const vv = memoMethod(k, v, {
29941
30073
  options,
29942
- context
30074
+ context: context2
29943
30075
  });
29944
30076
  this.set(k, vv, options);
29945
30077
  return vv;
@@ -39190,17 +39322,17 @@ function pipeThroughCommpressionStream(readable, useCompressionStream, options,
39190
39322
  const format = options.deflate64 ? FORMAT_DEFLATE64_RAW : FORMAT_DEFLATE_RAW;
39191
39323
  try {
39192
39324
  readable = pipeThrough(readable, new Stream2(format, options));
39193
- } catch (error47) {
39325
+ } catch (error48) {
39194
39326
  if (useCompressionStream) {
39195
39327
  if (CompressionStreamZlib2) {
39196
39328
  readable = pipeThrough(readable, new CompressionStreamZlib2(format, options));
39197
39329
  } else if (CompressionStream2) {
39198
39330
  readable = pipeThrough(readable, new CompressionStream2(format, options));
39199
39331
  } else {
39200
- throw error47;
39332
+ throw error48;
39201
39333
  }
39202
39334
  } else {
39203
- throw error47;
39335
+ throw error48;
39204
39336
  }
39205
39337
  }
39206
39338
  return readable;
@@ -39521,7 +39653,7 @@ function _make(isCompress, type, options = {}) {
39521
39653
  }
39522
39654
  offset += consumed;
39523
39655
  }
39524
- } catch (error47) {
39656
+ } catch (error48) {
39525
39657
  if (this._end && this.streamHandle) {
39526
39658
  this._end(this.streamHandle);
39527
39659
  }
@@ -39531,7 +39663,7 @@ function _make(isCompress, type, options = {}) {
39531
39663
  if (this.out && free) {
39532
39664
  free(this.out);
39533
39665
  }
39534
- controller.error(error47);
39666
+ controller.error(error48);
39535
39667
  }
39536
39668
  },
39537
39669
  flush(controller) {
@@ -39558,8 +39690,8 @@ function _make(isCompress, type, options = {}) {
39558
39690
  break;
39559
39691
  }
39560
39692
  }
39561
- } catch (error47) {
39562
- controller.error(error47);
39693
+ } catch (error48) {
39694
+ controller.error(error48);
39563
39695
  } finally {
39564
39696
  if (this._end && this.streamHandle) {
39565
39697
  const result = this._end(this.streamHandle);
@@ -39600,11 +39732,11 @@ async function initModule2(wasmURI, { baseURI }) {
39600
39732
  }
39601
39733
  const response = await fetch(uri);
39602
39734
  arrayBuffer = await response.arrayBuffer();
39603
- } catch (error47) {
39735
+ } catch (error48) {
39604
39736
  if (wasmURI.startsWith("data:application/wasm;base64,")) {
39605
39737
  arrayBuffer = arrayBufferFromDataURI(wasmURI);
39606
39738
  } else {
39607
- throw error47;
39739
+ throw error48;
39608
39740
  }
39609
39741
  }
39610
39742
  const wasmInstance = await WebAssembly.instantiate(arrayBuffer);
@@ -43656,7 +43788,7 @@ var UNKNOWN_CSS_FONT_PROPS_WARNINGS2 = groupMessages_default.GROUP.UnknownCSSFon
43656
43788
  var FILTER_WARNINGS3 = groupMessages_default.GROUP.FilteredOutputReferences;
43657
43789
  var { throw: throwBrokenReference } = logBrokenReferenceLevels;
43658
43790
  var { default: defaultVerbosity, silent: silent2, verbose } = logVerbosityLevels;
43659
- var { error: error46, warn, disabled } = logWarningLevels;
43791
+ var { error: error47, warn, disabled } = logWarningLevels;
43660
43792
 
43661
43793
  // ../design-tokens/src/generators/defaults.ts
43662
43794
  var DEFAULT_NEUTRAL_SCALE = {
@@ -46471,8 +46603,8 @@ var TokenRegistry = class {
46471
46603
  for (const dependentName of dependentsToUpdate) {
46472
46604
  try {
46473
46605
  await this.regenerateToken(dependentName);
46474
- } catch (error47) {
46475
- console.warn(`Failed to regenerate token ${dependentName}:`, error47);
46606
+ } catch (error48) {
46607
+ console.warn(`Failed to regenerate token ${dependentName}:`, error48);
46476
46608
  }
46477
46609
  }
46478
46610
  }
@@ -46512,8 +46644,8 @@ var TokenRegistry = class {
46512
46644
  computedValue: newComputedValue
46513
46645
  });
46514
46646
  }
46515
- } catch (error47) {
46516
- throw new Error(`Failed to regenerate token ${tokenName}: ${error47}`);
46647
+ } catch (error48) {
46648
+ throw new Error(`Failed to regenerate token ${tokenName}: ${error48}`);
46517
46649
  }
46518
46650
  }
46519
46651
  /**
@@ -47658,8 +47790,8 @@ function generateProgression(type, options) {
47658
47790
  cachedRatio = getRatio(type);
47659
47791
  }
47660
47792
  value2 = i === 0 && includeZero ? 0 : baseValue * cachedRatio ** (includeZero ? i - 1 : i);
47661
- } catch (error47) {
47662
- throw new Error(`Invalid progression type: ${type}`, { cause: error47 });
47793
+ } catch (error48) {
47794
+ throw new Error(`Invalid progression type: ${type}`, { cause: error48 });
47663
47795
  }
47664
47796
  }
47665
47797
  result.push(value2);
@@ -49993,7 +50125,7 @@ async function updateMainCss(cwd, cssPath, themePath) {
49993
50125
  const themeFullPath = join8(cwd, themePath);
49994
50126
  const relativeThemePath = relative(cssDir, themeFullPath);
49995
50127
  if (cssContent.includes(".rafters/output/theme.css")) {
49996
- console.log({ event: "init:css_already_imported", cssPath });
50128
+ log({ event: "init:css_already_imported", cssPath });
49997
50129
  return;
49998
50130
  }
49999
50131
  await backupCss(fullCssPath);
@@ -50008,14 +50140,14 @@ async function updateMainCss(cwd, cssPath, themePath) {
50008
50140
  ${cssContent}`;
50009
50141
  }
50010
50142
  await writeFile3(fullCssPath, newContent);
50011
- console.log({
50143
+ log({
50012
50144
  event: "init:css_updated",
50013
50145
  cssPath,
50014
50146
  themePath: relativeThemePath
50015
50147
  });
50016
50148
  }
50017
50149
  async function regenerateFromExisting(cwd, paths, shadcn) {
50018
- console.log({ event: "init:regenerate", cwd });
50150
+ log({ event: "init:regenerate", cwd });
50019
50151
  const adapter = new NodePersistenceAdapter(cwd);
50020
50152
  const namespaces = await adapter.listNamespaces();
50021
50153
  if (namespaces.length === 0) {
@@ -50026,7 +50158,7 @@ async function regenerateFromExisting(cwd, paths, shadcn) {
50026
50158
  const tokens = await adapter.loadNamespace(namespace);
50027
50159
  allTokens.push(...tokens);
50028
50160
  }
50029
- console.log({
50161
+ log({
50030
50162
  event: "init:loaded",
50031
50163
  tokenCount: allTokens.length,
50032
50164
  namespaces
@@ -50039,18 +50171,19 @@ async function regenerateFromExisting(cwd, paths, shadcn) {
50039
50171
  await writeFile3(join8(paths.output, "theme.css"), tailwindCss);
50040
50172
  await writeFile3(join8(paths.output, "tokens.ts"), typescriptSrc);
50041
50173
  await writeFile3(join8(paths.output, "tokens.json"), JSON.stringify(dtcgJson, null, 2));
50042
- console.log({
50174
+ log({
50043
50175
  event: "init:complete",
50044
50176
  outputs: ["theme.css", "tokens.ts", "tokens.json"],
50045
50177
  path: paths.output
50046
50178
  });
50047
50179
  }
50048
50180
  async function init(options) {
50181
+ setAgentMode(options.agent ?? false);
50049
50182
  const cwd = process.cwd();
50050
50183
  const paths = getRaftersPaths(cwd);
50051
- console.log({ event: "init:start", cwd });
50184
+ log({ event: "init:start", cwd });
50052
50185
  const { framework, shadcn, tailwindVersion } = await detectProject(cwd);
50053
- console.log({
50186
+ log({
50054
50187
  event: "init:detected",
50055
50188
  framework,
50056
50189
  tailwindVersion,
@@ -50076,7 +50209,7 @@ async function init(options) {
50076
50209
  const cssContent = await readFile3(cssPath, "utf-8");
50077
50210
  existingColors = parseCssVariables(cssContent);
50078
50211
  const backupPath = await backupCss(cssPath);
50079
- console.log({
50212
+ log({
50080
50213
  event: "init:shadcn_detected",
50081
50214
  cssPath: shadcn.tailwind.css,
50082
50215
  backupPath,
@@ -50086,7 +50219,7 @@ async function init(options) {
50086
50219
  }
50087
50220
  });
50088
50221
  } catch (err) {
50089
- console.log({ event: "init:shadcn_css_error", error: String(err) });
50222
+ log({ event: "init:shadcn_css_error", error: String(err) });
50090
50223
  }
50091
50224
  }
50092
50225
  const result = buildColorSystem({
@@ -50125,12 +50258,12 @@ async function init(options) {
50125
50258
  registry2.updateToken(tokenName, colorValue);
50126
50259
  }
50127
50260
  }
50128
- console.log({
50261
+ log({
50129
50262
  event: "init:colors_imported",
50130
50263
  count: Object.keys(existingColors.light).length
50131
50264
  });
50132
50265
  }
50133
- console.log({
50266
+ log({
50134
50267
  event: "init:generated",
50135
50268
  tokenCount: registry2.size()
50136
50269
  });
@@ -50147,7 +50280,7 @@ async function init(options) {
50147
50280
  for (const [namespace, tokens] of tokensByNamespace) {
50148
50281
  await adapter.saveNamespace(namespace, tokens);
50149
50282
  }
50150
- console.log({
50283
+ log({
50151
50284
  event: "init:registry_saved",
50152
50285
  path: paths.tokens,
50153
50286
  namespaceCount: tokensByNamespace.size
@@ -50163,14 +50296,14 @@ async function init(options) {
50163
50296
  if (mainCssPath) {
50164
50297
  await updateMainCss(cwd, mainCssPath, ".rafters/output/theme.css");
50165
50298
  } else {
50166
- console.log({
50299
+ log({
50167
50300
  event: "init:css_not_found",
50168
50301
  message: 'No main CSS file found. Add @import ".rafters/output/theme.css" manually.',
50169
50302
  searchedLocations: CSS_LOCATIONS[framework] || CSS_LOCATIONS.unknown
50170
50303
  });
50171
50304
  }
50172
50305
  }
50173
- console.log({
50306
+ log({
50174
50307
  event: "init:complete",
50175
50308
  outputs: ["theme.css", "tokens.ts", "tokens.json"],
50176
50309
  path: paths.output
@@ -50590,8 +50723,8 @@ var RaftersToolHandler = class {
50590
50723
  }
50591
50724
  ]
50592
50725
  };
50593
- } catch (error47) {
50594
- return this.handleError("getVocabulary", error47);
50726
+ } catch (error48) {
50727
+ return this.handleError("getVocabulary", error48);
50595
50728
  }
50596
50729
  }
50597
50730
  /**
@@ -50909,8 +51042,8 @@ var RaftersToolHandler = class {
50909
51042
  }
50910
51043
  ]
50911
51044
  };
50912
- } catch (error47) {
50913
- return this.handleError("getComponent", error47);
51045
+ } catch (error48) {
51046
+ return this.handleError("getComponent", error48);
50914
51047
  }
50915
51048
  }
50916
51049
  // ==================== Tool 4: Token ====================
@@ -51016,15 +51149,15 @@ var RaftersToolHandler = class {
51016
51149
  }
51017
51150
  ]
51018
51151
  };
51019
- } catch (error47) {
51020
- return this.handleError("getToken", error47);
51152
+ } catch (error48) {
51153
+ return this.handleError("getToken", error48);
51021
51154
  }
51022
51155
  }
51023
51156
  /**
51024
51157
  * Handle errors consistently
51025
51158
  */
51026
- handleError(operation, error47) {
51027
- const message = error47 instanceof Error ? error47.message : "Unknown error occurred";
51159
+ handleError(operation, error48) {
51160
+ const message = error48 instanceof Error ? error48.message : "Unknown error occurred";
51028
51161
  return {
51029
51162
  content: [
51030
51163
  {
@@ -51138,8 +51271,8 @@ async function studio() {
51138
51271
  // src/index.ts
51139
51272
  var program = new Command();
51140
51273
  program.name("rafters").description("Design system CLI - scaffold tokens and serve MCP").version("0.0.1");
51141
- program.command("init").description("Initialize .rafters/ with default tokens and config").option("-f, --force", "Regenerate output files from existing config").action(init);
51142
- program.command("add").description("Add rafters components to the project").argument("<components...>", "Component names to add").option("--overwrite", "Overwrite existing component files").option("--registry-url <url>", "Custom registry URL").action(add);
51274
+ program.command("init").description("Initialize .rafters/ with default tokens and config").option("-f, --force", "Regenerate output files from existing config").option("--agent", "Output JSON for machine consumption").action(init);
51275
+ program.command("add").description("Add rafters components to the project").argument("<components...>", "Component names to add").option("--overwrite", "Overwrite existing component files").option("--registry-url <url>", "Custom registry URL").option("--agent", "Output JSON for machine consumption").action(add);
51143
51276
  program.command("mcp").description("Start MCP server for AI agent access (stdio)").action(mcp);
51144
51277
  program.command("studio").description("Open Studio UI for visual token editing").action(studio);
51145
51278
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rafters",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "CLI for Rafters design system - scaffold tokens and add components",
5
5
  "type": "module",
6
6
  "bin": {