semantic-complexity 0.0.2-1895c257 → 0.0.5-e791286c
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/README.md +72 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/tensor/canonical.d.ts +53 -0
- package/dist/tensor/canonical.d.ts.map +1 -0
- package/dist/tensor/canonical.js +192 -0
- package/dist/tensor/canonical.js.map +1 -0
- package/dist/tensor/index.d.ts +22 -0
- package/dist/tensor/index.d.ts.map +1 -0
- package/dist/tensor/index.js +22 -0
- package/dist/tensor/index.js.map +1 -0
- package/dist/tensor/matrix.d.ts +62 -0
- package/dist/tensor/matrix.d.ts.map +1 -0
- package/dist/tensor/matrix.js +187 -0
- package/dist/tensor/matrix.js.map +1 -0
- package/dist/tensor/scoring.d.ts +82 -0
- package/dist/tensor/scoring.d.ts.map +1 -0
- package/dist/tensor/scoring.js +233 -0
- package/dist/tensor/scoring.js.map +1 -0
- package/dist/tensor/types.d.ts +186 -0
- package/dist/tensor/types.d.ts.map +1 -0
- package/dist/tensor/types.js +15 -0
- package/dist/tensor/types.js.map +1 -0
- package/package.json +6 -2
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# semantic-complexity
|
|
2
|
+
|
|
3
|
+
Multi-dimensional code complexity analyzer using algebraic topology and tensor analysis.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install semantic-complexity
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { analyzeSource, calculateTensorScore } from 'semantic-complexity';
|
|
15
|
+
|
|
16
|
+
const source = `
|
|
17
|
+
function example(data) {
|
|
18
|
+
if (data) {
|
|
19
|
+
for (const item of data) {
|
|
20
|
+
console.log(item);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const result = analyzeSource(source);
|
|
27
|
+
console.log(result.functions[0].complexity);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Multi-Domain Complexity**: Control, Nesting, State, Async, Coupling
|
|
33
|
+
- **2nd-Order Tensor Scoring**: `score = vᵀMv + ⟨v,w⟩ + ε‖v‖²`
|
|
34
|
+
- **8 Module Types**: api, lib, app, web, data, infra, deploy, unknown
|
|
35
|
+
- **CDR-Inspired Dual Metrics**: Tensor Score + Raw Sum
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
### Core Functions
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Analyze source code
|
|
43
|
+
analyzeSource(source: string, fileName?: string): FileAnalysisResult
|
|
44
|
+
|
|
45
|
+
// Analyze file path
|
|
46
|
+
analyzeFilePath(filePath: string): FileAnalysisResult
|
|
47
|
+
|
|
48
|
+
// Calculate tensor score
|
|
49
|
+
calculateTensorScore(result: ExtendedComplexityResult, moduleType?: ModuleType): TensorScore
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Tensor Score
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
interface TensorScore {
|
|
56
|
+
linear: number; // ⟨v,w⟩
|
|
57
|
+
quadratic: number; // vᵀMv
|
|
58
|
+
raw: number; // linear + quadratic
|
|
59
|
+
regularized: number; // raw + ε‖v‖²
|
|
60
|
+
rawSum: number; // C + N + S + A + Λ
|
|
61
|
+
rawSumThreshold: number;
|
|
62
|
+
rawSumRatio: number;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
Full documentation: [GitHub Repository](https://github.com/yscha88/semantic-complexity)
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* semantic-complexity - Multi-dimensional code complexity analyzer
|
|
2
|
+
* semantic-complexity - Multi-dimensional code complexity analyzer (v0.0.3)
|
|
3
3
|
*
|
|
4
4
|
* Core 엔진 모듈
|
|
5
|
+
*
|
|
6
|
+
* v0.0.3 Features:
|
|
7
|
+
* - Second-order tensor: score = v^T M v + <v, w>
|
|
8
|
+
* - ε-regularization for convergence
|
|
9
|
+
* - Module-type canonical profiles
|
|
10
|
+
* - Hodge decomposition of complexity space
|
|
5
11
|
*/
|
|
6
12
|
export type { SourceLocation, FunctionInfo, ParameterInfo, ComplexityResult, ComplexityDetail, ComplexityContributor, FileAnalysisResult, ImportInfo, ImportSpecifier, ExportInfo, DependencyNode, CallNode, CallEdge, AnalysisContext, ProjectInfo, AnalysisOptions, DimensionalComplexity, DimensionalWeights, ExtendedComplexityResult, } from './types.js';
|
|
7
13
|
export { DEFAULT_OPTIONS } from './types.js';
|
|
@@ -14,6 +20,11 @@ export { MODULE_TYPE_INFO, DEFAULT_META_WEIGHTS, LEVEL_RANGES, CANONICAL_PROFILE
|
|
|
14
20
|
export type { GateType, GateInfo, ViolationSeverity, Violation, DeltaAnalysis, DeltaThresholds, GateDecision, GateResult, GatePipelineResult, } from './gates/index.js';
|
|
15
21
|
export { GATE_RESPONSIBILITIES, GATE_INFO, DEFAULT_DELTA_THRESHOLDS, calculateDelta, calculateDeltaPercent, detectViolations, analyzeDelta, checkGate, runGatePipeline, createSnapshot, } from './gates/index.js';
|
|
16
22
|
export { calculateSecurity, calculateContext, calculateBehavior, toMetaDimensions, calculateMetaWeightedSum, normalizeMetaDimensions, metaDistance, addMetaDimensions, subtractMetaDimensions, ZERO_META, } from './metrics/meta.js';
|
|
23
|
+
export type { Vector5D, ModuleType as TensorModuleType, Matrix5x5, TensorScore, ConvergenceStatus as TensorConvergenceStatus, ConvergenceAnalysis, HodgeDecomposition, ComplexityLevel, DeviationResult, RefactoringRecommendation, CanonicalBounds, } from './tensor/index.js';
|
|
24
|
+
export { IDX_CONTROL, IDX_NESTING, IDX_STATE, IDX_ASYNC, IDX_COUPLING, DEFAULT_MATRIX, MODULE_MATRICES, DEFAULT_WEIGHTS, CANONICAL_5D_PROFILES, } from './tensor/index.js';
|
|
25
|
+
export { getInteractionMatrix, vectorToArray, arrayToVector, zeroVector, vectorNorm, dotProduct, quadraticForm, isPositiveSemidefinite, euclideanDistance, mahalanobisDistance, } from './tensor/index.js';
|
|
26
|
+
export { calculateTensorScore, calculateRawSum, calculateRawSumThreshold, convergenceScore, estimateLipschitz, analyzeConvergence as analyzeTensorConvergence, hodgeDecomposition, classifyComplexityLevel, recommendRefactoring, isSafe, needsReview, isViolation, } from './tensor/index.js';
|
|
27
|
+
export { getCanonicalProfile, getProfileCentroid, isWithinCanonicalBounds, getViolationDimensions, isOrphan, analyzeDeviation, findBestModuleType as findBestTensorModuleType, } from './tensor/index.js';
|
|
17
28
|
import type { FileAnalysisResult } from './types.js';
|
|
18
29
|
/**
|
|
19
30
|
* 파일 경로로 복잡도 분석
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,YAAY,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,WAAW,EACX,eAAe,EAEf,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,C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SAAa,GACpB,kBAAkB,CAGpB"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* semantic-complexity - Multi-dimensional code complexity analyzer
|
|
2
|
+
* semantic-complexity - Multi-dimensional code complexity analyzer (v0.0.3)
|
|
3
3
|
*
|
|
4
4
|
* Core 엔진 모듈
|
|
5
|
+
*
|
|
6
|
+
* v0.0.3 Features:
|
|
7
|
+
* - Second-order tensor: score = v^T M v + <v, w>
|
|
8
|
+
* - ε-regularization for convergence
|
|
9
|
+
* - Module-type canonical profiles
|
|
10
|
+
* - Hodge decomposition of complexity space
|
|
5
11
|
*/
|
|
6
12
|
export { DEFAULT_OPTIONS } from './types.js';
|
|
7
13
|
// AST
|
|
@@ -16,6 +22,14 @@ export { MODULE_TYPE_INFO, DEFAULT_META_WEIGHTS, LEVEL_RANGES, CANONICAL_PROFILE
|
|
|
16
22
|
export { GATE_RESPONSIBILITIES, GATE_INFO, DEFAULT_DELTA_THRESHOLDS, calculateDelta, calculateDeltaPercent, detectViolations, analyzeDelta, checkGate, runGatePipeline, createSnapshot, } from './gates/index.js';
|
|
17
23
|
// Meta Dimensions (v0.0.2)
|
|
18
24
|
export { calculateSecurity, calculateContext, calculateBehavior, toMetaDimensions, calculateMetaWeightedSum, normalizeMetaDimensions, metaDistance, addMetaDimensions, subtractMetaDimensions, ZERO_META, } from './metrics/meta.js';
|
|
25
|
+
// Tensor constants
|
|
26
|
+
export { IDX_CONTROL, IDX_NESTING, IDX_STATE, IDX_ASYNC, IDX_COUPLING, DEFAULT_MATRIX, MODULE_MATRICES, DEFAULT_WEIGHTS, CANONICAL_5D_PROFILES, } from './tensor/index.js';
|
|
27
|
+
// Tensor matrix operations
|
|
28
|
+
export { getInteractionMatrix, vectorToArray, arrayToVector, zeroVector, vectorNorm, dotProduct, quadraticForm, isPositiveSemidefinite, euclideanDistance, mahalanobisDistance, } from './tensor/index.js';
|
|
29
|
+
// Tensor scoring
|
|
30
|
+
export { calculateTensorScore, calculateRawSum, calculateRawSumThreshold, convergenceScore, estimateLipschitz, analyzeConvergence as analyzeTensorConvergence, hodgeDecomposition, classifyComplexityLevel, recommendRefactoring, isSafe, needsReview, isViolation, } from './tensor/index.js';
|
|
31
|
+
// Tensor canonical profiles
|
|
32
|
+
export { getCanonicalProfile, getProfileCentroid, isWithinCanonicalBounds, getViolationDimensions, isOrphan, analyzeDeviation, findBestModuleType as findBestTensorModuleType, } from './tensor/index.js';
|
|
19
33
|
// ─── Convenience Functions ───────────────────────────────────────
|
|
20
34
|
import * as fs from 'node:fs';
|
|
21
35
|
import { parseSourceFile } from './ast/index.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA0BH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM;AACN,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,UAAU;AACV,OAAO,EACL,6BAA6B,EAC7B,4BAA4B,EAC5B,eAAe,EACf,uBAAuB,EACvB,WAAW,EACX,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,QAAQ;AACR,OAAO,EACL,eAAe,EACf,SAAS,EACT,WAAW,EACX,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,UAAU;AACV,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAmBpE,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,UAAU,EACV,sBA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/C,MAAM,mBAAmB,CAAC;AAE3B,oEAAoE;AAEpE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EACd,QAAQ,GAAG,UAAU;IAErB,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Canonical Profiles and Deviation Analysis
|
|
3
|
+
*
|
|
4
|
+
* Φ: ModuleType → CanonicalProfile
|
|
5
|
+
* δ(v, Φ(τ)) = ‖v - Φ(τ)‖_M (Mahalanobis-like distance)
|
|
6
|
+
*/
|
|
7
|
+
import type { Vector5D, ModuleType, DeviationResult } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Canonical profile bounds for a module type
|
|
10
|
+
*/
|
|
11
|
+
export interface CanonicalBounds {
|
|
12
|
+
control: [number, number];
|
|
13
|
+
nesting: [number, number];
|
|
14
|
+
state: [number, number];
|
|
15
|
+
async: [number, number];
|
|
16
|
+
coupling: [number, number];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Canonical profiles per module type (based on v0.0.3 spec)
|
|
20
|
+
*/
|
|
21
|
+
export declare const CANONICAL_5D_PROFILES: Record<ModuleType, CanonicalBounds>;
|
|
22
|
+
/**
|
|
23
|
+
* Get canonical profile for module type
|
|
24
|
+
*/
|
|
25
|
+
export declare function getCanonicalProfile(moduleType: ModuleType): CanonicalBounds;
|
|
26
|
+
/**
|
|
27
|
+
* Calculate centroid of canonical profile
|
|
28
|
+
*/
|
|
29
|
+
export declare function getProfileCentroid(profile: CanonicalBounds): Vector5D;
|
|
30
|
+
/**
|
|
31
|
+
* Check if vector is within canonical bounds
|
|
32
|
+
*/
|
|
33
|
+
export declare function isWithinCanonicalBounds(vector: Vector5D, profile: CanonicalBounds): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get dimensions that violate canonical bounds
|
|
36
|
+
*/
|
|
37
|
+
export declare function getViolationDimensions(vector: Vector5D, profile: CanonicalBounds): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Check if vector is orphan (outside ALL canonical regions)
|
|
40
|
+
*/
|
|
41
|
+
export declare function isOrphan(vector: Vector5D): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Analyze deviation from canonical form
|
|
44
|
+
*/
|
|
45
|
+
export declare function analyzeDeviation(vector: Vector5D, moduleType?: ModuleType): DeviationResult;
|
|
46
|
+
/**
|
|
47
|
+
* Find the best fitting module type for a vector
|
|
48
|
+
*/
|
|
49
|
+
export declare function findBestModuleType(vector: Vector5D): {
|
|
50
|
+
type: ModuleType;
|
|
51
|
+
distance: number;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/tensor/canonical.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQxE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,UAAU,EAAE,eAAe,CAyDrE,CAAC;AAEF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAE3E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,QAAQ,CAQrE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,eAAe,GACvB,OAAO,CAQT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,eAAe,GACvB,MAAM,EAAE,CAaV;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CASlD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,QAAQ,EAChB,UAAU,GAAE,UAAsB,GACjC,eAAe,CA2CjB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAsB3F"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Canonical Profiles and Deviation Analysis
|
|
3
|
+
*
|
|
4
|
+
* Φ: ModuleType → CanonicalProfile
|
|
5
|
+
* δ(v, Φ(τ)) = ‖v - Φ(τ)‖_M (Mahalanobis-like distance)
|
|
6
|
+
*/
|
|
7
|
+
import { getInteractionMatrix, euclideanDistance, mahalanobisDistance, vectorToArray, } from './matrix.js';
|
|
8
|
+
/**
|
|
9
|
+
* Canonical profiles per module type (based on v0.0.3 spec)
|
|
10
|
+
*/
|
|
11
|
+
export const CANONICAL_5D_PROFILES = {
|
|
12
|
+
api: {
|
|
13
|
+
control: [0, 5], // low: thin controllers
|
|
14
|
+
nesting: [0, 3], // low: flat structure
|
|
15
|
+
state: [0, 2], // low: stateless preferred
|
|
16
|
+
async: [0, 3], // low: simple I/O
|
|
17
|
+
coupling: [0, 3], // low: explicit deps
|
|
18
|
+
},
|
|
19
|
+
lib: {
|
|
20
|
+
control: [0, 10], // medium: algorithmic complexity ok
|
|
21
|
+
nesting: [0, 5], // medium: some depth acceptable
|
|
22
|
+
state: [0, 2], // low: pure functions preferred
|
|
23
|
+
async: [0, 2], // low: sync preferred
|
|
24
|
+
coupling: [0, 2], // low: minimal deps
|
|
25
|
+
},
|
|
26
|
+
app: {
|
|
27
|
+
control: [0, 10], // medium: business logic
|
|
28
|
+
nesting: [0, 5], // medium: reasonable depth
|
|
29
|
+
state: [0, 8], // medium: stateful ok
|
|
30
|
+
async: [0, 8], // medium: async workflows
|
|
31
|
+
coupling: [0, 5], // low: controlled deps
|
|
32
|
+
},
|
|
33
|
+
web: {
|
|
34
|
+
control: [0, 8], // medium: UI logic
|
|
35
|
+
nesting: [0, 10], // higher: component hierarchy
|
|
36
|
+
state: [0, 5], // medium: UI state
|
|
37
|
+
async: [0, 5], // medium: data fetching
|
|
38
|
+
coupling: [0, 3], // low: component isolation
|
|
39
|
+
},
|
|
40
|
+
data: {
|
|
41
|
+
control: [0, 3], // low: simple getters/setters
|
|
42
|
+
nesting: [0, 2], // low: flat structure
|
|
43
|
+
state: [0, 10], // high: entity field definitions
|
|
44
|
+
async: [0, 2], // low: typically sync
|
|
45
|
+
coupling: [0, 5], // medium: ORM relationships
|
|
46
|
+
},
|
|
47
|
+
infra: {
|
|
48
|
+
control: [0, 5], // low: simple CRUD
|
|
49
|
+
nesting: [0, 3], // low: flat queries
|
|
50
|
+
state: [0, 2], // low: stateless data access
|
|
51
|
+
async: [0, 8], // high: DB I/O
|
|
52
|
+
coupling: [0, 8], // high: external dependencies
|
|
53
|
+
},
|
|
54
|
+
deploy: {
|
|
55
|
+
control: [0, 3], // low: simple scripts
|
|
56
|
+
nesting: [0, 2], // low: flat
|
|
57
|
+
state: [0, 2], // low: idempotent
|
|
58
|
+
async: [0, 2], // low: sequential
|
|
59
|
+
coupling: [0, 3], // low: explicit config
|
|
60
|
+
},
|
|
61
|
+
unknown: {
|
|
62
|
+
control: [0, 15], // permissive
|
|
63
|
+
nesting: [0, 10],
|
|
64
|
+
state: [0, 10],
|
|
65
|
+
async: [0, 10],
|
|
66
|
+
coupling: [0, 10],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Get canonical profile for module type
|
|
71
|
+
*/
|
|
72
|
+
export function getCanonicalProfile(moduleType) {
|
|
73
|
+
return CANONICAL_5D_PROFILES[moduleType] ?? CANONICAL_5D_PROFILES.unknown;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Calculate centroid of canonical profile
|
|
77
|
+
*/
|
|
78
|
+
export function getProfileCentroid(profile) {
|
|
79
|
+
return {
|
|
80
|
+
control: (profile.control[0] + profile.control[1]) / 2,
|
|
81
|
+
nesting: (profile.nesting[0] + profile.nesting[1]) / 2,
|
|
82
|
+
state: (profile.state[0] + profile.state[1]) / 2,
|
|
83
|
+
async: (profile.async[0] + profile.async[1]) / 2,
|
|
84
|
+
coupling: (profile.coupling[0] + profile.coupling[1]) / 2,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if vector is within canonical bounds
|
|
89
|
+
*/
|
|
90
|
+
export function isWithinCanonicalBounds(vector, profile) {
|
|
91
|
+
return (vector.control >= profile.control[0] && vector.control <= profile.control[1] &&
|
|
92
|
+
vector.nesting >= profile.nesting[0] && vector.nesting <= profile.nesting[1] &&
|
|
93
|
+
vector.state >= profile.state[0] && vector.state <= profile.state[1] &&
|
|
94
|
+
vector.async >= profile.async[0] && vector.async <= profile.async[1] &&
|
|
95
|
+
vector.coupling >= profile.coupling[0] && vector.coupling <= profile.coupling[1]);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get dimensions that violate canonical bounds
|
|
99
|
+
*/
|
|
100
|
+
export function getViolationDimensions(vector, profile) {
|
|
101
|
+
const violations = [];
|
|
102
|
+
const dims = ['control', 'nesting', 'state', 'async', 'coupling'];
|
|
103
|
+
for (const dim of dims) {
|
|
104
|
+
const value = vector[dim];
|
|
105
|
+
const [min, max] = profile[dim];
|
|
106
|
+
if (value < min || value > max) {
|
|
107
|
+
violations.push(dim);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return violations;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if vector is orphan (outside ALL canonical regions)
|
|
114
|
+
*/
|
|
115
|
+
export function isOrphan(vector) {
|
|
116
|
+
for (const moduleType of Object.keys(CANONICAL_5D_PROFILES)) {
|
|
117
|
+
if (moduleType === 'unknown')
|
|
118
|
+
continue;
|
|
119
|
+
const profile = CANONICAL_5D_PROFILES[moduleType];
|
|
120
|
+
if (isWithinCanonicalBounds(vector, profile)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Analyze deviation from canonical form
|
|
128
|
+
*/
|
|
129
|
+
export function analyzeDeviation(vector, moduleType = 'unknown') {
|
|
130
|
+
const profile = getCanonicalProfile(moduleType);
|
|
131
|
+
const centroid = getProfileCentroid(profile);
|
|
132
|
+
const matrix = getInteractionMatrix(moduleType);
|
|
133
|
+
// Calculate distances
|
|
134
|
+
const eucDist = euclideanDistance(vector, centroid);
|
|
135
|
+
const mahDist = mahalanobisDistance(vector, centroid, matrix);
|
|
136
|
+
// Max dimension deviation
|
|
137
|
+
const arr = vectorToArray(vector);
|
|
138
|
+
const centArr = vectorToArray(centroid);
|
|
139
|
+
const maxDev = Math.max(...arr.map((v, i) => Math.abs(v - centArr[i])));
|
|
140
|
+
// Normalize to 0-1 scale (assuming max reasonable deviation is 50)
|
|
141
|
+
const normDev = Math.min(1.0, mahDist / 50.0);
|
|
142
|
+
// Check canonical bounds
|
|
143
|
+
const withinBounds = isWithinCanonicalBounds(vector, profile);
|
|
144
|
+
const violations = getViolationDimensions(vector, profile);
|
|
145
|
+
const orphan = isOrphan(vector);
|
|
146
|
+
let status;
|
|
147
|
+
if (withinBounds) {
|
|
148
|
+
status = 'canonical';
|
|
149
|
+
}
|
|
150
|
+
else if (orphan) {
|
|
151
|
+
status = 'orphan';
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
status = 'deviated';
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
euclideanDistance: Math.round(eucDist * 1000) / 1000,
|
|
158
|
+
mahalanobisDistance: Math.round(mahDist * 1000) / 1000,
|
|
159
|
+
maxDimensionDeviation: Math.round(maxDev * 1000) / 1000,
|
|
160
|
+
normalizedDeviation: Math.round(normDev * 1000) / 1000,
|
|
161
|
+
isCanonical: withinBounds,
|
|
162
|
+
isOrphan: orphan,
|
|
163
|
+
moduleType,
|
|
164
|
+
vector,
|
|
165
|
+
violationDimensions: violations,
|
|
166
|
+
status,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Find the best fitting module type for a vector
|
|
171
|
+
*/
|
|
172
|
+
export function findBestModuleType(vector) {
|
|
173
|
+
let bestType = 'unknown';
|
|
174
|
+
let bestDist = Infinity;
|
|
175
|
+
for (const moduleType of Object.keys(CANONICAL_5D_PROFILES)) {
|
|
176
|
+
if (moduleType === 'unknown')
|
|
177
|
+
continue;
|
|
178
|
+
const profile = CANONICAL_5D_PROFILES[moduleType];
|
|
179
|
+
const centroid = getProfileCentroid(profile);
|
|
180
|
+
const matrix = getInteractionMatrix(moduleType);
|
|
181
|
+
const dist = mahalanobisDistance(vector, centroid, matrix);
|
|
182
|
+
if (dist < bestDist) {
|
|
183
|
+
bestDist = dist;
|
|
184
|
+
bestType = moduleType;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
type: bestType,
|
|
189
|
+
distance: Math.round(bestDist * 1000) / 1000,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/tensor/canonical.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AAarB;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAwC;IACxE,GAAG,EAAE;QACH,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAO,wBAAwB;QAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAO,sBAAsB;QAC5C,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAS,2BAA2B;QACjD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAS,kBAAkB;QACxC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAM,qBAAqB;KAC5C;IACD,GAAG,EAAE;QACH,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAM,oCAAoC;QAC1D,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAO,gCAAgC;QACtD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAS,gCAAgC;QACtD,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAS,sBAAsB;QAC5C,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAM,oBA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,MAAM;QAChB,UAAU;QACV,MAAM;QACN,mBAAmB,EAAE,UAAU;QAC/B,MAAM;KACP,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAgB;IACjD,IAAI,QAAQ,GAAe,SAAS,CAAC;IACrC,IAAI,QAAQ,GAAG,QAAQ,CAAC;IAExB,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAiB,EAAE,CAAC;QAC5E,IAAI,UAAU,KAAK,SAAS;YAAE,SAAS;QAEvC,MAAM,OAAO,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAEhD,MAAM,IAAI,GAAG,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YACpB,QAAQ,GAAG,IAAI,CAAC;YAChB,QAAQ,GAAG,UAAU,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,IAAI;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Tensor-based Complexity Analysis
|
|
3
|
+
*
|
|
4
|
+
* Second-order tensor framework for multi-dimensional code complexity.
|
|
5
|
+
*
|
|
6
|
+
* Mathematical foundation:
|
|
7
|
+
* score = v^T M v + <v, w> + ε‖v‖²
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - 5D complexity vector: [Control, Nesting, State, Async, Coupling]
|
|
11
|
+
* - Interaction matrix M for dimension cross-effects
|
|
12
|
+
* - ε-regularization for convergence guarantee
|
|
13
|
+
* - Module-type canonical profiles
|
|
14
|
+
* - Hodge decomposition of complexity space
|
|
15
|
+
*/
|
|
16
|
+
export type { Vector5D, ModuleType, Matrix5x5, TensorScore, ConvergenceStatus, ConvergenceAnalysis, HodgeDecomposition, ComplexityLevel, DeviationResult, RefactoringRecommendation, } from './types.js';
|
|
17
|
+
export { IDX_CONTROL, IDX_NESTING, IDX_STATE, IDX_ASYNC, IDX_COUPLING, } from './types.js';
|
|
18
|
+
export { DEFAULT_MATRIX, MODULE_MATRICES, getInteractionMatrix, vectorToArray, arrayToVector, zeroVector, vectorNorm, dotProduct, quadraticForm, isPositiveSemidefinite, euclideanDistance, mahalanobisDistance, } from './matrix.js';
|
|
19
|
+
export { DEFAULT_WEIGHTS, calculateTensorScore, calculateRawSum, calculateRawSumThreshold, convergenceScore, estimateLipschitz, analyzeConvergence, hodgeDecomposition, classifyComplexityLevel, recommendRefactoring, isSafe, needsReview, isViolation, } from './scoring.js';
|
|
20
|
+
export type { CanonicalBounds } from './canonical.js';
|
|
21
|
+
export { CANONICAL_5D_PROFILES, getCanonicalProfile, getProfileCentroid, isWithinCanonicalBounds, getViolationDimensions, isOrphan, analyzeDeviation, findBestModuleType, } from './canonical.js';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tensor/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,YAAY,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,EACN,WAAW,EACX,WAAW,GACZ,MAAM,cAAc,CAAC;AAGtB,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Tensor-based Complexity Analysis
|
|
3
|
+
*
|
|
4
|
+
* Second-order tensor framework for multi-dimensional code complexity.
|
|
5
|
+
*
|
|
6
|
+
* Mathematical foundation:
|
|
7
|
+
* score = v^T M v + <v, w> + ε‖v‖²
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - 5D complexity vector: [Control, Nesting, State, Async, Coupling]
|
|
11
|
+
* - Interaction matrix M for dimension cross-effects
|
|
12
|
+
* - ε-regularization for convergence guarantee
|
|
13
|
+
* - Module-type canonical profiles
|
|
14
|
+
* - Hodge decomposition of complexity space
|
|
15
|
+
*/
|
|
16
|
+
export { IDX_CONTROL, IDX_NESTING, IDX_STATE, IDX_ASYNC, IDX_COUPLING, } from './types.js';
|
|
17
|
+
// Matrix operations
|
|
18
|
+
export { DEFAULT_MATRIX, MODULE_MATRICES, getInteractionMatrix, vectorToArray, arrayToVector, zeroVector, vectorNorm, dotProduct, quadraticForm, isPositiveSemidefinite, euclideanDistance, mahalanobisDistance, } from './matrix.js';
|
|
19
|
+
// Scoring
|
|
20
|
+
export { DEFAULT_WEIGHTS, calculateTensorScore, calculateRawSum, calculateRawSumThreshold, convergenceScore, estimateLipschitz, analyzeConvergence, hodgeDecomposition, classifyComplexityLevel, recommendRefactoring, isSafe, needsReview, isViolation, } from './scoring.js';
|
|
21
|
+
export { CANONICAL_5D_PROFILES, getCanonicalProfile, getProfileCentroid, isWithinCanonicalBounds, getViolationDimensions, isOrphan, analyzeDeviation, findBestModuleType, } from './canonical.js';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tensor/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgBH,OAAO,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,oBAAoB;AACpB,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,UAAU;AACV,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,EACN,WAAW,EACX,WAAW,GACZ,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Interaction Matrix for Second-Order Tensor Analysis
|
|
3
|
+
*
|
|
4
|
+
* M[i,j] represents the interaction strength between dimensions i and j.
|
|
5
|
+
* - Diagonal: self-interaction (typically 1.0)
|
|
6
|
+
* - Off-diagonal: cross-dimension interaction
|
|
7
|
+
*/
|
|
8
|
+
import type { Matrix5x5, ModuleType, Vector5D } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Default interaction matrix (symmetric, positive semi-definite)
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_MATRIX: Matrix5x5;
|
|
13
|
+
/**
|
|
14
|
+
* Module-type specific interaction matrices
|
|
15
|
+
*/
|
|
16
|
+
export declare const MODULE_MATRICES: Record<ModuleType, Matrix5x5>;
|
|
17
|
+
/**
|
|
18
|
+
* Get interaction matrix for module type
|
|
19
|
+
*/
|
|
20
|
+
export declare function getInteractionMatrix(moduleType: ModuleType): Matrix5x5;
|
|
21
|
+
/**
|
|
22
|
+
* Convert Vector5D to array
|
|
23
|
+
*/
|
|
24
|
+
export declare function vectorToArray(v: Vector5D): number[];
|
|
25
|
+
/**
|
|
26
|
+
* Create Vector5D from array
|
|
27
|
+
*/
|
|
28
|
+
export declare function arrayToVector(arr: number[]): Vector5D;
|
|
29
|
+
/**
|
|
30
|
+
* Create zero vector
|
|
31
|
+
*/
|
|
32
|
+
export declare function zeroVector(): Vector5D;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate L2 norm of vector
|
|
35
|
+
*/
|
|
36
|
+
export declare function vectorNorm(v: Vector5D): number;
|
|
37
|
+
/**
|
|
38
|
+
* Calculate dot product of two vectors
|
|
39
|
+
*/
|
|
40
|
+
export declare function dotProduct(v1: Vector5D, v2: Vector5D): number;
|
|
41
|
+
/**
|
|
42
|
+
* Calculate quadratic form: v^T M v
|
|
43
|
+
*
|
|
44
|
+
* This captures dimension interactions.
|
|
45
|
+
*/
|
|
46
|
+
export declare function quadraticForm(v: Vector5D, matrix: Matrix5x5): number;
|
|
47
|
+
/**
|
|
48
|
+
* Check if matrix is positive semi-definite using diagonal dominance
|
|
49
|
+
* (conservative approximation)
|
|
50
|
+
*/
|
|
51
|
+
export declare function isPositiveSemidefinite(matrix: Matrix5x5): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Euclidean distance between two vectors
|
|
54
|
+
*/
|
|
55
|
+
export declare function euclideanDistance(v1: Vector5D, v2: Vector5D): number;
|
|
56
|
+
/**
|
|
57
|
+
* Mahalanobis-like distance using interaction matrix
|
|
58
|
+
*
|
|
59
|
+
* δ(v, target) = sqrt((v - target)^T M (v - target))
|
|
60
|
+
*/
|
|
61
|
+
export declare function mahalanobisDistance(v: Vector5D, target: Vector5D, matrix: Matrix5x5): number;
|
|
62
|
+
//# sourceMappingURL=matrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../../src/tensor/matrix.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAO5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,CA0DzD,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAEtE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,EAAE,CAEnD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,CAWrD;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,QAAQ,CAErC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAG9C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,MA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