@appdirect/design-system 0.0.19 → 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 (29) hide show
  1. package/README.md +21 -0
  2. package/bin/ad-sync-agents.mjs +542 -0
  3. package/dist/DESIGN.md +49 -7
  4. package/dist/agent-kit/README.md +11 -0
  5. package/dist/agent-kit/manifest.json +81 -0
  6. package/dist/agent-kit/micro-ui/CLAUDE.md +1 -0
  7. package/dist/agent-kit/micro-ui/micro-ui.AGENTS.md +62 -0
  8. package/dist/agent-kit/rules/accessibility.mdc +46 -0
  9. package/dist/agent-kit/rules/module-federation.mdc +30 -0
  10. package/dist/agent-kit/rules/react-stack.mdc +73 -0
  11. package/dist/agent-kit/rules/testing.mdc +44 -0
  12. package/dist/agent-kit/skills/design-feature/SKILL.md +205 -0
  13. package/dist/agent-kit/skills/developer-handoff/SKILL.md +192 -0
  14. package/dist/agent-kit/skills/figma-mcp-integration/SKILL.md +134 -0
  15. package/dist/agent-kit/skills/figma-to-page/SKILL.md +24 -0
  16. package/dist/agent-kit/skills/mantine-combobox/SKILL.md +73 -0
  17. package/dist/agent-kit/skills/mantine-combobox/references/api.md +199 -0
  18. package/dist/agent-kit/skills/mantine-combobox/references/patterns.md +279 -0
  19. package/dist/agent-kit/skills/mantine-custom-components/SKILL.md +112 -0
  20. package/dist/agent-kit/skills/mantine-custom-components/references/api.md +407 -0
  21. package/dist/agent-kit/skills/mantine-custom-components/references/patterns.md +431 -0
  22. package/dist/agent-kit/skills/mantine-form/SKILL.md +103 -0
  23. package/dist/agent-kit/skills/mantine-form/references/api.md +313 -0
  24. package/dist/agent-kit/skills/mantine-form/references/patterns.md +310 -0
  25. package/dist/agent-kit/skills/prototype-page/SKILL.md +82 -0
  26. package/dist/contracts/index.json +1 -1
  27. package/dist/skills/design-feature/SKILL.md +205 -0
  28. package/dist/stories/index.json +1 -1
  29. 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
+ }
package/dist/DESIGN.md CHANGED
@@ -357,6 +357,8 @@ All inputs default to `radius="sm"` and `size="sm"` matching the button default.
357
357
 
358
358
  `SearchableSelect` and `AutocompleteClearable` are opinionated wrappers with built-in clear affordance. Use `Multiselect` for tag-style multi-value selection.
359
359
 
360
+ **Toolbar vs tag-editor chips** — in dense table toolbars, multi-select values belong in the **chip row above the table**, with a **count** in the control (see **DataTable patterns**). Do not pile chips inside the combobox there; it breaks horizontal layouts. Standalone tag editors (e.g. form fields that edit a list of tags) may keep chips in the field.
361
+
360
362
  ---
361
363
 
362
364
  ### Navigation
@@ -371,9 +373,10 @@ All inputs default to `radius="sm"` and `size="sm"` matching the button default.
371
373
 
372
374
  `Modal` · `ConfirmationModal` · `Drawer` · `Menu` · `Popover` · `ConfirmationPopover` · `Tooltip`
373
375
 
374
- - `ConfirmationModal` — preconfigured two-button (confirm/cancel) modal for destructive actions
375
- - `ConfirmationPopover` — inline confirm/cancel popover; preferred over modal for lower-stakes confirmations that don't require full-screen focus
376
- - `Menu` accepts typed `MenuItem` and `MenuSection` arrays for structured dropdowns
376
+ - `ConfirmationModal` — preconfigured two-button (confirm/cancel) modal. Use for **bulk, high-stakes, or multi-item** destructive actions that need full-screen focus. Pass `confirmVariant="danger"` and irreversible copy (e.g. “cannot be undone”); set `confirmLabel` to the action (e.g. Delete).
377
+ - `ConfirmationPopover` — inline confirm/cancel popover. **Preferred** for single-item, lower-stakes confirmations that do not need full-screen focus. Same `confirmVariant="danger"` / irreversible-copy rules for deletes.
378
+ - Destructive flows are always two-step: the user chooses Delete, then confirms in Modal or Popover. Never delete on the first click. There is no type-to-confirm or second dialog in the DS.
379
+ - `Menu` accepts typed `MenuItem` and `MenuSection` arrays for structured dropdowns. Use for overflow / row-action menus; mark destructive items with the menu’s danger affordance and open confirm (above) instead of deleting immediately.
377
380
 
378
381
  ---
379
382
 
@@ -381,6 +384,11 @@ All inputs default to `radius="sm"` and `size="sm"` matching the button default.
381
384
 
