@specdest/devkit 0.2.1 → 0.3.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.
Files changed (138) hide show
  1. package/README.md +15 -20
  2. package/package.json +4 -4
  3. package/src/canonical-project-operations.js +157 -0
  4. package/src/canonical-project.js +50 -0
  5. package/src/canonical-source.js +114 -0
  6. package/src/cli.js +2 -2
  7. package/src/git-catalog.js +105 -0
  8. package/src/index.js +6 -2
  9. package/src/project-operations.js +69 -9
  10. package/src/remote-installer.js +462 -0
  11. package/src/sync-core.js +26 -10
  12. package/catalog/README.md +0 -11
  13. package/catalog/modules/backend-convex/manifest.json +0 -14
  14. package/catalog/modules/backend-convex-expo/manifest.json +0 -11
  15. package/catalog/modules/backend-supabase/manifest.json +0 -15
  16. package/catalog/modules/backend-supabase-expo/manifest.json +0 -11
  17. package/catalog/modules/checker-runtime/config.ts +0 -25
  18. package/catalog/modules/checker-runtime/fs.ts +0 -48
  19. package/catalog/modules/checker-runtime/manifest.json +0 -28
  20. package/catalog/modules/checker-runtime/runtime.ts +0 -79
  21. package/catalog/modules/devflow/.agents/skills/devflow/SKILL.md +0 -33
  22. package/catalog/modules/devflow/.devflow.json +0 -10
  23. package/catalog/modules/devflow/manifest.json +0 -35
  24. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/SKILL.md +0 -85
  25. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/activeScenario.mjs +0 -130
  26. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/checkLocalEnvironment.mjs +0 -7
  27. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/completeActiveScenario.mjs +0 -36
  28. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/createActiveScenario.mjs +0 -143
  29. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/localEnvironment.mjs +0 -43
  30. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/prompt.mjs +0 -25
  31. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runActiveScenario.mjs +0 -66
  32. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/runAuthoringScenario.mjs +0 -146
  33. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seed.mjs +0 -56
  34. package/catalog/modules/e2e-playwright/.agents/skills/e2e-playwright/scripts/seedActiveScenario.mjs +0 -6
  35. package/catalog/modules/e2e-playwright/docs/e2e-playwright/README.md +0 -103
  36. package/catalog/modules/e2e-playwright/manifest.json +0 -206
  37. package/catalog/modules/e2e-playwright/playwright.e2e.config.ts +0 -39
  38. package/catalog/modules/e2e-playwright/tests/e2e/support/e2ePlaywrightFlow.ts +0 -107
  39. package/catalog/modules/e2e-playwright/tests/e2e/support/fixtures.ts +0 -27
  40. package/catalog/modules/local-log/AGENTS.local-log.md +0 -13
  41. package/catalog/modules/local-log/docs/features/local-logging/README.md +0 -70
  42. package/catalog/modules/local-log/manifest.json +0 -39
  43. package/catalog/modules/local-log/tmp/logs/.gitignore +0 -2
  44. package/catalog/modules/local-log/tools/local-log/README.md +0 -47
  45. package/catalog/modules/local-log/tools/local-log/local-log.mjs +0 -241
  46. package/catalog/modules/stack-common-vite/manifest.json +0 -16
  47. package/catalog/modules/stack-expo-convex/manifest.json +0 -31
  48. package/catalog/modules/stack-expo-supabase/manifest.json +0 -44
  49. package/catalog/modules/stack-vite-convex/manifest.json +0 -32
  50. package/catalog/modules/stack-vite-supabase/manifest.json +0 -45
  51. package/catalog/rules/abac-permissions-convex/SKILL.md +0 -17
  52. package/catalog/rules/abac-permissions-convex/check.ts +0 -87
  53. package/catalog/rules/abac-permissions-convex/manifest.json +0 -33
  54. package/catalog/rules/abac-permissions-supabase/SKILL.md +0 -17
  55. package/catalog/rules/abac-permissions-supabase/check.ts +0 -87
  56. package/catalog/rules/abac-permissions-supabase/manifest.json +0 -33
  57. package/catalog/rules/convex-multi-presentation/SKILL.md +0 -47
  58. package/catalog/rules/convex-multi-presentation/check.ts +0 -205
  59. package/catalog/rules/convex-multi-presentation/manifest.json +0 -47
  60. package/catalog/rules/convex-multi-presentation/policy.ts +0 -261
  61. package/catalog/rules/design-rules/SKILL.md +0 -12
  62. package/catalog/rules/design-rules/check.ts +0 -84
  63. package/catalog/rules/design-rules/config.json +0 -5
  64. package/catalog/rules/design-rules/manifest.json +0 -38
  65. package/catalog/rules/e2e-test-rules/SKILL.md +0 -46
  66. package/catalog/rules/e2e-test-rules/check.ts +0 -145
  67. package/catalog/rules/e2e-test-rules/config.json +0 -32
  68. package/catalog/rules/e2e-test-rules/manifest.json +0 -38
  69. package/catalog/rules/error-handling-rules/SKILL.md +0 -21
  70. package/catalog/rules/error-handling-rules/check.ts +0 -73
  71. package/catalog/rules/error-handling-rules/manifest.json +0 -33
  72. package/catalog/rules/layers-and-contracts/SKILL.md +0 -36
  73. package/catalog/rules/layers-and-contracts/check.ts +0 -266
  74. package/catalog/rules/layers-and-contracts/manifest.json +0 -33
  75. package/catalog/rules/layers-and-contracts-convex/SKILL.md +0 -49
  76. package/catalog/rules/layers-and-contracts-convex/check.ts +0 -289
  77. package/catalog/rules/layers-and-contracts-convex/manifest.json +0 -38
  78. package/catalog/rules/layers-and-contracts-convex/policy.ts +0 -68
  79. package/catalog/rules/layers-and-contracts-supabase/SKILL.md +0 -52
  80. package/catalog/rules/layers-and-contracts-supabase/check.ts +0 -371
  81. package/catalog/rules/layers-and-contracts-supabase/manifest.json +0 -38
  82. package/catalog/rules/layers-and-contracts-supabase/policy.ts +0 -68
  83. package/catalog/rules/module-size-rules/SKILL.md +0 -5
  84. package/catalog/rules/module-size-rules/check.ts +0 -144
  85. package/catalog/rules/module-size-rules/config.json +0 -6
  86. package/catalog/rules/module-size-rules/manifest.json +0 -38
  87. package/catalog/rules/module-size-rules-convex/SKILL.md +0 -5
  88. package/catalog/rules/module-size-rules-convex/check.ts +0 -146
  89. package/catalog/rules/module-size-rules-convex/config.json +0 -6
  90. package/catalog/rules/module-size-rules-convex/manifest.json +0 -38
  91. package/catalog/rules/module-size-rules-supabase/SKILL.md +0 -5
  92. package/catalog/rules/module-size-rules-supabase/check.ts +0 -146
  93. package/catalog/rules/module-size-rules-supabase/config.json +0 -12
  94. package/catalog/rules/module-size-rules-supabase/manifest.json +0 -38
  95. package/catalog/rules/mutation-command-rules/SKILL.md +0 -15
  96. package/catalog/rules/mutation-command-rules/check.ts +0 -30
  97. package/catalog/rules/mutation-command-rules/config.json +0 -19
  98. package/catalog/rules/mutation-command-rules/manifest.json +0 -38
  99. package/catalog/rules/nearby-contracts/SKILL.md +0 -18
  100. package/catalog/rules/nearby-contracts/check.ts +0 -138
  101. package/catalog/rules/nearby-contracts/config.json +0 -10
  102. package/catalog/rules/nearby-contracts/manifest.json +0 -38
  103. package/catalog/rules/no-raw-click-buttons/SKILL.md +0 -5
  104. package/catalog/rules/no-raw-click-buttons/check.ts +0 -37
  105. package/catalog/rules/no-raw-click-buttons/manifest.json +0 -33
  106. package/catalog/rules/public-api-export-barrels/SKILL.md +0 -45
  107. package/catalog/rules/public-api-export-barrels/check.ts +0 -73
  108. package/catalog/rules/public-api-export-barrels/config.json +0 -4
  109. package/catalog/rules/public-api-export-barrels/manifest.json +0 -38
  110. package/catalog/rules/route-tree-fresh/SKILL.md +0 -16
  111. package/catalog/rules/route-tree-fresh/check.ts +0 -66
  112. package/catalog/rules/route-tree-fresh/manifest.json +0 -33
  113. package/catalog/rules/strict-typescript/SKILL.md +0 -3
  114. package/catalog/rules/strict-typescript/check.ts +0 -119
  115. package/catalog/rules/strict-typescript/manifest.json +0 -33
  116. package/catalog/rules/supabase-contracts/SKILL.md +0 -3
  117. package/catalog/rules/supabase-contracts/check.ts +0 -172
  118. package/catalog/rules/supabase-contracts/manifest.json +0 -33
  119. package/catalog/rules/supabase-declarative-schema/SKILL.md +0 -30
  120. package/catalog/rules/supabase-declarative-schema/check.ts +0 -262
  121. package/catalog/rules/supabase-declarative-schema/config.json +0 -8
  122. package/catalog/rules/supabase-declarative-schema/manifest.json +0 -38
  123. package/catalog/rules/tanstack-form-rules/SKILL.md +0 -11
  124. package/catalog/rules/tanstack-form-rules/check.ts +0 -58
  125. package/catalog/rules/tanstack-form-rules/manifest.json +0 -33
  126. package/catalog/rules/unit-test-rules/SKILL.md +0 -55
  127. package/catalog/rules/unit-test-rules/check.ts +0 -132
  128. package/catalog/rules/unit-test-rules/config.json +0 -22
  129. package/catalog/rules/unit-test-rules/manifest.json +0 -38
  130. package/catalog/rules/unit-test-rules-convex/SKILL.md +0 -41
  131. package/catalog/rules/unit-test-rules-convex/check.ts +0 -418
  132. package/catalog/rules/unit-test-rules-convex/manifest.json +0 -33
  133. package/catalog/rules/unit-test-rules-supabase/SKILL.md +0 -40
  134. package/catalog/rules/unit-test-rules-supabase/check.ts +0 -492
  135. package/catalog/rules/unit-test-rules-supabase/manifest.json +0 -33
  136. package/catalog/rules/workstation-controller-rules/SKILL.md +0 -22
  137. package/catalog/rules/workstation-controller-rules/check.ts +0 -108
  138. package/catalog/rules/workstation-controller-rules/manifest.json +0 -33
