@reqvire-org/ads 0.3.3 → 0.3.6
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/README.md +17 -5
- package/dist/behaviors.mjs +157 -0
- package/dist/bootstrap-ds/ADS.md +16 -3
- package/dist/bootstrap-ds/README.md +10 -0
- package/dist/bootstrap-ds/design-system/controllers/.gitkeep +0 -0
- package/dist/boundaries.mjs +3 -0
- package/dist/check.mjs +20 -2
- package/dist/cli.mjs +17 -0
- package/dist/config.mjs +23 -3
- package/dist/css-values.mjs +26 -0
- package/dist/index.mjs +2 -0
- package/dist/init.mjs +1 -1
- package/dist/mcp/build-status.mjs +17 -7
- package/dist/mcp/catalog.mjs +11 -8
- package/dist/mcp/context.mjs +3 -3
- package/dist/mcp/edit-preparation.mjs +111 -0
- package/dist/mcp/mutations.mjs +64 -38
- package/dist/mcp/preview-owner-guard.mjs +29 -0
- package/dist/mcp/preview-watch.mjs +38 -8
- package/dist/mcp/preview-widget.bundle.js +2 -2
- package/dist/mcp/prompts.mjs +2 -2
- package/dist/mcp/server.mjs +88 -41
- package/dist/mcp/showcase-host.mjs +9 -5
- package/dist/mcp/text-diff.mjs +19 -0
- package/dist/preview-resources.mjs +45 -8
- package/dist/preview-scope.mjs +30 -0
- package/dist/public-api.mjs +39 -0
- package/dist/scenarios-compiler.mjs +41 -19
- package/dist/scenarios.mjs +72 -42
- package/dist/scoped-tokens.mjs +57 -0
- package/dist/skills/README.md +3 -3
- package/dist/skills/ads-break-ui/SKILL.md +26 -2
- package/dist/skills/ads-break-ui/references/guarded-editing.md +44 -0
- package/dist/skills/ads-break-ui/references/verification.md +6 -0
- package/dist/skills/ads-designer/SKILL.md +27 -3
- package/dist/skills/ads-designer/assets/bootstrap-ds/ADS.md +16 -3
- package/dist/skills/ads-designer/assets/bootstrap-ds/README.md +10 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/controllers/.gitkeep +0 -0
- package/dist/skills/ads-designer/references/cli.md +1 -1
- package/dist/skills/ads-designer/references/design-craft.md +1 -1
- package/dist/skills/ads-designer/references/guarded-editing.md +44 -0
- package/dist/skills/ads-import/SKILL.md +26 -2
- package/dist/skills/ads-import/references/cli.md +1 -1
- package/dist/skills/ads-import/references/guarded-editing.md +44 -0
- package/dist/skills/ads-import/references/tokens.md +4 -2
- package/dist/skills/{ads-assimilate → ads-migrate}/SKILL.md +32 -8
- package/dist/skills/ads-migrate/agents/openai.yaml +4 -0
- package/dist/skills/{ads-assimilate → ads-migrate}/references/cli.md +1 -1
- package/dist/skills/ads-migrate/references/guarded-editing.md +44 -0
- package/dist/skills/{ads-assimilate → ads-migrate}/references/native-implementation.md +11 -0
- package/dist/skills/ads-motion/SKILL.md +26 -2
- package/dist/skills/ads-motion/references/guarded-editing.md +44 -0
- package/dist/token-fixtures.mjs +30 -0
- package/dist/tokens.mjs +11 -4
- package/dist/units.mjs +35 -9
- package/dist/verification/browser.mjs +27 -0
- package/dist/verification/playwright-reporter.cjs +20 -0
- package/dist/verification.mjs +214 -0
- package/docs/ADS.md +72 -4
- package/docs/ARCHITECTURE.md +60 -1
- package/docs/BEHAVIORS.md +241 -0
- package/docs/CHANGELOG.md +56 -0
- package/docs/GUIDE.md +24 -4
- package/docs/MCP.md +106 -12
- package/package.json +4 -2
- package/dist/skills/ads-assimilate/agents/openai.yaml +0 -4
- /package/dist/skills/{ads-assimilate → ads-migrate}/references/lint-and-docs.md +0 -0
- /package/dist/skills/{ads-assimilate → ads-migrate}/references/testing.md +0 -0
package/README.md
CHANGED
|
@@ -58,6 +58,8 @@ Linaria; integrate its extraction with your build as described in the
|
|
|
58
58
|
| `ads init --framework react` | Set up ADS in the current project; also accepts `preact`; saved choices can omit the flag |
|
|
59
59
|
| `ads check` | Check tokens, styles, imports, and ADS ownership |
|
|
60
60
|
| `ads tokens` | Inspect token values and themes |
|
|
61
|
+
| `ads behaviors` | Inspect registered behavior guarantees and current evidence |
|
|
62
|
+
| `ads verify --unit <id>` | Run an owner's registered behavior checks |
|
|
61
63
|
| `ads assets` | Generate standard web icons from the project's SVG |
|
|
62
64
|
| `ads lint-config` | Generate lint config; normally called by the build |
|
|
63
65
|
| `ads mcp` | Start the stdio MCP server and its local showcase |
|
|
@@ -89,12 +91,22 @@ for config files and Claude Desktop setup.
|
|
|
89
91
|
To let the agent edit the ADS through enforced checks, append `--mutations` to
|
|
90
92
|
the MCP command. It accepts a Git patch for one ADS unit, including its owned scenarios and
|
|
91
93
|
fixtures, and runs the guards before applying it. Foundation styles, original
|
|
92
|
-
assets, guides and project configuration/guard extensions have editable units too.
|
|
94
|
+
assets, guides and project configuration/guard extensions have editable units too.
|
|
95
|
+
Coupled changes use bounded owner transactions with checks on the complete final
|
|
96
|
+
candidate. Local owner drafts and token-sample preparation reduce patch setup;
|
|
97
|
+
they keep source writes behind the same guards. See
|
|
98
|
+
[guarded editing](docs/MCP.md#guarded-editing).
|
|
93
99
|
|
|
94
100
|
The server exposes public components/patterns, token values,
|
|
95
|
-
source guides, architecture checks,
|
|
101
|
+
source guides, controllers/hooks, architecture checks, behavioral verification,
|
|
102
|
+
workflow prompts, and packaged ADS skills.
|
|
96
103
|
It supports older MCP clients and the newer Skills protocol.
|
|
97
104
|
|
|
105
|
+
Private controllers stay beside their component; shared controllers have their own
|
|
106
|
+
edit units. Optional behavior contracts connect guarantees to maintained checks.
|
|
107
|
+
Demonstrations and passing execution evidence remain distinct. See
|
|
108
|
+
[controllers and verification](docs/BEHAVIORS.md).
|
|
109
|
+
|
|
98
110
|
Experimental MCP Apps show an interactive token inspector and project-built
|
|
99
111
|
token, component, pattern and composition scenarios. They use the same public implementations and fixtures
|
|
100
112
|
as the showcase. Text and resource access remain available without Apps support.
|
|
@@ -202,13 +214,13 @@ app's bundler. With no icon source, generation is skipped. See the
|
|
|
202
214
|
Install skills with `npx skills`:
|
|
203
215
|
|
|
204
216
|
```sh
|
|
205
|
-
npx skills add reqvire-org/ads --skill ads-designer --skill ads-import --skill ads-
|
|
217
|
+
npx skills add reqvire-org/ads --skill ads-designer --skill ads-import --skill ads-migrate --skill ads-break-ui --skill ads-motion
|
|
206
218
|
```
|
|
207
219
|
|
|
208
220
|
For local development, install from this checkout:
|
|
209
221
|
|
|
210
222
|
```sh
|
|
211
|
-
npx skills add ./skills --skill ads-designer --skill ads-import --skill ads-
|
|
223
|
+
npx skills add ./skills --skill ads-designer --skill ads-import --skill ads-migrate --skill ads-break-ui --skill ads-motion
|
|
212
224
|
```
|
|
213
225
|
|
|
214
226
|
Acknowledgments: `ads-designer`'s craft/mobile guidance, `ads-break-ui`, and
|
|
@@ -220,7 +232,7 @@ notice beside its files.
|
|
|
220
232
|
|
|
221
233
|
- [ads-designer](skills/ads-designer/SKILL.md): start an ADS or build UI with your local ADS.
|
|
222
234
|
- [ads-import](skills/ads-import/SKILL.md): import external components, patterns, styles, token values, or brand artwork.
|
|
223
|
-
- [ads-
|
|
235
|
+
- [ads-migrate](skills/ads-migrate/SKILL.md): implement a native component inspired by an external library.
|
|
224
236
|
- [ads-break-ui](skills/ads-break-ui/SKILL.md): stress-test real components and patterns with difficult content.
|
|
225
237
|
- [ads-motion](skills/ads-motion/SKILL.md): implement, review, audit, or profile component animation.
|
|
226
238
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isBuiltin } from "node:module";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { isBehaviorFile, isDevelopmentFile, isInside, sourceFiles } from "./config.mjs";
|
|
7
|
+
import { importResolver, projectCompilerOptions } from "./boundaries.mjs";
|
|
8
|
+
import { inspectUnits } from "./units.mjs";
|
|
9
|
+
import { publicApi } from "./public-api.mjs";
|
|
10
|
+
import { inspectScenarios } from "./scenarios.mjs";
|
|
11
|
+
import { uiOperation } from "./ui-framework.mjs";
|
|
12
|
+
|
|
13
|
+
const id = z.string().regex(/^[a-zA-Z0-9][\w.-]{0,99}$/);
|
|
14
|
+
const reference = z.string().min(1).max(500);
|
|
15
|
+
const subject = z.union([
|
|
16
|
+
z.object({ api: reference }).strict(),
|
|
17
|
+
z.object({ source: reference, symbol: reference.optional() }).strict(),
|
|
18
|
+
]);
|
|
19
|
+
export const behaviorSchema = z.object({
|
|
20
|
+
schemaVersion: z.literal(1),
|
|
21
|
+
subjects: z.record(id, subject).refine(value => Object.keys(value).length > 0 && Object.keys(value).length <= 100),
|
|
22
|
+
guarantees: z.array(z.object({ id, description: z.string().min(1).max(2000), subjects: z.array(id).min(1).max(100), checks: z.array(id).min(1).max(100) }).strict()).min(1).max(100),
|
|
23
|
+
checks: z.record(id, z.object({ file: reference, case: id, scenario: reference.optional(), profile: id }).strict()).refine(value => Object.keys(value).length > 0 && Object.keys(value).length <= 100),
|
|
24
|
+
}).strict();
|
|
25
|
+
|
|
26
|
+
/** Static contracts never execute project code or certify natural-language claims. */
|
|
27
|
+
export function inspectBehaviors(options, suppliedProgram, suppliedRegistry) {
|
|
28
|
+
const { root, dsRoot, config } = options;
|
|
29
|
+
const inventory = inspectUnits(options);
|
|
30
|
+
const files = sourceFiles(dsRoot).filter(isBehaviorFile);
|
|
31
|
+
if (!files.length) return { contracts: [], diagnostics: [] };
|
|
32
|
+
const program = suppliedProgram ?? ts.createProgram(sourceFiles(dsRoot).filter(file => /\.[cm]?[jt]sx?$/.test(file)), { ...projectCompilerOptions(options), allowJs: true });
|
|
33
|
+
const checker = program.getTypeChecker();
|
|
34
|
+
const apis = new Map(publicApi(program, options).map(item => [item.name, item]));
|
|
35
|
+
const scenarios = (suppliedRegistry ?? inspectScenarios(options, program)).scenarios;
|
|
36
|
+
const diagnostics = [], contracts = [], owners = new Set();
|
|
37
|
+
const relative = file => path.relative(root, file).replaceAll("\\", "/");
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
const report = message => diagnostics.push({ file: relative(file), rule: "behavior-contract", line: 1, column: 1, message });
|
|
40
|
+
let value;
|
|
41
|
+
try {
|
|
42
|
+
if (statSync(file).size > 128 * 1024 || realpathSync(file) !== file) throw new Error("Behavior contracts must be regular files of at most 128 KiB.");
|
|
43
|
+
const parsed = behaviorSchema.safeParse(JSON.parse(readFileSync(file, "utf8")));
|
|
44
|
+
if (!parsed.success) throw new Error(parsed.error.issues.slice(0, 5).map(issue => `${issue.path.join(".")}: ${issue.message}`).join("; "));
|
|
45
|
+
value = parsed.data;
|
|
46
|
+
} catch (error) { report(error.message); continue; }
|
|
47
|
+
const unit = inventory.owner(inventory.relative(relative(file)));
|
|
48
|
+
if (!["components", "patterns", "controllers"].includes(unit?.split("/")[0])) { report("Behavior contracts belong to a component, pattern or controller unit."); continue; }
|
|
49
|
+
if (owners.has(unit)) { report(`Only one behavior contract may describe ${unit}.`); continue; }
|
|
50
|
+
owners.add(unit);
|
|
51
|
+
function owned(target, field) {
|
|
52
|
+
if (path.isAbsolute(target) || target.includes("\\") || target.includes("\0")) { report(`${field} must be an owner-local relative path.`); return null; }
|
|
53
|
+
const absolute = path.resolve(path.dirname(file), target);
|
|
54
|
+
if (!isInside(dsRoot, absolute) || inventory.owner(inventory.relative(relative(absolute))) !== unit
|
|
55
|
+
|| !existsSync(absolute) || !statSync(absolute).isFile() || realpathSync(absolute) !== absolute) { report(`${field} must resolve to a real file in ${unit}: ${target}`); return null; }
|
|
56
|
+
return absolute;
|
|
57
|
+
}
|
|
58
|
+
for (const [name, entry] of Object.entries(value.subjects)) {
|
|
59
|
+
if (entry.api) {
|
|
60
|
+
const api = apis.get(entry.api);
|
|
61
|
+
if (!api || inventory.owner(inventory.relative(relative(api.file))) !== unit) report(`Subject ${name} must resolve to a public API owned by ${unit}: ${entry.api}`);
|
|
62
|
+
} else {
|
|
63
|
+
const source = owned(entry.source, `Subject ${name}`);
|
|
64
|
+
if (source && isDevelopmentFile(source, options)) report(`Subject ${name} must identify runtime implementation, not a fixture, scenario or check.`);
|
|
65
|
+
if (source && entry.symbol) {
|
|
66
|
+
const ast = program.getSourceFile(source);
|
|
67
|
+
if (!ast || !checker.getSymbolsInScope(ast, ts.SymbolFlags.Value).some(symbol => symbol.name === entry.symbol && symbol.declarations?.some(declaration => declaration.getSourceFile() === ast))) report(`Subject ${name}: symbol ${entry.symbol} is not declared in ${entry.source}.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const guaranteeIds = new Set();
|
|
72
|
+
for (const guarantee of value.guarantees) {
|
|
73
|
+
if (guaranteeIds.has(guarantee.id)) report(`Duplicate guarantee ID ${guarantee.id}.`);
|
|
74
|
+
guaranteeIds.add(guarantee.id);
|
|
75
|
+
for (const name of guarantee.subjects) if (!Object.hasOwn(value.subjects, name)) report(`Guarantee ${guarantee.id} references unknown subject ${name}.`);
|
|
76
|
+
for (const check of guarantee.checks) if (!Object.hasOwn(value.checks, check)) report(`Guarantee ${guarantee.id} references unknown check ${check}.`);
|
|
77
|
+
}
|
|
78
|
+
const cases = new Set();
|
|
79
|
+
for (const [name, check] of Object.entries(value.checks)) {
|
|
80
|
+
const target = owned(check.file, `Check ${name}`);
|
|
81
|
+
if (target && !isDevelopmentFile(target, options)) report(`Check ${name} must use a development-only test/spec file.`);
|
|
82
|
+
if (!Object.hasOwn(config.mcp.behaviorProfiles, check.profile)) report(`Check ${name} references unregistered profile ${check.profile}. Register its literal runner command in ds.config.json; checks cannot install packages or assume host globals.`);
|
|
83
|
+
if (check.scenario && !scenarios.some(scenario => scenario.id === check.scenario)) report(`Check ${name} references unknown scenario ${check.scenario}.`);
|
|
84
|
+
const identity = JSON.stringify([check.file, check.case, check.profile]);
|
|
85
|
+
if (cases.has(identity)) report(`Duplicate execution identity for check ${name}. Use one check ID and reference it from several guarantees.`);
|
|
86
|
+
cases.add(identity);
|
|
87
|
+
}
|
|
88
|
+
contracts.push({ ...value, unit, file: relative(file), demonstrations: Object.fromEntries(Object.entries(value.subjects).filter(([, item]) => item.api).map(([name, item]) => [name, scenarios.filter(scenario => scenario.exercises?.includes(item.api)).map(scenario => scenario.id)])) });
|
|
89
|
+
}
|
|
90
|
+
return { contracts, diagnostics };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Headless ownership applies to shared controllers and explicitly named private subjects. */
|
|
94
|
+
export function inspectControllers(options, program, report, contracts = []) {
|
|
95
|
+
const { root, dsRoot, config } = options;
|
|
96
|
+
const resolve = importResolver(options);
|
|
97
|
+
const pkg = existsSync(path.join(root, "package.json")) ? JSON.parse(readFileSync(path.join(root, "package.json"), "utf8")) : {};
|
|
98
|
+
const declared = new Set(Object.keys({ ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies, ...pkg.optionalDependencies }));
|
|
99
|
+
const privateFiles = new Map();
|
|
100
|
+
for (const contract of contracts) for (const subject of Object.values(contract.subjects).filter(item => item.source)) {
|
|
101
|
+
const file = path.resolve(root, path.dirname(contract.file), subject.source);
|
|
102
|
+
if (!privateFiles.has(file)) privateFiles.set(file, new Set());
|
|
103
|
+
privateFiles.get(file).add(subject.symbol ?? null);
|
|
104
|
+
}
|
|
105
|
+
const checker = program.getTypeChecker();
|
|
106
|
+
for (const source of program.getSourceFiles()) {
|
|
107
|
+
const file = source.fileName;
|
|
108
|
+
if (isDevelopmentFile(file, options) || !isInside(path.join(dsRoot, "controllers"), file) && !privateFiles.has(file)) continue;
|
|
109
|
+
const wholeFile = isInside(path.join(dsRoot, "controllers"), file) || privateFiles.get(file)?.has(null);
|
|
110
|
+
const subjects = wholeFile ? [] : checker.getSymbolsInScope(source, ts.SymbolFlags.Value).filter(symbol => privateFiles.get(file)?.has(symbol.name)).flatMap(symbol => symbol.declarations ?? []);
|
|
111
|
+
const headless = node => wholeFile || subjects.some(subject => subject.getSourceFile() === source && node.pos >= subject.pos && node.end <= subject.end);
|
|
112
|
+
function emit(node, rule, message) { const p = source.getLineAndCharacterOfPosition(node.getStart()); report(file, rule, message, p.line + 1, p.character + 1); }
|
|
113
|
+
function visit(node) {
|
|
114
|
+
let specifier;
|
|
115
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) specifier = node.moduleSpecifier.text;
|
|
116
|
+
if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword || ts.isIdentifier(node.expression) && node.expression.text === "require") && node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) specifier = node.arguments[0].text;
|
|
117
|
+
if (specifier) {
|
|
118
|
+
const typeOnly = ts.isImportDeclaration(node) && (node.importClause?.isTypeOnly || node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings) && !node.importClause.name && node.importClause.namedBindings.elements.every(item => item.isTypeOnly)) || ts.isExportDeclaration(node) && node.isTypeOnly;
|
|
119
|
+
if (!typeOnly) {
|
|
120
|
+
if (wholeFile && /^(?:@linaria\/|.*\.css(?:[?#].*)?$)/.test(specifier)) emit(node, "controller-skin", "Controllers own behavior and measurements. Put CSS/Linaria skins in the consuming component or pattern.");
|
|
121
|
+
const framework = /^(?:react|react-dom)(?:\/|$)/.test(specifier) ? "react" : /^preact(?:\/|$)/.test(specifier) ? "preact" : null;
|
|
122
|
+
if (framework && config.framework !== framework) emit(node, "controller-framework", `Controller imports ${framework}, but ds.config.json selects ${config.framework ?? "no framework"}. Use the configured framework or plain TypeScript/browser APIs; MCP hosts do not supply another runtime.`);
|
|
123
|
+
const targets = resolve(specifier, file);
|
|
124
|
+
const local = specifier.startsWith(".") || specifier === config.publicAlias || targets.some(target => isInside(root, target) && !target.includes(`${path.sep}node_modules${path.sep}`) && existsSync(target));
|
|
125
|
+
if (local) {
|
|
126
|
+
if (targets.some(target => !existsSync(target))) emit(node, "controller-dependency", `Unresolved controller dependency ${specifier}. Declare real project dependencies and local modules; do not assume MCP host globals.`);
|
|
127
|
+
if (isInside(path.join(dsRoot, "controllers"), file)) {
|
|
128
|
+
const targetsInUi = targets.some(target => ["components", "patterns"].some(kind => isInside(path.join(dsRoot, kind), target)));
|
|
129
|
+
if (targetsInUi) emit(node, "controller-dependency", "Shared controllers cannot import component/pattern runtime implementations. Pass behavior adapters or callbacks from the consumer; type-only imports are allowed.");
|
|
130
|
+
if (specifier === config.publicAlias) {
|
|
131
|
+
for (const item of node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings) ? node.importClause.namedBindings.elements : []) {
|
|
132
|
+
let symbol = checker.getSymbolAtLocation(item.name);
|
|
133
|
+
if (symbol?.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
|
|
134
|
+
if (symbol?.declarations?.some(declaration => ["components", "patterns"].some(kind => isInside(path.join(dsRoot, kind), declaration.getSourceFile().fileName)))) emit(item, "controller-dependency", "Shared controllers consume behavior helpers, not styled component/pattern implementations.");
|
|
135
|
+
}
|
|
136
|
+
if (!node.importClause?.namedBindings || ts.isNamespaceImport(node.importClause.namedBindings)) emit(node, "controller-dependency", "Use explicit behavior imports in shared controllers so dependency ownership can be checked.");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else if (!isBuiltin(specifier)) {
|
|
140
|
+
const name = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
141
|
+
if (!declared.has(name)) emit(node, "controller-dependency", `Undeclared controller dependency ${name}. Register it in the project package; ADS does not install dependencies or receive them from an MCP host.`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (headless(node) && ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && ts.isIdentifier(node.tagName) && /^[a-z]/.test(node.tagName.text)
|
|
146
|
+
|| ts.isCallExpression(node) && uiOperation(node.expression, checker) === "createElement" && node.arguments[0] && ts.isStringLiteralLike(node.arguments[0]))) emit(node, "controller-skin", "Visual DOM markup belongs in components/patterns. Controllers may use framework hooks and context providers.");
|
|
147
|
+
if (!wholeFile && headless(node) && (ts.isTaggedTemplateExpression(node) || ts.isCallExpression(node))) {
|
|
148
|
+
let base = ts.isTaggedTemplateExpression(node) ? node.tag : node.expression;
|
|
149
|
+
while (ts.isPropertyAccessExpression(base) || ts.isCallExpression(base)) base = base.expression;
|
|
150
|
+
if (checker.getSymbolAtLocation(base)?.declarations?.some(declaration => ts.isImportSpecifier(declaration) && declaration.parent.parent.parent.moduleSpecifier.text.startsWith("@linaria/")
|
|
151
|
+
|| ts.isNamespaceImport(declaration) && declaration.parent.parent.moduleSpecifier.text.startsWith("@linaria/"))) emit(node, "controller-skin", "Keep Linaria styling outside the declared private controller subject, in its visual consumer.");
|
|
152
|
+
}
|
|
153
|
+
ts.forEachChild(node, visit);
|
|
154
|
+
}
|
|
155
|
+
visit(source);
|
|
156
|
+
}
|
|
157
|
+
}
|
package/dist/bootstrap-ds/ADS.md
CHANGED
|
@@ -36,8 +36,14 @@ Projects sharing this ADS use the same token names, meanings, and value types;
|
|
|
36
36
|
their concrete values and theme overrides can differ. Reuse existing local values
|
|
37
37
|
when importing components/patterns, add missing shared definitions, and import
|
|
38
38
|
source token values only when adopting that theme is requested.
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
Shared token names and prefixes follow the ADS contract. A component/pattern may
|
|
40
|
+
register one unique local namespace in colocated `tokens.json` and define it in
|
|
41
|
+
`tokens.css`, imported by its runtime. Flat owners use `<Owner>.tokens.json` and
|
|
42
|
+
`<Owner>.tokens.css`. These definition-only sheets contain root/theme custom
|
|
43
|
+
properties, not UI selectors or ordinary styles. Other owners consume shared
|
|
44
|
+
tokens; they cannot override or consume a peer's local namespace. A colocated
|
|
45
|
+
`kind:"tokens"` scenario needs real samples for every local token. Shared
|
|
46
|
+
assignments remain in the shared token files. Components own
|
|
41
47
|
`--ds-*`, patterns `--ux-*`, and the showcase `--showcase-*`; token files cannot
|
|
42
48
|
assign those local variables or override component state.
|
|
43
49
|
|
|
@@ -183,7 +189,7 @@ mounting, correct props, every branch/state or visual parity. The older
|
|
|
183
189
|
|
|
184
190
|
`token-scenario-reference` rejects undeclared token names in metadata and reachable
|
|
185
191
|
inputs. `token-scenario-render` rejects claimed tokens with no reachable input
|
|
186
|
-
reference; `token-scenario-coverage` requires every discovered
|
|
192
|
+
reference; `token-scenario-coverage` requires every discovered shared or owner-local token
|
|
187
193
|
to have coverage. A new or removed token therefore needs a scenario/fixture
|
|
188
194
|
update. All three are errors in `ads check`, run by `lint:ds` and the build.
|
|
189
195
|
Coverage is static reachability, not proof that every branch actually renders
|
|
@@ -241,3 +247,10 @@ Run `npm run build` after adding or changing components. Add meaningful tests
|
|
|
241
247
|
for stateful behavior, accessibility, gestures, or async lifecycle where needed.
|
|
242
248
|
Run `npm run dev` to inspect the real showcase. A screenshot alone does not
|
|
243
249
|
verify interaction or animation. Generated output and dependencies are not source.
|
|
250
|
+
|
|
251
|
+
Shared behavior may live in `controllers/<Name>/`; private controllers stay with
|
|
252
|
+
their component/pattern. Use the configured framework and declared dependencies.
|
|
253
|
+
Behavior contracts/checks are development-only, and scenario `exercises` links
|
|
254
|
+
public hooks to demonstrations separately from rendered `covers`. Read the
|
|
255
|
+
installed ADS package's `docs/BEHAVIORS.md` or MCP `ads://guides/behaviors` before
|
|
256
|
+
registering guarantees, profiles and verification.
|
|
@@ -62,6 +62,10 @@ the public `TokenPreview` pattern owns their presentation and applies the real C
|
|
|
62
62
|
variables. Add/remove samples alongside token definitions. `ads check` rejects
|
|
63
63
|
missing coverage and invented names; the App verifies the declared CSS bindings
|
|
64
64
|
in the browser. Extend or replace the project-owned pattern as your tokens evolve.
|
|
65
|
+
`ads_prepare_token_samples` can prepare a fixture patch from explicit project
|
|
66
|
+
property/probe bindings. It preserves existing samples and reports unmapped tokens;
|
|
67
|
+
it does not guess how a new value should look. Component/pattern constants can use
|
|
68
|
+
the colocated namespace contract in [ADS.md](ADS.md), with their own token scenario.
|
|
65
69
|
|
|
66
70
|
Create a component under `design-system/components/`, export it through `@ds`,
|
|
67
71
|
and colocate `Scenario.tsx` plus `fixture.ts` (or `<Owner>.scenario.tsx` and
|
|
@@ -79,6 +83,8 @@ stale retained output. Switching or rebuilding a scenario unmounts its previous
|
|
|
79
83
|
state. `showcase/mcp/main.tsx` exports `mountScenario(Scenario, container)` and
|
|
80
84
|
returns an unmount callback; it is not the shell. Keep the saved `framework`,
|
|
81
85
|
compiler and mount adapter consistent.
|
|
86
|
+
Managed sessions own their graph output; standalone prebuilds cannot replace it.
|
|
87
|
+
Verified generated graph snapshots preserve warm-start reuse across sessions.
|
|
82
88
|
|
|
83
89
|
The application and previews use the same foundation CSS and Linaria pipeline.
|
|
84
90
|
The source barrel loads the foundation once. The private `build:lib` script uses
|
|
@@ -98,3 +104,7 @@ from a user-selected external repository, preserving revisions and licenses.
|
|
|
98
104
|
inspection builds it automatically, then loads selected entries. Browser review
|
|
99
105
|
still checks layout, accessibility, keyboard/focus, states, themes and motion. A clean
|
|
100
106
|
build or delivered HTML alone does not establish those behaviors.
|
|
107
|
+
Opt-in MCP editing uses owner Git patches. `ads_prepare_patch` creates a temporary
|
|
108
|
+
owner draft/diff; `ads_apply_transaction` validates bounded coupled owner patches
|
|
109
|
+
against one final candidate. Preparation changes no live source. Keep all guards
|
|
110
|
+
and review the rendered result after applying.
|
|
File without changes
|
package/dist/boundaries.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import ts from "typescript";
|
|
|
3
3
|
import { importedUiName } from "./ui-framework.mjs";
|
|
4
4
|
import { isInside, isStateVariable, isTestFile, isDevelopmentFile } from "./config.mjs";
|
|
5
5
|
import { isSharedToken } from "./token-policy.mjs";
|
|
6
|
+
import { scopedTokenOwner } from "./scoped-tokens.mjs";
|
|
6
7
|
|
|
7
8
|
export function projectCompilerOptions({ root }) {
|
|
8
9
|
const file = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
|
|
@@ -59,6 +60,8 @@ export function checkComponentVariable(name, filename, options) {
|
|
|
59
60
|
const components = !development && isInside(path.join(dsRoot, "components"), filename);
|
|
60
61
|
const patterns = !development && isInside(path.join(dsRoot, "patterns"), filename);
|
|
61
62
|
const showcase = development;
|
|
63
|
+
const owned = scopedTokenOwner(options, name);
|
|
64
|
+
if (owned) return path.resolve(options.root, owned.file) === filename ? null : { rule: "token-ownership", message: `Define ${name} only in ${owned.file}, owned by ${owned.unit}. Consume it with var(); runtime geometry remains a separate styleWrites boundary.` };
|
|
62
65
|
if (isSharedToken(name)) return tokens ? null : { rule: "token-ownership", message: `Define ${name} in ADS tokens, not component, pattern, showcase, or app styles.` };
|
|
63
66
|
if (name.startsWith("--ux-")) return patterns || showcase ? null : { rule: "variable-ownership", message: "--ux-* variables belong to ADS patterns and showcase composition." };
|
|
64
67
|
if (name.startsWith("--showcase-")) return showcase ? null : { rule: "variable-ownership", message: "--showcase-* variables belong to the ADS showcase." };
|
package/dist/check.mjs
CHANGED
|
@@ -15,7 +15,10 @@ import { inspectShowcaseCoverage } from "./showcase-coverage.mjs";
|
|
|
15
15
|
import { inspectScenarioCoverage } from "./scenarios.mjs";
|
|
16
16
|
import { uiOperation, importedUiApi } from "./ui-framework.mjs";
|
|
17
17
|
import { inspectStyleBoundaries, pointerCaptureAdvisories } from "./style-boundaries.mjs";
|
|
18
|
+
import { inspectBehaviors, inspectControllers } from "./behaviors.mjs";
|
|
19
|
+
import { numericCssUnit, tokenLengthLiteral } from "./css-values.mjs";
|
|
18
20
|
import { foundationDeclaration, foundationSelector } from "./foundation.mjs";
|
|
21
|
+
import { scopedTokens, scopedTokenOwner } from "./scoped-tokens.mjs";
|
|
19
22
|
|
|
20
23
|
const scenarioLayoutGuidance = "Put demo-only sizing and framing in a public review/layout pattern. Keep required behavior in the runtime owner; add component props for deliberate product API needs.";
|
|
21
24
|
const inlineStyleGuidance = `Own visual styles in component/pattern Linaria. ${scenarioLayoutGuidance} Reserve inlineStyleFiles for documented measured geometry, not demo layout.`;
|
|
@@ -38,6 +41,8 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
38
41
|
diagnostics.push(...tokenInventory.diagnostics);
|
|
39
42
|
diagnostics.push(...inspectAssets(options));
|
|
40
43
|
const resolveImport = importResolver(options);
|
|
44
|
+
const scoped = scopedTokens(options);
|
|
45
|
+
const scopedFiles = new Set(scoped.definitions.map(entry => path.resolve(root, entry.file)));
|
|
41
46
|
const rootHtml = path.join(root, "index.html");
|
|
42
47
|
const files = [...new Set([...sourceFiles(sourceRoot), ...sourceFiles(dsRoot), ...(existsSync(rootHtml) ? [rootHtml] : [])])];
|
|
43
48
|
const boundaryFiles = [...config.inlineStyleFiles, ...config.boundaries.styleWrites.map(entry => entry.file)].map(file => path.resolve(root, file)).filter(file => existsSync(file) && statSync(file).isFile());
|
|
@@ -51,7 +56,10 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
51
56
|
inspectStyleBoundaries(options, program, report);
|
|
52
57
|
inspectShowcasePages(options, program, resolveImport, report);
|
|
53
58
|
inspectShowcaseCoverage(options, program, report);
|
|
54
|
-
inspectScenarioCoverage(options, program, report);
|
|
59
|
+
inspectScenarioCoverage(options, program, report, (file, rule, message) => advisories.push({ file: path.relative(root, file).replaceAll("\\", "/"), rule, message, line: 1, column: 1 }));
|
|
60
|
+
const behaviors = inspectBehaviors(options, program);
|
|
61
|
+
diagnostics.push(...behaviors.diagnostics);
|
|
62
|
+
inspectControllers(options, program, report, behaviors.contracts);
|
|
55
63
|
// The foundation remains a fixed import-only entry, not an extra styling layer.
|
|
56
64
|
const foundationEntry = path.join(dsRoot, config.stylesEntry);
|
|
57
65
|
try {
|
|
@@ -105,6 +113,11 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
105
113
|
const variable = checkComponentVariable(decl.prop, file, options);
|
|
106
114
|
if (variable) report(file, variable.rule, variable.message, offset.line + decl.source.start.line - 1, decl.source.start.column);
|
|
107
115
|
for (const ref of references(decl.value)) {
|
|
116
|
+
const owned = scopedTokenOwner(options, ref.name);
|
|
117
|
+
if (owned) {
|
|
118
|
+
if (scoped.inventory.owner(scoped.inventory.relative(path.relative(root, file))) !== owned.unit || !declaredTokens.has(ref.name)) report(file, "token-reference", `${ref.name} belongs to ${owned.unit}. Use shared tokens across owners; owner-local tokens must be defined and consumed by their owner.`, offset.line + decl.source.start.line - 1, decl.source.start.column);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
108
121
|
const local = /^(?:--ds-|--ux-|--showcase-)/.test(ref.name);
|
|
109
122
|
if (foundation && local) report(file, "foundation-role", "Foundation defaults consume shared tokens, not component, pattern or scenario-local variables.", offset.line + decl.source.start.line - 1, decl.source.start.column);
|
|
110
123
|
if (!local && !isSharedToken(ref.name)) report(file, "token-name", `${ref.name} does not follow ADS's fixed token naming contract.`, offset.line + decl.source.start.line - 1, decl.source.start.column);
|
|
@@ -114,7 +127,7 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
114
127
|
const violations = new Set();
|
|
115
128
|
valueParser(decl.value).walk((node) => {
|
|
116
129
|
if (node.type === "function" && node.value === "url") return false;
|
|
117
|
-
if (node.type === "word" &&
|
|
130
|
+
if (node.type === "word" && (/^#[\da-f]{3,8}$/i.test(node.value) || tokenLengthLiteral(node.value) || ["s", "ms"].includes(numericCssUnit(node.value)))) violations.add("Use a token for colors, absolute/font-relative lengths (including ch), and durations. Unitless geometry and structural angle/viewport/container relationships remain valid.");
|
|
118
131
|
if (node.type === "function" && /^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix|cubic-bezier)$/.test(node.value)) violations.add("Define color formulas and easing in tokens.");
|
|
119
132
|
if (node.type === "function" && /^(?:blur|brightness|contrast|drop-shadow|grayscale|hue-rotate|invert|saturate|sepia)$/.test(node.value)) violations.add("Define visual filter effects in tokens.");
|
|
120
133
|
if (node.type === "word" && /^ease(?:-in|-out|-in-out)?$/.test(node.value)) violations.add("Use a motion token for easing.");
|
|
@@ -125,6 +138,7 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
125
138
|
});
|
|
126
139
|
}
|
|
127
140
|
for (const file of files) {
|
|
141
|
+
if (scopedFiles.has(file)) continue; // Closed definition-only contract checked by inspectTokens.
|
|
128
142
|
if (file.endsWith(".css") && isInside(path.join(dsRoot, config.tokenDir), file) && !isDevelopmentFile(file, options)) { checkCss(file, readFileSync(file, "utf8"), undefined, true); continue; }
|
|
129
143
|
if (file.endsWith(".html")) { inspectHtml(readFileSync(file, "utf8"), (rule, message, line) => report(file, rule, message, line)); continue; }
|
|
130
144
|
if (file.endsWith(".css")) {
|
|
@@ -218,6 +232,10 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
218
232
|
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) specifier = node.moduleSpecifier.text;
|
|
219
233
|
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword && node.arguments[0] && ts.isStringLiteral(node.arguments[0])) specifier = node.arguments[0].text;
|
|
220
234
|
if (specifier && importViolation(specifier, file, options, resolveImport)) nodeReport(node, "public-import", `Import through ${config.publicAlias}, not ADS implementation paths.`);
|
|
235
|
+
if (specifier) for (const target of resolveImport(specifier, file)) {
|
|
236
|
+
const tokenOwner = scoped.definitions.find(entry => path.resolve(root, entry.file) === target);
|
|
237
|
+
if (tokenOwner && scoped.inventory.owner(scoped.inventory.relative(path.relative(root, file))) !== tokenOwner.unit) nodeReport(node, "token-ownership", `Only ${tokenOwner.unit} imports its token sheet. Import the public component/pattern to consume its design.`);
|
|
238
|
+
}
|
|
221
239
|
if (specifier && resolveImport(specifier, file).some((target) => (specifier.startsWith(".") || existsSync(target)) && target.endsWith(".css") && isInside(root, target) && !isInside(dsRoot, target) && target !== path.join(sourceRoot, "app-mount.css") && !isInside(path.join(root, "node_modules"), target))) nodeReport(node, "style-ownership", "Imported project CSS belongs to ADS components, patterns, or the foundation. Only structural app-mount.css is allowed outside the ADS.");
|
|
222
240
|
if (specifier && appImportViolation(specifier, file, options, resolveImport)) nodeReport(node, "no-app-import", "ADS implementations and showcase fixtures must not import app code. Use public ADS APIs with local fixture data; keep application integration harnesses in application tests.");
|
|
223
241
|
if (specifier && showcaseImportViolation(specifier, file, options, resolveImport)) nodeReport(node, "showcase-import", "Showcase code and styles are development fixtures; runtime code must not import them.");
|
package/dist/cli.mjs
CHANGED
|
@@ -11,6 +11,8 @@ Usage: ads init [options] Run inside your project
|
|
|
11
11
|
|
|
12
12
|
init Set up ADS in the current project (requires package.json)
|
|
13
13
|
check [directory] Check tokens, ownership, imports, and showcase coverage
|
|
14
|
+
behaviors [dir] Inspect behavior contracts and current verification evidence
|
|
15
|
+
verify [directory] Run registered behavior checks (--unit and --check select)
|
|
14
16
|
tokens [directory] Inspect local token values and theme definitions
|
|
15
17
|
assets [directory] Generate standard web icons in .ds/assets from assets.iconSource
|
|
16
18
|
lint-config [dir] Generate .ds/oxlintrc.json with core and project plugins
|
|
@@ -25,6 +27,8 @@ Usage: ads init [options] Run inside your project
|
|
|
25
27
|
--port number MCP/showcase only: loopback website port (default: automatic)
|
|
26
28
|
--no-showcase MCP only: disable the local website
|
|
27
29
|
--mutations MCP only: enable guarded ADS source editing
|
|
30
|
+
--unit id Verify only: select one discovered behavior contract owner
|
|
31
|
+
--check id Verify only: select a registered check (repeatable)
|
|
28
32
|
|
|
29
33
|
External components and examples are imported using the ADS skills.
|
|
30
34
|
No component library or example catalogue is bundled.
|
|
@@ -38,6 +42,8 @@ async function main(args) {
|
|
|
38
42
|
let packageManager;
|
|
39
43
|
let framework;
|
|
40
44
|
let port;
|
|
45
|
+
let unit;
|
|
46
|
+
const selectedChecks = [];
|
|
41
47
|
let showcase = true;
|
|
42
48
|
let mutations = false;
|
|
43
49
|
const positional = [];
|
|
@@ -46,6 +52,12 @@ async function main(args) {
|
|
|
46
52
|
if (argument === "--json") json = true;
|
|
47
53
|
else if (argument === "--no-showcase") showcase = false;
|
|
48
54
|
else if (argument === "--mutations") mutations = true;
|
|
55
|
+
else if (argument === "--unit" || argument === "--check") {
|
|
56
|
+
const value = args[++index];
|
|
57
|
+
if (!value || value.startsWith("-")) throw new Error(`${argument} needs a discovered unit/check ID.`);
|
|
58
|
+
if (argument === "--unit") { if (unit) throw new Error("Specify one --unit."); unit = value; }
|
|
59
|
+
else selectedChecks.push(value);
|
|
60
|
+
}
|
|
49
61
|
else if (argument === "--port") {
|
|
50
62
|
const value = args[++index];
|
|
51
63
|
if (port !== undefined || !/^\d+$/.test(value ?? "") || Number(value) > 65535) throw new Error("--port requires one port between 0 and 65535.");
|
|
@@ -72,6 +84,7 @@ async function main(args) {
|
|
|
72
84
|
if (packageManager !== undefined && command !== "init") throw new Error("--package-manager is supported only by init.");
|
|
73
85
|
if (framework !== undefined && command !== "init") throw new Error("--framework is supported only by init.");
|
|
74
86
|
if (command === "init" && directory) throw new Error("Run ads init inside the project, without a directory argument.");
|
|
87
|
+
if ((unit || selectedChecks.length) && command !== "verify") throw new Error("--unit and --check are supported only by verify.");
|
|
75
88
|
const target = path.resolve(directory ?? process.cwd());
|
|
76
89
|
if (command === "mcp" || command === "showcase") {
|
|
77
90
|
if (json) throw new Error("--json is not supported by mcp/showcase; mcp reserves stdout for JSON-RPC.");
|
|
@@ -82,6 +95,8 @@ async function main(args) {
|
|
|
82
95
|
let result;
|
|
83
96
|
if (command === "init") result = initProject(target, { toolPackage, packageManager, framework });
|
|
84
97
|
else if (command === "check") result = checkProject(target);
|
|
98
|
+
else if (command === "behaviors") { const {behaviorStatus}=await import("./verification.mjs"); const {loadConfig}=await import("./config.mjs"); result=behaviorStatus(loadConfig(target)); }
|
|
99
|
+
else if (command === "verify") { const {createVerificationController}=await import("./verification.mjs"); const verification=createVerificationController(target); try {result=await verification.run({...(unit?{unit}:{}),...(selectedChecks.length?{checks:selectedChecks}:{})});} finally {await verification.close();} }
|
|
85
100
|
else if (command === "tokens") result = inspectTokens(target);
|
|
86
101
|
else if (command === "assets") result = await generateBrandAssets(target);
|
|
87
102
|
else if (command === "lint-config") result = generateLintConfig(target);
|
|
@@ -90,6 +105,8 @@ async function main(args) {
|
|
|
90
105
|
else if (command === "init") console.log(`Initialized ${target}\nFramework: ${result.framework}\nAdded ${result.toolDependency.name} (${result.toolDependency.spec}) as a development dependency.\nRun ${result.packageManager} install and ${result.packageManager} run build; the build refreshes lint configuration, runs ADS checks, and generates configured brand assets automatically.`);
|
|
91
106
|
else if (command === "assets") console.log(result.skipped ? "No assets.iconSource configured; brand generation skipped." : `Generated ${result.files.length} brand assets in ${result.directory}.`);
|
|
92
107
|
else if (command === "lint-config") console.log(`Generated ${result.file}\nProjects initialized with ads init refresh this automatically during lint:ds/build.`);
|
|
108
|
+
else if (command === "behaviors") console.log(JSON.stringify(result, null, 2));
|
|
109
|
+
else if (command === "verify") { for (const item of result.results) console.log(`${item.unit}#${item.check}: ${item.status} (${item.profile})`); }
|
|
93
110
|
else if (command === "tokens") {
|
|
94
111
|
for (const token of result.tokens) console.log(`${token.name}${token.type ? ` (${token.type})` : ""}: ${token.definitions.map((entry) => `${entry.scope}: ${entry.value}`).join("; ")}`);
|
|
95
112
|
} else if (result.ok) console.log(`ADS check passed: ${target}`);
|
package/dist/config.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export const defaultConfig = {
|
|
|
17
17
|
boundaries: { styleWrites: [], componentVariables: [] },
|
|
18
18
|
assets: { publicDirs: ["public/assets"], generatedPaths: ["dist", "dist-showcase", ".vite", ".ds"], generatedFiles: [], iconSource: null },
|
|
19
19
|
oxlint: { plugins: [], rules: {}, overrides: [] },
|
|
20
|
-
mcp: { showcaseUrl: null, showcaseTitle: null, apps: [], previewWatch: null, previewManifest: null, mutationChecks: null },
|
|
20
|
+
mcp: { showcaseUrl: null, showcaseTitle: null, apps: [], previewWatch: null, previewManifest: null, mutationChecks: null, behaviorProfiles: {} },
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export function isInside(parent, file) {
|
|
@@ -100,6 +100,18 @@ export function loadConfig(directory = process.cwd()) {
|
|
|
100
100
|
}
|
|
101
101
|
if (config.mcp.showcaseTitle !== null && (typeof config.mcp.showcaseTitle !== "string" || !config.mcp.showcaseTitle.trim() || config.mcp.showcaseTitle.length > 120)) throw new Error("mcp.showcaseTitle must be a non-empty title of at most 120 characters or null.");
|
|
102
102
|
if (!Array.isArray(config.mcp.apps)) throw new Error("mcp.apps must be an array of built project previews.");
|
|
103
|
+
if (!config.mcp.behaviorProfiles || typeof config.mcp.behaviorProfiles !== "object" || Array.isArray(config.mcp.behaviorProfiles) || Object.keys(config.mcp.behaviorProfiles).length > 20) throw new Error("mcp.behaviorProfiles must be an object of up to 20 registered execution profiles.");
|
|
104
|
+
for (const [name, profile] of Object.entries(config.mcp.behaviorProfiles)) {
|
|
105
|
+
if (!/^[a-zA-Z0-9][\w.-]{0,79}$/.test(name) || !profile || typeof profile !== "object" || Array.isArray(profile)
|
|
106
|
+
|| Object.keys(profile).some(key => !["command", "args", "timeoutMs", "runner", "framework", "mode"].includes(key))
|
|
107
|
+
|| typeof profile.command !== "string" || !profile.command.trim() || profile.command.includes("\0")
|
|
108
|
+
|| !Array.isArray(profile.args) || profile.args.some(arg => typeof arg !== "string" || arg.includes("\0"))
|
|
109
|
+
|| !["protocol", "playwright"].includes(profile.runner ?? "protocol")
|
|
110
|
+
|| profile.framework !== undefined && profile.framework !== config.framework
|
|
111
|
+
|| profile.mode !== undefined && !["browser", "strict", "unit"].includes(profile.mode)
|
|
112
|
+
|| profile.timeoutMs !== undefined && (!Number.isInteger(profile.timeoutMs) || profile.timeoutMs < 100 || profile.timeoutMs > 300000)) throw new Error(`Invalid behavior profile ${name}. Use literal executable/args, a protocol or Playwright runner, a matching framework and a bounded timeout. Profiles do not install dependencies or receive APIs from an MCP host.`);
|
|
113
|
+
if (profile.mode === "strict" && config.framework !== "react") throw new Error(`Behavior profile ${name}: React StrictMode requires framework react; use the configured framework's lifecycle tests instead.`);
|
|
114
|
+
}
|
|
103
115
|
if (config.mcp.mutationChecks !== null && (!Array.isArray(config.mcp.mutationChecks) || config.mcp.mutationChecks.length > 12 || new Set(config.mcp.mutationChecks).size !== config.mcp.mutationChecks.length || config.mcp.mutationChecks.some(name => typeof name !== "string" || !/^[a-zA-Z0-9][\w:.-]*$/.test(name)))) throw new Error("mcp.mutationChecks must be null or up to 12 unique package script names.");
|
|
104
116
|
if (config.mcp.previewManifest !== null) {
|
|
105
117
|
const manifest = projectPath(root, config.mcp.previewManifest, "mcp.previewManifest");
|
|
@@ -136,10 +148,18 @@ export function isFixtureFile(file) {
|
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
/** File role, rather than folder location, keeps colocated preview code private. */
|
|
151
|
+
export function isBehaviorFile(file) {
|
|
152
|
+
return /(?:^|[\\/])behavior\.json$|\.behavior\.json$/.test(file);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function isTokenManifestFile(file) {
|
|
156
|
+
return /(?:^|[\\/])tokens\.json$|\.tokens\.json$/.test(file);
|
|
157
|
+
}
|
|
158
|
+
|
|
139
159
|
export function isDevelopmentFile(file, { dsRoot }) {
|
|
140
160
|
if (!isInside(dsRoot, file)) return isTestFile(file);
|
|
141
161
|
const relative = path.relative(dsRoot, file).replaceAll("\\", "/");
|
|
142
|
-
return isTestFile(file) || isScenarioFile(file) || isFixtureFile(file)
|
|
162
|
+
return isTestFile(file) || isScenarioFile(file) || isFixtureFile(file) || isBehaviorFile(file) || isTokenManifestFile(file)
|
|
143
163
|
|| /^(?:showcase|composition)\//.test(relative)
|
|
144
164
|
|| /(?:^|\/)(?:scenario|fixtures)(?:\/|$)/.test(relative)
|
|
145
165
|
|| /\.scenario(?:-adapter)?\.[cm]?[jt]sx?$/.test(relative);
|
|
@@ -154,7 +174,7 @@ export function sourceFiles(root) {
|
|
|
154
174
|
if (ignored.has(entry.name) || entry.isSymbolicLink()) continue;
|
|
155
175
|
const file = path.join(root, entry.name);
|
|
156
176
|
if (entry.isDirectory()) files.push(...sourceFiles(file));
|
|
157
|
-
else if (entry.isFile() && /\.(css|html|[cm]?[jt]sx?)$/.test(entry.name)) files.push(file);
|
|
177
|
+
else if (entry.isFile() && (/\.(css|html|[cm]?[jt]sx?)$/.test(entry.name) || isBehaviorFile(entry.name) || isTokenManifestFile(entry.name))) files.push(file);
|
|
158
178
|
}
|
|
159
179
|
return files.sort();
|
|
160
180
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import valueParser from "postcss-value-parser";
|
|
2
|
+
|
|
3
|
+
// CSS-language categories, independent of any project's token names or values.
|
|
4
|
+
// https://www.w3.org/TR/css-values-4/#lengths
|
|
5
|
+
const absoluteLengths = new Set(["px", "cm", "mm", "q", "in", "pt", "pc"]);
|
|
6
|
+
const fontLengths = new Set(["em", "rem", "ex", "rex", "cap", "rcap", "ch", "rch", "ic", "ric", "lh", "rlh"]);
|
|
7
|
+
const responsiveLength = /^(?:[sld]?v(?:w|h|i|b|min|max)|cq(?:w|h|i|b|min|max))$/;
|
|
8
|
+
|
|
9
|
+
export function numericCssUnit(value) {
|
|
10
|
+
const parsed = valueParser.unit(value);
|
|
11
|
+
return parsed ? parsed.unit.toLowerCase() : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Skin lengths use tokens regardless of font metrics, physical units or notation.
|
|
15
|
+
* Responsive viewport/container relationships retain their structural treatment. */
|
|
16
|
+
export function tokenLengthLiteral(value) {
|
|
17
|
+
const unit = numericCssUnit(value);
|
|
18
|
+
return absoluteLengths.has(unit) || fontLengths.has(unit);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The same CSS categories apply to length-valued foundation tokens. */
|
|
22
|
+
export function dimensionValue(value) {
|
|
23
|
+
const unit = numericCssUnit(value);
|
|
24
|
+
return unit !== null && (absoluteLengths.has(unit) || fontLengths.has(unit)
|
|
25
|
+
|| responsiveLength.test(unit) || unit === "%" || unit === "" && Number(value) === 0);
|
|
26
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -7,3 +7,5 @@ export { generateBrandAssets } from "./brand-assets.mjs";
|
|
|
7
7
|
// same validated configuration and property boundary as the core checker.
|
|
8
8
|
export { loadConfig } from "./config.mjs";
|
|
9
9
|
export { importResolver, styleWriteViolation } from "./boundaries.mjs";
|
|
10
|
+
export { inspectBehaviors } from "./behaviors.mjs";
|
|
11
|
+
export { behaviorStatus, createVerificationController } from "./verification.mjs";
|
package/dist/init.mjs
CHANGED
|
@@ -183,7 +183,7 @@ export function initProject(directory = process.cwd(), { toolPackage, packageMan
|
|
|
183
183
|
}
|
|
184
184
|
updates.set(entryFile, current + "\n" + reviewExport);
|
|
185
185
|
}
|
|
186
|
-
for (const section of ["components", "patterns", "composition"]) addMissing(path.join(dsRoot, section, ".gitkeep"), "");
|
|
186
|
+
for (const section of ["components", "patterns", "controllers", "composition"]) addMissing(path.join(dsRoot, section, ".gitkeep"), "");
|
|
187
187
|
addMissing(path.join(dsRoot, "assets/brand/README.md"), readFileSync(path.join(starter, "design-system/assets/brand/README.md")));
|
|
188
188
|
addMissing(path.join(dsRoot, "assets/fonts/.gitkeep"), "");
|
|
189
189
|
const configFile = path.join(root, "ds.config.json");
|