@specdest/devkit 0.1.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/catalog/README.md +11 -0
- package/catalog/modules/backend-convex/manifest.json +14 -0
- package/catalog/modules/backend-convex-expo/manifest.json +11 -0
- package/catalog/modules/backend-supabase/manifest.json +15 -0
- package/catalog/modules/backend-supabase-expo/manifest.json +11 -0
- package/catalog/modules/checker-runtime/config.ts +24 -0
- package/catalog/modules/checker-runtime/fs.ts +47 -0
- package/catalog/modules/checker-runtime/manifest.json +23 -0
- package/catalog/modules/devflow/.agents/skills/devflow/SKILL.md +33 -0
- package/catalog/modules/devflow/.devflow.json +10 -0
- package/catalog/modules/devflow/manifest.json +35 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/SKILL.md +85 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/activeScenario.mjs +130 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/checkLocalEnvironment.mjs +7 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/completeActiveScenario.mjs +36 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/createActiveScenario.mjs +143 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/localEnvironment.mjs +43 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/prompt.mjs +25 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runActiveScenario.mjs +66 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runAuthoringScenario.mjs +146 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seed.mjs +56 -0
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seedActiveScenario.mjs +6 -0
- package/catalog/modules/e2e-playwright/docs/e2e-playwright/README.md +103 -0
- package/catalog/modules/e2e-playwright/manifest.json +206 -0
- package/catalog/modules/e2e-playwright/playwright.e2e.config.ts +39 -0
- package/catalog/modules/e2e-playwright/tests/e2e/support/e2ePlaywrightFlow.ts +107 -0
- package/catalog/modules/e2e-playwright/tests/e2e/support/fixtures.ts +27 -0
- package/catalog/modules/local-log/AGENTS.local-log.md +13 -0
- package/catalog/modules/local-log/docs/features/local-logging/README.md +70 -0
- package/catalog/modules/local-log/manifest.json +39 -0
- package/catalog/modules/local-log/tmp/logs/.gitignore +2 -0
- package/catalog/modules/local-log/tools/local-log/README.md +47 -0
- package/catalog/modules/local-log/tools/local-log/local-log.mjs +241 -0
- package/catalog/modules/stack-common-vite/manifest.json +16 -0
- package/catalog/modules/stack-expo-convex/manifest.json +31 -0
- package/catalog/modules/stack-expo-supabase/manifest.json +44 -0
- package/catalog/modules/stack-vite-convex/manifest.json +32 -0
- package/catalog/modules/stack-vite-supabase/manifest.json +45 -0
- package/catalog/rules/abac-permissions-convex/SKILL.md +17 -0
- package/catalog/rules/abac-permissions-convex/check.ts +86 -0
- package/catalog/rules/abac-permissions-convex/manifest.json +35 -0
- package/catalog/rules/abac-permissions-supabase/SKILL.md +17 -0
- package/catalog/rules/abac-permissions-supabase/check.ts +86 -0
- package/catalog/rules/abac-permissions-supabase/manifest.json +35 -0
- package/catalog/rules/convex-multi-presentation/SKILL.md +48 -0
- package/catalog/rules/convex-multi-presentation/boundary-test-baseline.json +3 -0
- package/catalog/rules/convex-multi-presentation/check.ts +271 -0
- package/catalog/rules/convex-multi-presentation/manifest.json +45 -0
- package/catalog/rules/convex-multi-presentation/policy.ts +261 -0
- package/catalog/rules/design-rules/SKILL.md +12 -0
- package/catalog/rules/design-rules/check.ts +83 -0
- package/catalog/rules/design-rules/config.json +5 -0
- package/catalog/rules/design-rules/manifest.json +40 -0
- package/catalog/rules/e2e-test-rules/SKILL.md +46 -0
- package/catalog/rules/e2e-test-rules/check.ts +144 -0
- package/catalog/rules/e2e-test-rules/config.json +32 -0
- package/catalog/rules/e2e-test-rules/manifest.json +40 -0
- package/catalog/rules/error-handling-rules/SKILL.md +21 -0
- package/catalog/rules/error-handling-rules/check.ts +72 -0
- package/catalog/rules/error-handling-rules/manifest.json +35 -0
- package/catalog/rules/layers-and-contracts/SKILL.md +36 -0
- package/catalog/rules/layers-and-contracts/check.ts +265 -0
- package/catalog/rules/layers-and-contracts/manifest.json +35 -0
- package/catalog/rules/layers-and-contracts-convex/SKILL.md +49 -0
- package/catalog/rules/layers-and-contracts-convex/check.ts +288 -0
- package/catalog/rules/layers-and-contracts-convex/manifest.json +40 -0
- package/catalog/rules/layers-and-contracts-convex/policy.ts +68 -0
- package/catalog/rules/layers-and-contracts-supabase/SKILL.md +52 -0
- package/catalog/rules/layers-and-contracts-supabase/check.ts +370 -0
- package/catalog/rules/layers-and-contracts-supabase/manifest.json +40 -0
- package/catalog/rules/layers-and-contracts-supabase/policy.ts +68 -0
- package/catalog/rules/module-size-rules/SKILL.md +5 -0
- package/catalog/rules/module-size-rules/check.ts +143 -0
- package/catalog/rules/module-size-rules/config.json +6 -0
- package/catalog/rules/module-size-rules/manifest.json +40 -0
- package/catalog/rules/module-size-rules-convex/SKILL.md +5 -0
- package/catalog/rules/module-size-rules-convex/check.ts +145 -0
- package/catalog/rules/module-size-rules-convex/config.json +6 -0
- package/catalog/rules/module-size-rules-convex/manifest.json +40 -0
- package/catalog/rules/module-size-rules-supabase/SKILL.md +5 -0
- package/catalog/rules/module-size-rules-supabase/check.ts +145 -0
- package/catalog/rules/module-size-rules-supabase/config.json +12 -0
- package/catalog/rules/module-size-rules-supabase/manifest.json +40 -0
- package/catalog/rules/mutation-command-rules/SKILL.md +15 -0
- package/catalog/rules/mutation-command-rules/check.ts +29 -0
- package/catalog/rules/mutation-command-rules/config.json +19 -0
- package/catalog/rules/mutation-command-rules/manifest.json +40 -0
- package/catalog/rules/nearby-contracts/SKILL.md +18 -0
- package/catalog/rules/nearby-contracts/check.ts +137 -0
- package/catalog/rules/nearby-contracts/config.json +10 -0
- package/catalog/rules/nearby-contracts/manifest.json +40 -0
- package/catalog/rules/no-raw-click-buttons/SKILL.md +5 -0
- package/catalog/rules/no-raw-click-buttons/check.ts +36 -0
- package/catalog/rules/no-raw-click-buttons/manifest.json +35 -0
- package/catalog/rules/public-api-export-barrels/SKILL.md +45 -0
- package/catalog/rules/public-api-export-barrels/check.ts +72 -0
- package/catalog/rules/public-api-export-barrels/config.json +4 -0
- package/catalog/rules/public-api-export-barrels/manifest.json +40 -0
- package/catalog/rules/route-tree-fresh/SKILL.md +16 -0
- package/catalog/rules/route-tree-fresh/check.ts +64 -0
- package/catalog/rules/route-tree-fresh/manifest.json +35 -0
- package/catalog/rules/strict-typescript/SKILL.md +3 -0
- package/catalog/rules/strict-typescript/check.ts +111 -0
- package/catalog/rules/strict-typescript/manifest.json +35 -0
- package/catalog/rules/supabase-contracts/SKILL.md +3 -0
- package/catalog/rules/supabase-contracts/check.ts +171 -0
- package/catalog/rules/supabase-contracts/manifest.json +35 -0
- package/catalog/rules/supabase-declarative-schema/SKILL.md +30 -0
- package/catalog/rules/supabase-declarative-schema/check.ts +261 -0
- package/catalog/rules/supabase-declarative-schema/config.json +8 -0
- package/catalog/rules/supabase-declarative-schema/manifest.json +40 -0
- package/catalog/rules/tanstack-form-rules/SKILL.md +11 -0
- package/catalog/rules/tanstack-form-rules/check.ts +57 -0
- package/catalog/rules/tanstack-form-rules/manifest.json +35 -0
- package/catalog/rules/unit-test-rules/SKILL.md +55 -0
- package/catalog/rules/unit-test-rules/check.ts +131 -0
- package/catalog/rules/unit-test-rules/config.json +22 -0
- package/catalog/rules/unit-test-rules/manifest.json +40 -0
- package/catalog/rules/unit-test-rules-convex/SKILL.md +41 -0
- package/catalog/rules/unit-test-rules-convex/check.ts +417 -0
- package/catalog/rules/unit-test-rules-convex/manifest.json +35 -0
- package/catalog/rules/unit-test-rules-supabase/SKILL.md +40 -0
- package/catalog/rules/unit-test-rules-supabase/check.ts +491 -0
- package/catalog/rules/unit-test-rules-supabase/manifest.json +35 -0
- package/catalog/rules/workstation-controller-rules/SKILL.md +22 -0
- package/catalog/rules/workstation-controller-rules/check.ts +107 -0
- package/catalog/rules/workstation-controller-rules/manifest.json +35 -0
- package/package.json +22 -0
- package/src/catalog-snapshot.js +39 -0
- package/src/catalog.js +117 -0
- package/src/cli.js +11 -0
- package/src/index.js +30 -0
- package/src/installer-primitives.js +198 -0
- package/src/project-operations.js +126 -0
- package/src/setup-requirements.js +82 -0
- package/src/shared-file.js +131 -0
- package/src/sync-core.js +276 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { runtimeBoundarySchemaUsageViolations } from "./policy.ts";
|
|
2
|
+
|
|
3
|
+
// oxlint-disable no-console no-await-in-loop
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
const violations: string[] = [];
|
|
6
|
+
|
|
7
|
+
async function exists(path: string): Promise<boolean> {
|
|
8
|
+
try {
|
|
9
|
+
await Deno.stat(path);
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function* walk(dir: string): AsyncGenerator<string> {
|
|
17
|
+
try {
|
|
18
|
+
for await (const entry of Deno.readDir(dir)) {
|
|
19
|
+
const path = `${dir}/${entry.name}`;
|
|
20
|
+
if (entry.isDirectory) yield* walk(path);
|
|
21
|
+
if (entry.isFile && /\.(ts|tsx)$/.test(entry.name)) yield path;
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function implementationFile(file: string): boolean {
|
|
29
|
+
return (
|
|
30
|
+
/\.(ts|tsx)$/.test(file) &&
|
|
31
|
+
!file.endsWith(".test.ts") &&
|
|
32
|
+
!file.endsWith(".test.tsx") &&
|
|
33
|
+
!file.endsWith(".stories.tsx") &&
|
|
34
|
+
!file.endsWith(".input.schema.ts") &&
|
|
35
|
+
!file.endsWith(".output.schema.ts") &&
|
|
36
|
+
!file.endsWith(".callbackInput.schema.ts") &&
|
|
37
|
+
!file.endsWith(".form.schema.ts") &&
|
|
38
|
+
!file.endsWith(".schema.ts") &&
|
|
39
|
+
!file.endsWith(".contract.ts")
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isDalOperationBoundary(file: string): boolean {
|
|
44
|
+
if (!file.includes("/queries/") && !file.includes("/mutations/")) return false;
|
|
45
|
+
if (file.includes("-architecture-fixture/")) return false;
|
|
46
|
+
const name = file.split("/").at(-1) ?? "";
|
|
47
|
+
if (/\.(?:good|bad)\.(?:ts|tsx)$/u.test(name)) return false;
|
|
48
|
+
if (/Wrappers?\.(?:ts|tsx)$/u.test(name)) return false;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function importsDal(text: string): boolean {
|
|
53
|
+
return /from\s+["']@\/dal\//.test(text) || /import\(["']@\/dal\//.test(text);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function importsApplication(text: string): boolean {
|
|
57
|
+
return /from\s+["']@\/application\//.test(text) || /import\(["']@\/application\//.test(text);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function exportsHook(file: string, text: string): boolean {
|
|
61
|
+
const name = baseName(file).replace(/\.(ts|tsx)$/u, "");
|
|
62
|
+
if (!/^use[A-Z0-9]/u.test(name)) return false;
|
|
63
|
+
return new RegExp(
|
|
64
|
+
`export\\s+(?:async\\s+)?function\\s+${name}\\b|export\\s+const\\s+${name}\\b`,
|
|
65
|
+
"u",
|
|
66
|
+
).test(text);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isUiHookBoundary(file: string, text: string): boolean {
|
|
70
|
+
return /\/[-_]components\/ui-hooks\//u.test(file) && exportsHook(file, text);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isUiFormHook(file: string, text: string): boolean {
|
|
74
|
+
return isUiHookBoundary(file, text) && /\buse(?:App)?Form\s*\(/u.test(text);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isUiComponentBoundary(file: string, text: string): boolean {
|
|
78
|
+
if (!/\/[-_]components\/ui\//u.test(file) || !file.endsWith(".tsx")) return false;
|
|
79
|
+
const name = baseName(file).replace(/\.tsx$/u, "");
|
|
80
|
+
if (!/^[A-Z][A-Za-z0-9]*$/u.test(name)) return false;
|
|
81
|
+
return new RegExp(`export\\s+(?:function|const)\\s+${name}\\b`, "u").test(text);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isDataHookBoundary(file: string, text: string): boolean {
|
|
85
|
+
if (!/\/[-_]components\/data-hooks\//u.test(file)) return false;
|
|
86
|
+
return exportsHook(file, text) || importsApplication(text) || importsDal(text);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function importsRouteLayer(text: string, layer: string): boolean {
|
|
90
|
+
return new RegExp(`/[-_]components/${layer}/`).test(text);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function importsDataHook(text: string): boolean {
|
|
94
|
+
return text.includes("../data-hooks/") || /\/[-_]components\/data-hooks\//u.test(text);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isRouteFile(file: string): boolean {
|
|
98
|
+
return /^(?:src\/(?:routes|pages)\/)/u.test(file) && !/\/[-_]components\//u.test(file);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isPageContainer(file: string): boolean {
|
|
102
|
+
return /\/[-_]components\/container\//u.test(file) && file.endsWith("Page.tsx");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function importSpecs(text: string): string[] {
|
|
106
|
+
const specs: string[] = [];
|
|
107
|
+
for (const match of text.matchAll(/from\s+["']([^"']+)["']/gu)) {
|
|
108
|
+
specs.push(match[1] ?? "");
|
|
109
|
+
}
|
|
110
|
+
for (const match of text.matchAll(/import\(["']([^"']+)["']\)/gu)) {
|
|
111
|
+
specs.push(match[1] ?? "");
|
|
112
|
+
}
|
|
113
|
+
return specs;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function routeComponentRoot(file: string): string | null {
|
|
117
|
+
const match = file.match(/\/[-_]components\//u);
|
|
118
|
+
const index = match?.index ?? -1;
|
|
119
|
+
if (index === -1) return null;
|
|
120
|
+
return file.slice(0, index);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function resolvesToDifferentRouteComponentRoot(file: string, spec: string): boolean {
|
|
124
|
+
if (!spec.startsWith(".")) return false;
|
|
125
|
+
const fromRoot = routeComponentRoot(file);
|
|
126
|
+
if (!fromRoot) return false;
|
|
127
|
+
const base = file.split("/").slice(0, -1);
|
|
128
|
+
for (const part of spec.split("/")) {
|
|
129
|
+
if (part === "." || part === "") continue;
|
|
130
|
+
if (part === "..") base.pop();
|
|
131
|
+
else base.push(part);
|
|
132
|
+
}
|
|
133
|
+
const target = base.join("/");
|
|
134
|
+
if (!/\/[-_]components\//u.test(target)) return false;
|
|
135
|
+
const targetRoot = routeComponentRoot(target);
|
|
136
|
+
if (!targetRoot) return false;
|
|
137
|
+
if (targetRoot === fromRoot) return false;
|
|
138
|
+
if (fromRoot.startsWith(`${targetRoot}/`)) return false;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function baseName(file: string): string {
|
|
143
|
+
return file.split("/").at(-1) ?? file;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function routeComponentRootForFile(file: string): string | null {
|
|
147
|
+
const match = file.match(/\/[-_]components\//u);
|
|
148
|
+
const index = match?.index ?? -1;
|
|
149
|
+
if (index === -1) return null;
|
|
150
|
+
return file.slice(0, index);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function hasRouteLocalDataHooks(file: string): Promise<boolean> {
|
|
154
|
+
const root = routeComponentRootForFile(file);
|
|
155
|
+
if (!root) return false;
|
|
156
|
+
return (
|
|
157
|
+
(await exists(`${root}/-components/data-hooks`)) ||
|
|
158
|
+
(await exists(`${root}/_components/data-hooks`))
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function requireSibling(file: string, suffix: string, message: string): Promise<void> {
|
|
163
|
+
const sibling = file.replace(/\.(ts|tsx)$/, suffix);
|
|
164
|
+
if (!(await exists(sibling))) {
|
|
165
|
+
violations.push(`${file}: ${message}: ${sibling}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function requireRuntimeBoundarySchemaUsage(
|
|
170
|
+
file: string,
|
|
171
|
+
text: string,
|
|
172
|
+
kind: "input" | "output",
|
|
173
|
+
): Promise<void> {
|
|
174
|
+
const schemaFile = file.replace(/\.(ts|tsx)$/u, `.${kind}.schema.ts`);
|
|
175
|
+
if (!(await exists(schemaFile))) return;
|
|
176
|
+
const implementationName = baseName(file).replace(/\.(ts|tsx)$/u, "");
|
|
177
|
+
const schemaText = await Deno.readTextFile(schemaFile);
|
|
178
|
+
for (const violation of runtimeBoundarySchemaUsageViolations({
|
|
179
|
+
expectedImportSpec: `./${implementationName}.${kind}.schema`,
|
|
180
|
+
implementationText: text,
|
|
181
|
+
schemaSuffix: kind === "input" ? "InputSchema" : "OutputSchema",
|
|
182
|
+
schemaText,
|
|
183
|
+
})) {
|
|
184
|
+
violations.push(`${file}: ${violation}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function forbid(condition: boolean, file: string, message: string): void {
|
|
189
|
+
if (condition) violations.push(`${file}: ${message}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function requireOperationSpecificFormName(file: string): void {
|
|
193
|
+
if (/\/new\/[-_]components\/ui-hooks\//u.test(file) && !/Create/.test(baseName(file))) {
|
|
194
|
+
violations.push(
|
|
195
|
+
`${file}: new/create form hooks and schemas must be explicitly named for create contracts`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
if (/\/edit\/[-_]components\/ui-hooks\//u.test(file) && !/Edit/.test(baseName(file))) {
|
|
199
|
+
violations.push(
|
|
200
|
+
`${file}: edit form hooks and schemas must be explicitly named for edit contracts`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!(await exists("src/dal"))) {
|
|
206
|
+
violations.push("missing required architecture path: src/dal");
|
|
207
|
+
}
|
|
208
|
+
const routeRoot = (await exists("src/routes"))
|
|
209
|
+
? "src/routes"
|
|
210
|
+
: (await exists("src/pages"))
|
|
211
|
+
? "src/pages"
|
|
212
|
+
: null;
|
|
213
|
+
if (!routeRoot) {
|
|
214
|
+
violations.push("missing required architecture path: src/routes or src/pages");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
for await (const file of walk(routeRoot ?? "src/routes")) {
|
|
218
|
+
if (file.endsWith(".form.schema.ts")) requireOperationSpecificFormName(file);
|
|
219
|
+
if (!implementationFile(file)) continue;
|
|
220
|
+
|
|
221
|
+
const text = decoder.decode(await Deno.readFile(file));
|
|
222
|
+
const specs = importSpecs(text);
|
|
223
|
+
|
|
224
|
+
for (const spec of specs) {
|
|
225
|
+
forbid(
|
|
226
|
+
resolvesToDifferentRouteComponentRoot(file, spec),
|
|
227
|
+
file,
|
|
228
|
+
`route-local components must not import another route's -components tree: ${spec}`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
forbid(isRouteFile(file) && importsDal(text), file, "route files must not import DAL");
|
|
233
|
+
forbid(
|
|
234
|
+
/\/[-_]components\/container\//u.test(file) && importsDal(text),
|
|
235
|
+
file,
|
|
236
|
+
"containers must not import DAL",
|
|
237
|
+
);
|
|
238
|
+
forbid(/\/[-_]components\/ui\//u.test(file) && importsDal(text), file, "UI must not import DAL");
|
|
239
|
+
forbid(
|
|
240
|
+
/\/[-_]components\/ui-hooks\//u.test(file) && importsDal(text),
|
|
241
|
+
file,
|
|
242
|
+
"UI hooks must not import DAL",
|
|
243
|
+
);
|
|
244
|
+
forbid(
|
|
245
|
+
/\/[-_]components\/ui-hooks\//u.test(file) && importsRouteLayer(text, "data-hooks"),
|
|
246
|
+
file,
|
|
247
|
+
"UI hooks must not import data hooks",
|
|
248
|
+
);
|
|
249
|
+
forbid(
|
|
250
|
+
/\/[-_]components\/ui-hooks\//u.test(file) && importsRouteLayer(text, "ui"),
|
|
251
|
+
file,
|
|
252
|
+
"UI hooks must not import UI components",
|
|
253
|
+
);
|
|
254
|
+
forbid(
|
|
255
|
+
/\/[-_]components\/ui-hooks\//u.test(file) && importsRouteLayer(text, "container"),
|
|
256
|
+
file,
|
|
257
|
+
"UI hooks must not import containers",
|
|
258
|
+
);
|
|
259
|
+
forbid(
|
|
260
|
+
/\/[-_]components\/ui\//u.test(file) && importsRouteLayer(text, "data-hooks"),
|
|
261
|
+
file,
|
|
262
|
+
"UI must not import data hooks",
|
|
263
|
+
);
|
|
264
|
+
forbid(
|
|
265
|
+
/\/[-_]components\/ui\//u.test(file) && importsRouteLayer(text, "container"),
|
|
266
|
+
file,
|
|
267
|
+
"UI must not import containers",
|
|
268
|
+
);
|
|
269
|
+
forbid(
|
|
270
|
+
/\/[-_]components\/data-hooks\//u.test(file) && importsRouteLayer(text, "ui-hooks"),
|
|
271
|
+
file,
|
|
272
|
+
"data hooks must not import UI hooks",
|
|
273
|
+
);
|
|
274
|
+
forbid(
|
|
275
|
+
isPageContainer(file) && (await hasRouteLocalDataHooks(file)) && !importsDataHook(text),
|
|
276
|
+
file,
|
|
277
|
+
"page containers must use data hooks when the page owns data hooks",
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
if (isUiFormHook(file, text)) {
|
|
281
|
+
await requireSibling(
|
|
282
|
+
file,
|
|
283
|
+
".form.schema.ts",
|
|
284
|
+
"form UI hooks must declare form schema contracts",
|
|
285
|
+
);
|
|
286
|
+
requireOperationSpecificFormName(file);
|
|
287
|
+
}
|
|
288
|
+
if (isUiComponentBoundary(file, text)) {
|
|
289
|
+
await requireSibling(
|
|
290
|
+
file,
|
|
291
|
+
".input.schema.ts",
|
|
292
|
+
"UI components must declare input schema contracts",
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (isDataHookBoundary(file, text)) {
|
|
296
|
+
await requireSibling(
|
|
297
|
+
file,
|
|
298
|
+
".input.schema.ts",
|
|
299
|
+
"data hooks must declare input schema contracts",
|
|
300
|
+
);
|
|
301
|
+
await requireSibling(
|
|
302
|
+
file,
|
|
303
|
+
".output.schema.ts",
|
|
304
|
+
"data hooks must declare output schema contracts",
|
|
305
|
+
);
|
|
306
|
+
forbid(importsDal(text), file, "data hooks must not import DAL directly");
|
|
307
|
+
forbid(
|
|
308
|
+
!importsApplication(text),
|
|
309
|
+
file,
|
|
310
|
+
"data hooks must call logical actions through @/application imports",
|
|
311
|
+
);
|
|
312
|
+
forbid(importsRouteLayer(text, "ui"), file, "data hooks must not import UI components");
|
|
313
|
+
forbid(importsRouteLayer(text, "container"), file, "data hooks must not import containers");
|
|
314
|
+
await requireRuntimeBoundarySchemaUsage(file, text, "input");
|
|
315
|
+
await requireRuntimeBoundarySchemaUsage(file, text, "output");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
for await (const file of walk("src/application")) {
|
|
320
|
+
if (!implementationFile(file)) continue;
|
|
321
|
+
|
|
322
|
+
const text = decoder.decode(await Deno.readFile(file));
|
|
323
|
+
forbid(/@\/routes\//.test(text), file, "application must not import route-layer code");
|
|
324
|
+
forbid(/@\/components\//.test(text), file, "application must not import UI components");
|
|
325
|
+
forbid(
|
|
326
|
+
!importsDal(text),
|
|
327
|
+
file,
|
|
328
|
+
"application actions must call DAL operations through @/dal imports",
|
|
329
|
+
);
|
|
330
|
+
await requireSibling(
|
|
331
|
+
file,
|
|
332
|
+
".input.schema.ts",
|
|
333
|
+
"application actions must declare input schema contracts",
|
|
334
|
+
);
|
|
335
|
+
await requireSibling(
|
|
336
|
+
file,
|
|
337
|
+
".output.schema.ts",
|
|
338
|
+
"application actions must declare output schema contracts",
|
|
339
|
+
);
|
|
340
|
+
await requireRuntimeBoundarySchemaUsage(file, text, "input");
|
|
341
|
+
await requireRuntimeBoundarySchemaUsage(file, text, "output");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for await (const file of walk("src/dal")) {
|
|
345
|
+
if (!implementationFile(file)) continue;
|
|
346
|
+
|
|
347
|
+
const text = decoder.decode(await Deno.readFile(file));
|
|
348
|
+
forbid(/@\/routes\//.test(text), file, "DAL must not import route-layer code");
|
|
349
|
+
forbid(/@\/components\//.test(text), file, "DAL must not import UI components");
|
|
350
|
+
|
|
351
|
+
if (!isDalOperationBoundary(file)) continue;
|
|
352
|
+
await requireSibling(
|
|
353
|
+
file,
|
|
354
|
+
".input.schema.ts",
|
|
355
|
+
"DAL operations must declare input schema contracts",
|
|
356
|
+
);
|
|
357
|
+
await requireSibling(
|
|
358
|
+
file,
|
|
359
|
+
".output.schema.ts",
|
|
360
|
+
"DAL operations must declare output schema contracts",
|
|
361
|
+
);
|
|
362
|
+
await requireRuntimeBoundarySchemaUsage(file, text, "input");
|
|
363
|
+
await requireRuntimeBoundarySchemaUsage(file, text, "output");
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (violations.length) {
|
|
367
|
+
console.error(violations.join("\n"));
|
|
368
|
+
Deno.exit(1);
|
|
369
|
+
}
|
|
370
|
+
console.log("layers-and-contracts ok");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "layers-and-contracts-supabase",
|
|
3
|
+
"kind": "rule",
|
|
4
|
+
"version": "1.0.6",
|
|
5
|
+
"requires": [
|
|
6
|
+
"checker-runtime"
|
|
7
|
+
],
|
|
8
|
+
"artifacts": [
|
|
9
|
+
{
|
|
10
|
+
"kind": "managed-file",
|
|
11
|
+
"path": ".agents/skills/layers-and-contracts/SKILL.md",
|
|
12
|
+
"source": "SKILL.md"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"kind": "managed-file",
|
|
16
|
+
"path": ".agents/skills/layers-and-contracts/check.ts",
|
|
17
|
+
"source": "check.ts"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"kind": "managed-file",
|
|
21
|
+
"path": ".agents/skills/layers-and-contracts/policy.ts",
|
|
22
|
+
"source": "policy.ts"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"kind": "shared-markdown-section",
|
|
26
|
+
"path": "AGENTS.md",
|
|
27
|
+
"heading": "## Specdest backend rule: layers-and-contracts",
|
|
28
|
+
"body": "Use `.agents/skills/layers-and-contracts/SKILL.md` for this backend-specific rule. Run `deno run --allow-read .agents/skills/layers-and-contracts/check.ts` before handoff."
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"obsolete": [],
|
|
32
|
+
"check": {
|
|
33
|
+
"command": [
|
|
34
|
+
"deno",
|
|
35
|
+
"run",
|
|
36
|
+
"--allow-read",
|
|
37
|
+
".agents/skills/layers-and-contracts/check.ts"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
function importSpecs(text: string): string[] {
|
|
2
|
+
const specs: string[] = [];
|
|
3
|
+
for (const match of text.matchAll(/from\s+["']([^"']+)["']/gu)) {
|
|
4
|
+
specs.push(match[1] ?? "");
|
|
5
|
+
}
|
|
6
|
+
for (const match of text.matchAll(/import\(["']([^"']+)["']\)/gu)) {
|
|
7
|
+
specs.push(match[1] ?? "");
|
|
8
|
+
}
|
|
9
|
+
return specs;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function runtimeBoundarySchemaUsageViolations({
|
|
13
|
+
expectedImportSpec,
|
|
14
|
+
implementationText,
|
|
15
|
+
schemaSuffix,
|
|
16
|
+
schemaText,
|
|
17
|
+
}: {
|
|
18
|
+
readonly expectedImportSpec: string;
|
|
19
|
+
readonly implementationText: string;
|
|
20
|
+
readonly schemaSuffix: "InputSchema" | "OutputSchema";
|
|
21
|
+
readonly schemaText: string;
|
|
22
|
+
}): string[] {
|
|
23
|
+
const kind = schemaSuffix === "InputSchema" ? "input" : "output";
|
|
24
|
+
const implementationName = expectedImportSpec.split("/").at(-1)?.replace(`.${kind}.schema`, "");
|
|
25
|
+
const expectedSchemaName = implementationName ? `${implementationName}${schemaSuffix}` : "";
|
|
26
|
+
const exportedNames = new Set<string>();
|
|
27
|
+
|
|
28
|
+
for (const match of schemaText.matchAll(/\bexport\s+const\s+(\w+Schema)\b/gu)) {
|
|
29
|
+
if (match[1]) exportedNames.add(match[1]);
|
|
30
|
+
}
|
|
31
|
+
for (const match of schemaText.matchAll(/export\s*\{([^}]*)\}\s*from/gisu)) {
|
|
32
|
+
for (const rawPart of (match[1] ?? "").split(",")) {
|
|
33
|
+
const part = rawPart.trim();
|
|
34
|
+
if (!part || part.startsWith("type ")) continue;
|
|
35
|
+
exportedNames.add(part.match(/^(\w+)\s+as\s+(\w+)$/u)?.[2] ?? part);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const violations: string[] = [];
|
|
40
|
+
const importsExpectedModule = importSpecs(implementationText).includes(expectedImportSpec);
|
|
41
|
+
if (!importsExpectedModule) {
|
|
42
|
+
violations.push(`missing schema import: ${expectedImportSpec}`);
|
|
43
|
+
} else if (expectedSchemaName) {
|
|
44
|
+
const runtimeImportPattern = /import\s*\{([^}]*)\}\s*from\s*["']([^"']+)["']/gisu;
|
|
45
|
+
const hasRuntimeSchemaImport = [...implementationText.matchAll(runtimeImportPattern)].some(
|
|
46
|
+
(match) =>
|
|
47
|
+
match[2] === expectedImportSpec &&
|
|
48
|
+
(match[1] ?? "")
|
|
49
|
+
.split(",")
|
|
50
|
+
.map((part) => part.trim())
|
|
51
|
+
.some((part) => part === expectedSchemaName),
|
|
52
|
+
);
|
|
53
|
+
if (!hasRuntimeSchemaImport) {
|
|
54
|
+
violations.push(`missing runtime schema import: ${expectedSchemaName}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!expectedSchemaName || !exportedNames.has(expectedSchemaName)) {
|
|
59
|
+
violations.push(`missing boundary schema export: ${expectedSchemaName}`);
|
|
60
|
+
return violations;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const parsePattern = new RegExp(`\\b${expectedSchemaName}\\.parse\\s*\\(`, "u");
|
|
64
|
+
if (!parsePattern.test(implementationText)) {
|
|
65
|
+
violations.push(`missing runtime parse: ${expectedSchemaName}`);
|
|
66
|
+
}
|
|
67
|
+
return violations;
|
|
68
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const textEncoder = new TextEncoder();
|
|
2
|
+
|
|
3
|
+
function writeLine(message: string): void {
|
|
4
|
+
Deno.stdout.writeSync(textEncoder.encode(`${message}\n`));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function writeError(message: string): void {
|
|
8
|
+
Deno.stderr.writeSync(textEncoder.encode(`${message}\n`));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type ModuleSizeConfig = {
|
|
12
|
+
readonly maxFileLines?: number;
|
|
13
|
+
readonly maxComponentLines?: number;
|
|
14
|
+
readonly maxFunctionLines?: number;
|
|
15
|
+
readonly ignoredGlobs?: readonly string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const root = Deno.cwd();
|
|
19
|
+
const config = await readConfig();
|
|
20
|
+
const maxFileLines = Number(config.maxFileLines ?? 260);
|
|
21
|
+
const maxComponentLines = Number(config.maxComponentLines ?? 180);
|
|
22
|
+
const maxFunctionLines = Number(config.maxFunctionLines ?? 80);
|
|
23
|
+
const ignored = [
|
|
24
|
+
"src/routeTree.gen.ts",
|
|
25
|
+
"src/__generated__/**",
|
|
26
|
+
"src/test/**",
|
|
27
|
+
".agents/skills/**",
|
|
28
|
+
"code-templates/**",
|
|
29
|
+
"node_modules/**",
|
|
30
|
+
"dist/**",
|
|
31
|
+
"coverage/**",
|
|
32
|
+
...(config.ignoredGlobs ?? []),
|
|
33
|
+
];
|
|
34
|
+
const errors: string[] = [];
|
|
35
|
+
|
|
36
|
+
async function readConfig(): Promise<ModuleSizeConfig> {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(
|
|
39
|
+
await Deno.readTextFile(".agents/skills/module-size-rules/config.json"),
|
|
40
|
+
) as ModuleSizeConfig;
|
|
41
|
+
return parsed;
|
|
42
|
+
} catch {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function toRelative(path: string): string {
|
|
48
|
+
return path.replace(`${root}/`, "").split("\\").join("/");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function matchesGlobish(rel: string, pattern: string): boolean {
|
|
52
|
+
const normalized = pattern.replaceAll("\\", "/");
|
|
53
|
+
if (normalized.endsWith("/**")) {
|
|
54
|
+
const prefix = normalized.slice(0, -3);
|
|
55
|
+
return rel === prefix || rel.startsWith(`${prefix}/`);
|
|
56
|
+
}
|
|
57
|
+
if (normalized.startsWith("**/")) {
|
|
58
|
+
const suffix = normalized.slice(3);
|
|
59
|
+
return rel === suffix || rel.endsWith(`/${suffix}`);
|
|
60
|
+
}
|
|
61
|
+
return rel === normalized || rel.endsWith(normalized);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function shouldIgnore(rel: string): boolean {
|
|
65
|
+
return (
|
|
66
|
+
ignored.some((item) => matchesGlobish(rel, item)) ||
|
|
67
|
+
rel.endsWith(".config.ts") ||
|
|
68
|
+
rel.endsWith(".config.mjs") ||
|
|
69
|
+
rel.endsWith(".test.ts") ||
|
|
70
|
+
rel.endsWith(".test.tsx") ||
|
|
71
|
+
rel.endsWith(".stories.tsx") ||
|
|
72
|
+
rel.endsWith(".generated.ts") ||
|
|
73
|
+
rel.endsWith(".generated.tsx")
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function functionLineViolations(rel: string, text: string): string[] {
|
|
78
|
+
const lines = text.split(/\r?\n/u);
|
|
79
|
+
const violations: string[] = [];
|
|
80
|
+
const startPattern =
|
|
81
|
+
/^\s*(?:export\s+)?(?:async\s+)?function\s+[A-Za-z0-9_$]+\s*\(|^\s*(?:const|let|var)\s+[A-Za-z0-9_$]+\s*=\s*(?:async\s*)?\([^)]*\)\s*=>\s*\{/u;
|
|
82
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
83
|
+
const line = lines[index] ?? "";
|
|
84
|
+
if (!startPattern.test(line)) continue;
|
|
85
|
+
let depth = 0;
|
|
86
|
+
let sawBrace = false;
|
|
87
|
+
for (let cursor = index; cursor < lines.length; cursor += 1) {
|
|
88
|
+
for (const char of lines[cursor] ?? "") {
|
|
89
|
+
if (char === "{") {
|
|
90
|
+
depth += 1;
|
|
91
|
+
sawBrace = true;
|
|
92
|
+
}
|
|
93
|
+
if (char === "}") depth -= 1;
|
|
94
|
+
}
|
|
95
|
+
if (sawBrace && depth <= 0) {
|
|
96
|
+
const length = cursor - index + 1;
|
|
97
|
+
if (length > maxFunctionLines) {
|
|
98
|
+
violations.push(
|
|
99
|
+
`${rel}:${
|
|
100
|
+
index + 1
|
|
101
|
+
} function has ${length} lines, exceeds limit ${maxFunctionLines}. Split responsibilities.`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
index = cursor;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return violations;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function walk(dir: string): Promise<void> {
|
|
113
|
+
try {
|
|
114
|
+
for await (const ent of Deno.readDir(dir)) {
|
|
115
|
+
const p = `${dir}/${ent.name}`;
|
|
116
|
+
if (ent.isDirectory) {
|
|
117
|
+
if (!["node_modules", ".git", "dist", "coverage", "code-templates"].includes(ent.name)) {
|
|
118
|
+
await walk(p);
|
|
119
|
+
}
|
|
120
|
+
} else if (/\.(ts|tsx)$/u.test(ent.name)) {
|
|
121
|
+
const rel = toRelative(p);
|
|
122
|
+
if (shouldIgnore(rel)) continue;
|
|
123
|
+
const text = await Deno.readTextFile(p);
|
|
124
|
+
const lines = text.split(/\r?\n/u).length;
|
|
125
|
+
const limit = rel.endsWith(".tsx") ? maxComponentLines : maxFileLines;
|
|
126
|
+
if (lines > limit) {
|
|
127
|
+
errors.push(`${rel}: ${lines} lines exceeds limit ${limit}. Split responsibilities.`);
|
|
128
|
+
}
|
|
129
|
+
errors.push(...functionLineViolations(rel, text));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (!(error instanceof Deno.errors.NotFound)) throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
await walk(`${root}/src`);
|
|
138
|
+
await walk(`${root}/.agents/skills`);
|
|
139
|
+
if (errors.length > 0) {
|
|
140
|
+
writeError(errors.join("\n"));
|
|
141
|
+
Deno.exit(1);
|
|
142
|
+
}
|
|
143
|
+
writeLine("module-size-rules ok");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "module-size-rules",
|
|
3
|
+
"kind": "rule",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"requires": [
|
|
6
|
+
"checker-runtime"
|
|
7
|
+
],
|
|
8
|
+
"artifacts": [
|
|
9
|
+
{
|
|
10
|
+
"kind": "managed-file",
|
|
11
|
+
"path": ".agents/skills/module-size-rules/SKILL.md",
|
|
12
|
+
"source": "SKILL.md"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"kind": "managed-file",
|
|
16
|
+
"path": ".agents/skills/module-size-rules/check.ts",
|
|
17
|
+
"source": "check.ts"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"kind": "scaffold",
|
|
21
|
+
"path": ".agents/skills/module-size-rules/config.json",
|
|
22
|
+
"source": "config.json"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"kind": "shared-markdown-section",
|
|
26
|
+
"path": "AGENTS.md",
|
|
27
|
+
"heading": "## Specdest rule: module-size-rules",
|
|
28
|
+
"body": "Use `.agents/skills/module-size-rules/SKILL.md` when working in this rule area. Run `deno run --allow-read .agents/skills/module-size-rules/check.ts` before handoff."
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"obsolete": [],
|
|
32
|
+
"check": {
|
|
33
|
+
"command": [
|
|
34
|
+
"deno",
|
|
35
|
+
"run",
|
|
36
|
+
"--allow-read",
|
|
37
|
+
".agents/skills/module-size-rules/check.ts"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|