@codexa/cli 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/architect.ts +896 -0
- package/commands/check.ts +131 -0
- package/commands/clear.ts +174 -0
- package/commands/decide.ts +249 -0
- package/commands/discover.ts +1000 -0
- package/commands/knowledge.ts +362 -0
- package/commands/patterns.ts +621 -0
- package/commands/plan.ts +376 -0
- package/commands/product.ts +628 -0
- package/commands/research.ts +754 -0
- package/commands/review.ts +463 -0
- package/commands/standards.ts +224 -0
- package/commands/task.ts +624 -0
- package/commands/utils.ts +1021 -0
- package/db/connection.ts +32 -0
- package/db/schema.ts +788 -0
- package/detectors/README.md +110 -0
- package/detectors/dotnet.ts +358 -0
- package/detectors/flutter.ts +351 -0
- package/detectors/go.ts +325 -0
- package/detectors/index.ts +388 -0
- package/detectors/jvm.ts +434 -0
- package/detectors/loader.ts +141 -0
- package/detectors/node.ts +494 -0
- package/detectors/python.ts +424 -0
- package/detectors/rust.ts +349 -0
- package/gates/standards-validator.ts +205 -0
- package/gates/validator.ts +441 -0
- package/package.json +43 -0
- package/protocol/process-return.ts +451 -0
- package/protocol/subagent-protocol.ts +412 -0
- package/workflow.ts +801 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rust Ecosystem Detector
|
|
3
|
+
*
|
|
4
|
+
* Detects Rust projects including:
|
|
5
|
+
* - Frameworks: Actix-web, Axum, Rocket, Warp, Tide
|
|
6
|
+
* - ORMs: Diesel, SeaORM, SQLx
|
|
7
|
+
* - Testing: built-in, proptest, criterion
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { join } from "path";
|
|
11
|
+
import {
|
|
12
|
+
registerDetector,
|
|
13
|
+
Detector,
|
|
14
|
+
DetectorResult,
|
|
15
|
+
DetectedTechnology,
|
|
16
|
+
fileExists,
|
|
17
|
+
dirExists,
|
|
18
|
+
findFiles,
|
|
19
|
+
readText,
|
|
20
|
+
parseToml,
|
|
21
|
+
} from "./index";
|
|
22
|
+
|
|
23
|
+
interface CargoToml {
|
|
24
|
+
package?: {
|
|
25
|
+
name?: string;
|
|
26
|
+
version?: string;
|
|
27
|
+
edition?: string;
|
|
28
|
+
};
|
|
29
|
+
dependencies?: Record<string, any>;
|
|
30
|
+
"dev-dependencies"?: Record<string, any>;
|
|
31
|
+
"build-dependencies"?: Record<string, any>;
|
|
32
|
+
workspace?: {
|
|
33
|
+
members?: string[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseCargoToml(content: string): CargoToml {
|
|
38
|
+
return parseToml(content) as CargoToml;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const rustDetector: Detector = {
|
|
42
|
+
name: "rust",
|
|
43
|
+
ecosystem: "rust",
|
|
44
|
+
priority: 75,
|
|
45
|
+
markers: [
|
|
46
|
+
{ type: "file", pattern: "Cargo.toml", weight: 1.0 },
|
|
47
|
+
{ type: "file", pattern: "Cargo.lock", weight: 0.9 },
|
|
48
|
+
{ type: "file", pattern: "rust-toolchain.toml", weight: 0.8 },
|
|
49
|
+
{ type: "file", pattern: "rust-toolchain", weight: 0.8 },
|
|
50
|
+
{ type: "glob", pattern: "**/*.rs", weight: 0.7 },
|
|
51
|
+
{ type: "directory", pattern: "src", weight: 0.4 },
|
|
52
|
+
{ type: "directory", pattern: "target", weight: 0.3 },
|
|
53
|
+
],
|
|
54
|
+
|
|
55
|
+
async detect(cwd: string): Promise<DetectorResult | null> {
|
|
56
|
+
const technologies: DetectedTechnology[] = [];
|
|
57
|
+
const structure: Record<string, string> = {};
|
|
58
|
+
const configFiles: string[] = [];
|
|
59
|
+
|
|
60
|
+
// Check for Cargo.toml
|
|
61
|
+
const cargoPath = join(cwd, "Cargo.toml");
|
|
62
|
+
if (!fileExists(cargoPath)) {
|
|
63
|
+
// Check for Rust files without Cargo.toml
|
|
64
|
+
const rsFiles = findFiles(cwd, "**/*.rs");
|
|
65
|
+
if (rsFiles.length === 0) return null;
|
|
66
|
+
|
|
67
|
+
technologies.push({
|
|
68
|
+
name: "Rust",
|
|
69
|
+
confidence: 0.6,
|
|
70
|
+
source: "*.rs files (no Cargo.toml)",
|
|
71
|
+
category: "runtime",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return { ecosystem: "rust", technologies, structure, configFiles };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
configFiles.push("Cargo.toml");
|
|
78
|
+
if (fileExists(join(cwd, "Cargo.lock"))) configFiles.push("Cargo.lock");
|
|
79
|
+
if (fileExists(join(cwd, "rust-toolchain.toml"))) configFiles.push("rust-toolchain.toml");
|
|
80
|
+
|
|
81
|
+
const cargoContent = readText(cargoPath);
|
|
82
|
+
if (!cargoContent) return null;
|
|
83
|
+
|
|
84
|
+
const cargo = parseCargoToml(cargoContent);
|
|
85
|
+
|
|
86
|
+
// Add Rust runtime
|
|
87
|
+
technologies.push({
|
|
88
|
+
name: "Rust",
|
|
89
|
+
version: cargo.package?.edition ? `Edition ${cargo.package.edition}` : undefined,
|
|
90
|
+
confidence: 1.0,
|
|
91
|
+
source: "Cargo.toml",
|
|
92
|
+
category: "runtime",
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Check for workspace
|
|
96
|
+
if (cargo.workspace?.members) {
|
|
97
|
+
technologies.push({
|
|
98
|
+
name: "Cargo Workspace",
|
|
99
|
+
confidence: 1.0,
|
|
100
|
+
source: "Cargo.toml [workspace]",
|
|
101
|
+
category: "build",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Collect all dependencies
|
|
106
|
+
const allDeps = new Map<string, any>();
|
|
107
|
+
const addDeps = (deps: Record<string, any> | undefined) => {
|
|
108
|
+
if (!deps) return;
|
|
109
|
+
for (const [name, value] of Object.entries(deps)) {
|
|
110
|
+
allDeps.set(name, value);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
addDeps(cargo.dependencies);
|
|
115
|
+
addDeps(cargo["dev-dependencies"]);
|
|
116
|
+
addDeps(cargo["build-dependencies"]);
|
|
117
|
+
|
|
118
|
+
// Web Framework Detection
|
|
119
|
+
const webFrameworks = [
|
|
120
|
+
{ deps: ["actix-web"], name: "Actix Web", confidence: 1.0 },
|
|
121
|
+
{ deps: ["axum"], name: "Axum", confidence: 1.0 },
|
|
122
|
+
{ deps: ["rocket"], name: "Rocket", confidence: 1.0 },
|
|
123
|
+
{ deps: ["warp"], name: "Warp", confidence: 1.0 },
|
|
124
|
+
{ deps: ["tide"], name: "Tide", confidence: 1.0 },
|
|
125
|
+
{ deps: ["hyper"], name: "Hyper", confidence: 0.85 },
|
|
126
|
+
{ deps: ["poem"], name: "Poem", confidence: 1.0 },
|
|
127
|
+
{ deps: ["salvo"], name: "Salvo", confidence: 1.0 },
|
|
128
|
+
{ deps: ["ntex"], name: "Ntex", confidence: 1.0 },
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
for (const fw of webFrameworks) {
|
|
132
|
+
const found = fw.deps.find(d => allDeps.has(d));
|
|
133
|
+
if (found) {
|
|
134
|
+
const depValue = allDeps.get(found);
|
|
135
|
+
const version = typeof depValue === "string" ? depValue : depValue?.version;
|
|
136
|
+
technologies.push({
|
|
137
|
+
name: fw.name,
|
|
138
|
+
version,
|
|
139
|
+
confidence: fw.confidence,
|
|
140
|
+
source: `Dependency: ${found}`,
|
|
141
|
+
category: "backend",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ORM/Database Library Detection
|
|
147
|
+
const orms = [
|
|
148
|
+
{ deps: ["diesel"], name: "Diesel", confidence: 1.0 },
|
|
149
|
+
{ deps: ["sea-orm"], name: "SeaORM", confidence: 1.0 },
|
|
150
|
+
{ deps: ["sqlx"], name: "SQLx", confidence: 1.0 },
|
|
151
|
+
{ deps: ["rbatis"], name: "Rbatis", confidence: 1.0 },
|
|
152
|
+
{ deps: ["rusqlite"], name: "rusqlite", confidence: 0.9 },
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
for (const orm of orms) {
|
|
156
|
+
const found = orm.deps.find(d => allDeps.has(d));
|
|
157
|
+
if (found) {
|
|
158
|
+
const depValue = allDeps.get(found);
|
|
159
|
+
const version = typeof depValue === "string" ? depValue : depValue?.version;
|
|
160
|
+
technologies.push({
|
|
161
|
+
name: orm.name,
|
|
162
|
+
version,
|
|
163
|
+
confidence: orm.confidence,
|
|
164
|
+
source: `Dependency: ${found}`,
|
|
165
|
+
category: "orm",
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Database Drivers
|
|
171
|
+
const dbDrivers = [
|
|
172
|
+
{ deps: ["tokio-postgres", "postgres"], name: "PostgreSQL", confidence: 0.9 },
|
|
173
|
+
{ deps: ["mysql", "mysql_async"], name: "MySQL", confidence: 0.9 },
|
|
174
|
+
{ deps: ["mongodb"], name: "MongoDB", confidence: 0.9 },
|
|
175
|
+
{ deps: ["redis"], name: "Redis", confidence: 0.9 },
|
|
176
|
+
{ deps: ["elasticsearch"], name: "Elasticsearch", confidence: 0.9 },
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
const detectedDbs = new Set<string>();
|
|
180
|
+
for (const db of dbDrivers) {
|
|
181
|
+
const found = db.deps.find(d => allDeps.has(d));
|
|
182
|
+
if (found && !detectedDbs.has(db.name)) {
|
|
183
|
+
technologies.push({
|
|
184
|
+
name: db.name,
|
|
185
|
+
confidence: db.confidence,
|
|
186
|
+
source: `Dependency: ${found}`,
|
|
187
|
+
category: "database",
|
|
188
|
+
});
|
|
189
|
+
detectedDbs.add(db.name);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Async Runtime
|
|
194
|
+
const asyncRuntimes = [
|
|
195
|
+
{ deps: ["tokio"], name: "Tokio", confidence: 1.0 },
|
|
196
|
+
{ deps: ["async-std"], name: "async-std", confidence: 1.0 },
|
|
197
|
+
{ deps: ["smol"], name: "Smol", confidence: 1.0 },
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
for (const runtime of asyncRuntimes) {
|
|
201
|
+
const found = runtime.deps.find(d => allDeps.has(d));
|
|
202
|
+
if (found) {
|
|
203
|
+
technologies.push({
|
|
204
|
+
name: runtime.name,
|
|
205
|
+
confidence: runtime.confidence,
|
|
206
|
+
source: `Dependency: ${found}`,
|
|
207
|
+
category: "runtime",
|
|
208
|
+
metadata: { type: "async-runtime" },
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Serialization
|
|
214
|
+
const serializationLibs = [
|
|
215
|
+
{ deps: ["serde", "serde_json"], name: "Serde", confidence: 0.95 },
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
for (const lib of serializationLibs) {
|
|
219
|
+
const found = lib.deps.find(d => allDeps.has(d));
|
|
220
|
+
if (found) {
|
|
221
|
+
technologies.push({
|
|
222
|
+
name: lib.name,
|
|
223
|
+
confidence: lib.confidence,
|
|
224
|
+
source: `Dependency: ${found}`,
|
|
225
|
+
category: "backend",
|
|
226
|
+
metadata: { type: "serialization" },
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Testing Tools
|
|
232
|
+
const testingTools = [
|
|
233
|
+
{ deps: ["proptest"], name: "Proptest", confidence: 1.0 },
|
|
234
|
+
{ deps: ["quickcheck"], name: "QuickCheck", confidence: 1.0 },
|
|
235
|
+
{ deps: ["criterion"], name: "Criterion (Benchmarks)", confidence: 1.0 },
|
|
236
|
+
{ deps: ["mockall"], name: "Mockall", confidence: 1.0 },
|
|
237
|
+
{ deps: ["rstest"], name: "rstest", confidence: 1.0 },
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
for (const test of testingTools) {
|
|
241
|
+
const found = test.deps.find(d => allDeps.has(d));
|
|
242
|
+
if (found) {
|
|
243
|
+
technologies.push({
|
|
244
|
+
name: test.name,
|
|
245
|
+
confidence: test.confidence,
|
|
246
|
+
source: `Dependency: ${found}`,
|
|
247
|
+
category: "testing",
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// CLI/DevTools
|
|
253
|
+
const devTools = [
|
|
254
|
+
{ deps: ["clap"], name: "Clap CLI", confidence: 0.9 },
|
|
255
|
+
{ deps: ["structopt"], name: "StructOpt CLI", confidence: 0.9 },
|
|
256
|
+
{ deps: ["tracing"], name: "Tracing", confidence: 0.9 },
|
|
257
|
+
{ deps: ["log", "env_logger"], name: "log", confidence: 0.85 },
|
|
258
|
+
{ deps: ["config"], name: "config-rs", confidence: 0.9 },
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
for (const tool of devTools) {
|
|
262
|
+
const found = tool.deps.find(d => allDeps.has(d));
|
|
263
|
+
if (found) {
|
|
264
|
+
technologies.push({
|
|
265
|
+
name: tool.name,
|
|
266
|
+
confidence: tool.confidence,
|
|
267
|
+
source: `Dependency: ${found}`,
|
|
268
|
+
category: "devops",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// WASM Support
|
|
274
|
+
if (allDeps.has("wasm-bindgen") || allDeps.has("wasm-pack")) {
|
|
275
|
+
technologies.push({
|
|
276
|
+
name: "WebAssembly",
|
|
277
|
+
confidence: 1.0,
|
|
278
|
+
source: "wasm-bindgen/wasm-pack dependency",
|
|
279
|
+
category: "frontend",
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Embedded/Systems
|
|
284
|
+
if (allDeps.has("embedded-hal") || allDeps.has("cortex-m")) {
|
|
285
|
+
technologies.push({
|
|
286
|
+
name: "Embedded Systems",
|
|
287
|
+
confidence: 1.0,
|
|
288
|
+
source: "embedded-hal/cortex-m dependency",
|
|
289
|
+
category: "backend",
|
|
290
|
+
metadata: { type: "embedded" },
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Structure detection
|
|
295
|
+
const structurePaths = [
|
|
296
|
+
{ key: "src", paths: ["src"] },
|
|
297
|
+
{ key: "api", paths: ["src/api", "src/routes", "src/handlers"] },
|
|
298
|
+
{ key: "models", paths: ["src/models", "src/domain", "src/entities"] },
|
|
299
|
+
{ key: "services", paths: ["src/services", "src/service"] },
|
|
300
|
+
{ key: "repository", paths: ["src/repository", "src/db", "src/repos"] },
|
|
301
|
+
{ key: "config", paths: ["src/config", "config"] },
|
|
302
|
+
{ key: "migrations", paths: ["migrations", "src/migrations"] },
|
|
303
|
+
{ key: "tests", paths: ["tests"] },
|
|
304
|
+
{ key: "benches", paths: ["benches"] },
|
|
305
|
+
{ key: "examples", paths: ["examples"] },
|
|
306
|
+
];
|
|
307
|
+
|
|
308
|
+
for (const { key, paths } of structurePaths) {
|
|
309
|
+
for (const p of paths) {
|
|
310
|
+
if (dirExists(join(cwd, p))) {
|
|
311
|
+
structure[key] = p;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Config files
|
|
318
|
+
const configPatterns = [
|
|
319
|
+
".cargo/config.toml",
|
|
320
|
+
"clippy.toml",
|
|
321
|
+
".clippy.toml",
|
|
322
|
+
"rustfmt.toml",
|
|
323
|
+
".rustfmt.toml",
|
|
324
|
+
"deny.toml",
|
|
325
|
+
"Makefile",
|
|
326
|
+
"Makefile.toml",
|
|
327
|
+
"Dockerfile",
|
|
328
|
+
"docker-compose.yml",
|
|
329
|
+
];
|
|
330
|
+
|
|
331
|
+
for (const pattern of configPatterns) {
|
|
332
|
+
if (fileExists(join(cwd, pattern))) {
|
|
333
|
+
configFiles.push(pattern);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return {
|
|
338
|
+
ecosystem: "rust",
|
|
339
|
+
technologies,
|
|
340
|
+
structure,
|
|
341
|
+
configFiles: [...new Set(configFiles)],
|
|
342
|
+
};
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// Register the detector
|
|
347
|
+
registerDetector(rustDetector);
|
|
348
|
+
|
|
349
|
+
export default rustDetector;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { getDb } from "../db/connection";
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { basename, extname } from "path";
|
|
4
|
+
|
|
5
|
+
interface Violation {
|
|
6
|
+
file: string;
|
|
7
|
+
rule: string;
|
|
8
|
+
category: string;
|
|
9
|
+
enforcement: string;
|
|
10
|
+
detail?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ValidationResult {
|
|
14
|
+
passed: boolean;
|
|
15
|
+
violations: Violation[];
|
|
16
|
+
warnings: Violation[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function validateAgainstStandards(
|
|
20
|
+
files: string[],
|
|
21
|
+
agentDomain: string
|
|
22
|
+
): ValidationResult {
|
|
23
|
+
const db = getDb();
|
|
24
|
+
const violations: Violation[] = [];
|
|
25
|
+
const warnings: Violation[] = [];
|
|
26
|
+
|
|
27
|
+
// Buscar standards aplicáveis
|
|
28
|
+
const standards = db
|
|
29
|
+
.query(
|
|
30
|
+
`SELECT * FROM standards
|
|
31
|
+
WHERE (scope = 'all' OR scope = ?)
|
|
32
|
+
ORDER BY enforcement DESC, category`
|
|
33
|
+
)
|
|
34
|
+
.all(agentDomain) as any[];
|
|
35
|
+
|
|
36
|
+
if (standards.length === 0) {
|
|
37
|
+
return { passed: true, violations: [], warnings: [] };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
if (!existsSync(file)) continue;
|
|
42
|
+
|
|
43
|
+
let content: string;
|
|
44
|
+
try {
|
|
45
|
+
content = readFileSync(file, "utf-8");
|
|
46
|
+
} catch {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const fileName = basename(file);
|
|
51
|
+
const ext = extname(file);
|
|
52
|
+
|
|
53
|
+
for (const std of standards) {
|
|
54
|
+
let violated = false;
|
|
55
|
+
let detail: string | undefined;
|
|
56
|
+
|
|
57
|
+
// Validações por categoria
|
|
58
|
+
switch (std.category) {
|
|
59
|
+
case "naming":
|
|
60
|
+
// Validar PascalCase para componentes React/Next
|
|
61
|
+
if (std.rule.toLowerCase().includes("pascalcase") && (ext === ".tsx" || ext === ".jsx")) {
|
|
62
|
+
const nameWithoutExt = fileName.replace(ext, "");
|
|
63
|
+
// Ignorar arquivos especiais (page, layout, loading, etc.)
|
|
64
|
+
const specialFiles = ["page", "layout", "loading", "error", "not-found", "template", "default"];
|
|
65
|
+
if (!specialFiles.includes(nameWithoutExt)) {
|
|
66
|
+
violated = !/^[A-Z][a-zA-Z0-9]*$/.test(nameWithoutExt);
|
|
67
|
+
if (violated) {
|
|
68
|
+
detail = `"${fileName}" deveria ser PascalCase (ex: ${nameWithoutExt.charAt(0).toUpperCase() + nameWithoutExt.slice(1)}.tsx)`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Validar camelCase para hooks
|
|
74
|
+
if (std.rule.toLowerCase().includes("use") && std.rule.toLowerCase().includes("hook")) {
|
|
75
|
+
if (fileName.includes("use") || fileName.includes("Use")) {
|
|
76
|
+
violated = !/^use[A-Z][a-zA-Z0-9]*\.ts$/.test(fileName);
|
|
77
|
+
if (violated) {
|
|
78
|
+
detail = `Hook "${fileName}" deveria seguir padrao useXxx.ts`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case "code":
|
|
85
|
+
// Validar Server Components (sem "use client" desnecessário)
|
|
86
|
+
if (std.rule.toLowerCase().includes("server component")) {
|
|
87
|
+
// Se está em app/ e não é um componente interativo, não deveria ter "use client"
|
|
88
|
+
if (file.includes("/app/") && !file.includes("/components/")) {
|
|
89
|
+
const hasUseClient = content.includes('"use client"') || content.includes("'use client'");
|
|
90
|
+
const hasInteractiveCode =
|
|
91
|
+
content.includes("useState") ||
|
|
92
|
+
content.includes("useEffect") ||
|
|
93
|
+
content.includes("onClick") ||
|
|
94
|
+
content.includes("onChange");
|
|
95
|
+
|
|
96
|
+
if (hasUseClient && !hasInteractiveCode) {
|
|
97
|
+
violated = true;
|
|
98
|
+
detail = `Arquivo tem "use client" mas nao usa hooks ou eventos interativos`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Validar uso de @ alias
|
|
104
|
+
if (std.rule.toLowerCase().includes("@") && std.rule.toLowerCase().includes("alias")) {
|
|
105
|
+
// Verificar imports relativos profundos
|
|
106
|
+
const deepRelativeImport = /from ['"]\.\.\/\.\.\/\.\.\//;
|
|
107
|
+
if (deepRelativeImport.test(content)) {
|
|
108
|
+
violated = true;
|
|
109
|
+
detail = `Imports relativos profundos (../../..) deveriam usar @ alias`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
case "structure":
|
|
115
|
+
// Validar pasta de componentes
|
|
116
|
+
if (std.rule.toLowerCase().includes("component") && (ext === ".tsx" || ext === ".jsx")) {
|
|
117
|
+
const isComponent = /^[A-Z]/.test(fileName) && !file.includes("/app/");
|
|
118
|
+
if (isComponent && !file.includes("/components/")) {
|
|
119
|
+
violated = true;
|
|
120
|
+
detail = `Componente "${fileName}" deveria estar em /components/`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case "library":
|
|
126
|
+
// Validar anti-exemplos (bibliotecas proibidas)
|
|
127
|
+
const antiExamples = std.anti_examples ? JSON.parse(std.anti_examples) : [];
|
|
128
|
+
for (const anti of antiExamples) {
|
|
129
|
+
if (content.includes(anti)) {
|
|
130
|
+
violated = true;
|
|
131
|
+
detail = `Uso de "${anti}" nao permitido. ${std.rule}`;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
case "practice":
|
|
138
|
+
// Validar práticas obrigatórias
|
|
139
|
+
if (std.rule.toLowerCase().includes("zod") && std.rule.toLowerCase().includes("valid")) {
|
|
140
|
+
// Se arquivo define tipos/interfaces com Props, deveria usar Zod
|
|
141
|
+
const hasPropsInterface = /interface\s+\w*Props\b/.test(content);
|
|
142
|
+
const hasPropsType = /type\s+\w*Props\s*=/.test(content);
|
|
143
|
+
const usesZod = content.includes("z.") || content.includes("from 'zod'") || content.includes('from "zod"');
|
|
144
|
+
|
|
145
|
+
if ((hasPropsInterface || hasPropsType) && !usesZod && file.includes("/components/")) {
|
|
146
|
+
// Isso é mais um warning do que violation
|
|
147
|
+
if (std.enforcement === "required") {
|
|
148
|
+
violated = true;
|
|
149
|
+
detail = `Componente define Props mas nao usa Zod para validacao`;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (violated) {
|
|
157
|
+
const violation: Violation = {
|
|
158
|
+
file,
|
|
159
|
+
rule: std.rule,
|
|
160
|
+
category: std.category,
|
|
161
|
+
enforcement: std.enforcement,
|
|
162
|
+
detail,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (std.enforcement === "required") {
|
|
166
|
+
violations.push(violation);
|
|
167
|
+
} else {
|
|
168
|
+
warnings.push(violation);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
passed: violations.length === 0,
|
|
176
|
+
violations,
|
|
177
|
+
warnings,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function printValidationResult(result: ValidationResult): void {
|
|
182
|
+
if (result.violations.length > 0) {
|
|
183
|
+
console.error("\n⛔ VIOLACOES DE STANDARDS (required):\n");
|
|
184
|
+
for (const v of result.violations) {
|
|
185
|
+
console.error(` [${v.category}] ${basename(v.file)}`);
|
|
186
|
+
console.error(` Regra: ${v.rule}`);
|
|
187
|
+
if (v.detail) {
|
|
188
|
+
console.error(` Detalhe: ${v.detail}`);
|
|
189
|
+
}
|
|
190
|
+
console.error();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (result.warnings.length > 0) {
|
|
195
|
+
console.warn("\n⚠ AVISOS (recommended):\n");
|
|
196
|
+
for (const w of result.warnings) {
|
|
197
|
+
console.warn(` [${w.category}] ${basename(w.file)}`);
|
|
198
|
+
console.warn(` Regra: ${w.rule}`);
|
|
199
|
+
if (w.detail) {
|
|
200
|
+
console.warn(` Detalhe: ${w.detail}`);
|
|
201
|
+
}
|
|
202
|
+
console.warn();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|