382
385
  `Alert` · `Avatar` · `Badge` · `Card` · `CardSection` · `Chip` · `Pill` · `Indicator` · `Progress` · `ThemeIcon` · `List` · `Table`
383
386
 
387
+ **Alert vs Notification**
388
+ - Prefer micro-container **toasts** via `document.body.dispatchEvent(new CustomEvent('ad-toast', { detail: { title, message, type } }))` for transient success/info after an action (saved, exported, queued). Do **not** use Mantine `Notification` / `@mantine/notifications` in app or prototype code — `ds-enforce` disallows it.
389
+ - Use **Alert** for persistent in-page status: errors that block or explain the view, empty/error banners in the table shell, or page-level messaging that must stay visible until dismissed or resolved.
390
+ - Alert stays `variant="light"`. Status color is `info` / `success` / `danger` / `pending` / `default` — never `warning` on Alert. Always pair status color with icon and text.
391
+
384
392
  **Badge:**
385
393
  - Variants: `filled` (default) · `outline` · `info` · `success` · `pending` · `warning` · `danger` · `default`
386
394
  - Colors: `info` · `success` · `pending` · `warning` · `danger` · `default` · `blue` · `green` · `yellow` · `red` · `gray`
@@ -489,9 +497,43 @@ Figma auto-layout mapping: `flex-direction: column` → `Stack`; `flex-direction
489
497
  - Server-side sort via `SortableHeaderCell` in column headers (state lives in the page)
490
498
  - Row selection (`rowSelection`, `onRowSelectionChange`) with a selection banner and bulk `selectionActions`
491
499
  - Density (`xs` 10px, `md` 16px, `xl` 32px; both axes) and fullscreen, both controlled
492
- - Top toolbar with search, filter chips and date range; bottom toolbar with pagination
500
+ - Top toolbar with search, filter toggle, filter chips and date range; bottom toolbar with pagination
493
501
  - Loading skeleton rows, empty and error states
494
502
  - Styled with `--ad-table-*` tokens in CSS modules (the one place CSS modules are allowed, because the grid diverges from Mantine's supported MRT)
503
+ - Interaction patterns (filters, delete confirm, row overflow menu, narrow width) — see **DataTable patterns** below
504
+
505
+ #### DataTable patterns
506
+
507
+ **Filters (toolbar)** — search stays always visible. Extra filters are tucked behind a filter `ActionIcon` next to search (`variant="default"` when closed, `"outline"` when open). Show an `Indicator` on the toggle when any non-search filter is active. Opening the toggle reveals a panel (`SimpleGrid`, typically 3 columns) of filter controls. Applied filters appear as dismissible chips; toolbar “Clear filters” clears chip filters but **keeps** search. Empty-state / full reset may also clear search — treat that as a different action from toolbar clear. Product tables own filter state via controlled `filters` / `onFiltersChange` / `showFilters` / `onFilterToggleChange`. The reference toolbar’s city + date-range filters are demo-hardcoded; replace them with the page’s real filter fields. Do not treat the orphan `FilterSystem` demo as the DataTable filter API.
508
+
509
+ **Multi-select filters / chips** — multi-select controls show a **count** in the control; selected values appear as **chips in the chip row above** the table, not stuffed inside the combobox. Do **not** use Mantine’s default of rendering many chips inside the combobox — it breaks horizontal toolbar layouts. Single-value filters (e.g. a date string) may display their value inside the control. See also Combobox.
510
+
511
+ **Selection** — changing search or filters clears all row selections. Selecting rows across pages is allowed while the same search/filter criteria stay in place.
512
+
513
+ **Action hierarchy (list pages)**
514
+ - **Primary** (page / `PageContentHeader` or facets bar): Create new, Export / Download CSV — one primary CTA max.
515
+ - **Secondary** (selection banner): bulk actions on selected rows (delete, save, duplicate) — still confirm destructive ones (see Overlays).
516
+ - **Tertiary** (row ⋯ / table kebab): Export CSV and other low-frequency table actions.
517
+ - **Facets**: when the page has facet navigation, use `Tabs` **outside** the expandable filters panel.
518
+ - **Toolbar**: search always visible; show/hide filters; density (3 levels); fullscreen expand/shrink; optional show/hide columns when product needs it.
519
+ - **Footer**: result/record count + cursor pagination.
520
+
521
+ **Destructive delete** — always two-step (see Overlays). Wire confirm from `selectionActions.onClick` (bulk) or the row Delete menu item; do not delete on first click. Bulk / multi-item / high-stakes → `ConfirmationModal` with `confirmVariant="danger"`. Single low-stakes row delete → `ConfirmationPopover`. The reference table’s selection banner Delete does not open confirm yet — product UIs must still follow this pattern.
522
+
523
+ **Row actions (⋯)** — DataTable has no built-in actions column. Compose a trailing column (or last cell) with one overflow control: `ActionIcon` (default variant) + `RiMore2Fill`, translated `aria-label`, opening a `Menu` of secondary actions. `secret` is a Button variant only — never use it on ActionIcon (allowed ActionIcon variants: `default`, `outline`, `link`). Prefer the overflow menu over a row of icon buttons when there is more than one secondary action. Destructive items use the menu danger affordance and open confirm (above), not immediate delete. Same overflow trigger pattern as `DashboardWidget`’s actions menu.
524
+
525
+ **Narrow width** — supported strategy is horizontal scroll inside the table shell (`overflow: auto`) with a sticky header. Columns keep min widths; the grid does not collapse to cards or hide columns at breakpoints. Use `CellHoverReveal` for truncated cell text. Prioritize fewer, meaningful default columns. Do not invent stacked/card table layouts for admin list pages unless product design (Design Ops / the owning UX designer) explicitly adds them and updates this file.
526
+
527
+ #### List page composition
528
+
529
+ Standard admin list stack (top → bottom):
530
+
531
+ 1. `PageContentHeader` — icon, title, subhead, page-level actions (required on prototype/admin list and detail pages). Pick one `contentSection`: Insights, Description, Name/Value Pairs, or Drawer. Keep description copy short; link out rather than long text that goes stale.
532
+ 2. Optional page-level status — Panel Notification or in-page `Alert` (not a toast) when the whole view needs persistent messaging.
533
+ 3. Optional facet `Tabs` — outside the DataTable filter panel when the page has facet navigation.
534
+ 4. `DataTable` — toolbar → grid → footer (see **DataTable patterns**).
535
+
536
+ Detail pages use `PageContentHeader` + Cards / forms instead of DataTable. Do not invent alternate list chrome that skips PCH or relocates search/filters outside the DataTable toolbar pattern above.
495
537
 
496
538
  **KeyInsight** — single KPI tile: `value`, `title`, `subtitle`, optional right border divider
497
539
 
@@ -597,7 +639,7 @@ This order is already configured in `app/layout.tsx` and `.storybook/preview.tsx
597
639
  | `@mantine/core` | `^9.6.0` | Base component library |
