tribunal-kit 5.7.0 → 5.8.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.
Files changed (59) hide show
  1. package/.agent/ARCHITECTURE.md +6 -7
  2. package/.agent/agents/frontend-reviewer.md +13 -0
  3. package/.agent/agents/frontend-specialist.md +14 -0
  4. package/.agent/agents/logic-reviewer.md +11 -0
  5. package/.agent/agents/orchestrator.md +15 -0
  6. package/.agent/agents/project-planner.md +5 -0
  7. package/.agent/agents/security-auditor.md +13 -0
  8. package/.agent/agents/ui-ux-auditor.md +7 -31
  9. package/.agent/history/memory/.memory.idx +1693 -0
  10. package/.agent/history/memory/MEMORY.md +123 -0
  11. package/.agent/routing_index.json +694 -714
  12. package/.agent/rules/GEMINI.md +88 -13
  13. package/.agent/scripts/_colors.js +131 -89
  14. package/.agent/scripts/_utils.js +163 -128
  15. package/.agent/scripts/auto_preview.js +207 -197
  16. package/.agent/scripts/bundle_analyzer.js +227 -192
  17. package/.agent/scripts/case_law_manager.js +991 -689
  18. package/.agent/scripts/checklist.js +233 -190
  19. package/.agent/scripts/context_broker.js +930 -605
  20. package/.agent/scripts/dependency_analyzer.js +275 -184
  21. package/.agent/scripts/graph_builder.js +412 -341
  22. package/.agent/scripts/graph_visualizer.js +392 -390
  23. package/.agent/scripts/graph_zoom.js +198 -156
  24. package/.agent/scripts/inner_loop_validator.js +523 -445
  25. package/.agent/scripts/lint_runner.js +199 -157
  26. package/.agent/scripts/marathon_harness.js +819 -661
  27. package/.agent/scripts/minify_context.js +115 -100
  28. package/.agent/scripts/mutation_runner.js +321 -280
  29. package/.agent/scripts/prompt_compiler.js +62 -42
  30. package/.agent/scripts/schema_validator.js +373 -280
  31. package/.agent/scripts/security_scan.js +333 -190
  32. package/.agent/scripts/session_manager.js +306 -270
  33. package/.agent/scripts/skill_evolution.js +810 -637
  34. package/.agent/scripts/skill_integrator.js +327 -307
  35. package/.agent/scripts/strengthen_skills.js +203 -193
  36. package/.agent/scripts/swarm_dispatcher.js +558 -457
  37. package/.agent/scripts/test_runner.js +178 -152
  38. package/.agent/scripts/verify_all.js +200 -168
  39. package/.agent/skills/fabel-protocol/SKILL.md +271 -0
  40. package/.agent/skills/thinking-protocol/SKILL.md +27 -0
  41. package/.agent/workflows/generate.md +2 -1
  42. package/.agent/workflows/tribunal-full.md +4 -3
  43. package/.agent/workflows/tribunal-speed.md +1 -1
  44. package/README.md +184 -58
  45. package/bin/mcp-server.js +496 -173
  46. package/bin/tribunal-kit.js +1245 -987
  47. package/bin/wrapper.js +108 -74
  48. package/dist/cli.js +44 -0
  49. package/dist/commands/align.js +201 -0
  50. package/dist/commands/case.js +23 -0
  51. package/dist/commands/compile.js +84 -0
  52. package/dist/commands/init.js +42 -0
  53. package/dist/commands/learn.js +57 -0
  54. package/dist/commands/memory.js +456 -0
  55. package/package.json +22 -10
  56. package/scripts/benchmark.js +162 -125
  57. package/scripts/changelog.js +196 -168
  58. package/scripts/sync-version.js +94 -81
  59. package/scripts/validate-payload.js +85 -78
