@revikornmann/muka-ui 0.35.1 → 0.37.0
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.
- package/cli/bin/muka-ui.js +18 -0
- package/cli/commands/check.js +174 -0
- package/cli/commands/init.js +8 -20
- package/cli/commands/install-skill.js +37 -26
- package/cli/commands/sync.js +90 -0
- package/cli/lib/agents-block.js +139 -0
- package/cli/lib/skills.js +182 -0
- package/cli/templates/{AGENTS.md → agents-block.md} +53 -16
- package/dist/cjs/components/Dialog/Dialog.css +10 -0
- package/dist/cjs/components/Dialog/Dialog.js +58 -48
- package/dist/cjs/components/Dialog/Dialog.js.map +1 -1
- package/dist/cjs/components/Dialog/index.js +5 -1
- package/dist/cjs/components/Dialog/index.js.map +1 -1
- package/dist/cjs/components/Drawer/Drawer.css +4 -24
- package/dist/cjs/components/Drawer/Drawer.js +20 -10
- package/dist/cjs/components/Drawer/Drawer.js.map +1 -1
- package/dist/cjs/components/NumberInput/NumberInput.js +88 -3
- package/dist/cjs/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/cjs/components/Table/Table.css +12 -0
- package/dist/cjs/components/Table/Table.js +2 -1
- package/dist/cjs/components/Table/Table.js.map +1 -1
- package/dist/cjs/components/Toggle/Toggle.js +2 -2
- package/dist/cjs/components/Toggle/Toggle.js.map +1 -1
- package/dist/cjs/components/TopBar/TopBar.css +11 -10
- package/dist/cjs/components/TopBar/TopBar.js +33 -3
- package/dist/cjs/components/TopBar/TopBar.js.map +1 -1
- package/dist/cjs/components/View/View.js +11 -12
- package/dist/cjs/components/View/View.js.map +1 -1
- package/dist/cjs/components/index.js +6 -3
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/utils/useDismissGuard.js +85 -0
- package/dist/cjs/utils/useDismissGuard.js.map +1 -0
- package/dist/esm/components/Dialog/Dialog.css +10 -0
- package/dist/esm/components/Dialog/Dialog.js +57 -49
- package/dist/esm/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/components/Dialog/index.js +2 -1
- package/dist/esm/components/Dialog/index.js.map +1 -1
- package/dist/esm/components/Drawer/Drawer.css +4 -24
- package/dist/esm/components/Drawer/Drawer.js +21 -11
- package/dist/esm/components/Drawer/Drawer.js.map +1 -1
- package/dist/esm/components/NumberInput/NumberInput.js +88 -3
- package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/esm/components/Table/Table.css +12 -0
- package/dist/esm/components/Table/Table.js +2 -1
- package/dist/esm/components/Table/Table.js.map +1 -1
- package/dist/esm/components/Toggle/Toggle.js +2 -2
- package/dist/esm/components/Toggle/Toggle.js.map +1 -1
- package/dist/esm/components/TopBar/TopBar.css +11 -10
- package/dist/esm/components/TopBar/TopBar.js +30 -3
- package/dist/esm/components/TopBar/TopBar.js.map +1 -1
- package/dist/esm/components/View/View.js +11 -12
- package/dist/esm/components/View/View.js.map +1 -1
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/utils/useDismissGuard.js +79 -0
- package/dist/esm/utils/useDismissGuard.js.map +1 -0
- package/dist/styles/components/Dialog.css +10 -0
- package/dist/styles/components/Drawer.css +4 -24
- package/dist/styles/components/Table.css +12 -0
- package/dist/styles/index.css +874 -858
- package/dist/styles/muka-dark.css +874 -858
- package/dist/styles/muka-light.css +874 -858
- package/dist/styles/tokens-bouwplan-dark.css +2 -0
- package/dist/styles/tokens-bouwplan-light.css +2 -0
- package/dist/styles/tokens-fscl-dark.css +2 -0
- package/dist/styles/tokens-fscl-light.css +2 -0
- package/dist/styles/tokens-grip-dark.css +2 -0
- package/dist/styles/tokens-grip-light.css +2 -0
- package/dist/styles/tokens-muka-dark.css +2 -0
- package/dist/styles/tokens-muka-light.css +2 -0
- package/dist/styles/tokens-wireframe-dark.css +2 -0
- package/dist/styles/tokens-wireframe-light.css +2 -0
- package/dist/styles/wireframe-dark.css +874 -858
- package/dist/styles/wireframe-light.css +874 -858
- package/dist/types/components/Dialog/Dialog.d.ts +51 -11
- package/dist/types/components/Dialog/Dialog.d.ts.map +1 -1
- package/dist/types/components/Dialog/index.d.ts +2 -1
- package/dist/types/components/Dialog/index.d.ts.map +1 -1
- package/dist/types/components/Drawer/Drawer.d.ts +35 -5
- package/dist/types/components/Drawer/Drawer.d.ts.map +1 -1
- package/dist/types/components/NumberInput/NumberInput.d.ts +9 -0
- package/dist/types/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/types/components/Table/Table.d.ts +7 -0
- package/dist/types/components/Table/Table.d.ts.map +1 -1
- package/dist/types/components/Toggle/Toggle.d.ts +6 -0
- package/dist/types/components/Toggle/Toggle.d.ts.map +1 -1
- package/dist/types/components/TopBar/TopBar.d.ts +12 -1
- package/dist/types/components/TopBar/TopBar.d.ts.map +1 -1
- package/dist/types/components/View/View.d.ts +4 -3
- package/dist/types/components/View/View.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -1
- package/dist/types/components/index.d.ts.map +1 -1
- package/dist/types/utils/useDismissGuard.d.ts +68 -0
- package/dist/types/utils/useDismissGuard.d.ts.map +1 -0
- package/docs/consumers/README.md +6 -2
- package/docs/consumers/dialogs.md +102 -0
- package/docs/consumers/setup-instructions.md +55 -9
- package/docs/consumers/skills.md +29 -13
- package/eslint/index.js +284 -0
- package/package.json +14 -2
- package/skills/setup-muka/SKILL.md +59 -7
- package/templates/muka-check.yml +45 -0
- package/templates/update-muka.yml +17 -4
- package/tokens/t4-components/table.json +13 -0
- package/cli/templates/CLAUDE.md +0 -15
package/cli/bin/muka-ui.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Commands:
|
|
7
7
|
* init - Set up a project to use Muka UI
|
|
8
|
+
* sync - Write the Muka rules for this version into AGENTS.md
|
|
9
|
+
* check - Lint the source with Muka's guardrail rules
|
|
8
10
|
* install-skill - Copy shipped skills into .claude/skills
|
|
9
11
|
* brand init <name> - Scaffold a custom brand override
|
|
10
12
|
* link [path] - Set up npm link for local development
|
|
@@ -25,6 +27,10 @@ Usage:
|
|
|
25
27
|
|
|
26
28
|
Commands:
|
|
27
29
|
init Set up project for Muka UI (creates AGENTS.md, guidelines)
|
|
30
|
+
sync [--check] Write the Muka rules for the installed version into
|
|
31
|
+
AGENTS.md (CLAUDE.md imports it); --check only verifies
|
|
32
|
+
check [paths] Lint with Muka's guardrail ESLint rules and verify
|
|
33
|
+
AGENTS.md; exits 1 on problems (for CI)
|
|
28
34
|
install-skill Copy shipped skills into .claude/skills
|
|
29
35
|
brand init <name> Scaffold a custom brand (T2 tokens, manifest, build script)
|
|
30
36
|
link [path] Set up npm link for local muka-ui development
|
|
@@ -38,6 +44,8 @@ Examples:
|
|
|
38
44
|
npx muka-ui install-skill --list # what skills ship with the package
|
|
39
45
|
npx muka-ui install-skill # install them, then run /setup-muka
|
|
40
46
|
npx muka-ui init
|
|
47
|
+
npx muka-ui sync
|
|
48
|
+
npx muka-ui check
|
|
41
49
|
npx muka-ui brand init acme
|
|
42
50
|
npx muka-ui link /path/to/muka
|
|
43
51
|
npx muka-ui components
|
|
@@ -81,6 +89,16 @@ async function main() {
|
|
|
81
89
|
await installSkill(commandArgs);
|
|
82
90
|
break;
|
|
83
91
|
}
|
|
92
|
+
case 'sync': {
|
|
93
|
+
const sync = require('../commands/sync');
|
|
94
|
+
await sync(commandArgs);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case 'check': {
|
|
98
|
+
const check = require('../commands/check');
|
|
99
|
+
await check(commandArgs);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
84
102
|
case 'link': {
|
|
85
103
|
const link = require('../commands/link');
|
|
86
104
|
await link(commandArgs);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muka-ui check` command
|
|
3
|
+
*
|
|
4
|
+
* Lints the consumer's source with Muka's ESLint rules only, independent of
|
|
5
|
+
* the repo's own ESLint setup (or the lack of one), and checks that AGENTS.md
|
|
6
|
+
* matches the installed version. Exit code 1 on any problem, so CI can gate
|
|
7
|
+
* on it whichever agent or person wrote the code.
|
|
8
|
+
*
|
|
9
|
+
* npx muka-ui check lint src/ (or the repo root)
|
|
10
|
+
* npx muka-ui check app components lint these paths
|
|
11
|
+
* npx muka-ui check --update-baseline record today's problems as known
|
|
12
|
+
*
|
|
13
|
+
* Adopting the rules in an existing repo: `--update-baseline` writes
|
|
14
|
+
* `.muka-check-baseline.json` (problems per file and rule). From then on only
|
|
15
|
+
* problems beyond the baseline fail, so CI blocks new violations while old
|
|
16
|
+
* ones are cleaned up; re-run it after a cleanup to tighten the baseline.
|
|
17
|
+
*
|
|
18
|
+
* Needs `eslint` (9+) and `typescript-eslint` (or `@typescript-eslint/parser`)
|
|
19
|
+
* installed in the project.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const { findProjectRoot } = require('../lib/fs-utils');
|
|
25
|
+
const muka = require('../../eslint');
|
|
26
|
+
const sync = require('./sync');
|
|
27
|
+
|
|
28
|
+
const BASELINE_FILE = '.muka-check-baseline.json';
|
|
29
|
+
|
|
30
|
+
/** Problems per file (relative path) and rule. */
|
|
31
|
+
function countProblems(results, projectRoot) {
|
|
32
|
+
const counts = {};
|
|
33
|
+
for (const result of results) {
|
|
34
|
+
const file = path.relative(projectRoot, result.filePath).split(path.sep).join('/');
|
|
35
|
+
for (const m of result.messages) {
|
|
36
|
+
if (!m.ruleId) continue;
|
|
37
|
+
counts[file] = counts[file] || {};
|
|
38
|
+
counts[file][m.ruleId] = (counts[file][m.ruleId] || 0) + 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return counts;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Drop the problems the baseline allows: per file and rule, the first
|
|
46
|
+
* `baseline` problems are known; any beyond that are new.
|
|
47
|
+
*/
|
|
48
|
+
function applyBaseline(results, baseline, projectRoot) {
|
|
49
|
+
let known = 0;
|
|
50
|
+
for (const result of results) {
|
|
51
|
+
const file = path.relative(projectRoot, result.filePath).split(path.sep).join('/');
|
|
52
|
+
const allowed = { ...(baseline[file] || {}) };
|
|
53
|
+
result.messages = result.messages.filter((m) => {
|
|
54
|
+
if (m.ruleId && allowed[m.ruleId] > 0) {
|
|
55
|
+
allowed[m.ruleId] -= 1;
|
|
56
|
+
known += 1;
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return known;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Resolve a dependency from the consumer project, not from Muka. */
|
|
66
|
+
function requireFromProject(projectRoot, name) {
|
|
67
|
+
try {
|
|
68
|
+
return require(require.resolve(name, { paths: [projectRoot] }));
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function findParser(projectRoot) {
|
|
75
|
+
const tsEslint = requireFromProject(projectRoot, 'typescript-eslint');
|
|
76
|
+
if (tsEslint && tsEslint.parser) return tsEslint.parser;
|
|
77
|
+
return requireFromProject(projectRoot, '@typescript-eslint/parser');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function check(args = []) {
|
|
81
|
+
const projectRoot = findProjectRoot();
|
|
82
|
+
if (!projectRoot) {
|
|
83
|
+
throw new Error('Could not find package.json. Are you in a Node.js project?');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const eslintModule = requireFromProject(projectRoot, 'eslint');
|
|
87
|
+
const parser = findParser(projectRoot);
|
|
88
|
+
if (!eslintModule || !eslintModule.ESLint || !parser) {
|
|
89
|
+
console.error('✗ muka-ui check needs ESLint 9+ and the TypeScript parser in this project:');
|
|
90
|
+
console.error(' npm install --save-dev eslint typescript-eslint');
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const paths = args.filter((a) => !a.startsWith('-'));
|
|
96
|
+
const targets = paths.length
|
|
97
|
+
? paths
|
|
98
|
+
: [fs.existsSync(path.join(projectRoot, 'src')) ? 'src' : '.'];
|
|
99
|
+
|
|
100
|
+
const eslint = new eslintModule.ESLint({
|
|
101
|
+
cwd: projectRoot,
|
|
102
|
+
// Only Muka's rules: the repo's own config (or none) doesn't change the result.
|
|
103
|
+
overrideConfigFile: true,
|
|
104
|
+
overrideConfig: [
|
|
105
|
+
{
|
|
106
|
+
ignores: [
|
|
107
|
+
'**/node_modules/**', '**/dist/**', '**/build/**', '**/.next/**',
|
|
108
|
+
'**/out/**', '**/coverage/**', '**/*.d.ts', '**/*.test.*', '**/*.stories.*',
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
...muka.configs.recommended.map((config) => ({
|
|
112
|
+
...config,
|
|
113
|
+
languageOptions: {
|
|
114
|
+
parser,
|
|
115
|
+
parserOptions: { ecmaFeatures: { jsx: true }, sourceType: 'module' },
|
|
116
|
+
},
|
|
117
|
+
// The repo's disable comments name its own rules, unknown here.
|
|
118
|
+
linterOptions: { reportUnusedDisableDirectives: 'off' },
|
|
119
|
+
})),
|
|
120
|
+
],
|
|
121
|
+
errorOnUnmatchedPattern: false,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const results = await eslint.lintFiles(targets);
|
|
125
|
+
const baselinePath = path.join(projectRoot, BASELINE_FILE);
|
|
126
|
+
const updateBaseline = args.includes('--update-baseline');
|
|
127
|
+
// Keep Muka findings and parse errors; drop "rule not found" noise from
|
|
128
|
+
// disable comments for the repo's other plugins.
|
|
129
|
+
for (const result of results) {
|
|
130
|
+
result.messages = result.messages.filter(
|
|
131
|
+
(m) => (m.ruleId && m.ruleId.startsWith('muka/')) || (m.fatal && !m.ruleId)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (updateBaseline) {
|
|
136
|
+
const counts = countProblems(results, projectRoot);
|
|
137
|
+
const total = Object.values(counts).reduce(
|
|
138
|
+
(n, rules) => n + Object.values(rules).reduce((a, b) => a + b, 0), 0
|
|
139
|
+
);
|
|
140
|
+
fs.writeFileSync(baselinePath, `${JSON.stringify(counts, null, 2)}\n`, 'utf-8');
|
|
141
|
+
console.log(`✓ Wrote ${BASELINE_FILE}: ${total} known problem${total === 1 ? '' : 's'}. Commit it; only new problems fail from now on.`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let known = 0;
|
|
146
|
+
if (fs.existsSync(baselinePath)) {
|
|
147
|
+
known = applyBaseline(results, JSON.parse(fs.readFileSync(baselinePath, 'utf-8')), projectRoot);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (const result of results) {
|
|
151
|
+
result.errorCount = result.messages.filter((m) => m.severity === 2).length;
|
|
152
|
+
result.warningCount = result.messages.filter((m) => m.severity === 1).length;
|
|
153
|
+
result.fatalErrorCount = result.messages.filter((m) => m.fatal).length;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const formatter = await eslint.loadFormatter('stylish');
|
|
157
|
+
const output = await formatter.format(results);
|
|
158
|
+
const errors = results.reduce((n, r) => n + r.errorCount, 0);
|
|
159
|
+
if (output) console.log(output);
|
|
160
|
+
const knownNote = known ? ` (${known} known in ${BASELINE_FILE})` : '';
|
|
161
|
+
if (errors) {
|
|
162
|
+
console.error(`✗ ${errors} new Muka UI guardrail problem${errors === 1 ? '' : 's'}${knownNote}. See AGENTS.md.`);
|
|
163
|
+
process.exitCode = 1;
|
|
164
|
+
} else {
|
|
165
|
+
console.log(`✓ No new Muka UI guardrail problems in ${targets.join(', ')}${knownNote}.`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// The rules agents read must match the installed version too.
|
|
169
|
+
if (!args.includes('--no-sync-check')) await sync(['--check']);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = check;
|
|
173
|
+
module.exports.countProblems = countProblems;
|
|
174
|
+
module.exports.applyBaseline = applyBaseline;
|
package/cli/commands/init.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* `muka-ui init` command
|
|
3
3
|
*
|
|
4
4
|
* Sets up a project for Muka UI usage:
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
5
|
+
* - Writes the Muka block into AGENTS.md (via `muka-ui sync`), the brief every
|
|
6
|
+
* coding agent reads, and makes CLAUDE.md import it
|
|
7
7
|
* - Creates docs/muka-ui-guidelines.md with usage documentation
|
|
8
8
|
* - Checks for conflicting dependencies and warns
|
|
9
9
|
*/
|
|
@@ -20,6 +20,7 @@ const {
|
|
|
20
20
|
} = require('../lib/fs-utils');
|
|
21
21
|
const { detectConflicts, printConflicts } = require('../lib/detect-conflicts');
|
|
22
22
|
const manifest = require('../manifest.json');
|
|
23
|
+
const sync = require('./sync');
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Generate component list for templates
|
|
@@ -97,24 +98,11 @@ async function init(args) {
|
|
|
97
98
|
const replacements = getReplacements();
|
|
98
99
|
|
|
99
100
|
// --- Agent briefs ---
|
|
100
|
-
// AGENTS.md
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (fileExists(target)) {
|
|
107
|
-
console.log(`${name} already exists.`);
|
|
108
|
-
write = await confirm('Overwrite with Muka UI template?');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (write) {
|
|
112
|
-
writeFile(target, loadTemplate(name, replacements));
|
|
113
|
-
console.log(`✓ Created ${name}\n`);
|
|
114
|
-
} else {
|
|
115
|
-
console.log(`⏭ Skipped ${name}\n`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
101
|
+
// AGENTS.md is the brief every coding agent reads; Muka owns a marked block
|
|
102
|
+
// in it that `muka-ui sync` refreshes on every update. CLAUDE.md imports it
|
|
103
|
+
// (`@AGENTS.md`) so Claude Code reads the same rules, not a second copy.
|
|
104
|
+
await sync([]);
|
|
105
|
+
console.log('');
|
|
118
106
|
|
|
119
107
|
// --- docs/muka-ui-guidelines.md ---
|
|
120
108
|
const docsDir = path.join(projectRoot, 'docs');
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* `muka-ui install-skill` command
|
|
3
3
|
*
|
|
4
4
|
* Copies the consumer-facing skills shipped inside the package (under
|
|
5
|
-
* `skills/`) into the consuming repo's `.
|
|
6
|
-
*
|
|
5
|
+
* `skills/`) into the consuming repo's `.agents/skills/`, the vendor-neutral
|
|
6
|
+
* location, and links `.claude/skills/<name>` to each (Claude Code and Cursor
|
|
7
|
+
* read that path), so there is one copy. `muka-ui sync` keeps them current on
|
|
8
|
+
* every update; see cli/lib/skills.js.
|
|
7
9
|
*
|
|
8
|
-
* Agents discover skills
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Agents discover skills in the repo, never inside `node_modules/`, so a skill
|
|
11
|
+
* shipped in the package is present but not discoverable until it is copied
|
|
12
|
+
* in. This command is that bridge.
|
|
11
13
|
*
|
|
12
14
|
* npx muka-ui install-skill # install all shipped skills
|
|
13
15
|
* npx muka-ui install-skill setup-muka # install specific skills
|
|
@@ -19,16 +21,16 @@ const fs = require('fs');
|
|
|
19
21
|
const {
|
|
20
22
|
fileExists,
|
|
21
23
|
dirExists,
|
|
22
|
-
ensureDir,
|
|
23
24
|
readFile,
|
|
24
|
-
writeFile,
|
|
25
25
|
confirm,
|
|
26
26
|
findProjectRoot
|
|
27
27
|
} = require('../lib/fs-utils');
|
|
28
|
+
const skills = require('../lib/skills');
|
|
28
29
|
|
|
29
30
|
// Package root = two levels up from cli/commands.
|
|
30
31
|
const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
31
32
|
const SHIPPED_SKILLS_DIR = path.join(PACKAGE_ROOT, 'skills');
|
|
33
|
+
const PACKAGE_VERSION = require(path.join(PACKAGE_ROOT, 'package.json')).version;
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* List the skill names shipped in the package.
|
|
@@ -73,8 +75,11 @@ function skillFiles(skillDir, prefix = '') {
|
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
+
* Install one shipped skill: the files in `.agents/skills/<name>/`, and
|
|
79
|
+
* `.claude/skills/<name>` linked to them. Asks before replacing a copy that
|
|
80
|
+
* differs from what Muka installed (local edits, or an older copy in
|
|
81
|
+
* `.claude/skills/` from before skills moved to `.agents/skills/`).
|
|
82
|
+
* Returns true if anything was written.
|
|
78
83
|
*/
|
|
79
84
|
async function installOne(skillName, projectRoot) {
|
|
80
85
|
const srcDir = path.join(SHIPPED_SKILLS_DIR, skillName);
|
|
@@ -83,35 +88,41 @@ async function installOne(skillName, projectRoot) {
|
|
|
83
88
|
return false;
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const canonical = path.join(projectRoot, skills.CANONICAL, skillName);
|
|
92
|
+
const claudeDir = path.join(projectRoot, skills.CLAUDE, skillName);
|
|
93
|
+
const shippedHash = skills.hashDir(srcDir);
|
|
94
|
+
const lock = skills.readLock(projectRoot);
|
|
95
|
+
const installedHash = skills.hashDir(canonical);
|
|
96
|
+
|
|
97
|
+
let claudeIsLink = false;
|
|
98
|
+
try {
|
|
99
|
+
claudeIsLink = fs.lstatSync(claudeDir).isSymbolicLink();
|
|
100
|
+
} catch {
|
|
101
|
+
// absent
|
|
102
|
+
}
|
|
93
103
|
|
|
94
|
-
if (
|
|
104
|
+
if (installedHash === shippedHash && lock.skills[skillName] && claudeIsLink) {
|
|
95
105
|
console.log(`✓ /${skillName} already up to date`);
|
|
96
106
|
return false;
|
|
97
107
|
}
|
|
98
108
|
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
// Something there that Muka didn't put there as-is: ask first.
|
|
110
|
+
const editedCanonical = installedHash && installedHash !== (lock.skills[skillName] || {}).hash;
|
|
111
|
+
const legacyCopy = !claudeIsLink && dirExists(claudeDir);
|
|
112
|
+
if (editedCanonical || legacyCopy) {
|
|
113
|
+
const where = legacyCopy ? `.claude/skills/${skillName}` : `.agents/skills/${skillName}`;
|
|
114
|
+
const overwrite = await confirm(`/${skillName} exists in ${where} with other content. Replace it with the shipped version?`);
|
|
101
115
|
if (!overwrite) {
|
|
102
116
|
console.log(`⏭ Skipped /${skillName}`);
|
|
103
117
|
return false;
|
|
104
118
|
}
|
|
105
119
|
}
|
|
106
120
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
ensureDir(path.dirname(dest));
|
|
110
|
-
writeFile(dest, readFile(path.join(srcDir, file)));
|
|
111
|
-
}
|
|
112
|
-
|
|
121
|
+
const { claude } = skills.install(projectRoot, skillName, { version: PACKAGE_VERSION });
|
|
122
|
+
const files = skillFiles(srcDir);
|
|
113
123
|
const extra = files.length > 1 ? ` (+${files.length - 1} reference file(s))` : '';
|
|
114
|
-
|
|
124
|
+
const how = claude === 'copy' ? 'copied to' : 'linked from';
|
|
125
|
+
console.log(`✓ Installed /${skillName} → .agents/skills/${skillName}/${extra}, ${how} .claude/skills/${skillName}`);
|
|
115
126
|
return true;
|
|
116
127
|
}
|
|
117
128
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muka-ui sync` command
|
|
3
|
+
*
|
|
4
|
+
* Writes the Muka rules for the installed version into the consumer's
|
|
5
|
+
* AGENTS.md, inside a marked block, makes CLAUDE.md import AGENTS.md, and
|
|
6
|
+
* refreshes the Muka skills installed in `.agents/skills/` (skipping any that
|
|
7
|
+
* were edited locally).
|
|
8
|
+
* Run it after every Muka update (the update-muka workflow does), so the
|
|
9
|
+
* rules every coding agent reads always match the installed code.
|
|
10
|
+
*
|
|
11
|
+
* npx muka-ui sync write the files
|
|
12
|
+
* npx muka-ui sync --check exit 1 if they are out of date (for CI)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const { findProjectRoot } = require('../lib/fs-utils');
|
|
18
|
+
const { renderBlock, applyBlock, ensureClaudeImport } = require('../lib/agents-block');
|
|
19
|
+
const { syncSkills } = require('../lib/skills');
|
|
20
|
+
|
|
21
|
+
const read = (file) => (fs.existsSync(file) ? fs.readFileSync(file, 'utf-8') : null);
|
|
22
|
+
|
|
23
|
+
async function sync(args = []) {
|
|
24
|
+
const check = args.includes('--check');
|
|
25
|
+
const projectRoot = findProjectRoot();
|
|
26
|
+
if (!projectRoot) {
|
|
27
|
+
throw new Error('Could not find package.json. Are you in a Node.js project?');
|
|
28
|
+
}
|
|
29
|
+
const packageRoot = path.join(__dirname, '..', '..');
|
|
30
|
+
|
|
31
|
+
const agentsPath = path.join(projectRoot, 'AGENTS.md');
|
|
32
|
+
const claudePath = path.join(projectRoot, 'CLAUDE.md');
|
|
33
|
+
const agents = applyBlock(read(agentsPath), renderBlock(packageRoot));
|
|
34
|
+
const claude = ensureClaudeImport(read(claudePath));
|
|
35
|
+
const version = require(path.join(packageRoot, 'package.json')).version;
|
|
36
|
+
const skills = syncSkills(projectRoot, { check, version });
|
|
37
|
+
|
|
38
|
+
const outdated = [
|
|
39
|
+
agents.action !== 'unchanged' && 'AGENTS.md',
|
|
40
|
+
claude.action !== 'unchanged' && 'CLAUDE.md',
|
|
41
|
+
!skills.current && `skills (${skills.updated.join(', ')})`,
|
|
42
|
+
].filter(Boolean);
|
|
43
|
+
|
|
44
|
+
if (check) {
|
|
45
|
+
if (outdated.length) {
|
|
46
|
+
console.error(`✗ ${outdated.join(' and ')} out of date with the installed Muka UI.`);
|
|
47
|
+
console.error(' Run `npx muka-ui sync` and commit the result.');
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
} else {
|
|
50
|
+
console.log('✓ AGENTS.md, CLAUDE.md and the Muka skills match the installed Muka UI.');
|
|
51
|
+
}
|
|
52
|
+
reportSkillNotes(skills);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (agents.action !== 'unchanged') fs.writeFileSync(agentsPath, agents.content, 'utf-8');
|
|
57
|
+
if (claude.action !== 'unchanged') fs.writeFileSync(claudePath, claude.content, 'utf-8');
|
|
58
|
+
|
|
59
|
+
console.log(`AGENTS.md: ${agents.action}`);
|
|
60
|
+
console.log(`CLAUDE.md: ${claude.action === 'updated' ? 'now imports @AGENTS.md' : claude.action}`);
|
|
61
|
+
if (skills.updated.length) console.log(`Skills: updated ${skills.updated.map((n) => `/${n}`).join(', ')}`);
|
|
62
|
+
reportSkillNotes(skills);
|
|
63
|
+
if (agents.action === 'inserted') {
|
|
64
|
+
console.log(
|
|
65
|
+
'\nAGENTS.md had no Muka block, so it was added under the first heading.\n' +
|
|
66
|
+
'Remove any Muka rules copied in earlier (an old `muka-ui init`) and keep\n' +
|
|
67
|
+
"this repo's own rules outside the block."
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function reportSkillNotes(skills) {
|
|
73
|
+
if (skills.modified.length) {
|
|
74
|
+
console.log(
|
|
75
|
+
`\nNot refreshed, edited in this repo: ${skills.modified.map((n) => `/${n}`).join(', ')}.\n` +
|
|
76
|
+
'Run `npx muka-ui install-skill <name>` to replace it with the shipped version.'
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (skills.removed.length) {
|
|
80
|
+
console.log(`\nNo longer shipped by Muka: ${skills.removed.map((n) => `/${n}`).join(', ')}. Delete them from .agents/skills/ and .claude/skills/.`);
|
|
81
|
+
}
|
|
82
|
+
if (skills.legacy.length) {
|
|
83
|
+
console.log(
|
|
84
|
+
`\nOlder copies in .claude/skills/: ${skills.legacy.map((n) => `/${n}`).join(', ')}.\n` +
|
|
85
|
+
'Run `npx muka-ui install-skill` once to move them to .agents/skills/, where sync keeps them current.'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = sync;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Muka-managed block in a consumer's AGENTS.md.
|
|
3
|
+
*
|
|
4
|
+
* AGENTS.md is the agent brief every coding agent reads (Codex, Cursor,
|
|
5
|
+
* Copilot, Gemini, …); CLAUDE.md imports it with `@AGENTS.md`. Muka owns one
|
|
6
|
+
* marked block inside it and `muka-ui sync` rewrites only that block from the
|
|
7
|
+
* installed version, so the rules always match the code. Everything outside
|
|
8
|
+
* the markers belongs to the repo and is never touched.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const START = '<!-- muka-ui:start';
|
|
15
|
+
const END = '<!-- muka-ui:end -->';
|
|
16
|
+
const CLAUDE_IMPORT = '@AGENTS.md';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Names exported by the installed package, read from its type entry point so
|
|
20
|
+
* the list is exactly what this version ships. In Muka's own repo before a
|
|
21
|
+
* build there is no `dist/`, so it reads the same exports from the source.
|
|
22
|
+
*/
|
|
23
|
+
function readExports(packageRoot) {
|
|
24
|
+
const entry = [
|
|
25
|
+
path.join(packageRoot, 'dist', 'types', 'components', 'index.d.ts'),
|
|
26
|
+
path.join(packageRoot, 'components', 'index.ts'),
|
|
27
|
+
].find((file) => fs.existsSync(file));
|
|
28
|
+
if (!entry) throw new Error(`No component exports found in ${packageRoot}.`);
|
|
29
|
+
const source = fs.readFileSync(entry, 'utf-8');
|
|
30
|
+
const names = new Set();
|
|
31
|
+
for (const match of source.matchAll(/export\s*\{([^}]*)\}\s*from/g)) {
|
|
32
|
+
for (const raw of match[1].split(',')) {
|
|
33
|
+
const name = raw.trim();
|
|
34
|
+
if (!name || name.startsWith('type ')) continue;
|
|
35
|
+
names.add(name.split(/\s+as\s+/).pop().trim());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const sorted = [...names].sort((a, b) => a.localeCompare(b));
|
|
39
|
+
// Components are PascalCase (or an acronym like FAB); constants have an underscore.
|
|
40
|
+
const isComponent = (n) => /^[A-Z]/.test(n) && !n.includes('_');
|
|
41
|
+
return {
|
|
42
|
+
components: sorted.filter(isComponent),
|
|
43
|
+
helpers: sorted.filter((n) => !isComponent(n)),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fillTemplate(template, replacements) {
|
|
48
|
+
return template.replace(/\{\{(\w+)\}\}/g, (whole, key) =>
|
|
49
|
+
key in replacements ? replacements[key] : whole
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The block, markers included, for the given package root. */
|
|
54
|
+
function renderBlock(packageRoot) {
|
|
55
|
+
const pkg = require(path.join(packageRoot, 'package.json'));
|
|
56
|
+
const manifest = require('../manifest.json');
|
|
57
|
+
const { components, helpers } = readExports(packageRoot);
|
|
58
|
+
const template = fs.readFileSync(
|
|
59
|
+
path.join(__dirname, '..', 'templates', 'agents-block.md'),
|
|
60
|
+
'utf-8'
|
|
61
|
+
);
|
|
62
|
+
const body = fillTemplate(template, {
|
|
63
|
+
VERSION: pkg.version,
|
|
64
|
+
PACKAGE_NAME: pkg.name,
|
|
65
|
+
STORYBOOK_URL: manifest.storybook_url,
|
|
66
|
+
COMPONENT_COUNT: String(components.length),
|
|
67
|
+
COMPONENT_LIST: components.map((n) => `\`${n}\``).join(', '),
|
|
68
|
+
HELPER_LIST: helpers.length ? helpers.map((n) => `\`${n}\``).join(', ') : '—',
|
|
69
|
+
}).trim();
|
|
70
|
+
return [
|
|
71
|
+
`${START} v${pkg.version} — managed by \`npx muka-ui sync\`; edits inside this block are overwritten -->`,
|
|
72
|
+
body,
|
|
73
|
+
END,
|
|
74
|
+
].join('\n');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const NEW_AGENTS = (block) => `# Agent guidelines
|
|
78
|
+
|
|
79
|
+
This is the brief every coding agent reads, whichever tool it is. \`CLAUDE.md\`
|
|
80
|
+
imports it, so there is one copy to keep current.
|
|
81
|
+
|
|
82
|
+
${block}
|
|
83
|
+
|
|
84
|
+
## Project rules
|
|
85
|
+
|
|
86
|
+
Rules that belong to this repo go here, outside the Muka block, so
|
|
87
|
+
\`npx muka-ui sync\` never overwrites them.
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Put the block into AGENTS.md content.
|
|
92
|
+
* @returns {{ content: string, action: 'created' | 'updated' | 'unchanged' | 'inserted' }}
|
|
93
|
+
*/
|
|
94
|
+
function applyBlock(existing, block) {
|
|
95
|
+
if (existing == null) return { content: NEW_AGENTS(block), action: 'created' };
|
|
96
|
+
|
|
97
|
+
const start = existing.indexOf(START);
|
|
98
|
+
const end = existing.indexOf(END);
|
|
99
|
+
if (start !== -1 && end > start) {
|
|
100
|
+
const content = existing.slice(0, start) + block + existing.slice(end + END.length);
|
|
101
|
+
return { content, action: content === existing ? 'unchanged' : 'updated' };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// No markers yet: an older AGENTS.md. Put the block under its first heading
|
|
105
|
+
// and leave the rest for the repo to clean up.
|
|
106
|
+
const lines = existing.split('\n');
|
|
107
|
+
const h1 = lines.findIndex((l) => /^#\s/.test(l));
|
|
108
|
+
const at = h1 === -1 ? 0 : h1 + 1;
|
|
109
|
+
lines.splice(at, 0, ...(at > 0 ? [''] : []), block, '');
|
|
110
|
+
return { content: lines.join('\n'), action: 'inserted' };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const NEW_CLAUDE = `${CLAUDE_IMPORT}
|
|
114
|
+
|
|
115
|
+
<!-- The rules live in AGENTS.md, which every coding agent reads. Claude Code
|
|
116
|
+
imports it with the line above; keep Claude-only notes below. -->
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Make CLAUDE.md import AGENTS.md, so Claude reads the same rules.
|
|
121
|
+
* @returns {{ content: string, action: 'created' | 'updated' | 'unchanged' }}
|
|
122
|
+
*/
|
|
123
|
+
function ensureClaudeImport(existing) {
|
|
124
|
+
if (existing == null) return { content: NEW_CLAUDE, action: 'created' };
|
|
125
|
+
if (existing.split('\n').some((l) => l.trim() === CLAUDE_IMPORT)) {
|
|
126
|
+
return { content: existing, action: 'unchanged' };
|
|
127
|
+
}
|
|
128
|
+
return { content: `${CLAUDE_IMPORT}\n\n${existing}`, action: 'updated' };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = {
|
|
132
|
+
START,
|
|
133
|
+
END,
|
|
134
|
+
CLAUDE_IMPORT,
|
|
135
|
+
readExports,
|
|
136
|
+
renderBlock,
|
|
137
|
+
applyBlock,
|
|
138
|
+
ensureClaudeImport,
|
|
139
|
+
};
|