@appdirect/design-system 0.0.18 → 0.0.20

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 (36) hide show
  1. package/README.md +21 -0
  2. package/bin/ad-sync-agents.mjs +542 -0
  3. package/dist/ComplexComponents/DashboardWidget/DashboardWidget.js +15 -51
  4. package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +91 -139
  5. package/dist/ComplexComponents/KeyInsight/index.ts +1 -1
  6. package/dist/DESIGN.md +49 -7
  7. package/dist/agent-kit/README.md +11 -0
  8. package/dist/agent-kit/manifest.json +81 -0
  9. package/dist/agent-kit/micro-ui/CLAUDE.md +1 -0
  10. package/dist/agent-kit/micro-ui/micro-ui.AGENTS.md +62 -0
  11. package/dist/agent-kit/rules/accessibility.mdc +46 -0
  12. package/dist/agent-kit/rules/module-federation.mdc +30 -0
  13. package/dist/agent-kit/rules/react-stack.mdc +73 -0
  14. package/dist/agent-kit/rules/testing.mdc +44 -0
  15. package/dist/agent-kit/skills/design-feature/SKILL.md +205 -0
  16. package/dist/agent-kit/skills/developer-handoff/SKILL.md +192 -0
  17. package/dist/agent-kit/skills/figma-mcp-integration/SKILL.md +134 -0
  18. package/dist/agent-kit/skills/figma-to-page/SKILL.md +24 -0
  19. package/dist/agent-kit/skills/mantine-combobox/SKILL.md +73 -0
  20. package/dist/agent-kit/skills/mantine-combobox/references/api.md +199 -0
  21. package/dist/agent-kit/skills/mantine-combobox/references/patterns.md +279 -0
  22. package/dist/agent-kit/skills/mantine-custom-components/SKILL.md +112 -0
  23. package/dist/agent-kit/skills/mantine-custom-components/references/api.md +407 -0
  24. package/dist/agent-kit/skills/mantine-custom-components/references/patterns.md +431 -0
  25. package/dist/agent-kit/skills/mantine-form/SKILL.md +103 -0
  26. package/dist/agent-kit/skills/mantine-form/references/api.md +313 -0
  27. package/dist/agent-kit/skills/mantine-form/references/patterns.md +310 -0
  28. package/dist/agent-kit/skills/prototype-page/SKILL.md +82 -0
  29. package/dist/contracts/DashboardWidget.json +92 -0
  30. package/dist/contracts/index.json +6 -1
  31. package/dist/css/mantine.css +172 -6
  32. package/dist/css/tokens.css +54 -4
  33. package/dist/skills/design-feature/SKILL.md +205 -0
  34. package/dist/stories/ComplexComponents/DashboardWidget/DashboardWidget.stories.tsx +76 -1
  35. package/dist/stories/index.json +4 -1
  36. package/package.json +8 -4
package/README.md CHANGED
@@ -26,6 +26,8 @@ Peer dependencies (install at the versions declared by this package):
26
26
  | Design spec | `@appdirect/design-system/DESIGN.md` | Canonical `apps/design-system/DESIGN.md` (token tables + prose) |
27
27
  | CLI | `ds-audit` | Audit a prototype or app against contracts |
28
28
  | CLI | `ad-sync-design-md` | Copy `DESIGN.md` into the consumer repo (`postinstall` / `sync-design-docs`) |
29
+ | CLI | `ad-sync-agents` | Copy micro-UI agent kit (AGENTS.md, rules, skills) into the consumer (`postinstall` / `sync-agents`) |
30
+ | Agent kit | `dist/agent-kit/` | Source for `ad-sync-agents` |
29
31
 
30
32
  Bundlers (Rspack, webpack, Vite, Next) should resolve the package entry to **`.js`**. You do **not** need `transpilePackages` / SWC includes for this package’s TypeScript. Keep loading `*.module.css` from the package with your CSS-modules rule.
31
33
 
@@ -46,6 +48,25 @@ Do **not** hand-copy the design spec. Wire consumers to pull the published file
46
48
  - Repo-root destination: `DESIGN_MD_PATH=DESIGN.md` or `ad-sync-design-md --out DESIGN.md`
47
49
  - Authoring source of truth in this monorepo: [`apps/design-system/DESIGN.md`](../../apps/design-system/DESIGN.md)
48
50
 
