tribunal-kit 4.3.1 → 4.4.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 (67) hide show
  1. package/.agent/agents/api-architect.md +66 -66
  2. package/.agent/agents/db-latency-auditor.md +216 -216
  3. package/.agent/agents/precedence-reviewer.md +250 -250
  4. package/.agent/agents/resilience-reviewer.md +88 -88
  5. package/.agent/agents/schema-reviewer.md +67 -67
  6. package/.agent/agents/throughput-optimizer.md +299 -299
  7. package/.agent/agents/ui-ux-auditor.md +292 -292
  8. package/.agent/agents/vitals-reviewer.md +223 -223
  9. package/.agent/scripts/_colors.js +18 -18
  10. package/.agent/scripts/_utils.js +42 -42
  11. package/.agent/scripts/append_flow.js +72 -72
  12. package/.agent/scripts/auto_preview.js +197 -197
  13. package/.agent/scripts/bundle_analyzer.js +290 -290
  14. package/.agent/scripts/case_law_manager.js +17 -6
  15. package/.agent/scripts/checklist.js +266 -266
  16. package/.agent/scripts/colors.js +17 -17
  17. package/.agent/scripts/compress_skills.js +141 -141
  18. package/.agent/scripts/consolidate_skills.js +149 -149
  19. package/.agent/scripts/context_broker.js +611 -609
  20. package/.agent/scripts/deep_compress.js +150 -150
  21. package/.agent/scripts/dependency_analyzer.js +272 -272
  22. package/.agent/scripts/graph_builder.js +151 -37
  23. package/.agent/scripts/graph_visualizer.js +384 -0
  24. package/.agent/scripts/inner_loop_validator.js +451 -465
  25. package/.agent/scripts/lint_runner.js +187 -187
  26. package/.agent/scripts/minify_context.js +100 -100
  27. package/.agent/scripts/mutation_runner.js +280 -0
  28. package/.agent/scripts/patch_skills_meta.js +156 -156
  29. package/.agent/scripts/patch_skills_output.js +244 -244
  30. package/.agent/scripts/schema_validator.js +297 -297
  31. package/.agent/scripts/security_scan.js +303 -303
  32. package/.agent/scripts/session_manager.js +276 -276
  33. package/.agent/scripts/skill_evolution.js +644 -644
  34. package/.agent/scripts/skill_integrator.js +313 -313
  35. package/.agent/scripts/strengthen_skills.js +193 -193
  36. package/.agent/scripts/strip_tribunal.js +47 -47
  37. package/.agent/scripts/swarm_dispatcher.js +360 -360
  38. package/.agent/scripts/test_runner.js +193 -193
  39. package/.agent/scripts/utils.js +32 -32
  40. package/.agent/scripts/verify_all.js +257 -256
  41. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +1 -1
  42. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +1 -1
  43. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +1 -1
  44. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +1 -1
  45. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +1 -1
  46. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +1 -1
  47. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +1 -1
  48. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +1 -1
  49. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
  50. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +1 -1
  51. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +1 -1
  52. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +1 -1
  53. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +1 -1
  54. package/.agent/skills/doc.md +1 -1
  55. package/.agent/skills/knowledge-graph/SKILL.md +32 -16
  56. package/.agent/skills/testing-patterns/SKILL.md +19 -2
  57. package/.agent/skills/ui-ux-pro-max/SKILL.md +480 -43
  58. package/.agent/workflows/generate.md +183 -183
  59. package/.agent/workflows/tribunal-speed.md +183 -183
  60. package/README.md +1 -1
  61. package/bin/tribunal-kit.js +134 -17
  62. package/package.json +6 -3
  63. package/scripts/changelog.js +167 -167
  64. package/scripts/sync-version.js +81 -81
  65. package/.agent/scripts/__pycache__/_colors.cpython-311.pyc +0 -0
  66. package/.agent/scripts/__pycache__/_utils.cpython-311.pyc +0 -0
  67. package/.agent/scripts/__pycache__/case_law_manager.cpython-311.pyc +0 -0
