@paths.design/caws-cli 7.0.2 → 7.0.3
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/budget-derivation.js +5 -4
- package/dist/commands/diagnose.js +24 -19
- package/dist/commands/init.js +51 -4
- package/dist/commands/specs.js +40 -1
- package/dist/commands/status.js +2 -2
- package/dist/commands/tool.js +2 -3
- package/dist/config/index.js +17 -8
- package/dist/generators/working-spec.js +19 -6
- package/dist/scaffold/git-hooks.js +127 -29
- package/dist/scaffold/index.js +53 -7
- package/dist/templates/.caws/tools/README.md +20 -0
- package/dist/templates/.cursor/README.md +311 -0
- package/dist/templates/.cursor/hooks/audit.sh +55 -0
- package/dist/templates/.cursor/hooks/block-dangerous.sh +83 -0
- package/dist/templates/.cursor/hooks/caws-quality-check.sh +52 -0
- package/dist/templates/.cursor/hooks/caws-scope-guard.sh +130 -0
- package/dist/templates/.cursor/hooks/caws-tool-validation.sh +121 -0
- package/dist/templates/.cursor/hooks/format.sh +38 -0
- package/dist/templates/.cursor/hooks/naming-check.sh +64 -0
- package/dist/templates/.cursor/hooks/scan-secrets.sh +46 -0
- package/dist/templates/.cursor/hooks/scope-guard.sh +52 -0
- package/dist/templates/.cursor/hooks/validate-spec.sh +83 -0
- package/dist/templates/.cursor/hooks.json +59 -0
- package/dist/templates/.cursor/rules/00-claims-verification.mdc +144 -0
- package/dist/templates/.cursor/rules/01-working-style.mdc +50 -0
- package/dist/templates/.cursor/rules/02-quality-gates.mdc +370 -0
- package/dist/templates/.cursor/rules/03-naming-and-refactor.mdc +33 -0
- package/dist/templates/.cursor/rules/04-logging-language-style.mdc +23 -0
- package/dist/templates/.cursor/rules/05-safe-defaults-guards.mdc +23 -0
- package/dist/templates/.cursor/rules/06-typescript-conventions.mdc +36 -0
- package/dist/templates/.cursor/rules/07-process-ops.mdc +20 -0
- package/dist/templates/.cursor/rules/08-solid-and-architecture.mdc +16 -0
- package/dist/templates/.cursor/rules/09-docstrings.mdc +89 -0
- package/dist/templates/.cursor/rules/10-documentation-quality-standards.mdc +390 -0
- package/dist/templates/.cursor/rules/11-scope-management-waivers.mdc +385 -0
- package/dist/templates/.cursor/rules/12-implementation-completeness.mdc +516 -0
- package/dist/templates/.cursor/rules/13-language-agnostic-standards.mdc +588 -0
- package/dist/templates/.cursor/rules/README.md +148 -0
- package/dist/templates/.github/copilot/instructions.md +311 -0
- package/dist/templates/.idea/runConfigurations/CAWS_Evaluate.xml +5 -0
- package/dist/templates/.idea/runConfigurations/CAWS_Validate.xml +5 -0
- package/dist/templates/.vscode/launch.json +56 -0
- package/dist/templates/.vscode/settings.json +93 -0
- package/dist/templates/.windsurf/workflows/caws-guided-development.md +92 -0
- package/dist/templates/COMMIT_CONVENTIONS.md +86 -0
- package/dist/templates/OIDC_SETUP.md +300 -0
- package/dist/templates/agents.md +1047 -0
- package/dist/templates/codemod/README.md +1 -0
- package/dist/templates/codemod/test.js +93 -0
- package/dist/templates/docs/README.md +150 -0
- package/dist/templates/scripts/quality-gates/check-god-objects.js +146 -0
- package/dist/templates/scripts/quality-gates/run-quality-gates.js +50 -0
- package/dist/templates/scripts/v3/analysis/todo_analyzer.py +1997 -0
- package/dist/tool-loader.js +6 -1
- package/dist/tool-validator.js +8 -2
- package/dist/utils/detection.js +4 -3
- package/dist/utils/git-lock.js +118 -0
- package/dist/utils/gitignore-updater.js +148 -0
- package/dist/utils/quality-gates.js +47 -7
- package/dist/utils/spec-resolver.js +23 -3
- package/dist/utils/yaml-validation.js +155 -0
- package/dist/validation/spec-validation.js +81 -2
- package/package.json +2 -2
- package/templates/.caws/schemas/waivers.schema.json +30 -0
- package/templates/.caws/schemas/working-spec.schema.json +133 -0
- package/templates/.caws/templates/working-spec.template.yml +74 -0
- package/templates/.caws/tools/README.md +20 -0
- package/templates/.caws/tools/scope-guard.js +208 -0
- package/templates/.caws/tools-allow.json +331 -0
- package/templates/.caws/waivers.yml +19 -0
- package/templates/.cursor/hooks/scope-guard.sh +2 -2
- package/templates/.cursor/hooks/validate-spec.sh +42 -7
- package/templates/apps/tools/caws/COMPLETION_REPORT.md +0 -331
- package/templates/apps/tools/caws/MIGRATION_SUMMARY.md +0 -360
- package/templates/apps/tools/caws/README.md +0 -463
- package/templates/apps/tools/caws/TEST_STATUS.md +0 -365
- package/templates/apps/tools/caws/attest.js +0 -357
- package/templates/apps/tools/caws/ci-optimizer.js +0 -642
- package/templates/apps/tools/caws/config.ts +0 -245
- package/templates/apps/tools/caws/cross-functional.js +0 -876
- package/templates/apps/tools/caws/dashboard.js +0 -1112
- package/templates/apps/tools/caws/flake-detector.ts +0 -362
- package/templates/apps/tools/caws/gates.js +0 -198
- package/templates/apps/tools/caws/gates.ts +0 -271
- package/templates/apps/tools/caws/language-adapters.ts +0 -381
- package/templates/apps/tools/caws/language-support.d.ts +0 -367
- package/templates/apps/tools/caws/language-support.d.ts.map +0 -1
- package/templates/apps/tools/caws/language-support.js +0 -585
- package/templates/apps/tools/caws/legacy-assessment.ts +0 -408
- package/templates/apps/tools/caws/legacy-assessor.js +0 -764
- package/templates/apps/tools/caws/mutant-analyzer.js +0 -734
- package/templates/apps/tools/caws/perf-budgets.ts +0 -349
- package/templates/apps/tools/caws/prompt-lint.js.backup +0 -274
- package/templates/apps/tools/caws/property-testing.js +0 -707
- package/templates/apps/tools/caws/provenance.d.ts +0 -14
- package/templates/apps/tools/caws/provenance.d.ts.map +0 -1
- package/templates/apps/tools/caws/provenance.js +0 -132
- package/templates/apps/tools/caws/provenance.js.backup +0 -73
- package/templates/apps/tools/caws/provenance.ts +0 -211
- package/templates/apps/tools/caws/security-provenance.ts +0 -483
- package/templates/apps/tools/caws/shared/base-tool.ts +0 -281
- package/templates/apps/tools/caws/shared/config-manager.ts +0 -366
- package/templates/apps/tools/caws/shared/gate-checker.ts +0 -849
- package/templates/apps/tools/caws/shared/types.ts +0 -444
- package/templates/apps/tools/caws/shared/validator.ts +0 -305
- package/templates/apps/tools/caws/shared/waivers-manager.ts +0 -174
- package/templates/apps/tools/caws/spec-test-mapper.ts +0 -391
- package/templates/apps/tools/caws/test-quality.js +0 -578
- package/templates/apps/tools/caws/validate.js +0 -76
- package/templates/apps/tools/caws/validate.ts +0 -228
- package/templates/apps/tools/caws/waivers.js +0 -344
- /package/{templates/apps/tools/caws → dist/templates/.caws}/schemas/waivers.schema.json +0 -0
- /package/{templates/apps/tools/caws → dist/templates/.caws}/schemas/working-spec.schema.json +0 -0
- /package/{templates/apps/tools/caws → dist/templates/.caws}/templates/working-spec.template.yml +0 -0
- /package/{templates/apps/tools/caws → dist/templates/.caws/tools}/scope-guard.js +0 -0
- /package/{templates/apps/tools/caws → dist/templates/.caws}/tools-allow.json +0 -0
- /package/{templates/apps/tools/caws → dist/templates/.caws}/waivers.yml +0 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Language-agnostic engineering standards and universal code quality metrics
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Language-Agnostic Engineering Standards
|
|
8
|
+
|
|
9
|
+
## Core Principle
|
|
10
|
+
|
|
11
|
+
**Engineering standards must apply universally across all programming languages.** Focus on architectural patterns, quality metrics, and maintainability principles that transcend specific language syntax.
|
|
12
|
+
|
|
13
|
+
## Universal Code Quality Metrics
|
|
14
|
+
|
|
15
|
+
### Complexity Standards
|
|
16
|
+
|
|
17
|
+
**Cyclomatic Complexity:**
|
|
18
|
+
|
|
19
|
+
- **Maximum per function**: 10
|
|
20
|
+
- **Maximum per class/module**: 20
|
|
21
|
+
- **Critical functions**: 5 (auth, billing, data processing)
|
|
22
|
+
|
|
23
|
+
**Cognitive Complexity:**
|
|
24
|
+
|
|
25
|
+
- **Maximum per function**: 15
|
|
26
|
+
- **Maximum per class/module**: 30
|
|
27
|
+
- **UI components**: 20 (higher due to rendering logic)
|
|
28
|
+
|
|
29
|
+
**Nesting Depth:**
|
|
30
|
+
|
|
31
|
+
- **Maximum nesting levels**: 4
|
|
32
|
+
- **Preferred**: 2-3 levels with guard clauses
|
|
33
|
+
- **Exception**: Complex algorithms with documented justification
|
|
34
|
+
|
|
35
|
+
### Maintainability Standards
|
|
36
|
+
|
|
37
|
+
**Function Size:**
|
|
38
|
+
|
|
39
|
+
- **Maximum lines per function**: 50
|
|
40
|
+
- **Preferred**: 20-30 lines
|
|
41
|
+
- **Exception**: Complex algorithms with documentation
|
|
42
|
+
|
|
43
|
+
**File Size:**
|
|
44
|
+
|
|
45
|
+
- **Maximum lines per file**: 1000
|
|
46
|
+
- **Preferred**: 200-500 lines
|
|
47
|
+
- **Exception**: Generated code or data files
|
|
48
|
+
|
|
49
|
+
**Parameter Count:**
|
|
50
|
+
|
|
51
|
+
- **Maximum parameters per function**: 5
|
|
52
|
+
- **Preferred**: 2-3 parameters
|
|
53
|
+
- **Exception**: Configuration objects or builder patterns
|
|
54
|
+
|
|
55
|
+
**Class/Module Size:**
|
|
56
|
+
|
|
57
|
+
- **Maximum methods per class**: 10
|
|
58
|
+
- **Maximum fields per class**: 15
|
|
59
|
+
- **Preferred**: 5-7 methods, 8-10 fields
|
|
60
|
+
|
|
61
|
+
## Universal Architectural Patterns
|
|
62
|
+
|
|
63
|
+
### Dependency Injection
|
|
64
|
+
|
|
65
|
+
**All languages must support:**
|
|
66
|
+
|
|
67
|
+
- Constructor injection for dependencies
|
|
68
|
+
- Interface/contract-based design
|
|
69
|
+
- Testable dependency substitution
|
|
70
|
+
- Clear dependency graphs
|
|
71
|
+
|
|
72
|
+
**Implementation Examples:**
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// TypeScript/JavaScript
|
|
76
|
+
class OrderService {
|
|
77
|
+
constructor(
|
|
78
|
+
private userRepo: UserRepository,
|
|
79
|
+
private paymentService: PaymentService,
|
|
80
|
+
private notificationService: NotificationService
|
|
81
|
+
) {}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```rust
|
|
86
|
+
// Rust
|
|
87
|
+
struct OrderService {
|
|
88
|
+
user_repo: Box<dyn UserRepository>,
|
|
89
|
+
payment_service: Box<dyn PaymentService>,
|
|
90
|
+
notification_service: Box<dyn NotificationService>,
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Python
|
|
96
|
+
class OrderService:
|
|
97
|
+
def __init__(self, user_repo: UserRepository, payment_service: PaymentService):
|
|
98
|
+
self.user_repo = user_repo
|
|
99
|
+
self.payment_service = payment_service
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Error Handling Patterns
|
|
103
|
+
|
|
104
|
+
**Universal Error Handling Requirements:**
|
|
105
|
+
|
|
106
|
+
- Explicit error types (no generic exceptions)
|
|
107
|
+
- Error context preservation
|
|
108
|
+
- Graceful degradation capabilities
|
|
109
|
+
- Comprehensive error logging
|
|
110
|
+
|
|
111
|
+
**Implementation Examples:**
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// TypeScript - Result pattern
|
|
115
|
+
type Result<T, E> = { success: true; data: T } | { success: false; error: E };
|
|
116
|
+
|
|
117
|
+
async function processOrder(order: Order): Promise<Result<OrderResult, OrderError>> {
|
|
118
|
+
try {
|
|
119
|
+
const result = await validateOrder(order);
|
|
120
|
+
return { success: true, data: result };
|
|
121
|
+
} catch (error) {
|
|
122
|
+
return { success: false, error: new OrderError(error.message) };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```rust
|
|
128
|
+
// Rust - Result type
|
|
129
|
+
fn process_order(order: Order) -> Result<OrderResult, OrderError> {
|
|
130
|
+
let validated = validate_order(&order)?;
|
|
131
|
+
let result = calculate_total(&validated)?;
|
|
132
|
+
Ok(result)
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
# Python - Custom exceptions
|
|
138
|
+
class OrderError(Exception):
|
|
139
|
+
def __init__(self, message: str, context: dict = None):
|
|
140
|
+
super().__init__(message)
|
|
141
|
+
self.context = context or {}
|
|
142
|
+
|
|
143
|
+
def process_order(order: Order) -> OrderResult:
|
|
144
|
+
try:
|
|
145
|
+
validated = validate_order(order)
|
|
146
|
+
return calculate_total(validated)
|
|
147
|
+
except ValidationError as e:
|
|
148
|
+
raise OrderError(f"Order validation failed: {e}", {"order_id": order.id})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Configuration Management
|
|
152
|
+
|
|
153
|
+
**Universal Configuration Standards:**
|
|
154
|
+
|
|
155
|
+
- Environment-based configuration
|
|
156
|
+
- Type-safe configuration objects
|
|
157
|
+
- Validation of configuration values
|
|
158
|
+
- Secrets management integration
|
|
159
|
+
|
|
160
|
+
**Implementation Examples:**
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// TypeScript
|
|
164
|
+
interface Config {
|
|
165
|
+
database: {
|
|
166
|
+
host: string;
|
|
167
|
+
port: number;
|
|
168
|
+
ssl: boolean;
|
|
169
|
+
};
|
|
170
|
+
api: {
|
|
171
|
+
timeout: number;
|
|
172
|
+
retries: number;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const config: Config = {
|
|
177
|
+
database: {
|
|
178
|
+
host: process.env.DB_HOST || 'localhost',
|
|
179
|
+
port: parseInt(process.env.DB_PORT || '5432'),
|
|
180
|
+
ssl: process.env.DB_SSL === 'true',
|
|
181
|
+
},
|
|
182
|
+
api: {
|
|
183
|
+
timeout: parseInt(process.env.API_TIMEOUT || '5000'),
|
|
184
|
+
retries: parseInt(process.env.API_RETRIES || '3'),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```rust
|
|
190
|
+
// Rust
|
|
191
|
+
#[derive(Debug, Deserialize)]
|
|
192
|
+
struct Config {
|
|
193
|
+
database: DatabaseConfig,
|
|
194
|
+
api: ApiConfig,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#[derive(Debug, Deserialize)]
|
|
198
|
+
struct DatabaseConfig {
|
|
199
|
+
host: String,
|
|
200
|
+
port: u16,
|
|
201
|
+
ssl: bool,
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
impl Config {
|
|
205
|
+
fn from_env() -> Result<Self, ConfigError> {
|
|
206
|
+
let host = env::var("DB_HOST").unwrap_or_else(|_| "localhost".to_string());
|
|
207
|
+
let port = env::var("DB_PORT")
|
|
208
|
+
.unwrap_or_else(|_| "5432".to_string())
|
|
209
|
+
.parse()
|
|
210
|
+
.map_err(|_| ConfigError::InvalidPort)?;
|
|
211
|
+
|
|
212
|
+
Ok(Config {
|
|
213
|
+
database: DatabaseConfig {
|
|
214
|
+
host,
|
|
215
|
+
port,
|
|
216
|
+
ssl: env::var("DB_SSL").unwrap_or_else(|_| "false".to_string()) == "true",
|
|
217
|
+
},
|
|
218
|
+
api: ApiConfig::from_env()?,
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Universal Testing Standards
|
|
225
|
+
|
|
226
|
+
### Test Structure Requirements
|
|
227
|
+
|
|
228
|
+
**All languages must follow:**
|
|
229
|
+
|
|
230
|
+
- Given-When-Then structure
|
|
231
|
+
- Descriptive test names
|
|
232
|
+
- Independent test execution
|
|
233
|
+
- Proper setup/teardown
|
|
234
|
+
|
|
235
|
+
**Implementation Examples:**
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// TypeScript/JavaScript
|
|
239
|
+
describe('OrderService', () => {
|
|
240
|
+
describe('when processing a valid order', () => {
|
|
241
|
+
it('should return order confirmation', async () => {
|
|
242
|
+
// Given: Valid order data
|
|
243
|
+
const order = createValidOrder();
|
|
244
|
+
|
|
245
|
+
// When: Processing the order
|
|
246
|
+
const result = await orderService.processOrder(order);
|
|
247
|
+
|
|
248
|
+
// Then: Should return confirmation
|
|
249
|
+
expect(result.success).toBe(true);
|
|
250
|
+
expect(result.data.orderId).toBeDefined();
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```rust
|
|
257
|
+
// Rust
|
|
258
|
+
#[cfg(test)]
|
|
259
|
+
mod tests {
|
|
260
|
+
use super::*;
|
|
261
|
+
|
|
262
|
+
#[tokio::test]
|
|
263
|
+
async fn test_process_valid_order() {
|
|
264
|
+
// Given: Valid order data
|
|
265
|
+
let order = create_valid_order();
|
|
266
|
+
|
|
267
|
+
// When: Processing the order
|
|
268
|
+
let result = order_service.process_order(order).await;
|
|
269
|
+
|
|
270
|
+
// Then: Should return confirmation
|
|
271
|
+
assert!(result.is_ok());
|
|
272
|
+
let order_result = result.unwrap();
|
|
273
|
+
assert!(order_result.order_id.is_some());
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
# Python
|
|
280
|
+
class TestOrderService:
|
|
281
|
+
def test_process_valid_order_returns_confirmation(self):
|
|
282
|
+
# Given: Valid order data
|
|
283
|
+
order = self.create_valid_order()
|
|
284
|
+
|
|
285
|
+
# When: Processing the order
|
|
286
|
+
result = self.order_service.process_order(order)
|
|
287
|
+
|
|
288
|
+
# Then: Should return confirmation
|
|
289
|
+
assert result.success is True
|
|
290
|
+
assert result.data.order_id is not None
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Test Data Management
|
|
294
|
+
|
|
295
|
+
**Universal Requirements:**
|
|
296
|
+
|
|
297
|
+
- Realistic test data factories
|
|
298
|
+
- Deterministic test execution
|
|
299
|
+
- Proper cleanup procedures
|
|
300
|
+
- Isolated test environments
|
|
301
|
+
|
|
302
|
+
## Universal Documentation Standards
|
|
303
|
+
|
|
304
|
+
### API Documentation
|
|
305
|
+
|
|
306
|
+
**All languages must provide:**
|
|
307
|
+
|
|
308
|
+
- Function/method signatures with types
|
|
309
|
+
- Parameter descriptions and constraints
|
|
310
|
+
- Return value specifications
|
|
311
|
+
- Error conditions and exceptions
|
|
312
|
+
- Usage examples
|
|
313
|
+
|
|
314
|
+
**Implementation Examples:**
|
|
315
|
+
|
|
316
|
+
````typescript
|
|
317
|
+
/**
|
|
318
|
+
* Processes a customer order and returns confirmation details.
|
|
319
|
+
*
|
|
320
|
+
* @param order - The order to process with validated items and payment info
|
|
321
|
+
* @param options - Optional processing options for customization
|
|
322
|
+
* @returns Promise resolving to order confirmation or rejection details
|
|
323
|
+
* @throws ValidationError when order data is invalid
|
|
324
|
+
* @throws PaymentError when payment processing fails
|
|
325
|
+
* @throws InventoryError when items are unavailable
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const order = { items: [...], payment: {...} };
|
|
330
|
+
* const result = await processOrder(order);
|
|
331
|
+
* console.log(`Order ${result.orderId} confirmed`);
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
async function processOrder(order: Order, options?: ProcessingOptions): Promise<OrderResult> {
|
|
335
|
+
// Implementation
|
|
336
|
+
}
|
|
337
|
+
````
|
|
338
|
+
|
|
339
|
+
````rust
|
|
340
|
+
/// Processes a customer order and returns confirmation details.
|
|
341
|
+
///
|
|
342
|
+
/// # Arguments
|
|
343
|
+
/// * `order` - The order to process with validated items and payment info
|
|
344
|
+
/// * `options` - Optional processing options for customization
|
|
345
|
+
///
|
|
346
|
+
/// # Returns
|
|
347
|
+
/// Returns `Ok(OrderResult)` with confirmation details on success
|
|
348
|
+
///
|
|
349
|
+
/// # Errors
|
|
350
|
+
/// * `ValidationError` - When order data is invalid
|
|
351
|
+
/// * `PaymentError` - When payment processing fails
|
|
352
|
+
/// * `InventoryError` - When items are unavailable
|
|
353
|
+
///
|
|
354
|
+
/// # Examples
|
|
355
|
+
/// ```rust
|
|
356
|
+
/// let order = Order { items: vec![...], payment: PaymentInfo {...} };
|
|
357
|
+
/// let result = process_order(order).await?;
|
|
358
|
+
/// println!("Order {} confirmed", result.order_id);
|
|
359
|
+
/// ```
|
|
360
|
+
pub async fn process_order(
|
|
361
|
+
order: Order,
|
|
362
|
+
options: Option<ProcessingOptions>
|
|
363
|
+
) -> Result<OrderResult, OrderError> {
|
|
364
|
+
// Implementation
|
|
365
|
+
}
|
|
366
|
+
````
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
def process_order(order: Order, options: Optional[ProcessingOptions] = None) -> OrderResult:
|
|
370
|
+
"""Process a customer order and return confirmation details.
|
|
371
|
+
|
|
372
|
+
Args:
|
|
373
|
+
order: The order to process with validated items and payment info
|
|
374
|
+
options: Optional processing options for customization
|
|
375
|
+
|
|
376
|
+
Returns:
|
|
377
|
+
OrderResult with confirmation details
|
|
378
|
+
|
|
379
|
+
Raises:
|
|
380
|
+
ValidationError: When order data is invalid
|
|
381
|
+
PaymentError: When payment processing fails
|
|
382
|
+
InventoryError: When items are unavailable
|
|
383
|
+
|
|
384
|
+
Example:
|
|
385
|
+
>>> order = Order(items=[...], payment=PaymentInfo(...))
|
|
386
|
+
>>> result = process_order(order)
|
|
387
|
+
>>> print(f"Order {result.order_id} confirmed")
|
|
388
|
+
"""
|
|
389
|
+
# Implementation
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Universal Security Standards
|
|
393
|
+
|
|
394
|
+
### Input Validation
|
|
395
|
+
|
|
396
|
+
**All languages must implement:**
|
|
397
|
+
|
|
398
|
+
- Schema-based validation
|
|
399
|
+
- Type checking at boundaries
|
|
400
|
+
- Sanitization of user input
|
|
401
|
+
- Length and format constraints
|
|
402
|
+
|
|
403
|
+
### Authentication & Authorization
|
|
404
|
+
|
|
405
|
+
**Universal Requirements:**
|
|
406
|
+
|
|
407
|
+
- Token-based authentication
|
|
408
|
+
- Role-based access control
|
|
409
|
+
- Session management
|
|
410
|
+
- Audit logging
|
|
411
|
+
|
|
412
|
+
### Data Protection
|
|
413
|
+
|
|
414
|
+
**Universal Standards:**
|
|
415
|
+
|
|
416
|
+
- Encryption at rest and in transit
|
|
417
|
+
- Secure key management
|
|
418
|
+
- Data anonymization capabilities
|
|
419
|
+
- Privacy compliance measures
|
|
420
|
+
|
|
421
|
+
## Universal Performance Standards
|
|
422
|
+
|
|
423
|
+
### Response Time SLAs
|
|
424
|
+
|
|
425
|
+
**Universal Performance Requirements:**
|
|
426
|
+
|
|
427
|
+
- API endpoints: P95 < 250ms
|
|
428
|
+
- Database queries: P95 < 100ms
|
|
429
|
+
- File operations: P95 < 500ms
|
|
430
|
+
- Complex computations: P95 < 2000ms
|
|
431
|
+
|
|
432
|
+
### Resource Management
|
|
433
|
+
|
|
434
|
+
**Universal Resource Standards:**
|
|
435
|
+
|
|
436
|
+
- Memory usage monitoring
|
|
437
|
+
- CPU utilization limits
|
|
438
|
+
- Connection pool management
|
|
439
|
+
- Garbage collection optimization
|
|
440
|
+
|
|
441
|
+
## Universal Monitoring Standards
|
|
442
|
+
|
|
443
|
+
### Logging Requirements
|
|
444
|
+
|
|
445
|
+
**All applications must provide:**
|
|
446
|
+
|
|
447
|
+
- Structured logging (JSON format)
|
|
448
|
+
- Log levels (ERROR, WARN, INFO, DEBUG)
|
|
449
|
+
- Request correlation IDs
|
|
450
|
+
- Performance metrics
|
|
451
|
+
|
|
452
|
+
### Metrics Collection
|
|
453
|
+
|
|
454
|
+
**Universal Metrics:**
|
|
455
|
+
|
|
456
|
+
- Request/response times
|
|
457
|
+
- Error rates and types
|
|
458
|
+
- Resource utilization
|
|
459
|
+
- Business KPIs
|
|
460
|
+
|
|
461
|
+
### Health Checks
|
|
462
|
+
|
|
463
|
+
**Universal Health Endpoints:**
|
|
464
|
+
|
|
465
|
+
- Application health status
|
|
466
|
+
- Dependency health checks
|
|
467
|
+
- Resource availability
|
|
468
|
+
- Business logic validation
|
|
469
|
+
|
|
470
|
+
## CAWS Integration
|
|
471
|
+
|
|
472
|
+
### Quality Gate Integration
|
|
473
|
+
|
|
474
|
+
```bash
|
|
475
|
+
# Run complexity analysis
|
|
476
|
+
caws quality-gates --check-complexity
|
|
477
|
+
|
|
478
|
+
# Check architectural patterns
|
|
479
|
+
caws quality-gates --check-architecture
|
|
480
|
+
|
|
481
|
+
# Validate universal standards
|
|
482
|
+
caws quality-gates --check-universal-standards
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Metrics Tracking
|
|
486
|
+
|
|
487
|
+
```bash
|
|
488
|
+
# Track complexity metrics
|
|
489
|
+
caws metrics track --metric="cyclomatic_complexity" --value=8
|
|
490
|
+
|
|
491
|
+
# Track maintainability metrics
|
|
492
|
+
caws metrics track --metric="function_size" --value=25
|
|
493
|
+
|
|
494
|
+
# Track architectural compliance
|
|
495
|
+
caws metrics track --metric="dependency_injection" --value=1
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Progress Tracking
|
|
499
|
+
|
|
500
|
+
```bash
|
|
501
|
+
# Update progress with complexity compliance
|
|
502
|
+
caws progress update --criterion-id="COMPLEXITY-001" --status="completed"
|
|
503
|
+
|
|
504
|
+
# Track architectural pattern implementation
|
|
505
|
+
caws progress update --criterion-id="ARCHITECTURE-001" --status="in_progress"
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
## Enforcement Mechanisms
|
|
509
|
+
|
|
510
|
+
### Static Analysis Integration
|
|
511
|
+
|
|
512
|
+
**Universal Static Analysis:**
|
|
513
|
+
|
|
514
|
+
- Complexity analysis
|
|
515
|
+
- Dependency analysis
|
|
516
|
+
- Security vulnerability scanning
|
|
517
|
+
- Code quality metrics
|
|
518
|
+
|
|
519
|
+
### CI/CD Integration
|
|
520
|
+
|
|
521
|
+
**Universal CI/CD Requirements:**
|
|
522
|
+
|
|
523
|
+
- Automated testing
|
|
524
|
+
- Quality gate enforcement
|
|
525
|
+
- Security scanning
|
|
526
|
+
- Performance regression testing
|
|
527
|
+
|
|
528
|
+
### CAWS Quality Gates
|
|
529
|
+
|
|
530
|
+
```yaml
|
|
531
|
+
# In .caws/working-spec.yaml
|
|
532
|
+
quality_gates:
|
|
533
|
+
complexity:
|
|
534
|
+
max_cyclomatic: 10
|
|
535
|
+
max_cognitive: 15
|
|
536
|
+
max_nesting: 4
|
|
537
|
+
|
|
538
|
+
maintainability:
|
|
539
|
+
max_function_lines: 50
|
|
540
|
+
max_file_lines: 1000
|
|
541
|
+
max_parameters: 5
|
|
542
|
+
|
|
543
|
+
architecture:
|
|
544
|
+
dependency_injection: required
|
|
545
|
+
error_handling: required
|
|
546
|
+
configuration_management: required
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
## Quality Metrics Dashboard
|
|
550
|
+
|
|
551
|
+
### Universal Quality Score
|
|
552
|
+
|
|
553
|
+
**Calculation Formula:**
|
|
554
|
+
|
|
555
|
+
```
|
|
556
|
+
Quality Score = (
|
|
557
|
+
Complexity Score * 0.2 +
|
|
558
|
+
Test Coverage Score * 0.3 +
|
|
559
|
+
Security Score * 0.2 +
|
|
560
|
+
Performance Score * 0.15 +
|
|
561
|
+
Documentation Score * 0.15
|
|
562
|
+
) * 100
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
### Trend Analysis
|
|
566
|
+
|
|
567
|
+
**Track over time:**
|
|
568
|
+
|
|
569
|
+
- Quality score trends
|
|
570
|
+
- Complexity growth
|
|
571
|
+
- Test coverage changes
|
|
572
|
+
- Security vulnerability rates
|
|
573
|
+
- Performance degradation
|
|
574
|
+
|
|
575
|
+
### CAWS Integration
|
|
576
|
+
|
|
577
|
+
```bash
|
|
578
|
+
# Generate quality report
|
|
579
|
+
caws quality-report --include-complexity --include-architecture
|
|
580
|
+
|
|
581
|
+
# Track quality trends
|
|
582
|
+
caws metrics trends --metric="quality_score" --period="30d"
|
|
583
|
+
|
|
584
|
+
# Export quality metrics
|
|
585
|
+
caws metrics export --format=json --include-universal-standards
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
This rule ensures consistent engineering standards across all programming languages while respecting language-specific idioms and capabilities, fully integrated with CAWS quality gates and metrics tracking.
|