598
640
  | `@mantine/hooks` | `^9.6.0` | Utility hooks (useDisclosure, etc.) |
599
641
  | `@mantine/dates` | `^9.6.0` | Date/time inputs |
600
- | `@mantine/notifications` | `^9.6.0` | Toast notifications |
642
+ | `@mantine/notifications` | `^9.6.0` | Do not use in apps — prefer micro-container `ad-toast` (see Alert vs Notification) |
601
643
  | `@mantine/dropzone` | `^9.6.0` | File drag-and-drop |
602
644
  | `@appdirect/design-tokens` | `^0.0.6` | AppDirect token CSS variables (`--ad-*`) |
603
645
  | `@tabler/icons-react` | `^3.33.0` | Icon library (supplementary) |
@@ -626,9 +668,9 @@ Per-token annotations that don't fit naturally into the prose sections above. Th
626
668
  1. **AppDirect Navy tokenization** — `#011B58` is hardcoded in `AppShellLayout.tsx`; will become `--ad-color-brand-navy` (or similar) once the brand color group is added to `@appdirect/design-tokens`
627
669
  2. **Dark mode toggle** — `[data-theme="dark"]` tokens are fully defined; the app needs a toggle that sets this attribute on `<html>` and persists the preference
628
670
  3. **Form composition patterns** — document label placement, required field indicators, error/validation states, help text, and field grouping conventions
629
- 4. **Page-level composition patterns** — document standard list page (PageContentHeader + DataTable) and detail page (PageContentHeader + Cards) structures with code examples
671
+ 4. **Page-level composition patterns** — list-page stack and detail-page sketch are documented under **List page composition** and **DataTable patterns** (including Figma-derived action hierarchy, selection, and chip rules). Remaining work is optional code examples for full page scaffolding.
630
672
  5. **Loading / empty / error states** — document how to handle async loading (Button `loading`, Progress, Skeleton), empty DataTable, and form validation errors
631
673
  6. **Component token expansion** — remaining components in `@appdirect/design-tokens/tokens/components/*.json` (30+ files) not yet reflected in the `components:` YAML block
632
674
  7. **Prose pass** — brand/DS leads should revise Overview + Do's-and-Don'ts sections for voice and rationale
633
- 8. **Harvest Figma component docs** — each Figma component has a `utilities/doc-section` with usage guidance; extract and merge into Components subsections
675
+ 8. **Selective Figma harvest** — prefer AppDirect annotations / IA (e.g. Table Control Panel) over generic `utilities/doc-section` boilerplate. This pass covers table/list composition, filter chips, selection rules, and Alert vs Notification. Harvest further component pages only when marker annotations or AppDirect-specific descriptions add new rules.
634
676
  9. **Wire into tokens pipeline** — `@appdirect/design-tokens` will emit a `dist/design-spec.yaml` adapter; a `sync-design-docs` script in this repo will replace the YAML front matter automatically on `npm install`. Backlog item added to `appdirect-design-tokens/CLAUDE.md`.