@@ -1,297 +1,297 @@
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 { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
17
-
18
- function header(title) {
19
- console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`);
20
- }
21
-
22
- function ok(msg) {
23
- console.log(` ${GREEN}✅ ${msg}${RESET}`);
24
- }
25
-
26
- function fail(msg) {
27
- console.log(` ${RED}❌ ${msg}${RESET}`);
28
- }
29
-
30
- function warn(msg) {
31
- console.log(` ${YELLOW}⚠️ ${msg}${RESET}`);
32
- }
33
-
34
- function skip(msg) {
35
- console.log(` ${YELLOW}⏭️ ${msg}${RESET}`);
36
- }
37
-
38
- function detectOrm(projectRoot) {
39
- if (fs.existsSync(path.join(projectRoot, "prisma", "schema.prisma"))) {
40
- return "prisma";
41
- }
42
-
43
- function searchFor(dir, patterns) {
44
- let items;
45
- try {
46
- items = fs.readdirSync(dir, { withFileTypes: true });
47
- } catch {
48
- return false;
49
- }
50
-
51
- for (const item of items) {
52
- if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
53
- if (searchFor(path.join(dir, item.name), patterns)) return true;
54
- if (item.name === "migrations") {
55
- try {
56
- const mFiles = fs.readdirSync(path.join(dir, item.name));
57
- if (mFiles.some(f => f.endsWith(".sql"))) return "sql";
58
- } catch {}
59
- }
60
- } else {
61
- for (const p of patterns) {
62
- if (p.test(item.name)) return p.type;
63
- }
64
- }
65
- }
66
- return null;
67
- }
68
-
69
- const type = searchFor(projectRoot, [{ test: name => name.startsWith("drizzle.config."), type: "drizzle" }]);
70
- if (type) return type;
71
-
72
- if (fs.existsSync(path.join(projectRoot, "knexfile.js")) || fs.existsSync(path.join(projectRoot, "knexfile.ts"))) {
73
- return "knex";
74
- }
75
-
76
- return null;
77
- }
78
-
79
- function validatePrisma(filepath) {
80
- const issues = [];
81
- let lines;
82
- try {
83
- lines = fs.readFileSync(filepath, 'utf8').split('\n');
84
- } catch {
85
- return [["error", `Cannot read file: ${filepath}`, 0]];
86
- }
87
-
88
- let currentModel = "";
89
- let hasCreatedAt = false;
90
- let hasUpdatedAt = false;
91
- let modelStartLine = 0;
92
- let fieldsWithRelation = [];
93
- let indexedFields = new Set();
94
- let hasIdField = false;
95
-
96
- for (let i = 0; i < lines.length; i++) {
97
- const lineNum = i + 1;
98
- const line = lines[i];
99
- const stripped = line.trim();
100
-
101
- const modelMatch = stripped.match(/^model\s+(\w+)\s*\{/);
102
- if (modelMatch) {
103
- if (currentModel) {
104
- if (!hasCreatedAt) issues.push(["warn", `Model '${currentModel}' missing createdAt timestamp`, modelStartLine]);
105
- if (!hasUpdatedAt) issues.push(["warn", `Model '${currentModel}' missing updatedAt timestamp`, modelStartLine]);
106
- if (!hasIdField) issues.push(["warn", `Model '${currentModel}' has no @id field`, modelStartLine]);
107
- for (const [fieldName, fieldLine] of fieldsWithRelation) {
108
- if (!indexedFields.has(fieldName)) {
109
- issues.push(["warn", `Model '${currentModel}': foreign key '${fieldName}' has no @@index`, fieldLine]);
110
- }
111
- }
112
- }
113
-
114
- currentModel = modelMatch[1];
115
- modelStartLine = lineNum;
116
- hasCreatedAt = false;
117
- hasUpdatedAt = false;
118
- hasIdField = false;
119
- fieldsWithRelation = [];
120
- indexedFields.clear();
121
-
122
- if (currentModel[0] !== currentModel[0].toUpperCase()) {
123
- issues.push(["warn", `Model '${currentModel}' should use PascalCase`, lineNum]);
124
- }
125
- }
126
-
127
- if (currentModel) {
128
- if (stripped.includes("createdAt") || stripped.includes("created_at")) hasCreatedAt = true;
129
- if (stripped.includes("updatedAt") || stripped.includes("updated_at")) hasUpdatedAt = true;
130
- if (stripped.includes("@id")) hasIdField = true;
131
-
132
- const fkMatch = stripped.match(/^\s*(\w+Id)\s+(Int|String|BigInt)/);
133
- if (fkMatch && !stripped.includes("@relation")) {
134
- fieldsWithRelation.push([fkMatch[1], lineNum]);
135
- }
136
-
137
- const indexMatch = stripped.match(/@@index\(\[([^\]]+)\]/);
138
- if (indexMatch) {
139
- for (const field of indexMatch[1].split(",")) {
140
- indexedFields.add(field.trim());
141
- }
142
- }
143
- }
144
- }
145
-
146
- if (currentModel) {
147
- if (!hasCreatedAt) issues.push(["warn", `Model '${currentModel}' missing createdAt timestamp`, modelStartLine]);
148
- if (!hasUpdatedAt) issues.push(["warn", `Model '${currentModel}' missing updatedAt timestamp`, modelStartLine]);
149
- if (!hasIdField) issues.push(["warn", `Model '${currentModel}' has no @id field`, modelStartLine]);
150
- for (const [fieldName, fieldLine] of fieldsWithRelation) {
151
- if (!indexedFields.has(fieldName)) {
152
- issues.push(["warn", `Model '${currentModel}': foreign key '${fieldName}' may need @@index`, fieldLine]);
153
- }
154
- }
155
- }
156
-
157
- return issues;
158
- }
159
-
160
- function validateSqlMigration(filepath) {
161
- const issues = [];
162
- let lines;
163
- try {
164
- lines = fs.readFileSync(filepath, 'utf8').split('\n');
165
- } catch {
166
- return [["error", `Cannot read file: ${filepath}`, 0]];
167
- }
168
-
169
- for (let i = 0; i < lines.length; i++) {
170
- const lineNum = i + 1;
171
- const stripped = lines[i].trim().toUpperCase();
172
-
173
- if (stripped.includes("DROP TABLE") && !stripped.includes("IF EXISTS")) {
174
- issues.push(["warn", "DROP TABLE without IF EXISTS — may fail on clean databases", lineNum]);
175
- }
176
- if (stripped.includes("REFERENCES") && !stripped.includes("NOT NULL") && !stripped.includes("NULL")) {
177
- issues.push(["warn", "Foreign key without explicit NULL/NOT NULL constraint", lineNum]);
178
- }
179
- if (stripped.includes("CREATE TABLE")) {
180
- issues.push(["info", "Verify this table includes created_at / updated_at columns", lineNum]);
181
- }
182
- }
183
-
184
- return issues;
185
- }
186
-
187
- function main() {
188
- const args = process.argv.slice(2);
189
- let targetPath = null;
190
- let typeArg = "auto";
191
- let fileArg = null;
192
-
193
- let i = 0;
194
- while (i < args.length) {
195
- if (args[i] === '--type' && i + 1 < args.length) typeArg = args[++i];
196
- else if (args[i] === '--file' && i + 1 < args.length) fileArg = args[++i];
197
- else if (!targetPath && !args[i].startsWith('-')) targetPath = args[i];
198
- i++;
199
- }
200
-
201
- if (!targetPath) {
202
- console.log("Usage: node schema_validator.js <path> [--type <prisma|drizzle|sql>] [--file <filepath>]");
203
- process.exit(1);
204
- }
205
-
206
- const projectRoot = path.resolve(targetPath);
207
- if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
208
- fail(`Directory not found: ${projectRoot}`);
209
- process.exit(1);
210
- }
211
-
212
- console.log(`${BOLD}Tribunal — schema_validator.js${RESET}`);
213
- console.log(`Project: ${projectRoot}`);
214
-
215
- const ormType = typeArg !== "auto" ? typeArg : detectOrm(projectRoot);
216
- if (!ormType && !fileArg) {
217
- skip("No schema files detected — skipping validation");
218
- process.exit(0);
219
- }
220
-
221
- let issuesCount = 0;
222
-
223
- if (fileArg) {
224
- header(`Validating: ${fileArg}`);
225
- const filepath = path.isAbsolute(fileArg) ? fileArg : path.join(projectRoot, fileArg);
226
- let issues = [];
227
- if (filepath.endsWith(".prisma")) issues = validatePrisma(filepath);
228
- else if (filepath.endsWith(".sql")) issues = validateSqlMigration(filepath);
229
- else {
230
- skip(`Unknown schema file type: ${fileArg}`);
231
- process.exit(0);
232
- }
233
-
234
- for (const [severity, message, line] of issues) {
235
- if (severity === "error") { fail(`L${line}: ${message}`); issuesCount++; }
236
- else if (severity === "warn") { warn(`L${line}: ${message}`); issuesCount++; }
237
- else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
238
- }
239
- } else if (ormType === "prisma") {
240
- const schemaPath = path.join(projectRoot, "prisma", "schema.prisma");
241
- if (fs.existsSync(schemaPath)) {
242
- header("Prisma Schema Validation");
243
- const issues = validatePrisma(schemaPath);
244
- for (const [severity, message, line] of issues) {
245
- if (severity === "error") { fail(`L${line}: ${message}`); issuesCount++; }
246
- else if (severity === "warn") { warn(`L${line}: ${message}`); issuesCount++; }
247
- else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
248
- }
249
- } else {
250
- skip(`Prisma schema not found at ${schemaPath}`);
251
- }
252
- } else if (ormType === "sql") {
253
- header("SQL Migration Validation");
254
- // Very basic recursion for migrations dir
255
- function findMigrations(dir) {
256
- let res = [];
257
- try {
258
- const items = fs.readdirSync(dir, { withFileTypes: true });
259
- for (const item of items) {
260
- if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
261
- if (item.name === "migrations") {
262
- const sqls = fs.readdirSync(path.join(dir, item.name)).filter(f => f.endsWith(".sql")).map(f => path.join(dir, item.name, f));
263
- res.push(...sqls);
264
- } else {
265
- res.push(...findMigrations(path.join(dir, item.name)));
266
- }
267
- }
268
- }
269
- } catch {}
270
- return res;
271
- }
272
-
273
- const mFiles = findMigrations(projectRoot).sort();
274
- for (const sqlFile of mFiles) {
275
- console.log(`\n 📄 ${path.basename(sqlFile)}`);
276
- const issues = validateSqlMigration(sqlFile);
277
- for (const [severity, message, line] of issues) {
278
- if (severity === "error") { fail(` L${line}: ${message}`); issuesCount++; }
279
- else if (severity === "warn") { warn(` L${line}: ${message}`); issuesCount++; }
280
- else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
281
- }
282
- }
283
- } else if (ormType === "drizzle") {
284
- header("Drizzle Schema");
285
- skip("Drizzle validation not yet implemented — validate manually");
286
- }
287
-
288
- console.log(`\n${BOLD}━━━ Schema Validation Summary ━━━${RESET}`);
289
- if (issuesCount === 0) ok("No schema issues found");
290
- else warn(`${issuesCount} issue(s) found — review above`);
291
-
292
- process.exit(0);
293
- }
294
-
295
- if (require.main === module) {
296
- main();
297
- }
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 { RED, GREEN, YELLOW, BLUE, BOLD, RESET } = require('./colors.js');
17
+
18
+ function header(title) {
19
+ console.log(`\n${BOLD}${BLUE}━━━ ${title} ━━━${RESET}`);
20
+ }
21
+
22
+ function ok(msg) {
23
+ console.log(` ${GREEN}✅ ${msg}${RESET}`);
24
+ }
25
+
26
+ function fail(msg) {
27
+ console.log(` ${RED}❌ ${msg}${RESET}`);
28
+ }
29
+
30
+ function warn(msg) {
31
+ console.log(` ${YELLOW}⚠️ ${msg}${RESET}`);
32
+ }
33
+
34
+ function skip(msg) {
35
+ console.log(` ${YELLOW}⏭️ ${msg}${RESET}`);
36
+ }
37
+
38
+ function detectOrm(projectRoot) {
39
+ if (fs.existsSync(path.join(projectRoot, "prisma", "schema.prisma"))) {
40
+ return "prisma";
41
+ }
42
+
43
+ function searchFor(dir, patterns) {
44
+ let items;
45
+ try {
46
+ items = fs.readdirSync(dir, { withFileTypes: true });
47
+ } catch {
48
+ return false;
49
+ }
50
+
51
+ for (const item of items) {
52
+ if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
53
+ if (searchFor(path.join(dir, item.name), patterns)) return true;
54
+ if (item.name === "migrations") {
55
+ try {
56
+ const mFiles = fs.readdirSync(path.join(dir, item.name));
57
+ if (mFiles.some(f => f.endsWith(".sql"))) return "sql";
58
+ } catch {}
59
+ }
60
+ } else {
61
+ for (const p of patterns) {
62
+ if (p.test(item.name)) return p.type;
63
+ }
64
+ }
65
+ }
66
+ return null;
67
+ }
68
+
69
+ const type = searchFor(projectRoot, [{ test: name => name.startsWith("drizzle.config."), type: "drizzle" }]);
70
+ if (type) return type;
71
+
72
+ if (fs.existsSync(path.join(projectRoot, "knexfile.js")) || fs.existsSync(path.join(projectRoot, "knexfile.ts"))) {
73
+ return "knex";
74
+ }
75
+
76
+ return null;
77
+ }
78
+
79
+ function validatePrisma(filepath) {
80
+ const issues = [];
81
+ let lines;
82
+ try {
83
+ lines = fs.readFileSync(filepath, 'utf8').split('\n');
84
+ } catch {
85
+ return [["error", `Cannot read file: ${filepath}`, 0]];
86
+ }
87
+
88
+ let currentModel = "";
89
+ let hasCreatedAt = false;
90
+ let hasUpdatedAt = false;
91
+ let modelStartLine = 0;
92
+ let fieldsWithRelation = [];
93
+ let indexedFields = new Set();
94
+ let hasIdField = false;
95
+
96
+ for (let i = 0; i < lines.length; i++) {
97
+ const lineNum = i + 1;
98
+ const line = lines[i];
99
+ const stripped = line.trim();
100
+
101
+ const modelMatch = stripped.match(/^model\s+(\w+)\s*\{/);
102
+ if (modelMatch) {
103
+ if (currentModel) {
104
+ if (!hasCreatedAt) issues.push(["warn", `Model '${currentModel}' missing createdAt timestamp`, modelStartLine]);
105
+ if (!hasUpdatedAt) issues.push(["warn", `Model '${currentModel}' missing updatedAt timestamp`, modelStartLine]);
106
+ if (!hasIdField) issues.push(["warn", `Model '${currentModel}' has no @id field`, modelStartLine]);
107
+ for (const [fieldName, fieldLine] of fieldsWithRelation) {
108
+ if (!indexedFields.has(fieldName)) {
109
+ issues.push(["warn", `Model '${currentModel}': foreign key '${fieldName}' has no @@index`, fieldLine]);
110
+ }
111
+ }
112
+ }
113
+
114
+ currentModel = modelMatch[1];
115
+ modelStartLine = lineNum;
116
+ hasCreatedAt = false;
117
+ hasUpdatedAt = false;
118
+ hasIdField = false;
119
+ fieldsWithRelation = [];
120
+ indexedFields.clear();
121
+
122
+ if (currentModel[0] !== currentModel[0].toUpperCase()) {
123
+ issues.push(["warn", `Model '${currentModel}' should use PascalCase`, lineNum]);
124
+ }
125
+ }
126
+
127
+ if (currentModel) {
128
+ if (stripped.includes("createdAt") || stripped.includes("created_at")) hasCreatedAt = true;
129
+ if (stripped.includes("updatedAt") || stripped.includes("updated_at")) hasUpdatedAt = true;
130
+ if (stripped.includes("@id")) hasIdField = true;
131
+
132
+ const fkMatch = stripped.match(/^\s*(\w+Id)\s+(Int|String|BigInt)/);
133
+ if (fkMatch && !stripped.includes("@relation")) {
134
+ fieldsWithRelation.push([fkMatch[1], lineNum]);
135
+ }
136
+
137
+ const indexMatch = stripped.match(/@@index\(\[([^\]]+)\]/);
138
+ if (indexMatch) {
139
+ for (const field of indexMatch[1].split(",")) {
140
+ indexedFields.add(field.trim());
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ if (currentModel) {
147
+ if (!hasCreatedAt) issues.push(["warn", `Model '${currentModel}' missing createdAt timestamp`, modelStartLine]);
148
+ if (!hasUpdatedAt) issues.push(["warn", `Model '${currentModel}' missing updatedAt timestamp`, modelStartLine]);
149
+ if (!hasIdField) issues.push(["warn", `Model '${currentModel}' has no @id field`, modelStartLine]);
150
+ for (const [fieldName, fieldLine] of fieldsWithRelation) {
151
+ if (!indexedFields.has(fieldName)) {
152
+ issues.push(["warn", `Model '${currentModel}': foreign key '${fieldName}' may need @@index`, fieldLine]);
153
+ }
154
+ }
155
+ }
156
+
157
+ return issues;
158
+ }
159
+
160
+ function validateSqlMigration(filepath) {
161
+ const issues = [];
162
+ let lines;
163
+ try {
164
+ lines = fs.readFileSync(filepath, 'utf8').split('\n');
165
+ } catch {
166
+ return [["error", `Cannot read file: ${filepath}`, 0]];
167
+ }
168
+
169
+ for (let i = 0; i < lines.length; i++) {
170
+ const lineNum = i + 1;
171
+ const stripped = lines[i].trim().toUpperCase();
172
+
173
+ if (stripped.includes("DROP TABLE") && !stripped.includes("IF EXISTS")) {
174
+ issues.push(["warn", "DROP TABLE without IF EXISTS — may fail on clean databases", lineNum]);
175
+ }
176
+ if (stripped.includes("REFERENCES") && !stripped.includes("NOT NULL") && !stripped.includes("NULL")) {
177
+ issues.push(["warn", "Foreign key without explicit NULL/NOT NULL constraint", lineNum]);
178
+ }
179
+ if (stripped.includes("CREATE TABLE")) {
180
+ issues.push(["info", "Verify this table includes created_at / updated_at columns", lineNum]);
181
+ }
182
+ }
183
+
184
+ return issues;
185
+ }
186
+
187
+ function main() {
188
+ const args = process.argv.slice(2);
189
+ let targetPath = null;
190
+ let typeArg = "auto";
191
+ let fileArg = null;
192
+
193
+ let i = 0;
194
+ while (i < args.length) {
195
+ if (args[i] === '--type' && i + 1 < args.length) typeArg = args[++i];
196
+ else if (args[i] === '--file' && i + 1 < args.length) fileArg = args[++i];
197
+ else if (!targetPath && !args[i].startsWith('-')) targetPath = args[i];
198
+ i++;
199
+ }
200
+
201
+ if (!targetPath) {
202
+ console.log("Usage: node schema_validator.js <path> [--type <prisma|drizzle|sql>] [--file <filepath>]");
203
+ process.exit(1);
204
+ }
205
+
206
+ const projectRoot = path.resolve(targetPath);
207
+ if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
208
+ fail(`Directory not found: ${projectRoot}`);
209
+ process.exit(1);
210
+ }
211
+
212
+ console.log(`${BOLD}Tribunal — schema_validator.js${RESET}`);
213
+ console.log(`Project: ${projectRoot}`);
214
+
215
+ const ormType = typeArg !== "auto" ? typeArg : detectOrm(projectRoot);
216
+ if (!ormType && !fileArg) {
217
+ skip("No schema files detected — skipping validation");
218
+ process.exit(0);
219
+ }
220
+
221
+ let issuesCount = 0;
222
+
223
+ if (fileArg) {
224
+ header(`Validating: ${fileArg}`);
225
+ const filepath = path.isAbsolute(fileArg) ? fileArg : path.join(projectRoot, fileArg);
226
+ let issues = [];
227
+ if (filepath.endsWith(".prisma")) issues = validatePrisma(filepath);
228
+ else if (filepath.endsWith(".sql")) issues = validateSqlMigration(filepath);
229
+ else {
230
+ skip(`Unknown schema file type: ${fileArg}`);
231
+ process.exit(0);
232
+ }
233
+
234
+ for (const [severity, message, line] of issues) {
235
+ if (severity === "error") { fail(`L${line}: ${message}`); issuesCount++; }
236
+ else if (severity === "warn") { warn(`L${line}: ${message}`); issuesCount++; }
237
+ else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
238
+ }
239
+ } else if (ormType === "prisma") {
240
+ const schemaPath = path.join(projectRoot, "prisma", "schema.prisma");
241
+ if (fs.existsSync(schemaPath)) {
242
+ header("Prisma Schema Validation");
243
+ const issues = validatePrisma(schemaPath);
244
+ for (const [severity, message, line] of issues) {
245
+ if (severity === "error") { fail(`L${line}: ${message}`); issuesCount++; }
246
+ else if (severity === "warn") { warn(`L${line}: ${message}`); issuesCount++; }
247
+ else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
248
+ }
249
+ } else {
250
+ skip(`Prisma schema not found at ${schemaPath}`);
251
+ }
252
+ } else if (ormType === "sql") {
253
+ header("SQL Migration Validation");
254
+ // Very basic recursion for migrations dir
255
+ function findMigrations(dir) {
256
+ let res = [];
257
+ try {
258
+ const items = fs.readdirSync(dir, { withFileTypes: true });
259
+ for (const item of items) {
260
+ if (item.isDirectory() && !["node_modules", ".git"].includes(item.name)) {
261
+ if (item.name === "migrations") {
262
+ const sqls = fs.readdirSync(path.join(dir, item.name)).filter(f => f.endsWith(".sql")).map(f => path.join(dir, item.name, f));
263
+ res.push(...sqls);
264
+ } else {
265
+ res.push(...findMigrations(path.join(dir, item.name)));
266
+ }
267
+ }
268
+ }
269
+ } catch {}
270
+ return res;
271
+ }
272
+
273
+ const mFiles = findMigrations(projectRoot).sort();
274
+ for (const sqlFile of mFiles) {
275
+ console.log(`\n 📄 ${path.basename(sqlFile)}`);
276
+ const issues = validateSqlMigration(sqlFile);
277
+ for (const [severity, message, line] of issues) {
278
+ if (severity === "error") { fail(` L${line}: ${message}`); issuesCount++; }
279
+ else if (severity === "warn") { warn(` L${line}: ${message}`); issuesCount++; }
280
+ else console.log(` ${BLUE}ℹ️ L${line}: ${message}${RESET}`);
281
+ }
282
+ }
283
+ } else if (ormType === "drizzle") {
284
+ header("Drizzle Schema");
285
+ skip("Drizzle validation not yet implemented — validate manually");
286
+ }
287
+
288
+ console.log(`\n${BOLD}━━━ Schema Validation Summary ━━━${RESET}`);
289
+ if (issuesCount === 0) ok("No schema issues found");
290
+ else warn(`${issuesCount} issue(s) found — review above`);
291
+
292
+ process.exit(0);
293
+ }
294
+
295
+ if (require.main === module) {
296
+ main();
297
+ }