@paths.design/caws-cli 4.0.0 → 4.1.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/dist/commands/archive.d.ts +50 -0
- package/dist/commands/archive.d.ts.map +1 -0
- package/dist/commands/archive.js +353 -0
- package/dist/commands/iterate.d.ts.map +1 -1
- package/dist/commands/iterate.js +12 -13
- package/dist/commands/mode.d.ts +24 -0
- package/dist/commands/mode.d.ts.map +1 -0
- package/dist/commands/mode.js +259 -0
- package/dist/commands/plan.d.ts +49 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +448 -0
- package/dist/commands/quality-gates.d.ts +52 -0
- package/dist/commands/quality-gates.d.ts.map +1 -0
- package/dist/commands/quality-gates.js +490 -0
- package/dist/commands/specs.d.ts +71 -0
- package/dist/commands/specs.d.ts.map +1 -0
- package/dist/commands/specs.js +735 -0
- package/dist/commands/status.d.ts +4 -3
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +552 -22
- package/dist/commands/tutorial.d.ts +55 -0
- package/dist/commands/tutorial.d.ts.map +1 -0
- package/dist/commands/tutorial.js +481 -0
- package/dist/commands/validate.d.ts +10 -3
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +137 -54
- package/dist/config/modes.d.ts +225 -0
- package/dist/config/modes.d.ts.map +1 -0
- package/dist/config/modes.js +321 -0
- package/dist/constants/spec-types.d.ts +41 -0
- package/dist/constants/spec-types.d.ts.map +1 -0
- package/dist/constants/spec-types.js +42 -0
- package/dist/index-new.d.ts +5 -0
- package/dist/index-new.d.ts.map +1 -0
- package/dist/index-new.js +317 -0
- package/dist/index.js +225 -10
- package/dist/index.js.backup +4711 -0
- package/dist/scaffold/git-hooks.d.ts.map +1 -1
- package/dist/scaffold/git-hooks.js +32 -44
- package/dist/scaffold/index.d.ts.map +1 -1
- package/dist/scaffold/index.js +19 -0
- package/dist/utils/quality-gates-errors.js +520 -0
- package/dist/utils/quality-gates.d.ts +49 -0
- package/dist/utils/quality-gates.d.ts.map +1 -0
- package/dist/utils/quality-gates.js +361 -0
- package/dist/utils/spec-resolver.d.ts +88 -0
- package/dist/utils/spec-resolver.d.ts.map +1 -0
- package/dist/utils/spec-resolver.js +602 -0
- package/package.json +6 -5
- package/templates/.cursor/hooks/caws-scope-guard.sh +64 -8
- package/templates/.cursor/hooks/validate-spec.sh +22 -12
- package/templates/.cursor/rules/{01-claims-verification.mdc → 00-claims-verification.mdc} +1 -1
- package/templates/.cursor/rules/01-working-style.mdc +50 -0
- package/templates/.cursor/rules/{02-testing-standards.mdc → 02-quality-gates.mdc} +84 -29
- package/templates/.cursor/rules/03-naming-and-refactor.mdc +33 -0
- package/templates/.cursor/rules/04-logging-language-style.mdc +23 -0
- package/templates/.cursor/rules/05-safe-defaults-guards.mdc +23 -0
- package/templates/.cursor/rules/06-typescript-conventions.mdc +36 -0
- package/templates/.cursor/rules/07-process-ops.mdc +20 -0
- package/templates/.cursor/rules/08-solid-and-architecture.mdc +16 -0
- package/templates/.cursor/rules/09-docstrings.mdc +89 -0
- package/templates/.cursor/rules/10-authorship-and-attribution.mdc +15 -0
- package/templates/.cursor/rules/11-documentation-quality-standards.mdc +390 -0
- package/templates/.cursor/rules/12-scope-management-waivers.mdc +385 -0
- package/templates/.cursor/rules/13-implementation-completeness.mdc +516 -0
- package/templates/.cursor/rules/14-language-agnostic-standards.mdc +588 -0
- package/templates/.cursor/rules/15-sophisticated-todo-detection.mdc +425 -0
- package/templates/.cursor/rules/README.md +93 -7
- package/templates/apps/tools/caws/prompt-lint.js.backup +274 -0
- package/templates/apps/tools/caws/provenance.js.backup +73 -0
- package/templates/scripts/quality-gates/check-god-objects.js +146 -0
- package/templates/scripts/quality-gates/run-quality-gates.js +50 -0
- package/templates/scripts/v3/analysis/todo_analyzer.py +1950 -0
- package/templates/.cursor/rules/03-infrastructure-standards.mdc +0 -251
- package/templates/.cursor/rules/04-documentation-integrity.mdc +0 -291
- package/templates/.cursor/rules/05-production-readiness-checklist.mdc +0 -214
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview CAWS Prompt Linter
|
|
5
|
+
* Validates prompts for secrets and ensures tool allowlist compliance
|
|
6
|
+
* @author @darianrosebrook
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Common secret patterns to detect
|
|
13
|
+
*/
|
|
14
|
+
const SECRET_PATTERNS = [
|
|
15
|
+
// API Keys
|
|
16
|
+
/api[_-]?key[_-]?token\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
17
|
+
/x-api-key\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
18
|
+
/authorization\s*[=:]\s*['"]?(Bearer\s+)?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
19
|
+
|
|
20
|
+
// Tokens
|
|
21
|
+
/token\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
22
|
+
/access[_-]?token\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
23
|
+
/refresh[_-]?token\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
24
|
+
/auth[_-]?token\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
25
|
+
|
|
26
|
+
// Passwords
|
|
27
|
+
/password\s*[=:]\s*['"]?([a-zA-Z0-9_-]{8,})['"]?/gi,
|
|
28
|
+
/passwd\s*[=:]\s*['"]?([a-zA-Z0-9_-]{8,})['"]?/gi,
|
|
29
|
+
/pwd\s*[=:]\s*['"]?([a-zA-Z0-9_-]{8,})['"]?/gi,
|
|
30
|
+
|
|
31
|
+
// Secrets
|
|
32
|
+
/secret\s*[=:]\s*['"]?([a-zA-Z0-9_-]{16,})['"]?/gi,
|
|
33
|
+
/private[_-]?key\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi,
|
|
34
|
+
|
|
35
|
+
// Environment variables that might contain secrets
|
|
36
|
+
/process\.env\.[A-Z_]+_KEY/gi,
|
|
37
|
+
/process\.env\.[A-Z_]+_TOKEN/gi,
|
|
38
|
+
/process\.env\.[A-Z_]+_SECRET/gi,
|
|
39
|
+
/process\.env\.[A-Z_]+_PASSWORD/gi,
|
|
40
|
+
|
|
41
|
+
// URLs with potential secrets
|
|
42
|
+
/https?:\/\/[^/]*@[^/]+/gi,
|
|
43
|
+
|
|
44
|
+
// Base64 encoded strings that might be secrets
|
|
45
|
+
/[A-Za-z0-9+/=]{40,}/g,
|
|
46
|
+
|
|
47
|
+
// AWS keys
|
|
48
|
+
/AKIA[A-Z0-9]{16}/gi,
|
|
49
|
+
|
|
50
|
+
// GitHub tokens
|
|
51
|
+
/ghp_[A-Za-z0-9]{36}/gi,
|
|
52
|
+
/github_pat_[A-Za-z0-9]{22}/gi,
|
|
53
|
+
|
|
54
|
+
// Slack tokens
|
|
55
|
+
/xoxb-[0-9]+-[0-9]+-[0-9]+-[a-zA-Z0-9]+/gi,
|
|
56
|
+
|
|
57
|
+
// Database connection strings
|
|
58
|
+
/mongodb(\+srv)?:\/\/[^:]+:[^@]+@[^/]+/gi,
|
|
59
|
+
/postgres:\/\/[^:]+:[^@]+@[^/]+/gi,
|
|
60
|
+
/mysql:\/\/[^:]+:[^@]+@[^/]+/gi,
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Scan file for potential secrets
|
|
65
|
+
* @param {string} filePath - Path to file to scan
|
|
66
|
+
* @returns {Array} Array of potential secret matches
|
|
67
|
+
*/
|
|
68
|
+
function scanForSecrets(filePath) {
|
|
69
|
+
try {
|
|
70
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
71
|
+
const matches = [];
|
|
72
|
+
|
|
73
|
+
for (const pattern of SECRET_PATTERNS) {
|
|
74
|
+
const patternMatches = [...content.matchAll(pattern)];
|
|
75
|
+
for (const match of patternMatches) {
|
|
76
|
+
matches.push({
|
|
77
|
+
file: filePath,
|
|
78
|
+
line: content.substring(0, match.index).split("\n").length,
|
|
79
|
+
pattern: pattern.toString(),
|
|
80
|
+
match: match[0],
|
|
81
|
+
severity: "high",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return matches;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error(`❌ Error scanning ${filePath}:`, error.message);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Validate tools against allowlist
|
|
95
|
+
* @param {Array} tools - Tools used in prompts
|
|
96
|
+
* @param {Array} allowlist - Allowed tools
|
|
97
|
+
* @returns {Array} Array of violations
|
|
98
|
+
*/
|
|
99
|
+
function validateToolAllowlist(tools, allowlist) {
|
|
100
|
+
const violations = [];
|
|
101
|
+
|
|
102
|
+
for (const tool of tools) {
|
|
103
|
+
if (!allowlist.includes(tool)) {
|
|
104
|
+
violations.push({
|
|
105
|
+
tool,
|
|
106
|
+
severity: "high",
|
|
107
|
+
message: `Tool "${tool}" not in allowlist`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return violations;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Extract tools from prompt content
|
|
117
|
+
* @param {string} content - Prompt content
|
|
118
|
+
* @returns {Array} Array of tools mentioned
|
|
119
|
+
*/
|
|
120
|
+
function extractTools(content) {
|
|
121
|
+
const tools = [];
|
|
122
|
+
|
|
123
|
+
// Common tool patterns
|
|
124
|
+
const toolPatterns = [
|
|
125
|
+
/using\s+(node|npm|yarn|pnpm|git|docker|kubectl|aws|azure|gcloud)/gi,
|
|
126
|
+
/(node|npm|yarn|pnpm|git|docker|kubectl|aws|azure|gcloud)\s+command/gi,
|
|
127
|
+
/execute\s+(node|npm|yarn|pnpm|git|docker|kubectl|aws|azure|gcloud)/gi,
|
|
128
|
+
/run\s+(node|npm|yarn|pnpm|git|docker|kubectl|aws|azure|gcloud)/gi,
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
for (const pattern of toolPatterns) {
|
|
132
|
+
const matches = [...content.matchAll(pattern)];
|
|
133
|
+
for (const match of matches) {
|
|
134
|
+
const tool = match[1] || match[0];
|
|
135
|
+
if (!tools.includes(tool)) {
|
|
136
|
+
tools.push(tool);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return tools;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Lint prompts for security and compliance
|
|
146
|
+
* @param {Array} promptFiles - Array of prompt file paths
|
|
147
|
+
* @param {Array} allowlist - Allowed tools
|
|
148
|
+
* @returns {Object} Lint results
|
|
149
|
+
*/
|
|
150
|
+
function lintPrompts(promptFiles, allowlist) {
|
|
151
|
+
const results = {
|
|
152
|
+
secrets: [],
|
|
153
|
+
violations: [],
|
|
154
|
+
cleanFiles: 0,
|
|
155
|
+
totalFiles: promptFiles.length,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
for (const file of promptFiles) {
|
|
159
|
+
if (!fs.existsSync(file)) {
|
|
160
|
+
console.warn(`⚠️ Prompt file not found: ${file}`);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Scan for secrets
|
|
165
|
+
const secretMatches = scanForSecrets(file);
|
|
166
|
+
results.secrets.push(...secretMatches);
|
|
167
|
+
|
|
168
|
+
// Extract and validate tools
|
|
169
|
+
const content = fs.readFileSync(file, "utf8");
|
|
170
|
+
const tools = extractTools(content);
|
|
171
|
+
const toolViolations = validateToolAllowlist(tools, allowlist);
|
|
172
|
+
results.violations.push(...toolViolations.map((v) => ({ ...v, file })));
|
|
173
|
+
|
|
174
|
+
// Check if file is clean
|
|
175
|
+
if (secretMatches.length === 0 && toolViolations.length === 0) {
|
|
176
|
+
results.cleanFiles++;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return results;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Load tool allowlist from file
|
|
185
|
+
* @param {string} allowlistPath - Path to allowlist file
|
|
186
|
+
* @returns {Array} Array of allowed tools
|
|
187
|
+
*/
|
|
188
|
+
function loadAllowlist(allowlistPath) {
|
|
189
|
+
try {
|
|
190
|
+
if (!fs.existsSync(allowlistPath)) {
|
|
191
|
+
console.warn(`⚠️ Allowlist file not found: ${allowlistPath}`);
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const content = fs.readFileSync(allowlistPath, "utf8");
|
|
196
|
+
return JSON.parse(content);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error(`❌ Error loading allowlist:`, error.message);
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// CLI interface
|
|
204
|
+
if (require.main === module) {
|
|
205
|
+
const promptFiles = process.argv.slice(2);
|
|
206
|
+
const allowlistArg = process.argv
|
|
207
|
+
.find((arg) => arg.startsWith("--allowlist="))
|
|
208
|
+
?.split("=")[1];
|
|
209
|
+
const allowlistPath = allowlistArg || ".agent/tools-allow.json";
|
|
210
|
+
|
|
211
|
+
if (promptFiles.length === 0) {
|
|
212
|
+
console.log("CAWS Prompt Linter");
|
|
213
|
+
console.log(
|
|
214
|
+
"Usage: node prompt-lint.js <prompt-file1> [prompt-file2] ... [options]"
|
|
215
|
+
);
|
|
216
|
+
console.log("Options:");
|
|
217
|
+
console.log(
|
|
218
|
+
" --allowlist=<path> Path to tools allowlist file (default: .agent/tools-allow.json)"
|
|
219
|
+
);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Load allowlist
|
|
224
|
+
const allowlist = loadAllowlist(allowlistPath);
|
|
225
|
+
|
|
226
|
+
console.log("🔍 Linting prompts for security and compliance...");
|
|
227
|
+
console.log(`📁 Allowlist loaded: ${allowlist.length} tools`);
|
|
228
|
+
console.log(`📄 Scanning ${promptFiles.length} files...`);
|
|
229
|
+
|
|
230
|
+
// Lint prompts
|
|
231
|
+
const results = lintPrompts(promptFiles, allowlist);
|
|
232
|
+
|
|
233
|
+
// Report results
|
|
234
|
+
if (results.secrets.length > 0) {
|
|
235
|
+
console.log("\n🚨 POTENTIAL SECRETS DETECTED:");
|
|
236
|
+
results.secrets.forEach((secret, index) => {
|
|
237
|
+
console.log(
|
|
238
|
+
` ${index + 1}. ${secret.file}:${
|
|
239
|
+
secret.line
|
|
240
|
+
} - ${secret.match.substring(0, 50)}...`
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (results.violations.length > 0) {
|
|
246
|
+
console.log("\n⚠️ TOOL VIOLATIONS:");
|
|
247
|
+
results.violations.forEach((violation, index) => {
|
|
248
|
+
console.log(` ${index + 1}. ${violation.file} - ${violation.message}`);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
console.log("\n📊 SUMMARY:");
|
|
253
|
+
console.log(` - Files scanned: ${results.totalFiles}`);
|
|
254
|
+
console.log(` - Clean files: ${results.cleanFiles}`);
|
|
255
|
+
console.log(` - Secrets found: ${results.secrets.length}`);
|
|
256
|
+
console.log(` - Violations: ${results.violations.length}`);
|
|
257
|
+
|
|
258
|
+
// Exit with error if issues found
|
|
259
|
+
if (results.secrets.length > 0 || results.violations.length > 0) {
|
|
260
|
+
console.log("\n❌ Linting failed - security issues detected");
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
console.log("✅ All prompts passed security checks");
|
|
265
|
+
process.exit(0);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
module.exports = {
|
|
269
|
+
scanForSecrets,
|
|
270
|
+
validateToolAllowlist,
|
|
271
|
+
extractTools,
|
|
272
|
+
lintPrompts,
|
|
273
|
+
loadAllowlist,
|
|
274
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview CAWS Provenance Tracker - Real Implementation
|
|
5
|
+
* @author @darianrosebrook
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const crypto = require('crypto');
|
|
11
|
+
const { execSync } = require('child_process');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate comprehensive provenance data for CAWS operations
|
|
15
|
+
* @param {Object} options - Configuration options
|
|
16
|
+
* @returns {Object} Complete provenance record
|
|
17
|
+
*/
|
|
18
|
+
function generateProvenance(options = {}) {
|
|
19
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
// Agent and model information
|
|
23
|
+
agent: options.agent || 'caws-cli',
|
|
24
|
+
model: options.model || 'cli-interactive',
|
|
25
|
+
model_hash: options.modelHash || generateModelHash(),
|
|
26
|
+
|
|
27
|
+
// Tool and security information
|
|
28
|
+
tool_allowlist: options.toolAllowlist || generateToolAllowlist(projectRoot),
|
|
29
|
+
prompts: options.prompts || [],
|
|
30
|
+
|
|
31
|
+
// Git and version control information
|
|
32
|
+
commit: getCurrentCommit(projectRoot),
|
|
33
|
+
branch: getCurrentBranch(projectRoot),
|
|
34
|
+
repository: getRepositoryInfo(projectRoot),
|
|
35
|
+
|
|
36
|
+
// File and artifact information
|
|
37
|
+
artifacts: generateArtifactList(projectRoot),
|
|
38
|
+
dependencies: generateDependencyInfo(projectRoot),
|
|
39
|
+
|
|
40
|
+
// Execution results and metadata
|
|
41
|
+
results: options.results || {},
|
|
42
|
+
approvals: options.approvals || [],
|
|
43
|
+
execution_context: generateExecutionContext(),
|
|
44
|
+
|
|
45
|
+
// Security and integrity
|
|
46
|
+
integrity: generateIntegrityInfo(),
|
|
47
|
+
|
|
48
|
+
// Timestamps and versioning
|
|
49
|
+
timestamp: new Date().toISOString(),
|
|
50
|
+
version: require(path.join(projectRoot, 'package.json')).version || '1.0.0',
|
|
51
|
+
provenance_hash: generateProvenanceHash(),
|
|
52
|
+
|
|
53
|
+
// Build and deployment information
|
|
54
|
+
build_info: generateBuildInfo(projectRoot),
|
|
55
|
+
|
|
56
|
+
// Change tracking
|
|
57
|
+
change_summary: generateChangeSummary(projectRoot),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Mock provenance saving
|
|
62
|
+
function saveProvenance(provenance, filepath) {
|
|
63
|
+
const dir = path.dirname(filepath);
|
|
64
|
+
if (!fs.existsSync(dir)) {
|
|
65
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
66
|
+
}
|
|
67
|
+
fs.writeFileSync(filepath, JSON.stringify(provenance, null, 2));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
generateProvenance,
|
|
72
|
+
saveProvenance,
|
|
73
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* God Object Detector
|
|
5
|
+
*
|
|
6
|
+
* Checks for god objects (large files) in staged files only.
|
|
7
|
+
* This script is automatically generated by CAWS scaffold.
|
|
8
|
+
*
|
|
9
|
+
* @author @darianrosebrook
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { execSync } = require('child_process');
|
|
15
|
+
|
|
16
|
+
// Configuration
|
|
17
|
+
const CONFIG = {
|
|
18
|
+
godObjectThresholds: {
|
|
19
|
+
warning: 1750,
|
|
20
|
+
critical: 2000,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Collect staged Rust files only
|
|
25
|
+
function collectStagedRustFiles() {
|
|
26
|
+
try {
|
|
27
|
+
// Get staged files
|
|
28
|
+
const stagedFiles = execSync("git diff --cached --name-only", {
|
|
29
|
+
encoding: "utf8",
|
|
30
|
+
})
|
|
31
|
+
.trim()
|
|
32
|
+
.split("\n")
|
|
33
|
+
.filter((file) => file.trim() !== "");
|
|
34
|
+
|
|
35
|
+
// Filter for Rust files
|
|
36
|
+
const rustFiles = stagedFiles.filter((file) => file.endsWith(".rs"));
|
|
37
|
+
|
|
38
|
+
// Convert to absolute paths
|
|
39
|
+
const RUST_FILES = [];
|
|
40
|
+
for (const file of rustFiles) {
|
|
41
|
+
const fullPath = path.resolve(file);
|
|
42
|
+
if (fs.existsSync(fullPath)) {
|
|
43
|
+
RUST_FILES.push(fullPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.log(`📁 Found ${rustFiles.length} staged Rust files to check`);
|
|
48
|
+
return RUST_FILES;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.warn(`⚠️ Could not get staged files: ${error.message}`);
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Check for god objects
|
|
56
|
+
function checkGodObjects() {
|
|
57
|
+
const RUST_FILES = collectStagedRustFiles();
|
|
58
|
+
|
|
59
|
+
if (RUST_FILES.length === 0) {
|
|
60
|
+
console.log("✅ No staged Rust files to check for god objects");
|
|
61
|
+
return { violations: [], warnings: [] };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const violations = [];
|
|
65
|
+
const warnings = [];
|
|
66
|
+
|
|
67
|
+
for (const filePath of RUST_FILES) {
|
|
68
|
+
try {
|
|
69
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
70
|
+
const lineCount = content.split('\n').length;
|
|
71
|
+
const relativePath = path.relative(process.cwd(), filePath);
|
|
72
|
+
|
|
73
|
+
if (lineCount >= CONFIG.godObjectThresholds.critical) {
|
|
74
|
+
violations.push({
|
|
75
|
+
file: relativePath,
|
|
76
|
+
lines: lineCount,
|
|
77
|
+
message: `CRITICAL: ${lineCount} LOC exceeds god object threshold (${CONFIG.godObjectThresholds.critical}+ LOC)`
|
|
78
|
+
});
|
|
79
|
+
} else if (lineCount >= CONFIG.godObjectThresholds.warning) {
|
|
80
|
+
warnings.push({
|
|
81
|
+
file: relativePath,
|
|
82
|
+
lines: lineCount,
|
|
83
|
+
message: `WARNING: ${lineCount} LOC approaches god object territory (${CONFIG.godObjectThresholds.warning}+ LOC)`
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.warn(`⚠️ Could not analyze ${filePath}: ${error.message}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return { violations, warnings };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Check for god object regression
|
|
95
|
+
function checkGodObjectRegression() {
|
|
96
|
+
const RUST_FILES = collectStagedRustFiles();
|
|
97
|
+
|
|
98
|
+
if (RUST_FILES.length === 0) {
|
|
99
|
+
return { regression: false };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// This is a simplified check - in a real implementation,
|
|
103
|
+
// you might want to compare against previous commits
|
|
104
|
+
const results = checkGodObjects();
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
regression: results.violations.length > 0,
|
|
108
|
+
violations: results.violations,
|
|
109
|
+
warnings: results.warnings
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Main execution
|
|
114
|
+
function main() {
|
|
115
|
+
console.log("🏗️ Checking god objects...");
|
|
116
|
+
|
|
117
|
+
const results = checkGodObjects();
|
|
118
|
+
|
|
119
|
+
if (results.violations.length > 0) {
|
|
120
|
+
console.log(" ❌ God object violations detected:");
|
|
121
|
+
results.violations.forEach(violation => {
|
|
122
|
+
console.log(` ${violation.file}: ${violation.message}`);
|
|
123
|
+
});
|
|
124
|
+
process.exit(1);
|
|
125
|
+
} else {
|
|
126
|
+
console.log(" ✅ No blocking god object violations");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (results.warnings.length > 0) {
|
|
130
|
+
console.log(" ⚠️ God object warnings:");
|
|
131
|
+
results.warnings.forEach(warning => {
|
|
132
|
+
console.log(` ${warning.file}: ${warning.message}`);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Run if called directly
|
|
138
|
+
if (require.main === module) {
|
|
139
|
+
main();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
module.exports = {
|
|
143
|
+
checkGodObjects,
|
|
144
|
+
checkGodObjectRegression,
|
|
145
|
+
collectStagedRustFiles,
|
|
146
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Quality Gates Runner
|
|
5
|
+
*
|
|
6
|
+
* Runs comprehensive quality gates on staged files only.
|
|
7
|
+
* This script is automatically generated by CAWS scaffold.
|
|
8
|
+
*
|
|
9
|
+
* @author @darianrosebrook
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { runQualityGates } = require('@paths.design/caws-cli/src/utils/quality-gates');
|
|
13
|
+
|
|
14
|
+
// Parse command line arguments
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const options = {
|
|
17
|
+
languages: ['rust'],
|
|
18
|
+
checkTodos: true,
|
|
19
|
+
checkGodObjects: true,
|
|
20
|
+
ci: args.includes('--ci') || args.includes('--ci-mode')
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Extract languages from arguments
|
|
24
|
+
const langIndex = args.indexOf('--languages');
|
|
25
|
+
if (langIndex !== -1 && args[langIndex + 1]) {
|
|
26
|
+
options.languages = args[langIndex + 1].split(',').map(lang => lang.trim());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check for disable flags
|
|
30
|
+
if (args.includes('--no-todos')) {
|
|
31
|
+
options.checkTodos = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (args.includes('--no-god-objects')) {
|
|
35
|
+
options.checkGodObjects = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Run quality gates
|
|
39
|
+
try {
|
|
40
|
+
const results = runQualityGates(options);
|
|
41
|
+
|
|
42
|
+
if (!results.passed && options.ci) {
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(`❌ Quality gates failed: ${error.message}`);
|
|
47
|
+
if (options.ci) {
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|