rafters 0.0.38 → 0.0.39

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 +122 -37
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -60352,6 +60352,10 @@ var TOOL_DEFINITIONS = [
60352
60352
  category: {
60353
60353
  type: "string",
60354
60354
  description: 'Token category (required for create). E.g., "color", "spacing", "font".'
60355
+ },
60356
+ dark: {
60357
+ type: "string",
60358
+ description: 'Dark mode color reference as "family-position" (e.g., "neutral-950"). For semantic tokens, sets dependsOn[1] so the CSS dark mode layer uses this reference instead of the light value.'
60355
60359
  }
60356
60360
  },
60357
60361
  required: ["name"]
@@ -61050,6 +61054,19 @@ var RaftersToolHandler = class _RaftersToolHandler {
61050
61054
  }
61051
61055
  }
61052
61056
  // ==================== Token Write Operations ====================
61057
+ static VALID_SCALE_POSITIONS = /^(50|100|200|300|400|500|600|700|800|900|950)$/;
61058
+ /**
61059
+ * Parse "family-position" string (e.g., "neutral-950") into { family, position }.
61060
+ * Returns null if the string is not a valid color reference.
61061
+ */
61062
+ static parseColorRef(ref) {
61063
+ const lastDash = ref.lastIndexOf("-");
61064
+ if (lastDash <= 0) return null;
61065
+ const position = ref.slice(lastDash + 1);
61066
+ const family = ref.slice(0, lastDash);
61067
+ if (!_RaftersToolHandler.VALID_SCALE_POSITIONS.test(position)) return null;
61068
+ return { family, position };
61069
+ }
61053
61070
  /**
61054
61071
  * Handle set, create, and reset actions for rafters_token.
61055
61072
  * Loads the full registry, mutates, cascades, persists, and regenerates outputs.
@@ -61058,6 +61075,7 @@ var RaftersToolHandler = class _RaftersToolHandler {
61058
61075
  const name2 = args.name;
61059
61076
  const reason = args.reason;
61060
61077
  const value2 = args.value;
61078
+ const dark = args.dark;
61061
61079
  if (!reason) {
61062
61080
  return {
61063
61081
  content: [
@@ -61103,14 +61121,64 @@ var RaftersToolHandler = class _RaftersToolHandler {
61103
61121
  isError: true
61104
61122
  };
61105
61123
  }
61124
+ if (dark) {
61125
+ if (existing.namespace !== "semantic") {
61126
+ return {
61127
+ content: [
61128
+ {
61129
+ type: "text",
61130
+ text: JSON.stringify({
61131
+ error: `The "dark" parameter only applies to semantic color tokens. Token "${name2}" is in the "${existing.namespace}" namespace.`
61132
+ })
61133
+ }
61134
+ ],
61135
+ isError: true
61136
+ };
61137
+ }
61138
+ if (!_RaftersToolHandler.parseColorRef(dark)) {
61139
+ return {
61140
+ content: [
61141
+ {
61142
+ type: "text",
61143
+ text: JSON.stringify({
61144
+ error: `Invalid dark reference "${dark}". Use format "family-position" (e.g., "neutral-950"). Valid positions: 50, 100-900 by 100, 950.`
61145
+ })
61146
+ }
61147
+ ],
61148
+ isError: true
61149
+ };
61150
+ }
61151
+ }
61106
61152
  const previousValue = existing.value;
61107
61153
  existing.userOverride = {
61108
61154
  previousValue: typeof previousValue === "string" ? previousValue : JSON.stringify(previousValue),
61109
61155
  reason
61110
61156
  };
61111
- await registry2.set(name2, value2);
61157
+ const parsed = existing.namespace === "semantic" && typeof value2 === "string" ? _RaftersToolHandler.parseColorRef(value2) : null;
61158
+ if (existing.namespace === "semantic" && typeof value2 === "string" && !parsed) {
61159
+ return {
61160
+ content: [
61161
+ {
61162
+ type: "text",
61163
+ text: JSON.stringify({
61164
+ error: `Semantic token "${name2}" requires a color reference in "family-position" format (e.g., "neutral-50"), not "${value2}". Use rafters_vocabulary to find available color families.`
61165
+ })
61166
+ }
61167
+ ],
61168
+ isError: true
61169
+ };
61170
+ }
61171
+ if (parsed) {
61172
+ existing.value = parsed;
61173
+ const lightRefStr = `${parsed.family}-${parsed.position}`;
61174
+ const darkRef = dark ?? existing.dependsOn?.[1] ?? lightRefStr;
61175
+ existing.dependsOn = [lightRefStr, darkRef];
61176
+ } else {
61177
+ existing.value = value2;
61178
+ }
61179
+ await registry2.setToken(existing);
61112
61180
  const affected = this.getAffectedTokens(registry2, name2);
61113
- await this.regenerateOutputs(registry2);
61181
+ const outputFiles = await this.regenerateOutputs(registry2);
61114
61182
  return {
61115
61183
  content: [
61116
61184
  {
@@ -61120,7 +61188,13 @@ var RaftersToolHandler = class _RaftersToolHandler {
61120
61188
  action: "set",
61121
61189
  name: name2,
61122
61190
  reason,
61123
- cascaded: affected
61191
+ persisted: {
61192
+ value: existing.value,
61193
+ dependsOn: existing.dependsOn,
61194
+ namespace: existing.namespace
61195
+ },
61196
+ cascaded: affected,
61197
+ outputFiles
61124
61198
  })
61125
61199
  }
61126
61200
  ]
@@ -61177,7 +61251,7 @@ var RaftersToolHandler = class _RaftersToolHandler {
61177
61251
  };
61178
61252
  registry2.add(newToken);
61179
61253
  await this.adapter.save(registry2.list());
61180
- await this.regenerateOutputs(registry2);
61254
+ const outputFiles = await this.regenerateOutputs(registry2);
61181
61255
  return {
61182
61256
  content: [
61183
61257
  {
@@ -61187,7 +61261,13 @@ var RaftersToolHandler = class _RaftersToolHandler {
61187
61261
  action: "create",
61188
61262
  name: name2,
61189
61263
  namespace,
61190
- reason
61264
+ reason,
61265
+ persisted: {
61266
+ value: newToken.value,
61267
+ dependsOn: newToken.dependsOn,
61268
+ namespace: newToken.namespace
61269
+ },
61270
+ outputFiles
61191
61271
  })
61192
61272
  }
61193
61273
  ]
@@ -61204,8 +61284,9 @@ var RaftersToolHandler = class _RaftersToolHandler {
61204
61284
  };
61205
61285
  }
61206
61286
  await registry2.set(name2, COMPUTED);
61287
+ const resolved = registry2.get(name2);
61207
61288
  const affected = this.getAffectedTokens(registry2, name2);
61208
- await this.regenerateOutputs(registry2);
61289
+ const outputFiles = await this.regenerateOutputs(registry2);
61209
61290
  return {
61210
61291
  content: [
61211
61292
  {
@@ -61215,7 +61296,13 @@ var RaftersToolHandler = class _RaftersToolHandler {
61215
61296
  action: "reset",
61216
61297
  name: name2,
61217
61298
  reason,
61218
- cascaded: affected
61299
+ persisted: {
61300
+ value: resolved?.value,
61301
+ dependsOn: resolved?.dependsOn,
61302
+ namespace: resolved?.namespace
61303
+ },
61304
+ cascaded: affected,
61305
+ outputFiles
61219
61306
  })
61220
61307
  }
61221
61308
  ]
@@ -61251,10 +61338,11 @@ var RaftersToolHandler = class _RaftersToolHandler {
61251
61338
  return affected;
61252
61339
  }
61253
61340
  /**
61254
- * Regenerate output files (CSS, TS, DTCG) from registry state
61341
+ * Regenerate output files (CSS, TS, DTCG) from registry state.
61342
+ * Returns list of files written so callers can report what changed.
61255
61343
  */