51
+ ## Keep agent kit in sync (micro UIs)
52
+
53
+ ```json
54
+ {
55
+ "scripts": {
56
+ "postinstall": "ad-sync-design-md && ad-sync-agents",
57
+ "sync-agents": "ad-sync-agents",
58
+ "sync-agents:force": "ad-sync-agents --force"
59
+ }
60
+ }
61
+ ```
62
+
63
+ - Default: add missing AGENTS.md / CLAUDE.md / `.cursor/rules` / skills; refresh untouched kit docs/skills; never overwrite existing rules
64
+ - `--force`: overwrite kit AGENTS.md, CLAUDE.md, and skills (skill dirs deleted/recreated; rules still add-only)
65
+ - Commit `.claude/skills/.ad-agent-kit.json` so refreshes work after a kit bump on fresh clones/CI
66
+ - `postinstall` errors are best-effort (warn + exit 0); explicit `npm run sync-agents` still exits 1 on failure
67
+ - `prototype-page` / `figma-to-page` sync only when `standalone/` exists
68
+ - Kit source in this monorepo: [`agent-kit/`](./agent-kit/)
69
+
49
70
  ## App usage
50
71
 
51
72
  Load token CSS once near the app root (standalone prototypes often use this package’s CSS re-exports; the tokens package is the same files):