@@ -1,280 +1,373 @@
1
- #!/usr/bin/env node
2
- /**
3
- * schema_validator.js — Database schema validator for the Tribunal Agent Kit.
4
- *
5
- * Usage:
6
- * node .agent/scripts/schema_validator.js .
7
- * node .agent/scripts/schema_validator.js . --type prisma
8
- * node .agent/scripts/schema_validator.js . --file prisma/schema.prisma
9
- */
10
-
11
- 'use strict';
12
-
13
- const fs = require('fs');
14
- const path = require('path');
15
-
16
- const {
17
- RED, GREEN, YELLOW, BLUE, BOLD, DIM, CYAN, RESET,
18
- sectionHeader: header, ok, fail, warn, skip,
19
- } = require('./_colors');
20
-
21
- function detectOrm(projectRoot) {
22
- if (fs.existsSync(path.join(projectRoot, "prisma", "schema.prisma"))) {
23
- return "prisma";
24
- }
25
-
26
- function searchFor(dir, patterns) {
27
- let items;
28
- try {
29
- items = fs.readdirSync(dir, { withFileTypes: true });
30
- } catch {
31
- return false;
32
- }
33
-
34
- for (const item of items) {
35
- if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
36
- if (searchFor(path.join(dir, item.name), patterns)) return true;
37
- if (item.name === "migrations") {
38
- try {
39
- const mFiles = fs.readdirSync(path.join(dir, item.name));
40
- if (mFiles.some(f => f.endsWith(".sql"))) return "sql";
41
- } catch {}
42
- }
43
- } else {
44
- for (const p of patterns) {
45
- if (p.test(item.name)) return p.type;
46
- }
47
- }
48
- }
49
- return null;
50
- }
51
-
52
- const type = searchFor(projectRoot, [{ test: name => name.startsWith("drizzle.config."), type: "drizzle" }]);
53
- if (type) return type;
54
-
55
- if (fs.existsSync(path.join(projectRoot, "knexfile.js")) || fs.existsSync(path.join(projectRoot, "knexfile.ts"))) {
56
- return "knex";
57
- }
58
-
59
- return null;
60
- }
61
-
62
- function validatePrisma(filepath) {
63
- const issues = [];
64
- let lines;
65
- try {
66
- lines = fs.readFileSync(filepath, 'utf8').split('\n');
67
- } catch {
68
- return [["error", `Cannot read file: ${filepath}`, 0]];
69
- }
70
-
71
- let currentModel = "";
72
- let hasCreatedAt = false;
73
- let hasUpdatedAt = false;
74
- let modelStartLine = 0;
75
- let fieldsWithRelation = [];
76
- let indexedFields = new Set();
77
- let hasIdField = false;
78
-
79
- for (let i = 0; i < lines.length; i++) {
80
- const lineNum = i + 1;
81
- const line = lines[i];
82
- const stripped = line.trim();
83
-
84
- const modelMatch = stripped.match(/^model\s+(\w+)\s*\{/);
85
- if (modelMatch) {
86
- if (currentModel) {
87
- if (!hasCreatedAt) issues.push(["warn", `Model '${currentModel}' missing createdAt timestamp`, modelStartLine]);
88
- if (!hasUpdatedAt) issues.push(["warn", `Model '${currentModel}' missing updatedAt timestamp`, modelStartLine]);
89
- if (!hasIdField) issues.push(["warn", `Model '${currentModel}' has no @id field`, modelStartLine]);
90
- for (const [fieldName, fieldLine] of fieldsWithRelation) {
91
- if (!indexedFields.has(fieldName)) {
92
- issues.push(["warn", `Model '${currentModel}': foreign key '${fieldName}' has no @@index`, fieldLine]);
93
- }
94
- }
95
- }
96
-
97
- currentModel = modelMatch[1];
98
- modelStartLine = lineNum;
99
- hasCreatedAt = false;
100
- hasUpdatedAt = false;
101
- hasIdField = false;
102
- fieldsWithRelation = [];
103
- indexedFields.clear();
104
-
105
- if (currentModel[0] !== currentModel[0].toUpperCase()) {
106
- issues.push(["warn", `Model '${currentModel}' should use PascalCase`, lineNum]);
107
- }
108
- }
109
-
110
- if (currentModel) {
111
- if (stripped.includes("createdAt") || stripped.includes("created_at")) hasCreatedAt = true;
112
- if (stripped.includes("updatedAt") || stripped.includes("updated_at")) hasUpdatedAt = true;
113
- if (stripped.includes("@id")) hasIdField = true;
114
-
115
- const fkMatch = stripped.match(/^\s*(\w+Id)\s+(Int|String|BigInt)/);
116
- if (fkMatch && !stripped.includes("@relation")) {
117
- fieldsWithRelation.push([fkMatch[1], lineNum]);
118
- }
119
-
120
- const indexMatch = stripped.match(/@@index\(\[([^\]]+)\]/);
121
- if (indexMatch) {
122
- for (const field of indexMatch[1].split(",")) {
123
- indexedFields.add(field.trim());
124
- }
125
- }
126
- }
127
- }
128
-
129
- if (currentModel) {
130
- if (!hasCreatedAt) issues.push(["warn", `Model '${currentModel}' missing createdAt timestamp`, modelStartLine]);
131
- if (!hasUpdatedAt) issues.push(["warn", `Model '${currentModel}' missing updatedAt timestamp`, modelStartLine]);
132
- if (!hasIdField) issues.push(["warn", `Model '${currentModel}' has no @id field`, modelStartLine]);
133
- for (const [fieldName, fieldLine] of fieldsWithRelation) {
134
- if (!indexedFields.has(fieldName)) {
135
- issues.push(["warn", `Model '${currentModel}': foreign key '${fieldName}' may need @@index`, fieldLine]);
136
- }
137
- }
138
- }
139
-
140
- return issues;
141
- }
142
-
143
- function validateSqlMigration(filepath) {
144
- const issues = [];
145
- let lines;
146
- try {
147
- lines = fs.readFileSync(filepath, 'utf8').split('\n');
148
- } catch {
149
- return [["error", `Cannot read file: ${filepath}`, 0]];
150
- }
151
-
152
- for (let i = 0; i < lines.length; i++) {
153
- const lineNum = i + 1;
154
- const stripped = lines[i].trim().toUpperCase();
155
-
156
- if (stripped.includes("DROP TABLE") && !stripped.includes("IF EXISTS")) {
157
- issues.push(["warn", "DROP TABLE without IF EXISTS — may fail on clean databases", lineNum]);
158
- }
159
- if (stripped.includes("REFERENCES") && !stripped.includes("NOT NULL") && !stripped.includes("NULL")) {
160
- issues.push(["warn", "Foreign key without explicit NULL/NOT NULL constraint", lineNum]);
161
- }
162
- if (stripped.includes("CREATE TABLE")) {
163
- issues.push(["info", "Verify this table includes created_at / updated_at columns", lineNum]);
164
- }
165
- }
166
-
167
- return issues;
168
- }
169
-
170
- function main() {
171
- const args = process.argv.slice(2);
172
- let targetPath = null;
173
- let typeArg = "auto";
174
- let fileArg = null;
175
-
176
- let i = 0;
177
- while (i < args.length) {
178
- if (args[i] === '--type' && i + 1 < args.length) typeArg = args[++i];
179
- else if (args[i] === '--file' && i + 1 < args.length) fileArg = args[++i];
180
- else if (!targetPath && !args[i].startsWith('-')) targetPath = args[i];
181
- i++;
182
- }
183
-
184
- if (!targetPath) {
185
- console.log("Usage: node schema_validator.js <path> [--type <prisma|drizzle|sql>] [--file <filepath>]");
186
- process.exit(1);
187
- }
188
-
189
- const projectRoot = path.resolve(targetPath);
190
- if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
191
- fail(`Directory not found: ${projectRoot}`);
192
- process.exit(1);
193
- }
194
-
195
- console.log(`${BOLD}Tribunal — schema_validator.js${RESET}`);
196
- console.log(`Project: ${projectRoot}`);
197
-
198
- const ormType = typeArg !== "auto" ? typeArg : detectOrm(projectRoot);
199
- if (!ormType && !fileArg) {
200
- skip("No schema files detected — skipping validation");
201
- process.exit(0);
202
- }
203
-
204
- let issuesCount = 0;
205
-
206
- if (fileArg) {
207
- console.log(header(`Validating: ${fileArg}`));
208
- const filepath = path.isAbsolute(fileArg) ? fileArg : path.join(projectRoot, fileArg);
209
- let issues = [];
210
- if (filepath.endsWith(".prisma")) issues = validatePrisma(filepath);
211
- else if (filepath.endsWith(".sql")) issues = validateSqlMigration(filepath);
212
- else {
213
- skip(`Unknown schema file type: ${fileArg}`);
214
- process.exit(0);
215
- }
216
-
217
- for (const [severity, message, line] of issues) {
218
- if (severity === "error") { fail(`L${line}: ${message}`); issuesCount++; }
219
- else if (severity === "warn") { warn(`L${line}: ${message}`); issuesCount++; }
220
- else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
221
- }
222
- } else if (ormType === "prisma") {
223
- const schemaPath = path.join(projectRoot, "prisma", "schema.prisma");
224
- if (fs.existsSync(schemaPath)) {
225
- console.log(header("Prisma Schema Validation"));
226
- const issues = validatePrisma(schemaPath);
227
- for (const [severity, message, line] of issues) {
228
- if (severity === "error") { fail(`L${line}: ${message}`); issuesCount++; }
229
- else if (severity === "warn") { warn(`L${line}: ${message}`); issuesCount++; }
230
- else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
231
- }
232
- } else {
233
- skip(`Prisma schema not found at ${schemaPath}`);
234
- }
235
- } else if (ormType === "sql") {
236
- console.log(header("SQL Migration Validation"));
237
- // Very basic recursion for migrations dir
238
- function findMigrations(dir) {
239
- let res = [];
240
- try {
241
- const items = fs.readdirSync(dir, { withFileTypes: true });
242
- for (const item of items) {
243
- if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
244
- if (item.name === "migrations") {
245
- const sqls = fs.readdirSync(path.join(dir, item.name)).filter(f => f.endsWith(".sql")).map(f => path.join(dir, item.name, f));
246
- res.push(...sqls);
247
- } else {
248
- res.push(...findMigrations(path.join(dir, item.name)));
249
- }
250
- }
251
- }
252
- } catch {}
253
- return res;
254
- }
255
-
256
- const mFiles = findMigrations(projectRoot).sort();
257
- for (const sqlFile of mFiles) {
258
- console.log(`\n 📄 ${path.basename(sqlFile)}`);
259
- const issues = validateSqlMigration(sqlFile);
260
- for (const [severity, message, line] of issues) {
261
- if (severity === "error") { fail(` L${line}: ${message}`); issuesCount++; }
262
- else if (severity === "warn") { warn(` L${line}: ${message}`); issuesCount++; }
263
- else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
264
- }
265
- }
266
- } else if (ormType === "drizzle") {
267
- console.log(header("Drizzle Schema"));
268
- skip("Drizzle validation not yet implemented validate manually");
269
- }
270
-
271
- console.log(`\n${BOLD}━━━ Schema Validation Summary ━━━${RESET}`);
272
- if (issuesCount === 0) ok("No schema issues found");
273
- else warn(`${issuesCount} issue(s) foundreview above`);
274
-
275
- process.exit(0);
276
- }
277
-
278
- if (require.main === module) {
279
- main();
280
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * schema_validator.js — Database schema validator for the Tribunal Agent Kit.
4
+ *
5
+ * Usage:
6
+ * node .agent/scripts/schema_validator.js .
7
+ * node .agent/scripts/schema_validator.js . --type prisma
8
+ * node .agent/scripts/schema_validator.js . --file prisma/schema.prisma
9
+ */
10
+
11
+ "use strict";
12
+
13
+ const fs = require("fs");
14
+ const path = require("path");
15
+
16
+ const {
17
+ BOLD,
18
+ RESET,
19
+ BLUE,
20
+ sectionHeader: header,
21
+ ok,
22
+ fail,
23
+ warn,
24
+ skip,
25
+ } = require("./_colors");
26
+
27
+ function detectOrm(projectRoot) {
28
+ if (fs.existsSync(path.join(projectRoot, "prisma", "schema.prisma"))) {
29
+ return "prisma";
30
+ }
31
+
32
+ function searchFor(dir, patterns) {
33
+ let items;
34
+ try {
35
+ items = fs.readdirSync(dir, { withFileTypes: true });
36
+ } catch {
37
+ return false;
38
+ }
39
+
40
+ for (const item of items) {
41
+ if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
42
+ if (searchFor(path.join(dir, item.name), patterns)) return true;
43
+ if (item.name === "migrations") {
44
+ try {
45
+ const mFiles = fs.readdirSync(path.join(dir, item.name));
46
+ if (mFiles.some((f) => f.endsWith(".sql"))) return "sql";
47
+ } catch {}
48
+ }
49
+ } else {
50
+ for (const p of patterns) {
51
+ if (p.test(item.name)) return p.type;
52
+ }
53
+ }
54
+ }
55
+ return null;
56
+ }
57
+
58
+ const type = searchFor(projectRoot, [
59
+ { test: (name) => name.startsWith("drizzle.config."), type: "drizzle" },
60
+ ]);
61
+ if (type) return type;
62
+
63
+ if (
64
+ fs.existsSync(path.join(projectRoot, "knexfile.js")) ||
65
+ fs.existsSync(path.join(projectRoot, "knexfile.ts"))
66
+ ) {
67
+ return "knex";
68
+ }
69
+
70
+ return null;
71
+ }
72
+
73
+ function validatePrisma(filepath) {
74
+ const issues = [];
75
+ let lines;
76
+ try {
77
+ lines = fs.readFileSync(filepath, "utf8").split("\n");
78
+ } catch {
79
+ return [["error", `Cannot read file: ${filepath}`, 0]];
80
+ }
81
+
82
+ let currentModel = "";
83
+ let hasCreatedAt = false;
84
+ let hasUpdatedAt = false;
85
+ let modelStartLine = 0;
86
+ let fieldsWithRelation = [];
87
+ let indexedFields = new Set();
88
+ let hasIdField = false;
89
+
90
+ for (let i = 0; i < lines.length; i++) {
91
+ const lineNum = i + 1;
92
+ const line = lines[i];
93
+ const stripped = line.trim();
94
+
95
+ const modelMatch = stripped.match(/^model\s+(\w+)\s*\{/);
96
+ if (modelMatch) {
97
+ if (currentModel) {
98
+ if (!hasCreatedAt)
99
+ issues.push([
100
+ "warn",
101
+ `Model '${currentModel}' missing createdAt timestamp`,
102
+ modelStartLine,
103
+ ]);
104
+ if (!hasUpdatedAt)
105
+ issues.push([
106
+ "warn",
107
+ `Model '${currentModel}' missing updatedAt timestamp`,
108
+ modelStartLine,
109
+ ]);
110
+ if (!hasIdField)
111
+ issues.push([
112
+ "warn",
113
+ `Model '${currentModel}' has no @id field`,
114
+ modelStartLine,
115
+ ]);
116
+ for (const [fieldName, fieldLine] of fieldsWithRelation) {
117
+ if (!indexedFields.has(fieldName)) {
118
+ issues.push([
119
+ "warn",
120
+ `Model '${currentModel}': foreign key '${fieldName}' has no @@index`,
121
+ fieldLine,
122
+ ]);
123
+ }
124
+ }
125
+ }
126
+
127
+ currentModel = modelMatch[1];
128
+ modelStartLine = lineNum;
129
+ hasCreatedAt = false;
130
+ hasUpdatedAt = false;
131
+ hasIdField = false;
132
+ fieldsWithRelation = [];
133
+ indexedFields.clear();
134
+
135
+ if (currentModel[0] !== currentModel[0].toUpperCase()) {
136
+ issues.push([
137
+ "warn",
138
+ `Model '${currentModel}' should use PascalCase`,
139
+ lineNum,
140
+ ]);
141
+ }
142
+ }
143
+
144
+ if (currentModel) {
145
+ if (stripped.includes("createdAt") || stripped.includes("created_at"))
146
+ hasCreatedAt = true;
147
+ if (stripped.includes("updatedAt") || stripped.includes("updated_at"))
148
+ hasUpdatedAt = true;
149
+ if (stripped.includes("@id")) hasIdField = true;
150
+
151
+ const fkMatch = stripped.match(/^\s*(\w+Id)\s+(Int|String|BigInt)/);
152
+ if (fkMatch && !stripped.includes("@relation")) {
153
+ fieldsWithRelation.push([fkMatch[1], lineNum]);
154
+ }
155
+
156
+ const indexMatch = stripped.match(/@@index\(\[([^\]]+)\]/);
157
+ if (indexMatch) {
158
+ for (const field of indexMatch[1].split(",")) {
159
+ indexedFields.add(field.trim());
160
+ }
161
+ }
162
+ }
163
+ }
164
+
165
+ if (currentModel) {
166
+ if (!hasCreatedAt)
167
+ issues.push([
168
+ "warn",
169
+ `Model '${currentModel}' missing createdAt timestamp`,
170
+ modelStartLine,
171
+ ]);
172
+ if (!hasUpdatedAt)
173
+ issues.push([
174
+ "warn",
175
+ `Model '${currentModel}' missing updatedAt timestamp`,
176
+ modelStartLine,
177
+ ]);
178
+ if (!hasIdField)
179
+ issues.push([
180
+ "warn",
181
+ `Model '${currentModel}' has no @id field`,
182
+ modelStartLine,
183
+ ]);
184
+ for (const [fieldName, fieldLine] of fieldsWithRelation) {
185
+ if (!indexedFields.has(fieldName)) {
186
+ issues.push([
187
+ "warn",
188
+ `Model '${currentModel}': foreign key '${fieldName}' may need @@index`,
189
+ fieldLine,
190
+ ]);
191
+ }
192
+ }
193
+ }
194
+
195
+ return issues;
196
+ }
197
+
198
+ function validateSqlMigration(filepath) {
199
+ const issues = [];
200
+ let lines;
201
+ try {
202
+ lines = fs.readFileSync(filepath, "utf8").split("\n");
203
+ } catch {
204
+ return [["error", `Cannot read file: ${filepath}`, 0]];
205
+ }
206
+
207
+ for (let i = 0; i < lines.length; i++) {
208
+ const lineNum = i + 1;
209
+ const stripped = lines[i].trim().toUpperCase();
210
+
211
+ if (stripped.includes("DROP TABLE") && !stripped.includes("IF EXISTS")) {
212
+ issues.push([
213
+ "warn",
214
+ "DROP TABLE without IF EXISTS — may fail on clean databases",
215
+ lineNum,
216
+ ]);
217
+ }
218
+ if (
219
+ stripped.includes("REFERENCES") &&
220
+ !stripped.includes("NOT NULL") &&
221
+ !stripped.includes("NULL")
222
+ ) {
223
+ issues.push([
224
+ "warn",
225
+ "Foreign key without explicit NULL/NOT NULL constraint",
226
+ lineNum,
227
+ ]);
228
+ }
229
+ if (stripped.includes("CREATE TABLE")) {
230
+ issues.push([
231
+ "info",
232
+ "Verify this table includes created_at / updated_at columns",
233
+ lineNum,
234
+ ]);
235
+ }
236
+ }
237
+
238
+ return issues;
239
+ }
240
+
241
+ function main() {
242
+ const args = process.argv.slice(2);
243
+ let targetPath = null;
244
+ let typeArg = "auto";
245
+ let fileArg = null;
246
+
247
+ let i = 0;
248
+ while (i < args.length) {
249
+ if (args[i] === "--type" && i + 1 < args.length) typeArg = args[++i];
250
+ else if (args[i] === "--file" && i + 1 < args.length) fileArg = args[++i];
251
+ else if (!targetPath && !args[i].startsWith("-")) targetPath = args[i];
252
+ i++;
253
+ }
254
+
255
+ if (!targetPath) {
256
+ console.log(
257
+ "Usage: node schema_validator.js <path> [--type <prisma|drizzle|sql>] [--file <filepath>]",
258
+ );
259
+ process.exit(1);
260
+ }
261
+
262
+ const projectRoot = path.resolve(targetPath);
263
+ if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
264
+ fail(`Directory not found: ${projectRoot}`);
265
+ process.exit(1);
266
+ }
267
+
268
+ console.log(`${BOLD}Tribunalschema_validator.js${RESET}`);
269
+ console.log(`Project: ${projectRoot}`);
270
+
271
+ const ormType = typeArg !== "auto" ? typeArg : detectOrm(projectRoot);
272
+ if (!ormType && !fileArg) {
273
+ skip("No schema files detected skipping validation");
274
+ process.exit(0);
275
+ }
276
+
277
+ let issuesCount = 0;
278
+
279
+ if (fileArg) {
280
+ console.log(header(`Validating: ${fileArg}`));
281
+ const filepath = path.isAbsolute(fileArg)
282
+ ? fileArg
283
+ : path.join(projectRoot, fileArg);
284
+ let issues = [];
285
+ if (filepath.endsWith(".prisma")) issues = validatePrisma(filepath);
286
+ else if (filepath.endsWith(".sql")) issues = validateSqlMigration(filepath);
287
+ else {
288
+ skip(`Unknown schema file type: ${fileArg}`);
289
+ process.exit(0);
290
+ }
291
+
292
+ for (const [severity, message, line] of issues) {
293
+ if (severity === "error") {
294
+ fail(`L${line}: ${message}`);
295
+ issuesCount++;
296
+ } else if (severity === "warn") {
297
+ warn(`L${line}: ${message}`);
298
+ issuesCount++;
299
+ } else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
300
+ }
301
+ } else if (ormType === "prisma") {
302
+ const schemaPath = path.join(projectRoot, "prisma", "schema.prisma");
303
+ if (fs.existsSync(schemaPath)) {
304
+ console.log(header("Prisma Schema Validation"));
305
+ const issues = validatePrisma(schemaPath);
306
+ for (const [severity, message, line] of issues) {
307
+ if (severity === "error") {
308
+ fail(`L${line}: ${message}`);
309
+ issuesCount++;
310
+ } else if (severity === "warn") {
311
+ warn(`L${line}: ${message}`);
312
+ issuesCount++;
313
+ } else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
314
+ }
315
+ } else {
316
+ skip(`Prisma schema not found at ${schemaPath}`);
317
+ }
318
+ } else if (ormType === "sql") {
319
+ console.log(header("SQL Migration Validation"));
320
+ // Very basic recursion for migrations dir
321
+ function findMigrations(dir) {
322
+ let res = [];
323
+ try {
324
+ const items = fs.readdirSync(dir, { withFileTypes: true });
325
+ for (const item of items) {
326
+ if (
327
+ item.isDirectory() &&
328
+ !["node_modules", ".git"].includes(item.name)
329
+ ) {
330
+ if (item.name === "migrations") {
331
+ const sqls = fs
332
+ .readdirSync(path.join(dir, item.name))
333
+ .filter((f) => f.endsWith(".sql"))
334
+ .map((f) => path.join(dir, item.name, f));
335
+ res.push(...sqls);
336
+ } else {
337
+ res.push(...findMigrations(path.join(dir, item.name)));
338
+ }
339
+ }
340
+ }
341
+ } catch {}
342
+ return res;
343
+ }
344
+
345
+ const mFiles = findMigrations(projectRoot).sort();
346
+ for (const sqlFile of mFiles) {
347
+ console.log(`\n 📄 ${path.basename(sqlFile)}`);
348
+ const issues = validateSqlMigration(sqlFile);
349
+ for (const [severity, message, line] of issues) {
350
+ if (severity === "error") {
351
+ fail(` L${line}: ${message}`);
352
+ issuesCount++;
353
+ } else if (severity === "warn") {
354
+ warn(` L${line}: ${message}`);
355
+ issuesCount++;
356
+ } else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
357
+ }
358
+ }
359
+ } else if (ormType === "drizzle") {
360
+ console.log(header("Drizzle Schema"));
361
+ skip("Drizzle validation not yet implemented — validate manually");
362
+ }
363
+
364
+ console.log(`\n${BOLD}━━━ Schema Validation Summary ━━━${RESET}`);
365
+ if (issuesCount === 0) ok("No schema issues found");
366
+ else warn(`${issuesCount} issue(s) found — review above`);
367
+
368
+ process.exit(0);
369
+ }
370
+
371
+ if (require.main === module) {
372
+ main();
373
+ }