61256
61344
  async regenerateOutputs(registry2) {
61257
- if (!this.projectRoot) return;
61345
+ if (!this.projectRoot) return [];
61258
61346
  const paths = getRaftersPaths(this.projectRoot);
61259
61347
  const config3 = await this.loadConfig();
61260
61348
  const exports = config3?.exports ?? {
@@ -61264,20 +61352,28 @@ var RaftersToolHandler = class _RaftersToolHandler {
61264
61352
  compiled: false
61265
61353
  };
61266
61354
  const shadcn = config3?.shadcn ?? false;
61355
+ const written = [];
61267
61356
  await mkdir4(paths.output, { recursive: true });
61268
61357
  if (exports.tailwind) {
61269
61358
  const darkMode = config3?.darkMode ?? "class";
61270
61359
  const css3 = registryToTailwind(registry2, { includeImport: !shadcn, darkMode });
61271
- await writeFile4(join10(paths.output, "rafters.css"), css3);
61360
+ const cssPath = join10(paths.output, "rafters.css");
61361
+ await writeFile4(cssPath, css3);
61362
+ written.push(relative2(this.projectRoot, cssPath));
61272
61363
  }
61273
61364
  if (exports.typescript) {
61274
61365
  const ts = registryToTypeScript(registry2, { includeJSDoc: true });
61275
- await writeFile4(join10(paths.output, "rafters.ts"), ts);
61366
+ const tsPath = join10(paths.output, "rafters.ts");
61367
+ await writeFile4(tsPath, ts);
61368
+ written.push(relative2(this.projectRoot, tsPath));
61276
61369
  }
61277
61370
  if (exports.dtcg) {
61278
61371
  const json3 = toDTCG(registry2.list());
61279
- await writeFile4(join10(paths.output, "rafters.json"), JSON.stringify(json3, null, 2));
61372
+ const jsonPath = join10(paths.output, "rafters.json");
61373
+ await writeFile4(jsonPath, JSON.stringify(json3, null, 2));
61374
+ written.push(relative2(this.projectRoot, jsonPath));
61280
61375
  }
61376
+ return written;
61281
61377
  }
61282
61378
  // ==================== Tool 6: Onboard ====================
61283
61379
  /**
@@ -61666,14 +61762,7 @@ var RaftersToolHandler = class _RaftersToolHandler {
61666
61762
  const registry2 = new TokenRegistry(allTokens);
61667
61763
  registry2.setAdapter(this.adapter);
61668
61764
  const results = [];
61669
- const parseRef = (ref) => {
61670
- const lastDash = ref.lastIndexOf("-");
61671
- if (lastDash <= 0) return null;
61672
- const position = ref.slice(lastDash + 1);
61673
- const family = ref.slice(0, lastDash);
61674
- if (!/^(50|100|200|300|400|500|600|700|800|900|950)$/.test(position)) return null;
61675
- return { family, position };
61676
- };
61765
+ const parseRef = _RaftersToolHandler.parseColorRef;
61677
61766
  for (const mapping of mappings) {
61678
61767
  const { source, target, value: value2, reason, namespace, category } = mapping;
61679
61768
  const lightRef = mapping.light;
@@ -61776,25 +61865,20 @@ var RaftersToolHandler = class _RaftersToolHandler {
61776
61865
  reason: `Remapped from ${source}: ${reason}`
61777
61866
  };
61778
61867
  const newColorRef = { family: newLight.family, position: newLight.position };
61779
- await registry2.set(target, newColorRef);
61780
- const updated = registry2.get(target);
61781
- if (updated) {
61782
- updated.dependsOn = [lightTokenName, darkTokenName];
61783
- } else {
61784
- results.push({
61785
- source,
61786
- target,
61787
- action: "skipped",
61788
- ok: false,
61789
- error: `Token "${target}" was set but could not be retrieved from registry to update dependencies.`
61790
- });
61791
- continue;
61792
- }
61868
+ await registry2.setToken({
61869
+ ...existing,
61870
+ value: newColorRef,
61871
+ dependsOn: [lightTokenName, darkTokenName]
61872
+ });
61793
61873
  results.push({
61794
61874
  source,
61795
61875
  target,
61796
61876
  action: "remap",
61797
- ok: true
61877
+ ok: true,
61878
+ persisted: {
61879
+ value: newColorRef,
61880
+ dependsOn: [lightTokenName, darkTokenName]
61881
+ }
61798
61882
  });
61799
61883
  continue;
61800
61884
  }
@@ -61856,7 +61940,7 @@ var RaftersToolHandler = class _RaftersToolHandler {
61856
61940
  }
61857
61941
  }
61858
61942
  await this.adapter.save(registry2.list());
61859
- await this.regenerateOutputs(registry2);
61943
+ const outputFiles = await this.regenerateOutputs(registry2);
61860
61944
  const setCount = results.filter((r) => r.action === "set" && r.ok).length;
61861
61945
  const createCount = results.filter((r) => r.action === "create" && r.ok).length;
61862
61946
  const remapCount = results.filter((r) => r.action === "remap" && r.ok).length;
@@ -61876,7 +61960,8 @@ var RaftersToolHandler = class _RaftersToolHandler {
61876
61960
  enriched: enrichedCount,
61877
61961
  failed: failCount
61878
61962
  },
61879
- results
61963
+ results,
61964
+ outputFiles
61880
61965
  },
61881
61966
  null,
61882
61967
  2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rafters",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "CLI for Rafters design system - scaffold tokens and add components",
5
5
  "license": "MIT",
6
6
  "type": "module",