@@ -0,0 +1,542 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Sync the micro-UI agent kit from @appdirect/design-system into a consumer.
4
+ *
5
+ * Safe (default): per destination — write only if missing for rules; docs and
6
+ * skills add if missing or refresh when the local hash still matches the last
7
+ * kit write.
8
+ *
9
+ * --force: overwrite kit AGENTS.md, CLAUDE.md, and skills (skill directories are
10
+ * deleted and recreated). Rules never overwrite.
11
+ *
12
+ * prototype-page / figma-to-page require a standalone/ directory.
13
+ *
14
+ * Intended for consumer package.json:
15
+ * "postinstall": "... ad-sync-agents"
16
+ * "sync-agents": "ad-sync-agents"
17
+ * "sync-agents:force": "ad-sync-agents --force"
18
+ *
19
+ * Commit `.claude/skills/.ad-agent-kit.json` so teammates and CI can refresh
20
+ * untouched kit files after a package bump.
21
+ */
22
+
23
+ import { createHash } from 'node:crypto';
24
+ import {
25
+ cpSync,
26
+ existsSync,
27
+ lstatSync,
28
+ mkdirSync,
29
+ readFileSync,
30
+ readdirSync,
31
+ realpathSync,
32
+ rmSync,
33
+ symlinkSync,
34
+ writeFileSync,
35
+ } from 'node:fs';
36
+ import path from 'node:path';
37
+ import { fileURLToPath, pathToFileURL } from 'node:url';
38
+
39
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
40
+ const DEFAULT_KIT = path.join(PACKAGE_ROOT, 'dist', 'agent-kit');
41
+ const STATE_FILE = '.claude/skills/.ad-agent-kit.json';
42
+
43
+ export function parseArgs(argv) {
44
+ const args = { force: false, dryRun: false, help: false };
45
+ for (const arg of argv) {
46
+ if (arg === '--help' || arg === '-h') args.help = true;
47
+ else if (arg === '--dry-run') args.dryRun = true;
48
+ else if (arg === '--force') args.force = true;
49
+ else throw new Error(`Unknown argument: ${arg}`);
50
+ }
51
+ return args;
52
+ }
53
+
54
+ export function resolveProjectRoot(options = {}) {
55
+ const initCwd = Object.prototype.hasOwnProperty.call(options, 'initCwd')
56
+ ? options.initCwd
57
+ : process.env.INIT_CWD;
58
+ const cwd = Object.prototype.hasOwnProperty.call(options, 'cwd')
59
+ ? options.cwd
60
+ : process.cwd();
61
+ if (typeof initCwd === 'string' && initCwd.length > 0 && path.isAbsolute(initCwd)) {
62
+ return initCwd;
63
+ }
64
+ return cwd;
65
+ }
66
+
67
+ function isDesignSystemRepo(projectRoot) {
68
+ return (
69
+ existsSync(path.join(projectRoot, 'packages', 'components', 'agent-kit')) ||
70
+ existsSync(path.join(projectRoot, 'apps', 'design-system', 'DESIGN.md'))
71
+ );
72
+ }
73
+
74
+ /**
75
+ * Micro UIs (and prototypes copied from micro-ui-ts) expose ./Root via Module Federation
76
+ * and keep the Root entry under src/components/Root.
77
+ */
78
+ export function isMicroUiProject(projectRoot) {
79
+ const rootCandidates = [
80
+ path.join(projectRoot, 'src', 'components', 'Root'),
81
+ path.join(projectRoot, 'src', 'components', 'Root.tsx'),
82
+ path.join(projectRoot, 'src', 'components', 'Root', 'index.tsx'),
83
+ path.join(projectRoot, 'src', 'components', 'Root', 'index.ts'),
84
+ ];
85
+ const hasRoot = rootCandidates.some((candidate) => existsSync(candidate));
86
+ if (!hasRoot) return false;
87
+
88
+ const bundlerConfigs = [
89
+ 'rspack.config.js',
90
+ 'rspack.config.cjs',
91
+ 'rspack.config.mjs',
92
+ 'rspack.config.ts',
93
+ 'webpack.config.js',
94
+ 'webpack.config.cjs',
95
+ 'webpack.config.mjs',
96
+ 'webpack.config.ts',
97
+ ];
98
+ for (const file of bundlerConfigs) {
99
+ const configPath = path.join(projectRoot, file);
100
+ if (!existsSync(configPath)) continue;
101
+ let text = '';
102
+ try {
103
+ text = readFileSync(configPath, 'utf8');
104
+ } catch {
105
+ continue;
106
+ }
107
+ const hasFederation = text.includes('ModuleFederation');
108
+ const hasExposeRoot =
109
+ text.includes('./Root') || text.includes('"./Root"') || text.includes("'./Root'");
110
+ if (hasFederation && hasExposeRoot) {
111
+ return true;
112
+ }
113
+ }
114
+ return false;
115
+ }
116
+
117
+ function collectFiles(dir, relativeBase = '', out = []) {
118
+ if (!existsSync(dir)) return out;
119
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
120
+ const full = path.join(dir, entry.name);
121
+ const rel = path.join(relativeBase, entry.name).replace(/\\/g, '/');
122
+ if (entry.isDirectory()) {
123
+ collectFiles(full, rel, out);
124
+ } else if (entry.isFile() || entry.isSymbolicLink()) {
125
+ out.push({ full, rel });
126
+ }
127
+ }
128
+ return out;
129
+ }
130
+
131
+ function hashBytes(buffer) {
132
+ return createHash('sha256').update(buffer).digest('hex');
133
+ }
134
+
135
+ function hashFile(filePath) {
136
+ return hashBytes(readFileSync(filePath));
137
+ }
138
+
139
+ function hashTree(dir) {
140
+ const files = collectFiles(dir).sort((a, b) => a.rel.localeCompare(b.rel));
141
+ const h = createHash('sha256');
142
+ for (const file of files) {
143
+ h.update(file.rel);
144
+ h.update('\0');
145
+ h.update(readFileSync(file.full));
146
+ h.update('\0');
147
+ }
148
+ return h.digest('hex');
149
+ }
150
+
151
+ function readState(projectRoot) {
152
+ const statePath = path.join(projectRoot, STATE_FILE);
153
+ if (!existsSync(statePath)) return { version: null, files: {} };
154
+ try {
155
+ return JSON.parse(readFileSync(statePath, 'utf8'));
156
+ } catch {
157
+ return { version: null, files: {} };
158
+ }
159
+ }
160
+
161
+ function writeState(projectRoot, state, { dryRun }) {
162
+ if (dryRun) return;
163
+ const statePath = path.join(projectRoot, STATE_FILE);
164
+ mkdirSync(path.dirname(statePath), { recursive: true });
165
+ writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
166
+ }
167
+
168
+ function copyFile(src, dest, { dryRun }) {
169
+ if (dryRun) return;
170
+ mkdirSync(path.dirname(dest), { recursive: true });
171
+ cpSync(src, dest);
172
+ }
173
+
174
+ function copyDir(src, dest, { dryRun }) {
175
+ if (dryRun) return;
176
+ mkdirSync(path.dirname(dest), { recursive: true });
177
+ if (existsSync(dest)) {
178
+ rmSync(dest, { recursive: true, force: true });
179
+ }
180
+ cpSync(src, dest, { recursive: true });
181
+ }
182
+
183
+ /**
184
+ * Convert a Cursor .mdc rule into a Claude Code .md rule (same as micro-ui-ts rules:sync).
185
+ */
186
+ export function renderClaudeRule(mdcText, sourceFile) {
187
+ const match = mdcText.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
188
+ if (!match) {
189
+ throw new Error(`${sourceFile} has no frontmatter`);
190
+ }
191
+ const fields = {};
192
+ for (const line of match[1].split('\n')) {
193
+ const colon = line.indexOf(':');
194
+ if (colon <= 0) continue;
195
+ const key = line.slice(0, colon);
196
+ if (!/^[A-Za-z0-9_]+$/.test(key)) continue;
197
+ fields[key] = line.slice(colon + 1).trim();
198
+ }
199
+ const globs = (fields.globs ?? '')
200
+ .split(',')
201
+ .map((glob) => glob.trim())
202
+ .filter(Boolean);
203
+ const body = match[2].replace(/^\n+/, '');
204
+ const frontmatter = globs.length
205
+ ? `---\npaths:\n${globs.map((glob) => ` - "${glob}"`).join('\n')}\n---\n\n`
206
+ : '';
207
+ return `${frontmatter}<!-- Generated from .cursor/rules/${sourceFile} by ad-sync-agents. Edit that file instead. -->\n\n${body}`;
208
+ }
209
+
210
+ function syncClaudeRuleFromMdc(projectRoot, mdcDestRelative, { dryRun, log, warn = console.warn }) {
211
+ const mdcPath = path.join(projectRoot, mdcDestRelative);
212
+ if (!existsSync(mdcPath)) return;
213
+ const base = path.basename(mdcDestRelative, '.mdc');
214
+ const claudeDest = path.join(projectRoot, '.claude', 'rules', `${base}.md`);
215
+ let rendered;
216
+ try {
217
+ rendered = renderClaudeRule(readFileSync(mdcPath, 'utf8'), path.basename(mdcDestRelative));
218
+ } catch (err) {
219
+ warn(`[ad-sync-agents] Skip Claude rule for ${mdcDestRelative}: ${err.message}`);
220
+ return;
221
+ }
222
+ if (existsSync(claudeDest) && readFileSync(claudeDest, 'utf8') === rendered) {
223
+ return;
224
+ }
225
+ if (!dryRun) {
226
+ mkdirSync(path.dirname(claudeDest), { recursive: true });
227
+ writeFileSync(claudeDest, rendered, 'utf8');
228
+ }
229
+ log(`[ad-sync-agents] Synced .claude/rules/${base}.md`);
230
+ }
231
+
232
+ function ensureCursorSkillsSymlink(projectRoot, { dryRun, log }) {
233
+ const linkPath = path.join(projectRoot, '.cursor', 'skills');
234
+ const target = '../.claude/skills';
235
+ let stat = null;
236
+ try {
237
+ stat = lstatSync(linkPath);
238
+ } catch {
239
+ // missing
240
+ }
241
+ if (stat) {
242
+ if (!stat.isSymbolicLink() && stat.isDirectory()) {
243
+ log(
244
+ '[ad-sync-agents] `.cursor/skills` exists and is not a symlink; kit skills are only visible to Claude Code'
245
+ );
246
+ }
247
+ return;
248
+ }
249
+ if (dryRun) {
250
+ log(`[ad-sync-agents] Dry run: would link .cursor/skills -> ${target}`);
251
+ return;
252
+ }
253
+ mkdirSync(path.join(projectRoot, '.cursor'), { recursive: true });
254
+ mkdirSync(path.join(projectRoot, '.claude', 'skills'), { recursive: true });
255
+ try {
256
+ symlinkSync(target, linkPath);
257
+ log(`[ad-sync-agents] Linked .cursor/skills -> ${target}`);
258
+ } catch (err) {
259
+ log(`[ad-sync-agents] Could not link .cursor/skills: ${err.message}`);
260
+ }
261
+ }
262
+
263
+ function meetsRequires(projectRoot, requires) {
264
+ if (!requires) return true;
265
+ if (requires === 'standalone') {
266
+ return existsSync(path.join(projectRoot, 'standalone'));
267
+ }
268
+ return existsSync(path.join(projectRoot, requires));
269
+ }
270
+
271
+ function recordStateHash(nextFiles, entry, result) {
272
+ if (result.hash && result.status !== 'skipped' && result.status !== 'kept') {
273
+ nextFiles[entry.id] = { hash: result.hash, dest: entry.dest };
274
+ }
275
+ }
276
+
277
+ function syncHashedPath({
278
+ id,
279
+ destRelative,
280
+ nextHash,
281
+ exists,
282
+ currentHash,
283
+ prevHash,
284
+ force,
285
+ dryRun,
286
+ log,
287
+ write,
288
+ forceNote,
289
+ }) {
290
+ if (!exists) {
291
+ if (dryRun) {
292
+ log(`[ad-sync-agents] Dry run: would add ${destRelative}`);
293
+ return { id, status: 'dry-run', hash: nextHash };
294
+ }
295
+ write();
296
+ log(`[ad-sync-agents] Added ${destRelative}`);
297
+ return { id, status: 'added', hash: nextHash };
298
+ }
299
+
300
+ if (force) {
301
+ if (dryRun) {
302
+ log(`[ad-sync-agents] Dry run: would overwrite ${destRelative}`);
303
+ return { id, status: 'dry-run', hash: nextHash };
304
+ }
305
+ if (forceNote) log(forceNote);
306
+ write();
307
+ log(`[ad-sync-agents] Updated ${destRelative} (--force)`);
308
+ return { id, status: 'updated', hash: nextHash };
309
+ }
310
+
311
+ if (currentHash === nextHash) {
312
+ log(`[ad-sync-agents] Already in sync ${destRelative}`);
313
+ return { id, status: 'unchanged', hash: nextHash };
314
+ }
315
+
316
+ if (prevHash && currentHash === prevHash) {
317
+ if (dryRun) {
318
+ log(`[ad-sync-agents] Dry run: would refresh ${destRelative}`);
319
+ return { id, status: 'dry-run', hash: nextHash };
320
+ }
321
+ write();
322
+ log(`[ad-sync-agents] Refreshed ${destRelative}`);
323
+ return { id, status: 'refreshed', hash: nextHash };
324
+ }
325
+
326
+ log(`[ad-sync-agents] Keep local edits ${destRelative}`);
327
+ return { id, status: 'kept', hash: prevHash || currentHash };
328
+ }
329
+
330
+ function syncDoc(entry, kitRoot, projectRoot, state, { force, dryRun, log }) {
331
+ const src = path.join(kitRoot, entry.source);
332
+ const dest = path.join(projectRoot, entry.dest);
333
+ if (!existsSync(src)) {
334
+ return { id: entry.id, status: 'skipped', reason: 'source-missing' };
335
+ }
336
+ const nextHash = hashFile(src);
337
+ const exists = existsSync(dest);
338
+ const prevHash = state.files?.[entry.id]?.hash;
339
+ const currentHash = exists ? hashFile(dest) : null;
340
+ return syncHashedPath({
341
+ id: entry.id,
342
+ destRelative: entry.dest,
343
+ nextHash,
344
+ exists,
345
+ currentHash,
346
+ prevHash,
347
+ force,
348
+ dryRun,
349
+ log,
350
+ write: () => copyFile(src, dest, { dryRun }),
351
+ });
352
+ }
353
+
354
+ function syncRule(entry, kitRoot, projectRoot, { dryRun, log, warn }) {
355
+ const src = path.join(kitRoot, entry.source);
356
+ const dest = path.join(projectRoot, entry.dest);
357
+ if (!existsSync(src)) {
358
+ return { id: entry.id, status: 'skipped', reason: 'source-missing' };
359
+ }
360
+ if (existsSync(dest)) {
361
+ log(`[ad-sync-agents] Keep existing ${entry.dest}`);
362
+ syncClaudeRuleFromMdc(projectRoot, entry.dest, { dryRun, log, warn });
363
+ return { id: entry.id, status: 'kept' };
364
+ }
365
+ if (dryRun) {
366
+ log(`[ad-sync-agents] Dry run: would write ${entry.dest}`);
367
+ return { id: entry.id, status: 'dry-run' };
368
+ }
369
+ copyFile(src, dest, { dryRun });
370
+ log(`[ad-sync-agents] Added ${entry.dest}`);
371
+ syncClaudeRuleFromMdc(projectRoot, entry.dest, { dryRun, log, warn });
372
+ return { id: entry.id, status: 'added' };
373
+ }
374
+
375
+ function syncSkill(entry, kitRoot, projectRoot, state, { force, dryRun, log }) {
376
+ const src = path.join(kitRoot, entry.source);
377
+ const dest = path.join(projectRoot, entry.dest);
378
+ if (!existsSync(src)) {
379
+ return { id: entry.id, status: 'skipped', reason: 'source-missing' };
380
+ }
381
+ if (!meetsRequires(projectRoot, entry.requires)) {
382
+ log(`[ad-sync-agents] Skip ${entry.id} (requires ${entry.requires}/, not present)`);
383
+ return { id: entry.id, status: 'skipped', reason: 'requires-missing' };
384
+ }
385
+
386
+ const nextHash = hashTree(src);
387
+ const exists = existsSync(dest);
388
+ const prevHash = state.files?.[entry.id]?.hash;
389
+ const currentHash = exists ? hashTree(dest) : null;
390
+ const locallyModified =
391
+ exists && currentHash !== nextHash && (!prevHash || currentHash !== prevHash);
392
+
393
+ return syncHashedPath({
394
+ id: entry.id,
395
+ destRelative: entry.dest,
396
+ nextHash,
397
+ exists,
398
+ currentHash,
399
+ prevHash,
400
+ force,
401
+ dryRun,
402
+ log,
403
+ forceNote: locallyModified
404
+ ? `[ad-sync-agents] --force: replacing locally modified ${entry.dest} (skill directory is deleted and recreated)`
405
+ : `[ad-sync-agents] --force: replacing ${entry.dest} (skill directory is deleted and recreated)`,
406
+ write: () => copyDir(src, dest, { dryRun }),
407
+ });
408
+ }
409
+
410
+ export async function syncAgents({
411
+ kitRoot = DEFAULT_KIT,
412
+ projectRoot = resolveProjectRoot(),
413
+ packageVersion = null,
414
+ force = false,
415
+ dryRun = false,
416
+ log = console.log,
417
+ warn = console.warn,
418
+ } = {}) {
419
+ if (isDesignSystemRepo(projectRoot)) {
420
+ log('[ad-sync-agents] Skip: project root looks like ad-design-system');
421
+ return { status: 'skipped', reason: 'design-system-repo' };
422
+ }
423
+
424
+ if (!isMicroUiProject(projectRoot)) {
425
+ log(
426
+ '[ad-sync-agents] Skip: not a micro UI (need src/components/Root and Module Federation exposes ./Root in rspack/webpack config)'
427
+ );
428
+ return { status: 'skipped', reason: 'not-micro-ui' };
429
+ }
430
+
431
+ const manifestPath = path.join(kitRoot, 'manifest.json');
432
+ if (!existsSync(manifestPath)) {
433
+ warn(`[ad-sync-agents] Kit not found at ${kitRoot}`);
434
+ warn('[ad-sync-agents] Skipping. Build or upgrade @appdirect/design-system to enable sync.');
435
+ return { status: 'skipped', reason: 'source-missing' };
436
+ }
437
+
438
+ let manifest;
439
+ try {
440
+ manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
441
+ } catch (err) {
442
+ warn(`[ad-sync-agents] Invalid manifest at ${manifestPath}: ${err.message}`);
443
+ return { status: 'skipped', reason: 'invalid-manifest' };
444
+ }
445
+
446
+ const state = readState(projectRoot);
447
+ const results = { docs: [], rules: [], skills: [] };
448
+ const nextFiles = { ...(state.files || {}) };
449
+
450
+ for (const entry of manifest.docs ?? []) {
451
+ const result = syncDoc(entry, kitRoot, projectRoot, state, { force, dryRun, log });
452
+ results.docs.push(result);
453
+ recordStateHash(nextFiles, entry, result);
454
+ }
455
+ for (const entry of manifest.rules ?? []) {
456
+ results.rules.push(syncRule(entry, kitRoot, projectRoot, { dryRun, log, warn }));
457
+ }
458
+
459
+ ensureCursorSkillsSymlink(projectRoot, { dryRun, log });
460
+
461
+ for (const entry of manifest.skills ?? []) {
462
+ const result = syncSkill(entry, kitRoot, projectRoot, state, { force, dryRun, log });
463
+ results.skills.push(result);
464
+ recordStateHash(nextFiles, entry, result);
465
+ }
466
+
467
+ let version = packageVersion;
468
+ if (!version) {
469
+ try {
470
+ version = JSON.parse(readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8')).version;
471
+ } catch {
472
+ version = null;
473
+ }
474
+ }
475
+
476
+ writeState(
477
+ projectRoot,
478
+ { version, package: '@appdirect/design-system', files: nextFiles },
479
+ { dryRun }
480
+ );
481
+
482
+ return { status: 'ok', results };
483
+ }
484
+
485
+ function printHelp() {
486
+ console.log(`Usage: ad-sync-agents [--force] [--dry-run]
487
+
488
+ Copies the micro-UI agent kit from @appdirect/design-system/dist/agent-kit
489
+ into the consumer project (AGENTS.md, CLAUDE.md, .cursor/rules, .claude/skills).
490
+
491
+ Only runs in micro UI projects (src/components/Root + Module Federation ./Root
492
+ in rspack/webpack config). Skips other apps quietly.
493
+
494
+ Default: add missing files; refresh untouched kit docs/skills; never overwrite rules.
495
+ --force: overwrite kit AGENTS.md, CLAUDE.md, and skills (skill directories are
496
+ deleted and recreated; rules still add-only).
497
+
498
+ Commit .claude/skills/.ad-agent-kit.json so refreshes work across clones/CI.
499
+ Postinstall errors warn and exit 0 so npm install is not blocked.
500
+ `);
501
+ }
502
+
503
+ /**
504
+ * True when this file is the process entrypoint. Resolve symlinks so npm's
505
+ * node_modules/.bin/ad-sync-agents link still matches import.meta.url.
506
+ */
507
+ export function isCliEntrypoint({
508
+ argv1 = process.argv[1],
509
+ moduleUrl = import.meta.url,
510
+ realpathFn = realpathSync,
511
+ } = {}) {
512
+ if (!argv1) return false;
513
+ try {
514
+ return moduleUrl === pathToFileURL(realpathFn(path.resolve(argv1))).href;
515
+ } catch {
516
+ return false;
517
+ }
518
+ }
519
+
520
+ if (isCliEntrypoint()) {
521
+ try {
522
+ const args = parseArgs(process.argv.slice(2));
523
+ if (args.help) {
524
+ printHelp();
525
+ process.exit(0);
526
+ }
527
+ const result = await syncAgents({
528
+ force: args.force,
529
+ dryRun: args.dryRun,
530
+ });
531
+ if (result.status === 'skipped') {
532
+ process.exit(0);
533
+ }
534
+ } catch (err) {
535
+ console.error(`[ad-sync-agents] ${err.message}`);
536
+ if (process.env.npm_lifecycle_event === 'postinstall') {
537
+ console.warn('[ad-sync-agents] Continuing after postinstall error (sync is best-effort).');
538
+ process.exit(0);
539
+ }
540
+ process.exit(1);
541
+ }
542
+ }
@@ -3,7 +3,6 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import React from 'react';
4
4
  import { Card } from '../../DataDisplay/Card.js';
5
5
  import { Alert } from '../../DataDisplay/Alert.js';
6
- import { Stack, Inline, Box } from '../../Layout/index.js';
7
6
  import { Title } from '../../Typography/Title.js';
8
7
  import { Text } from '../../Typography/Text.js';
9
8
  import { Switch } from '../../Inputs/Switch.js';
@@ -16,35 +15,29 @@ import { RiMore2Fill, RiArrowRightSLine, RiEditLine } from '@remixicon/react';
16
15
  * DashboardWidget Component
17
16
  *
18
17
  * A flexible widget container for dashboard content with optional controls.
19
- * Built on top of the Card component with consistent spacing and styling.
18
+ * Built on top of the Card component. Layout and color come from
19
+ * `.ad-DashboardWidget*` classes emitted by the dashboard-widget token adapter.
20
+ * The card is a flex column at height 100%. Extra equal-height grid space
21
+ * goes to the content slot. The footer is always the last in-flow child
22
+ * (links, or an empty spacer) so footers share one baseline across a row.
20
23
  *
21
24
  * @example
22
25
  * // Basic widget with content
23
26
  * <DashboardWidget title="A widget title">
24
- * <Text>This is a slot. To use it:</Text>
25
- * <ul>
26
- * <li>Create a local component with autolayout on</li>
27
- * <li>Switch out this slot with that component using the component instance switcher</li>
28
- * </ul>
27
+ * <Text>This is a slot.</Text>
29
28
  * </DashboardWidget>
30
29
  *
31
30
  * @example
32
31
  * // Widget with all features
33
32
  * <DashboardWidget
34
33
  * title="Analytics Widget"
34
+ * interactive
35
+ * selected
35
36
  * switch={{
36
37
  * label: "Live updates",
37
38
  * checked: true,
38
39
  * onChange: (checked) => console.log(checked)
39
40
  * }}
40
- * actionsMenu={{
41
- * sections: [{
42
- * items: [
43
- * { label: "Export", onClick: () => console.log("Export") },
44
- * { label: "Settings", onClick: () => console.log("Settings") }
45
- * ]
46
- * }]
47
- * }}
48
41
  * headerSelect={{
49
42
  * placeholder: "Select filter",
50
43
  * data: ["Option 1", "Option 2", "Option 3"],
@@ -52,45 +45,16 @@ import { RiMore2Fill, RiArrowRightSLine, RiEditLine } from '@remixicon/react';
52
45
  * }}
53
46
  * footerLinks={[
54
47
  * { label: "Link 1", onClick: () => console.log("Link 1") },
55
- * { label: "Link 2", onClick: () => console.log("Link 2") },
56
- * { label: "Link 3", onClick: () => console.log("Link 3") }
48
+ * { label: "Link 2", onClick: () => console.log("Link 2") }
57
49
  * ]}
58
50
  * >
59
51
  * <YourCustomContent />
60
52
  * </DashboardWidget>
61
53
  */
62
- export function DashboardWidget({ title, editable = false, onEdit, panelNotification = false, panelNotificationMessage, switch: switchConfig, actionsMenu, children, headerSelect, footerLinks, cardProps = {}, spacing = 'xs', }) {
63
- // ==================== RENDER FUNCTIONS ==========================
64
- const renderHeader = () => (_jsxs(Inline, { justify: "space-between", align: "flex-start", children: [_jsx(Stack, { gap: "xs", children: _jsxs(Inline, { gap: "xs", align: "center", children: [_jsx(Title, { order: 4, children: title }), editable && (_jsx(ActionIcon, { size: "sm", onClick: onEdit, "aria-label": "Edit title", children: _jsx(RiEditLine, { size: 16 }) }))] }) }), _jsxs(Inline, { gap: "sm", align: "center", children: [switchConfig && (_jsxs(Inline, { gap: "xs", align: "center", children: [_jsx(Text, { size: "sm", children: switchConfig.label }), _jsx(Switch, { checked: switchConfig.checked, onChange: (event) => switchConfig.onChange(event.currentTarget.checked), disabled: switchConfig.disabled, size: "sm" })] })), headerSelect && (_jsx(Select, { data: headerSelect.data, value: headerSelect.value, onChange: headerSelect.onChange, placeholder: headerSelect.placeholder, disabled: headerSelect.disabled, searchable: headerSelect.searchable, clearable: headerSelect.clearable, borderless: true, size: "sm" })), actionsMenu && !headerSelect && (_jsx(Menu, { trigger: _jsx(ActionIcon, { size: "sm", "aria-label": "Widget actions", children: _jsx(RiMore2Fill, { size: 16 }) }), position: "bottom-end", sections: actionsMenu.sections }))] })] }));
65
- const renderFooterLinks = () => {
66
- return (_jsx(Box, { p: "sm", pl: "lg", pr: "lg", children: footerLinks && footerLinks.length > 0 ? (_jsx(Inline, { gap: "xs", children: footerLinks.map((link, index) => (_jsxs(Inline, { gap: "xs", align: "center", onClick: link.disabled ? undefined : link.onClick, style: {
67
- cursor: link.disabled ? 'not-allowed' : 'pointer',
68
- opacity: link.disabled ? 0.5 : 1,
69
- color: link.disabled ? 'var(--ad-color-text-dimmed)' : 'var(--ad-color-brand-primary)',
70
- transition: 'color 0.2s ease',
71
- }, children: [_jsx(Text, { size: "sm", c: link.disabled ? 'dimmed' : 'blue', children: link.label }), _jsx(RiArrowRightSLine, { size: 14 })] }, index))) })) : (
72
- // Empty footer that maintains the same height
73
- _jsx(Box, { style: { height: '21px' } })) }));
74
- };
75
- // ==================== MAIN RENDER ==========================
76
- return (_jsxs(Card, { ...cardProps, pl: "lg", pr: "lg", pt: "sm", pb: 0, style: {
77
- position: 'relative',
78
- height: '100%',
79
- overflow: 'hidden',
80
- ...cardProps.style,
81
- }, children: [_jsxs(Stack, { gap: spacing, style: {
82
- height: '100%',
83
- paddingBottom: '60px', // Space for fixed footer
84
- }, children: [renderHeader(), panelNotification && (_jsx(Alert, { color: "info", children: panelNotificationMessage })), _jsx(Box, { style: {
85
- flex: 1,
86
- overflowY: 'auto',
87
- overflowX: 'hidden',
88
- paddingRight: '4px', // Space for scrollbar
89
- }, children: children })] }), _jsx("div", { style: {
90
- position: 'absolute',
91
- bottom: 0,
92
- left: 0,
93
- right: 0,
94
- backgroundColor: 'var(--ad-color-bg-default)',
95
- }, children: renderFooterLinks() })] }));
54
+ export function DashboardWidget({ title, editable = false, onEdit, panelNotification = false, panelNotificationMessage, switch: switchConfig, actionsMenu, children, headerSelect, footerLinks, cardProps = {}, spacing = 'lg', interactive = false, selected = false, }) {
55
+ const { className: cardClassName, style: cardStyle, ...restCardProps } = cardProps;
56
+ const hasFooterLinks = Boolean(footerLinks && footerLinks.length > 0);
57
+ const renderHeader = () => (_jsxs("div", { className: "ad-DashboardWidget-header", children: [_jsxs("div", { className: "ad-DashboardWidget-titleGroup", children: [_jsx(Title, { order: 4, className: "ad-DashboardWidget-title", children: title }), editable && (_jsx(ActionIcon, { size: "sm", onClick: onEdit, "aria-label": "Edit title", children: _jsx(RiEditLine, { size: 16 }) }))] }), _jsxs("div", { className: "ad-DashboardWidget-controls", children: [switchConfig && (_jsxs("div", { className: "ad-DashboardWidget-switch", children: [switchConfig.label ? _jsx(Text, { size: "sm", children: switchConfig.label }) : null, _jsx(Switch, { checked: switchConfig.checked, onChange: (event) => switchConfig.onChange(event.currentTarget.checked), disabled: switchConfig.disabled, size: "sm" })] })), headerSelect && (_jsx(Select, { data: headerSelect.data, value: headerSelect.value, onChange: headerSelect.onChange, placeholder: headerSelect.placeholder, disabled: headerSelect.disabled, searchable: headerSelect.searchable, clearable: headerSelect.clearable, borderless: true, size: "sm" })), actionsMenu && !headerSelect && (_jsx(Menu, { trigger: _jsx(ActionIcon, { size: "sm", "aria-label": "Widget actions", children: _jsx(RiMore2Fill, { size: 16 }) }), position: "bottom-end", sections: actionsMenu.sections }))] })] }));
58
+ const renderFooter = () => (_jsx("div", { className: "ad-DashboardWidget-footer", children: hasFooterLinks ? (_jsx("div", { className: "ad-DashboardWidget-footerLinks", children: footerLinks.map((link, index) => (_jsxs("button", { type: "button", className: "ad-DashboardWidget-footerLink", "data-disabled": link.disabled ? '' : undefined, disabled: link.disabled, onClick: link.disabled ? undefined : link.onClick, children: [_jsx(Text, { span: true, size: "sm", children: link.label }), _jsx(RiArrowRightSLine, { size: 14 })] }, index))) })) : (_jsx("div", { className: "ad-DashboardWidget-footerSpacer" })) }));
59
+ return (_jsxs(Card, { ...restCardProps, style: cardStyle, className: ['ad-DashboardWidget', cardClassName].filter(Boolean).join(' '), "data-interactive": interactive ? '' : undefined, "data-selected": selected ? '' : undefined, children: [_jsxs("div", { className: "ad-DashboardWidget-body", "data-spacing": spacing === 'lg' ? undefined : spacing, children: [renderHeader(), panelNotification && (_jsx(Alert, { color: "info", children: panelNotificationMessage })), _jsx("div", { className: "ad-DashboardWidget-content", children: children })] }), renderFooter()] }));
96
60
  }