@@ -1,172 +0,0 @@
1
- import { runtime } from "../shared/runtime.ts";
2
- // oxlint-disable no-console no-await-in-loop
3
- const required = [
4
- "src/__generated__/database.ts",
5
- "src/__generated__/schema.ts",
6
- "src/__generated__/edgeSchema.ts",
7
- "supabase/functions/_shared/database.ts",
8
- "supabase/functions/_shared/schema.ts",
9
- "supabase/functions/_shared/edgeSchema.ts",
10
- ];
11
- const sharedPairs = [
12
- ["src/__generated__/database.ts", "supabase/functions/_shared/database.ts"],
13
- ["src/__generated__/schema.ts", "supabase/functions/_shared/schema.ts"],
14
- ["src/__generated__/edgeSchema.ts", "supabase/functions/_shared/edgeSchema.ts"],
15
- ] as const;
16
-
17
- const missing: string[] = [];
18
- for (const path of required) {
19
- try {
20
- await runtime.stat(path);
21
- } catch {
22
- missing.push(path);
23
- }
24
- }
25
-
26
- const mismatches: string[] = [];
27
- for (const [left, right] of sharedPairs) {
28
- try {
29
- const leftText = await runtime.readTextFile(left);
30
- const rightText = await runtime.readTextFile(right);
31
- if (leftText !== rightText) mismatches.push(`${left} != ${right}`);
32
- } catch {
33
- // Missing files are reported above.
34
- }
35
- }
36
-
37
- const incompleteSchemas = await findIncompleteGeneratedSchemas();
38
- const missingDalTables = await findMissingDalTables();
39
-
40
- if (missing.length || mismatches.length || incompleteSchemas.length || missingDalTables.length) {
41
- const parts = [];
42
- if (missing.length) {
43
- parts.push(`missing Supabase contract files:\n${missing.join("\n")}`);
44
- }
45
- if (mismatches.length) {
46
- parts.push(`mismatched Supabase shared contracts:\n${mismatches.join("\n")}`);
47
- }
48
- if (incompleteSchemas.length) {
49
- parts.push(
50
- `incomplete generated DB Zod schemas; run pnpm exec nps db.generate.all:\n${incompleteSchemas.join(
51
- "\n",
52
- )}`,
53
- );
54
- }
55
- if (missingDalTables.length) {
56
- parts.push(
57
- `DAL references tables missing from src/__generated__/database.ts:\n${missingDalTables.join(
58
- "\n",
59
- )}`,
60
- );
61
- }
62
- console.error(parts.join("\n"));
63
- runtime.exit(1);
64
- }
65
- console.log("supabase-contracts ok");
66
-
67
- async function findIncompleteGeneratedSchemas(): Promise<string[]> {
68
- try {
69
- const databaseText = await runtime.readTextFile("src/__generated__/database.ts");
70
- const schemaText = await runtime.readTextFile("src/__generated__/schema.ts");
71
- const tableNames = getPublicTableNames(databaseText);
72
- const missingExports: string[] = [];
73
- for (const tableName of tableNames) {
74
- for (const suffix of ["RowSchema", "InsertSchema", "UpdateSchema"] as const) {
75
- const exportName = `${tableName}${suffix}`;
76
- if (!new RegExp(`export\\s+const\\s+${exportName}\\b`, "u").test(schemaText)) {
77
- missingExports.push(`src/__generated__/schema.ts: missing ${exportName}`);
78
- }
79
- }
80
- }
81
- return missingExports;
82
- } catch {
83
- return [];
84
- }
85
- }
86
-
87
- async function findMissingDalTables(): Promise<string[]> {
88
- try {
89
- const databaseText = await runtime.readTextFile("src/__generated__/database.ts");
90
- const tableNames = new Set(getAllTableNames(databaseText));
91
- const violations: string[] = [];
92
- for await (const file of walk("src/dal")) {
93
- if (!file.endsWith(".ts")) continue;
94
- if (file.endsWith(".test.ts")) continue;
95
- const text = await runtime.readTextFile(file);
96
- for (const tableName of getDalFromTableNames(text)) {
97
- if (!tableNames.has(tableName)) {
98
- violations.push(
99
- `${file}: .from("${tableName}") is not present in generated database types`,
100
- );
101
- }
102
- }
103
- }
104
- return violations;
105
- } catch {
106
- return [];
107
- }
108
- }
109
-
110
- function getDalFromTableNames(text: string): string[] {
111
- const names: string[] = [];
112
- let cursor = 0;
113
- while (cursor < text.length) {
114
- const index = text.indexOf(".from(", cursor);
115
- if (index === -1) break;
116
- const after = text.slice(index);
117
- const match = after.match(/^\.from\(\s*["']([^"']+)["']\s*\)/u);
118
- if (match?.[1]) names.push(match[1]);
119
- cursor = index + 6;
120
- }
121
- return names;
122
- }
123
-
124
- async function* walk(dir: string): AsyncGenerator<string> {
125
- try {
126
- for await (const entry of runtime.readDir(dir)) {
127
- const path = `${dir}/${entry.name}`;
128
- if (entry.isDirectory) yield* walk(path);
129
- if (entry.isFile) yield path;
130
- }
131
- } catch {
132
- return;
133
- }
134
- }
135
-
136
- function getAllTableNames(databaseText: string): string[] {
137
- const tableNames: string[] = [];
138
- let inTables = false;
139
- for (const line of databaseText.split("\n")) {
140
- if (line === " Tables: {") {
141
- inTables = true;
142
- continue;
143
- }
144
- if (inTables && line === " Views: {") {
145
- inTables = false;
146
- continue;
147
- }
148
- if (!inTables) continue;
149
- const match = line.match(/^ ([a-z][a-z0-9_]*): \{$/u);
150
- if (match?.[1]) tableNames.push(match[1]);
151
- }
152
- return tableNames;
153
- }
154
-
155
- function getPublicTableNames(databaseText: string): string[] {
156
- const publicTablesStart = databaseText.indexOf(" public: {\n Tables: {");
157
- if (publicTablesStart === -1) return [];
158
-
159
- const publicViewsStart = databaseText.indexOf(" Views: {", publicTablesStart);
160
- const tablesText =
161
- publicViewsStart === -1
162
- ? databaseText.slice(publicTablesStart)
163
- : databaseText.slice(publicTablesStart, publicViewsStart);
164
- const tableNames: string[] = [];
165
- const tablePattern = /^ ([a-z][a-z0-9_]*): \{$/gmu;
166
-
167
- for (const match of tablesText.matchAll(tablePattern)) {
168
- if (match[1]) tableNames.push(match[1]);
169
- }
170
-
171
- return tableNames;
172
- }
@@ -1,33 +0,0 @@
1
- {
2
- "id": "supabase-contracts",
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/supabase-contracts/SKILL.md",
12
- "source": "SKILL.md"
13
- },
14
- {
15
- "kind": "managed-file",
16
- "path": ".agents/skills/supabase-contracts/check.ts",
17
- "source": "check.ts"
18
- },
19
- {
20
- "kind": "shared-markdown-section",
21
- "path": "AGENTS.md",
22
- "heading": "## Specdest backend rule: supabase-contracts",
23
- "body": "Use `.agents/skills/supabase-contracts/SKILL.md` for this backend-specific rule. Run `node .agents/skills/supabase-contracts/check.ts` before handoff."
24
- }
25
- ],
26
- "obsolete": [],
27
- "check": {
28
- "command": [
29
- "node",
30
- ".agents/skills/supabase-contracts/check.ts"
31
- ]
32
- }
33
- }
@@ -1,30 +0,0 @@
1
- ---
2
- name: supabase-declarative-schema
3
- description: Rules and checker for declarative Supabase schema ownership and production migration wiring.
4
- ---
5
-
6
- # Supabase declarative schema
7
-
8
- Use this skill before adding, changing, or reviewing Supabase schema, generated database contracts, DB scripts, or seed scripts.
9
-
10
- ## Rules
11
-
12
- - Keep schema source files under `supabase/schemas/**`.
13
- - Generated files under `supabase/migrations/**` are allowed as deployment artifacts; do not treat them as the schema source of truth.
14
- - Keep `supabase/config.toml` wired for pg-delta declarative schema:
15
- - `[db.migrations].schema_paths = ["./schemas/*.sql"]`
16
- - `[experimental.pgdelta].enabled = true`
17
- - `[experimental.pgdelta].declarative_schema_path = "./schemas"`
18
- - Do not deploy production with `supabase migration up` when the source of truth is declarative schema.
19
- - Production migration scripts must run declarative schema sync before `supabase db push`.
20
- - Declarative schema sync commands must include `--experimental` for Supabase CLI compatibility.
21
- - Remote type generation must use `supabase gen types typescript --db-url "$SUPABASE_DB_URL"`; do not use `--local` for `db.generate.remote`.
22
- - Seed scripts must run only after the database schema contract exists on the target database.
23
-
24
- ## Check
25
-
26
- ```bash
27
- node .agents/skills/supabase-declarative-schema/check.ts
28
- ```
29
-
30
- Configuration lives in `./config.json` in this skill folder. Keep exceptions explicit and small.
@@ -1,262 +0,0 @@
1
- import { runtime } from "../shared/runtime.ts";
2
- // oxlint-disable no-console no-await-in-loop
3
- const violations: string[] = [];
4
-
5
- type DeclarativeSchemaConfig = {
6
- readonly schemaVersion: number;
7
- readonly schemaDirectories?: readonly string[];
8
- readonly declarativeSchemaDirectory?: string;
9
- readonly requiredTables?: readonly string[];
10
- };
11
-
12
- async function readText(path: string): Promise<string | null> {
13
- try {
14
- return await runtime.readTextFile(path);
15
- } catch {
16
- return null;
17
- }
18
- }
19
-
20
- async function exists(path: string): Promise<boolean> {
21
- try {
22
- await runtime.stat(path);
23
- return true;
24
- } catch {
25
- return false;
26
- }
27
- }
28
-
29
- async function* walk(dir: string): AsyncGenerator<string> {
30
- try {
31
- for await (const entry of runtime.readDir(dir)) {
32
- const path = `${dir}/${entry.name}`;
33
- if (entry.isDirectory) yield* walk(path);
34
- if (entry.isFile) yield path;
35
- }
36
- } catch {
37
- return;
38
- }
39
- }
40
-
41
- function section(text: string, name: string): string | null {
42
- const lines = text.split("\n");
43
- const start = lines.findIndex((line) => line.trim() === `[${name}]`);
44
- if (start < 0) return null;
45
- const body: string[] = [];
46
- for (const line of lines.slice(start + 1)) {
47
- if (/^\s*\[[^\]]+\]\s*$/.test(line)) break;
48
- body.push(line);
49
- }
50
- return body.join("\n");
51
- }
52
-
53
- function booleanSetting(sectionText: string | null, key: string): boolean | null {
54
- if (!sectionText) return null;
55
- for (const line of sectionText.split("\n")) {
56
- const trimmed = line.trim();
57
- if (trimmed === `${key} = true`) return true;
58
- if (trimmed === `${key} = false`) return false;
59
- }
60
- return null;
61
- }
62
-
63
- function stringSetting(sectionText: string | null, key: string): string | null {
64
- if (!sectionText) return null;
65
- for (const line of sectionText.split("\n")) {
66
- const match = line.trim().match(/^([a-zA-Z0-9_.-]+)\s*=\s*["']([^"']+)["']$/u);
67
- if (match?.[1] === key) return match[2] ?? null;
68
- }
69
- return null;
70
- }
71
-
72
- function arraySetting(sectionText: string | null, key: string): string[] {
73
- if (!sectionText) return [];
74
- for (const line of sectionText.split("\n")) {
75
- const trimmed = line.trim();
76
- if (!trimmed.startsWith(`${key} = [`)) continue;
77
- return Array.from(trimmed.matchAll(/["']([^"']+)["']/g), (item) => item[1] ?? "").filter(
78
- Boolean,
79
- );
80
- }
81
- return [];
82
- }
83
-
84
- function schemaGlobFor(directory: string): string {
85
- const normalized = directory.replace(/^supabase\//, "").replace(/\/$/, "");
86
- return `./${normalized}/*.sql`;
87
- }
88
-
89
- function declarativePathFor(directory: string): string {
90
- const normalized = directory.replace(/^supabase\//, "").replace(/\/$/, "");
91
- return `./${normalized}`;
92
- }
93
-
94
- function usesMigrationUp(text: string): boolean {
95
- return /supabase\s+migration\s+up/u.test(text);
96
- }
97
-
98
- function hasDeclarativeSyncCommand(text: string): boolean {
99
- return /supabase\s+db\s+schema\s+declarative\s+sync/u.test(text);
100
- }
101
-
102
- function declarativeSyncUsesExperimentalFlag(text: string): boolean {
103
- const matches = [...text.matchAll(/supabase\s+db\s+schema\s+declarative\s+sync/gu)];
104
- return (
105
- matches.length > 0 &&
106
- matches.every((match) => {
107
- const window = text.slice(match.index ?? 0, (match.index ?? 0) + 180);
108
- return /--experimental\b/u.test(window);
109
- })
110
- );
111
- }
112
-
113
- function commandWindowAfter(text: string, marker: RegExp): string[] {
114
- const lines = text.split("\n");
115
- const windows: string[] = [];
116
- for (let index = 0; index < lines.length; index += 1) {
117
- if (!marker.test(lines[index] ?? "")) continue;
118
- windows.push(lines.slice(index, index + 8).join("\n"));
119
- }
120
- return windows;
121
- }
122
-
123
- function hasRemoteTypeGeneration(text: string): boolean {
124
- return commandWindowAfter(text, /generate\.remote|remote:/u).some(
125
- (command) =>
126
- /supabase\s+gen\s+types\s+typescript/u.test(command) &&
127
- /--db-url\s+["']?\$SUPABASE_DB_URL/u.test(command),
128
- );
129
- }
130
-
131
- function remoteTypeGenerationUsesLocal(text: string): boolean {
132
- return commandWindowAfter(text, /generate\.remote|remote:/u).some((command) =>
133
- /supabase\s+gen\s+types\s+typescript\s+--local/u.test(command),
134
- );
135
- }
136
-
137
- function prodPushesAfterSync(text: string): boolean {
138
- return commandWindowAfter(text, /migrate\.prod|prod:/u).some(
139
- (command) => /nps\s+db\.schema\.sync/u.test(command) && /supabase\s+db\s+push/u.test(command),
140
- );
141
- }
142
-
143
- function hasRequiredTable(sqlText: string, table: string): boolean {
144
- const normalized = sqlText.toLowerCase().replace(/\s+/g, " ");
145
- const normalizedTable = table.toLowerCase();
146
- return (
147
- normalized.includes(`create table ${normalizedTable}`) ||
148
- normalized.includes(`create table if not exists ${normalizedTable}`)
149
- );
150
- }
151
-
152
- const skillDir = new URL(".", import.meta.url).pathname;
153
- const configPath = `${skillDir}/config.json`;
154
- const configText = await readText(configPath);
155
- const config = (
156
- configText ? JSON.parse(configText) : { schemaVersion: 1 }
157
- ) as DeclarativeSchemaConfig;
158
-
159
- if (config.schemaVersion !== 1) {
160
- violations.push(
161
- ".agents/skills/supabase-declarative-schema/config.json: schemaVersion must be 1",
162
- );
163
- }
164
-
165
- const schemaDirectories = Array.isArray(config.schemaDirectories)
166
- ? config.schemaDirectories.map(String)
167
- : ["supabase/schemas"];
168
- const declarativeSchemaDirectory = String(
169
- config.declarativeSchemaDirectory ?? schemaDirectories[0] ?? "supabase/schemas",
170
- );
171
- const requiredTables = Array.isArray(config.requiredTables)
172
- ? config.requiredTables.map(String)
173
- : [];
174
- const supabaseConfig = await readText("supabase/config.toml");
175
- if (!supabaseConfig) {
176
- violations.push("supabase/config.toml: required for declarative schema projects");
177
- } else {
178
- const migrations = section(supabaseConfig, "db.migrations");
179
- const pgdelta = section(supabaseConfig, "experimental.pgdelta");
180
- const expectedSchemaGlob = schemaGlobFor(declarativeSchemaDirectory);
181
- const expectedDeclarativePath = declarativePathFor(declarativeSchemaDirectory);
182
-
183
- if (booleanSetting(migrations, "enabled") !== true) {
184
- violations.push("supabase/config.toml: [db.migrations].enabled must be true");
185
- }
186
- if (!arraySetting(migrations, "schema_paths").includes(expectedSchemaGlob)) {
187
- violations.push(
188
- `supabase/config.toml: [db.migrations].schema_paths must include ${expectedSchemaGlob}`,
189
- );
190
- }
191
- if (booleanSetting(pgdelta, "enabled") !== true) {
192
- violations.push("supabase/config.toml: [experimental.pgdelta].enabled must be true");
193
- }
194
- if (stringSetting(pgdelta, "declarative_schema_path") !== expectedDeclarativePath) {
195
- violations.push(
196
- `supabase/config.toml: [experimental.pgdelta].declarative_schema_path must be ${expectedDeclarativePath}`,
197
- );
198
- }
199
- }
200
-
201
- for (const directory of schemaDirectories) {
202
- if (!(await exists(directory))) {
203
- violations.push(`${directory}: declarative schema directory is required`);
204
- continue;
205
- }
206
- const sqlFiles: string[] = [];
207
- for await (const file of walk(directory)) {
208
- if (file.endsWith(".sql")) sqlFiles.push(file);
209
- }
210
- if (!sqlFiles.length) {
211
- violations.push(`${directory}: at least one declarative .sql schema file is required`);
212
- }
213
-
214
- const sqlTexts = await Promise.all(sqlFiles.map((file) => readText(file)));
215
- for (const table of requiredTables) {
216
- const found = sqlTexts.some((text) => (text ? hasRequiredTable(text, table) : false));
217
- if (!found) violations.push(`${directory}: missing required table contract ${table}`);
218
- }
219
- }
220
-
221
- const packageScripts =
222
- (await readText("package-scripts.yml")) ?? (await readText("package-scripts.yaml"));
223
- if (!packageScripts) {
224
- violations.push("package-scripts.yml: required so DB deploy scripts are contract-checked");
225
- } else {
226
- if (usesMigrationUp(packageScripts)) {
227
- violations.push(
228
- "package-scripts.yml: do not use `supabase migration up` with declarative schemas; run declarative sync then `supabase db push`",
229
- );
230
- }
231
- if (!hasDeclarativeSyncCommand(packageScripts)) {
232
- violations.push("package-scripts.yml: missing db.schema.sync declarative sync command");
233
- }
234
- if (!declarativeSyncUsesExperimentalFlag(packageScripts)) {
235
- violations.push(
236
- "package-scripts.yml: declarative schema sync commands must include `--experimental` for Supabase CLI compatibility",
237
- );
238
- }
239
- if (!prodPushesAfterSync(packageScripts)) {
240
- violations.push(
241
- "package-scripts.yml: db.migrate.prod must run `nps db.schema.sync` before `supabase db push`",
242
- );
243
- }
244
- if (!hasRemoteTypeGeneration(packageScripts)) {
245
- violations.push(
246
- "package-scripts.yml: db.generate.remote must generate types from `$SUPABASE_DB_URL` with `supabase gen types typescript --db-url`",
247
- );
248
- }
249
- if (remoteTypeGenerationUsesLocal(packageScripts)) {
250
- violations.push(
251
- "package-scripts.yml: db.generate.remote must not use `supabase gen types typescript --local`",
252
- );
253
- }
254
- }
255
-
256
- if (violations.length) {
257
- console.error(`# supabase-declarative-schema violations: ${violations.length}`);
258
- for (const violation of violations) console.error(`- ${violation}`);
259
- runtime.exit(1);
260
- }
261
-
262
- console.log("supabase-declarative-schema ok");
@@ -1,8 +0,0 @@
1
- {
2
- "schemaVersion": 1,
3
- "schemaDirectories": [
4
- "supabase/schemas"
5
- ],
6
- "declarativeSchemaDirectory": "supabase/schemas",
7
- "requiredTables": []
8
- }
@@ -1,38 +0,0 @@
1
- {
2
- "id": "supabase-declarative-schema",
3
- "kind": "rule",
4
- "version": "1.0.3",
5
- "requires": [
6
- "checker-runtime"
7
- ],
8
- "artifacts": [
9
- {
10
- "kind": "managed-file",
11
- "path": ".agents/skills/supabase-declarative-schema/SKILL.md",
12
- "source": "SKILL.md"
13
- },
14
- {
15
- "kind": "managed-file",
16
- "path": ".agents/skills/supabase-declarative-schema/check.ts",
17
- "source": "check.ts"
18
- },
19
- {
20
- "kind": "scaffold",
21
- "path": ".agents/skills/supabase-declarative-schema/config.json",
22
- "source": "config.json"
23
- },
24
- {
25
- "kind": "shared-markdown-section",
26
- "path": "AGENTS.md",
27
- "heading": "## Specdest backend rule: supabase-declarative-schema",
28
- "body": "Use `.agents/skills/supabase-declarative-schema/SKILL.md` for this backend-specific rule. Run `node .agents/skills/supabase-declarative-schema/check.ts` before handoff."
29
- }
30
- ],
31
- "obsolete": [],
32
- "check": {
33
- "command": [
34
- "node",
35
- ".agents/skills/supabase-declarative-schema/check.ts"
36
- ]
37
- }
38
- }
@@ -1,11 +0,0 @@
1
- # TanStack Form rules
2
-
3
- Use TanStack Form for submitting route forms and form value state. Do not replace form state with ad hoc `useState` when the rule applies.
4
-
5
- Before changing route forms, inspect this skill and run:
6
-
7
- ```bash
8
- node .agents/skills/tanstack-form-rules/check.ts
9
- ```
10
-
11
- Fix violations in application code separately from Devkit `sync`.
@@ -1,58 +0,0 @@
1
- import { runtime } from "../shared/runtime.ts";
2
- // oxlint-disable no-console no-await-in-loop
3
- import { walk } from "../shared/fs.ts";
4
-
5
- const ignoredSuffixes = [".test.tsx", ".stories.tsx"];
6
-
7
- function shouldCheck(file: string): boolean {
8
- return (
9
- file.startsWith("src/routes/") &&
10
- file.endsWith(".tsx") &&
11
- file.includes("/-components/container/") &&
12
- !ignoredSuffixes.some((suffix) => file.endsWith(suffix))
13
- );
14
- }
15
-
16
- function lineNumber(text: string, index: number): number {
17
- return text.slice(0, index).split("\n").length;
18
- }
19
-
20
- function hasSubmittingForm(text: string): boolean {
21
- return /<form[\s\S]*?onSubmit=/u.test(text) || /<\w+Form\b[\s\S]*?onSubmit=/u.test(text);
22
- }
23
-
24
- const files = (await walk("src/routes")).map((file) => `src/routes/${file}`).filter(shouldCheck);
25
- const violations: string[] = [];
26
-
27
- for (const file of files) {
28
- const text = await runtime.readTextFile(file);
29
- if (/new\s+FormData\s*\(/u.test(text)) {
30
- for (const match of text.matchAll(/new\s+FormData\s*\(/gu)) {
31
- violations.push(
32
- `${file}:${lineNumber(text, match.index ?? 0)} FormData is forbidden for route forms; use @tanstack/react-form`,
33
- );
34
- }
35
- }
36
- if (!hasSubmittingForm(text)) continue;
37
- if (
38
- !text.includes("@tanstack/react-form") &&
39
- !/use[A-Z][A-Za-z0-9]*Form\(/u.test(text) &&
40
- !text.includes(".form.Subscribe")
41
- ) {
42
- violations.push(`${file}: submitting route forms must use a TanStack Form hook`);
43
- }
44
- const formFieldStatePattern =
45
- /const\s+\[\s*(?:email|password|name|hostname|description|rootPath|projectId|workstationId|serverId|url|oauthToken|fixedPort|content|tagsText|controllerUrl|helperToolCodePath)\b[\s\S]*?=\s*useState\s*(?:<[^>]+>)?\s*\(/u;
46
- if (formFieldStatePattern.test(text)) {
47
- violations.push(
48
- `${file}: route form value state must be managed by TanStack Form, not useState`,
49
- );
50
- }
51
- }
52
-
53
- if (violations.length > 0) {
54
- console.error(`# tanstack form rule violations: ${violations.length}`);
55
- console.error(violations.join("\n"));
56
- runtime.exit(1);
57
- }
58
- console.log("tanstack-form-rules ok");
@@ -1,33 +0,0 @@
1
- {
2
- "id": "tanstack-form-rules",
3
- "kind": "rule",
4
- "version": "1.0.1",
5
- "requires": [
6
- "checker-runtime"
7
- ],
8
- "artifacts": [
9
- {
10
- "kind": "managed-file",
11
- "path": ".agents/skills/tanstack-form-rules/SKILL.md",
12
- "source": "SKILL.md"
13
- },
14
- {
15
- "kind": "managed-file",
16
- "path": ".agents/skills/tanstack-form-rules/check.ts",
17
- "source": "check.ts"
18
- },
19
- {
20
- "kind": "shared-markdown-section",
21
- "path": "AGENTS.md",
22
- "heading": "## Specdest rule: tanstack-form-rules",
23
- "body": "Use `.agents/skills/tanstack-form-rules/SKILL.md` when working in this rule area. Run `node .agents/skills/tanstack-form-rules/check.ts` before handoff."
24
- }
25
- ],
26
- "obsolete": [],
27
- "check": {
28
- "command": [
29
- "node",
30
- ".agents/skills/tanstack-form-rules/check.ts"
31
- ]
32
- }
33
- }