@specdest/devkit 0.2.2 → 0.3.1
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 -18
- package/package.json +4 -4
- package/src/canonical-project-operations.js +164 -0
- package/src/canonical-project.js +78 -0
- package/src/canonical-source.js +114 -0
- package/src/cli.js +2 -2
- package/src/git-catalog.js +105 -0
- package/src/index.js +6 -2
- package/src/project-operations.js +65 -6
- package/src/remote-installer.js +478 -0
- package/src/sync-core.js +20 -7
- package/catalog/README.md +0 -11
- package/catalog/modules/backend-convex/manifest.json +0 -14
- package/catalog/modules/backend-convex-expo/manifest.json +0 -11
- package/catalog/modules/backend-supabase/manifest.json +0 -15
- package/catalog/modules/backend-supabase-expo/manifest.json +0 -11
- package/catalog/modules/checker-runtime/config.ts +0 -25
- package/catalog/modules/checker-runtime/fs.ts +0 -48
- package/catalog/modules/checker-runtime/manifest.json +0 -29
- package/catalog/modules/checker-runtime/runtime.ts +0 -79
- package/catalog/modules/devflow/.agents/skills/devflow/SKILL.md +0 -33
- package/catalog/modules/devflow/.devflow.json +0 -10
- package/catalog/modules/devflow/manifest.json +0 -35
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/SKILL.md +0 -85
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/activeScenario.mjs +0 -130
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/checkLocalEnvironment.mjs +0 -7
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/completeActiveScenario.mjs +0 -36
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/createActiveScenario.mjs +0 -143
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/localEnvironment.mjs +0 -43
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/prompt.mjs +0 -25
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runActiveScenario.mjs +0 -66
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runAuthoringScenario.mjs +0 -146
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seed.mjs +0 -56
- package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seedActiveScenario.mjs +0 -6
- package/catalog/modules/e2e-playwright/docs/e2e-playwright/README.md +0 -103
- package/catalog/modules/e2e-playwright/manifest.json +0 -206
- package/catalog/modules/e2e-playwright/playwright.e2e.config.ts +0 -39
- package/catalog/modules/e2e-playwright/tests/e2e/support/e2ePlaywrightFlow.ts +0 -107
- package/catalog/modules/e2e-playwright/tests/e2e/support/fixtures.ts +0 -27
- package/catalog/modules/local-log/AGENTS.local-log.md +0 -13
- package/catalog/modules/local-log/docs/features/local-logging/README.md +0 -70
- package/catalog/modules/local-log/manifest.json +0 -39
- package/catalog/modules/local-log/tmp/logs/.gitignore +0 -2
- package/catalog/modules/local-log/tools/local-log/README.md +0 -47
- package/catalog/modules/local-log/tools/local-log/local-log.mjs +0 -241
- package/catalog/modules/stack-common-vite/manifest.json +0 -16
- package/catalog/modules/stack-expo-convex/manifest.json +0 -31
- package/catalog/modules/stack-expo-supabase/manifest.json +0 -44
- package/catalog/modules/stack-vite-convex/manifest.json +0 -32
- package/catalog/modules/stack-vite-supabase/manifest.json +0 -45
- package/catalog/rules/abac-permissions-convex/SKILL.md +0 -17
- package/catalog/rules/abac-permissions-convex/check.ts +0 -87
- package/catalog/rules/abac-permissions-convex/manifest.json +0 -33
- package/catalog/rules/abac-permissions-supabase/SKILL.md +0 -17
- package/catalog/rules/abac-permissions-supabase/check.ts +0 -87
- package/catalog/rules/abac-permissions-supabase/manifest.json +0 -33
- package/catalog/rules/convex-multi-presentation/SKILL.md +0 -47
- package/catalog/rules/convex-multi-presentation/check.ts +0 -205
- package/catalog/rules/convex-multi-presentation/manifest.json +0 -47
- package/catalog/rules/convex-multi-presentation/policy.ts +0 -261
- package/catalog/rules/design-rules/SKILL.md +0 -12
- package/catalog/rules/design-rules/check.ts +0 -84
- package/catalog/rules/design-rules/config.json +0 -5
- package/catalog/rules/design-rules/manifest.json +0 -38
- package/catalog/rules/e2e-test-rules/SKILL.md +0 -46
- package/catalog/rules/e2e-test-rules/check.ts +0 -145
- package/catalog/rules/e2e-test-rules/config.json +0 -32
- package/catalog/rules/e2e-test-rules/manifest.json +0 -38
- package/catalog/rules/error-handling-rules/SKILL.md +0 -21
- package/catalog/rules/error-handling-rules/check.ts +0 -73
- package/catalog/rules/error-handling-rules/manifest.json +0 -33
- package/catalog/rules/layers-and-contracts/SKILL.md +0 -36
- package/catalog/rules/layers-and-contracts/check.ts +0 -266
- package/catalog/rules/layers-and-contracts/manifest.json +0 -33
- package/catalog/rules/layers-and-contracts-convex/SKILL.md +0 -49
- package/catalog/rules/layers-and-contracts-convex/check.ts +0 -289
- package/catalog/rules/layers-and-contracts-convex/manifest.json +0 -38
- package/catalog/rules/layers-and-contracts-convex/policy.ts +0 -68
- package/catalog/rules/layers-and-contracts-supabase/SKILL.md +0 -52
- package/catalog/rules/layers-and-contracts-supabase/check.ts +0 -371
- package/catalog/rules/layers-and-contracts-supabase/manifest.json +0 -38
- package/catalog/rules/layers-and-contracts-supabase/policy.ts +0 -68
- package/catalog/rules/module-size-rules/SKILL.md +0 -5
- package/catalog/rules/module-size-rules/check.ts +0 -144
- package/catalog/rules/module-size-rules/config.json +0 -6
- package/catalog/rules/module-size-rules/manifest.json +0 -38
- package/catalog/rules/module-size-rules-convex/SKILL.md +0 -5
- package/catalog/rules/module-size-rules-convex/check.ts +0 -146
- package/catalog/rules/module-size-rules-convex/config.json +0 -6
- package/catalog/rules/module-size-rules-convex/manifest.json +0 -38
- package/catalog/rules/module-size-rules-supabase/SKILL.md +0 -5
- package/catalog/rules/module-size-rules-supabase/check.ts +0 -146
- package/catalog/rules/module-size-rules-supabase/config.json +0 -12
- package/catalog/rules/module-size-rules-supabase/manifest.json +0 -38
- package/catalog/rules/mutation-command-rules/SKILL.md +0 -15
- package/catalog/rules/mutation-command-rules/check.ts +0 -30
- package/catalog/rules/mutation-command-rules/config.json +0 -19
- package/catalog/rules/mutation-command-rules/manifest.json +0 -38
- package/catalog/rules/nearby-contracts/SKILL.md +0 -18
- package/catalog/rules/nearby-contracts/check.ts +0 -138
- package/catalog/rules/nearby-contracts/config.json +0 -10
- package/catalog/rules/nearby-contracts/manifest.json +0 -38
- package/catalog/rules/no-raw-click-buttons/SKILL.md +0 -5
- package/catalog/rules/no-raw-click-buttons/check.ts +0 -37
- package/catalog/rules/no-raw-click-buttons/manifest.json +0 -33
- package/catalog/rules/public-api-export-barrels/SKILL.md +0 -45
- package/catalog/rules/public-api-export-barrels/check.ts +0 -73
- package/catalog/rules/public-api-export-barrels/config.json +0 -4
- package/catalog/rules/public-api-export-barrels/manifest.json +0 -38
- package/catalog/rules/route-tree-fresh/SKILL.md +0 -16
- package/catalog/rules/route-tree-fresh/check.ts +0 -66
- package/catalog/rules/route-tree-fresh/manifest.json +0 -33
- package/catalog/rules/strict-typescript/SKILL.md +0 -3
- package/catalog/rules/strict-typescript/check.ts +0 -119
- package/catalog/rules/strict-typescript/manifest.json +0 -33
- package/catalog/rules/supabase-contracts/SKILL.md +0 -3
- package/catalog/rules/supabase-contracts/check.ts +0 -172
- package/catalog/rules/supabase-contracts/manifest.json +0 -33
- package/catalog/rules/supabase-declarative-schema/SKILL.md +0 -30
- package/catalog/rules/supabase-declarative-schema/check.ts +0 -262
- package/catalog/rules/supabase-declarative-schema/config.json +0 -8
- package/catalog/rules/supabase-declarative-schema/manifest.json +0 -38
- package/catalog/rules/tanstack-form-rules/SKILL.md +0 -11
- package/catalog/rules/tanstack-form-rules/check.ts +0 -58
- package/catalog/rules/tanstack-form-rules/manifest.json +0 -33
- package/catalog/rules/unit-test-rules/SKILL.md +0 -55
- package/catalog/rules/unit-test-rules/check.ts +0 -132
- package/catalog/rules/unit-test-rules/config.json +0 -22
- package/catalog/rules/unit-test-rules/manifest.json +0 -38
- package/catalog/rules/unit-test-rules-convex/SKILL.md +0 -41
- package/catalog/rules/unit-test-rules-convex/check.ts +0 -418
- package/catalog/rules/unit-test-rules-convex/manifest.json +0 -33
- package/catalog/rules/unit-test-rules-supabase/SKILL.md +0 -40
- package/catalog/rules/unit-test-rules-supabase/check.ts +0 -492
- package/catalog/rules/unit-test-rules-supabase/manifest.json +0 -33
- package/catalog/rules/workstation-controller-rules/SKILL.md +0 -22
- package/catalog/rules/workstation-controller-rules/check.ts +0 -108
- package/catalog/rules/workstation-controller-rules/manifest.json +0 -33
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Layers and contracts
|
|
2
|
-
|
|
3
|
-
Use page-local architecture for route work.
|
|
4
|
-
|
|
5
|
-
Required shape:
|
|
6
|
-
|
|
7
|
-
- routes own URL params/search and render containers
|
|
8
|
-
- containers orchestrate hooks and UI only
|
|
9
|
-
- UI renders visible elements only
|
|
10
|
-
- UI-hooks own form/behavior mapping
|
|
11
|
-
- data-hooks call Reactless logical actions under `src/application` and map page data contracts
|
|
12
|
-
- logical actions own workflow/orchestration contracts and may call DAL operations
|
|
13
|
-
- DAL owns database/API payload conversion and output parsing
|
|
14
|
-
|
|
15
|
-
Enforced guardrails:
|
|
16
|
-
|
|
17
|
-
- route, container, and UI files must not import `@/dal`
|
|
18
|
-
- data-hooks must call logical actions through `@/application` and must not import DAL directly
|
|
19
|
-
- logical actions may call DAL and must not import presentation layers
|
|
20
|
-
- data-hooks must not import UI or container layers
|
|
21
|
-
- DAL must not import route/UI code
|
|
22
|
-
- placeholder/static page data belongs in UI-hooks or presentation view-models, not data-hooks
|
|
23
|
-
|
|
24
|
-
## Runtime boundary execution rule
|
|
25
|
-
|
|
26
|
-
A declared boundary contract must execute at runtime; a schema file or inferred TypeScript type alone is not enforcement.
|
|
27
|
-
|
|
28
|
-
- Data-hook implementations must import and call `.parse(...)` on their primary sibling `*InputSchema` and `*OutputSchema`.
|
|
29
|
-
- DAL query and mutation implementations must import and call `.parse(...)` on their primary sibling `*InputSchema` and `*OutputSchema`.
|
|
30
|
-
- Pass-through values follow the same rule as transformed values. There is no pass-through exception.
|
|
31
|
-
- Nested helper schemas are enforced through the primary schema that composes them; they are not separate layer boundaries.
|
|
32
|
-
- Type-only imports do not satisfy runtime enforcement. The schema value itself must be imported.
|
|
33
|
-
- Loading, skipped, or absent query states may remain outside a successful output schema, but every present successful value must be parsed.
|
|
34
|
-
- Form and callback-input boundaries continue to use their specialized nearby schema rules.
|
|
35
|
-
|
|
36
|
-
`runLayerContractChain` is test-only. Use it in contract integration tests to verify that real output schemas and production mappings are compatible with the next layer's input schema. Do not use it to orchestrate production behavior.
|
|
37
|
-
|
|
38
|
-
Boundary files use Zod schemas:
|
|
39
|
-
|
|
40
|
-
- `*.input.schema.ts`
|
|
41
|
-
- `*.output.schema.ts`
|
|
42
|
-
- `*.form.schema.ts`
|
|
43
|
-
|
|
44
|
-
Types at boundaries must be inferred from Zod schemas with `z.infer<typeof schema>`.
|
|
45
|
-
|
|
46
|
-
Form contract rules:
|
|
47
|
-
|
|
48
|
-
- Shared visual form UI is allowed when create/new and edit pages intentionally look the same.
|
|
49
|
-
- Do not share create/new and edit form contracts blindly. Each operation must choose an explicit schema/hook, such as `useResourceCreateForm.form.schema.ts` and `useResourceEditForm.form.schema.ts`, or clearly named equivalents.
|
|
50
|
-
- Shared base schemas are allowed only for common fields. Compose create/edit schemas from the base so divergent rules stay visible.
|
|
51
|
-
- Containers must choose the create/edit form contract explicitly before calling the mutation.
|
|
52
|
-
- Numeric-only fields must use a numeric form control that prevents/sanitizes non-digit input before validation and before network submission. Keep database constraints mirrored in form schemas so invalid values do not rely on backend errors for normal feedback.
|
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import { runtime } from "../shared/runtime.ts";
|
|
2
|
-
import { runtimeBoundarySchemaUsageViolations } from "./policy.ts";
|
|
3
|
-
|
|
4
|
-
// oxlint-disable no-console no-await-in-loop
|
|
5
|
-
const decoder = new TextDecoder();
|
|
6
|
-
const violations: string[] = [];
|
|
7
|
-
|
|
8
|
-
async function exists(path: string): Promise<boolean> {
|
|
9
|
-
try {
|
|
10
|
-
await runtime.stat(path);
|
|
11
|
-
return true;
|
|
12
|
-
} catch {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function* walk(dir: string): AsyncGenerator<string> {
|
|
18
|
-
try {
|
|
19
|
-
for await (const entry of runtime.readDir(dir)) {
|
|
20
|
-
const path = `${dir}/${entry.name}`;
|
|
21
|
-
if (entry.isDirectory) yield* walk(path);
|
|
22
|
-
if (entry.isFile && /\.(ts|tsx)$/.test(entry.name)) yield path;
|
|
23
|
-
}
|
|
24
|
-
} catch {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function implementationFile(file: string): boolean {
|
|
30
|
-
return (
|
|
31
|
-
/\.(ts|tsx)$/.test(file) &&
|
|
32
|
-
!file.endsWith(".test.ts") &&
|
|
33
|
-
!file.endsWith(".test.tsx") &&
|
|
34
|
-
!file.endsWith(".stories.tsx") &&
|
|
35
|
-
!file.endsWith(".input.schema.ts") &&
|
|
36
|
-
!file.endsWith(".output.schema.ts") &&
|
|
37
|
-
!file.endsWith(".callbackInput.schema.ts") &&
|
|
38
|
-
!file.endsWith(".form.schema.ts") &&
|
|
39
|
-
!file.endsWith(".schema.ts") &&
|
|
40
|
-
!file.endsWith(".contract.ts")
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function isDalOperationBoundary(file: string): boolean {
|
|
45
|
-
if (!file.includes("/queries/") && !file.includes("/mutations/")) return false;
|
|
46
|
-
if (file.includes("-architecture-fixture/")) return false;
|
|
47
|
-
const name = file.split("/").at(-1) ?? "";
|
|
48
|
-
if (/\.(?:good|bad)\.(?:ts|tsx)$/u.test(name)) return false;
|
|
49
|
-
if (/Wrappers?\.(?:ts|tsx)$/u.test(name)) return false;
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function importsDal(text: string): boolean {
|
|
54
|
-
return /from\s+["']@\/dal\//.test(text) || /import\(["']@\/dal\//.test(text);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function importsApplication(text: string): boolean {
|
|
58
|
-
return /from\s+["']@\/application\//.test(text) || /import\(["']@\/application\//.test(text);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function exportsHook(file: string, text: string): boolean {
|
|
62
|
-
const name = baseName(file).replace(/\.(ts|tsx)$/u, "");
|
|
63
|
-
if (!/^use[A-Z0-9]/u.test(name)) return false;
|
|
64
|
-
return new RegExp(
|
|
65
|
-
`export\\s+(?:async\\s+)?function\\s+${name}\\b|export\\s+const\\s+${name}\\b`,
|
|
66
|
-
"u",
|
|
67
|
-
).test(text);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isUiHookBoundary(file: string, text: string): boolean {
|
|
71
|
-
return /\/[-_]components\/ui-hooks\//u.test(file) && exportsHook(file, text);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function isUiFormHook(file: string, text: string): boolean {
|
|
75
|
-
return isUiHookBoundary(file, text) && /\buse(?:App)?Form\s*\(/u.test(text);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function isUiComponentBoundary(file: string, text: string): boolean {
|
|
79
|
-
if (!/\/[-_]components\/ui\//u.test(file) || !file.endsWith(".tsx")) return false;
|
|
80
|
-
const name = baseName(file).replace(/\.tsx$/u, "");
|
|
81
|
-
if (!/^[A-Z][A-Za-z0-9]*$/u.test(name)) return false;
|
|
82
|
-
return new RegExp(`export\\s+(?:function|const)\\s+${name}\\b`, "u").test(text);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function isDataHookBoundary(file: string, text: string): boolean {
|
|
86
|
-
if (!/\/[-_]components\/data-hooks\//u.test(file)) return false;
|
|
87
|
-
return exportsHook(file, text) || importsApplication(text) || importsDal(text);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function importsRouteLayer(text: string, layer: string): boolean {
|
|
91
|
-
return new RegExp(`/[-_]components/${layer}/`).test(text);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function importsDataHook(text: string): boolean {
|
|
95
|
-
return text.includes("../data-hooks/") || /\/[-_]components\/data-hooks\//u.test(text);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function isRouteFile(file: string): boolean {
|
|
99
|
-
return /^(?:src\/(?:routes|pages)\/)/u.test(file) && !/\/[-_]components\//u.test(file);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function isPageContainer(file: string): boolean {
|
|
103
|
-
return /\/[-_]components\/container\//u.test(file) && file.endsWith("Page.tsx");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function importSpecs(text: string): string[] {
|
|
107
|
-
const specs: string[] = [];
|
|
108
|
-
for (const match of text.matchAll(/from\s+["']([^"']+)["']/gu)) {
|
|
109
|
-
specs.push(match[1] ?? "");
|
|
110
|
-
}
|
|
111
|
-
for (const match of text.matchAll(/import\(["']([^"']+)["']\)/gu)) {
|
|
112
|
-
specs.push(match[1] ?? "");
|
|
113
|
-
}
|
|
114
|
-
return specs;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function routeComponentRoot(file: string): string | null {
|
|
118
|
-
const match = file.match(/\/[-_]components\//u);
|
|
119
|
-
const index = match?.index ?? -1;
|
|
120
|
-
if (index === -1) return null;
|
|
121
|
-
return file.slice(0, index);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function resolvesToDifferentRouteComponentRoot(file: string, spec: string): boolean {
|
|
125
|
-
if (!spec.startsWith(".")) return false;
|
|
126
|
-
const fromRoot = routeComponentRoot(file);
|
|
127
|
-
if (!fromRoot) return false;
|
|
128
|
-
const base = file.split("/").slice(0, -1);
|
|
129
|
-
for (const part of spec.split("/")) {
|
|
130
|
-
if (part === "." || part === "") continue;
|
|
131
|
-
if (part === "..") base.pop();
|
|
132
|
-
else base.push(part);
|
|
133
|
-
}
|
|
134
|
-
const target = base.join("/");
|
|
135
|
-
if (!/\/[-_]components\//u.test(target)) return false;
|
|
136
|
-
const targetRoot = routeComponentRoot(target);
|
|
137
|
-
if (!targetRoot) return false;
|
|
138
|
-
if (targetRoot === fromRoot) return false;
|
|
139
|
-
if (fromRoot.startsWith(`${targetRoot}/`)) return false;
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function baseName(file: string): string {
|
|
144
|
-
return file.split("/").at(-1) ?? file;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function routeComponentRootForFile(file: string): string | null {
|
|
148
|
-
const match = file.match(/\/[-_]components\//u);
|
|
149
|
-
const index = match?.index ?? -1;
|
|
150
|
-
if (index === -1) return null;
|
|
151
|
-
return file.slice(0, index);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function hasRouteLocalDataHooks(file: string): Promise<boolean> {
|
|
155
|
-
const root = routeComponentRootForFile(file);
|
|
156
|
-
if (!root) return false;
|
|
157
|
-
return (
|
|
158
|
-
(await exists(`${root}/-components/data-hooks`)) ||
|
|
159
|
-
(await exists(`${root}/_components/data-hooks`))
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async function requireSibling(file: string, suffix: string, message: string): Promise<void> {
|
|
164
|
-
const sibling = file.replace(/\.(ts|tsx)$/, suffix);
|
|
165
|
-
if (!(await exists(sibling))) {
|
|
166
|
-
violations.push(`${file}: ${message}: ${sibling}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function requireRuntimeBoundarySchemaUsage(
|
|
171
|
-
file: string,
|
|
172
|
-
text: string,
|
|
173
|
-
kind: "input" | "output",
|
|
174
|
-
): Promise<void> {
|
|
175
|
-
const schemaFile = file.replace(/\.(ts|tsx)$/u, `.${kind}.schema.ts`);
|
|
176
|
-
if (!(await exists(schemaFile))) return;
|
|
177
|
-
const implementationName = baseName(file).replace(/\.(ts|tsx)$/u, "");
|
|
178
|
-
const schemaText = await runtime.readTextFile(schemaFile);
|
|
179
|
-
for (const violation of runtimeBoundarySchemaUsageViolations({
|
|
180
|
-
expectedImportSpec: `./${implementationName}.${kind}.schema`,
|
|
181
|
-
implementationText: text,
|
|
182
|
-
schemaSuffix: kind === "input" ? "InputSchema" : "OutputSchema",
|
|
183
|
-
schemaText,
|
|
184
|
-
})) {
|
|
185
|
-
violations.push(`${file}: ${violation}`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function forbid(condition: boolean, file: string, message: string): void {
|
|
190
|
-
if (condition) violations.push(`${file}: ${message}`);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function requireOperationSpecificFormName(file: string): void {
|
|
194
|
-
if (/\/new\/[-_]components\/ui-hooks\//u.test(file) && !/Create/.test(baseName(file))) {
|
|
195
|
-
violations.push(
|
|
196
|
-
`${file}: new/create form hooks and schemas must be explicitly named for create contracts`,
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
if (/\/edit\/[-_]components\/ui-hooks\//u.test(file) && !/Edit/.test(baseName(file))) {
|
|
200
|
-
violations.push(
|
|
201
|
-
`${file}: edit form hooks and schemas must be explicitly named for edit contracts`,
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (!(await exists("src/dal"))) {
|
|
207
|
-
violations.push("missing required architecture path: src/dal");
|
|
208
|
-
}
|
|
209
|
-
const routeRoot = (await exists("src/routes"))
|
|
210
|
-
? "src/routes"
|
|
211
|
-
: (await exists("src/pages"))
|
|
212
|
-
? "src/pages"
|
|
213
|
-
: null;
|
|
214
|
-
if (!routeRoot) {
|
|
215
|
-
violations.push("missing required architecture path: src/routes or src/pages");
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
for await (const file of walk(routeRoot ?? "src/routes")) {
|
|
219
|
-
if (file.endsWith(".form.schema.ts")) requireOperationSpecificFormName(file);
|
|
220
|
-
if (!implementationFile(file)) continue;
|
|
221
|
-
|
|
222
|
-
const text = decoder.decode(await runtime.readFile(file));
|
|
223
|
-
const specs = importSpecs(text);
|
|
224
|
-
|
|
225
|
-
for (const spec of specs) {
|
|
226
|
-
forbid(
|
|
227
|
-
resolvesToDifferentRouteComponentRoot(file, spec),
|
|
228
|
-
file,
|
|
229
|
-
`route-local components must not import another route's -components tree: ${spec}`,
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
forbid(isRouteFile(file) && importsDal(text), file, "route files must not import DAL");
|
|
234
|
-
forbid(
|
|
235
|
-
/\/[-_]components\/container\//u.test(file) && importsDal(text),
|
|
236
|
-
file,
|
|
237
|
-
"containers must not import DAL",
|
|
238
|
-
);
|
|
239
|
-
forbid(/\/[-_]components\/ui\//u.test(file) && importsDal(text), file, "UI must not import DAL");
|
|
240
|
-
forbid(
|
|
241
|
-
/\/[-_]components\/ui-hooks\//u.test(file) && importsDal(text),
|
|
242
|
-
file,
|
|
243
|
-
"UI hooks must not import DAL",
|
|
244
|
-
);
|
|
245
|
-
forbid(
|
|
246
|
-
/\/[-_]components\/ui-hooks\//u.test(file) && importsRouteLayer(text, "data-hooks"),
|
|
247
|
-
file,
|
|
248
|
-
"UI hooks must not import data hooks",
|
|
249
|
-
);
|
|
250
|
-
forbid(
|
|
251
|
-
/\/[-_]components\/ui-hooks\//u.test(file) && importsRouteLayer(text, "ui"),
|
|
252
|
-
file,
|
|
253
|
-
"UI hooks must not import UI components",
|
|
254
|
-
);
|
|
255
|
-
forbid(
|
|
256
|
-
/\/[-_]components\/ui-hooks\//u.test(file) && importsRouteLayer(text, "container"),
|
|
257
|
-
file,
|
|
258
|
-
"UI hooks must not import containers",
|
|
259
|
-
);
|
|
260
|
-
forbid(
|
|
261
|
-
/\/[-_]components\/ui\//u.test(file) && importsRouteLayer(text, "data-hooks"),
|
|
262
|
-
file,
|
|
263
|
-
"UI must not import data hooks",
|
|
264
|
-
);
|
|
265
|
-
forbid(
|
|
266
|
-
/\/[-_]components\/ui\//u.test(file) && importsRouteLayer(text, "container"),
|
|
267
|
-
file,
|
|
268
|
-
"UI must not import containers",
|
|
269
|
-
);
|
|
270
|
-
forbid(
|
|
271
|
-
/\/[-_]components\/data-hooks\//u.test(file) && importsRouteLayer(text, "ui-hooks"),
|
|
272
|
-
file,
|
|
273
|
-
"data hooks must not import UI hooks",
|
|
274
|
-
);
|
|
275
|
-
forbid(
|
|
276
|
-
isPageContainer(file) && (await hasRouteLocalDataHooks(file)) && !importsDataHook(text),
|
|
277
|
-
file,
|
|
278
|
-
"page containers must use data hooks when the page owns data hooks",
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
if (isUiFormHook(file, text)) {
|
|
282
|
-
await requireSibling(
|
|
283
|
-
file,
|
|
284
|
-
".form.schema.ts",
|
|
285
|
-
"form UI hooks must declare form schema contracts",
|
|
286
|
-
);
|
|
287
|
-
requireOperationSpecificFormName(file);
|
|
288
|
-
}
|
|
289
|
-
if (isUiComponentBoundary(file, text)) {
|
|
290
|
-
await requireSibling(
|
|
291
|
-
file,
|
|
292
|
-
".input.schema.ts",
|
|
293
|
-
"UI components must declare input schema contracts",
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
if (isDataHookBoundary(file, text)) {
|
|
297
|
-
await requireSibling(
|
|
298
|
-
file,
|
|
299
|
-
".input.schema.ts",
|
|
300
|
-
"data hooks must declare input schema contracts",
|
|
301
|
-
);
|
|
302
|
-
await requireSibling(
|
|
303
|
-
file,
|
|
304
|
-
".output.schema.ts",
|
|
305
|
-
"data hooks must declare output schema contracts",
|
|
306
|
-
);
|
|
307
|
-
forbid(importsDal(text), file, "data hooks must not import DAL directly");
|
|
308
|
-
forbid(
|
|
309
|
-
!importsApplication(text),
|
|
310
|
-
file,
|
|
311
|
-
"data hooks must call logical actions through @/application imports",
|
|
312
|
-
);
|
|
313
|
-
forbid(importsRouteLayer(text, "ui"), file, "data hooks must not import UI components");
|
|
314
|
-
forbid(importsRouteLayer(text, "container"), file, "data hooks must not import containers");
|
|
315
|
-
await requireRuntimeBoundarySchemaUsage(file, text, "input");
|
|
316
|
-
await requireRuntimeBoundarySchemaUsage(file, text, "output");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
for await (const file of walk("src/application")) {
|
|
321
|
-
if (!implementationFile(file)) continue;
|
|
322
|
-
|
|
323
|
-
const text = decoder.decode(await runtime.readFile(file));
|
|
324
|
-
forbid(/@\/routes\//.test(text), file, "application must not import route-layer code");
|
|
325
|
-
forbid(/@\/components\//.test(text), file, "application must not import UI components");
|
|
326
|
-
forbid(
|
|
327
|
-
!importsDal(text),
|
|
328
|
-
file,
|
|
329
|
-
"application actions must call DAL operations through @/dal imports",
|
|
330
|
-
);
|
|
331
|
-
await requireSibling(
|
|
332
|
-
file,
|
|
333
|
-
".input.schema.ts",
|
|
334
|
-
"application actions must declare input schema contracts",
|
|
335
|
-
);
|
|
336
|
-
await requireSibling(
|
|
337
|
-
file,
|
|
338
|
-
".output.schema.ts",
|
|
339
|
-
"application actions must declare output schema contracts",
|
|
340
|
-
);
|
|
341
|
-
await requireRuntimeBoundarySchemaUsage(file, text, "input");
|
|
342
|
-
await requireRuntimeBoundarySchemaUsage(file, text, "output");
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
for await (const file of walk("src/dal")) {
|
|
346
|
-
if (!implementationFile(file)) continue;
|
|
347
|
-
|
|
348
|
-
const text = decoder.decode(await runtime.readFile(file));
|
|
349
|
-
forbid(/@\/routes\//.test(text), file, "DAL must not import route-layer code");
|
|
350
|
-
forbid(/@\/components\//.test(text), file, "DAL must not import UI components");
|
|
351
|
-
|
|
352
|
-
if (!isDalOperationBoundary(file)) continue;
|
|
353
|
-
await requireSibling(
|
|
354
|
-
file,
|
|
355
|
-
".input.schema.ts",
|
|
356
|
-
"DAL operations must declare input schema contracts",
|
|
357
|
-
);
|
|
358
|
-
await requireSibling(
|
|
359
|
-
file,
|
|
360
|
-
".output.schema.ts",
|
|
361
|
-
"DAL operations must declare output schema contracts",
|
|
362
|
-
);
|
|
363
|
-
await requireRuntimeBoundarySchemaUsage(file, text, "input");
|
|
364
|
-
await requireRuntimeBoundarySchemaUsage(file, text, "output");
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (violations.length) {
|
|
368
|
-
console.error(violations.join("\n"));
|
|
369
|
-
runtime.exit(1);
|
|
370
|
-
}
|
|
371
|
-
console.log("layers-and-contracts ok");
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "layers-and-contracts-supabase",
|
|
3
|
-
"kind": "rule",
|
|
4
|
-
"version": "1.0.7",
|
|
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 `node .agents/skills/layers-and-contracts/check.ts` before handoff."
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
"obsolete": [],
|
|
32
|
-
"check": {
|
|
33
|
-
"command": [
|
|
34
|
-
"node",
|
|
35
|
-
".agents/skills/layers-and-contracts/check.ts"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|