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
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v0.0.3: Tensor Types
|
|
3
|
+
*
|
|
4
|
+
* Mathematical foundation:
|
|
5
|
+
* score^(2) = v^T M v + <v, w>
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 5-dimensional complexity vector
|
|
9
|
+
*/
|
|
10
|
+
export interface Vector5D {
|
|
11
|
+
control: number;
|
|
12
|
+
nesting: number;
|
|
13
|
+
state: number;
|
|
14
|
+
async: number;
|
|
15
|
+
coupling: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Module type for context-aware analysis
|
|
19
|
+
*/
|
|
20
|
+
export type ModuleType = 'api' | 'lib' | 'app' | 'web' | 'data' | 'infra' | 'deploy' | 'unknown';
|
|
21
|
+
/**
|
|
22
|
+
* Dimension indices
|
|
23
|
+
*/
|
|
24
|
+
export declare const IDX_CONTROL = 0;
|
|
25
|
+
export declare const IDX_NESTING = 1;
|
|
26
|
+
export declare const IDX_STATE = 2;
|
|
27
|
+
export declare const IDX_ASYNC = 3;
|
|
28
|
+
export declare const IDX_COUPLING = 4;
|
|
29
|
+
/**
|
|
30
|
+
* 5x5 Interaction Matrix
|
|
31
|
+
*/
|
|
32
|
+
export type Matrix5x5 = [
|
|
33
|
+
[
|
|
34
|
+
number,
|
|
35
|
+
number,
|
|
36
|
+
number,
|
|
37
|
+
number,
|
|
38
|
+
number
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
number,
|
|
42
|
+
number,
|
|
43
|
+
number,
|
|
44
|
+
number,
|
|
45
|
+
number
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
number,
|
|
49
|
+
number,
|
|
50
|
+
number,
|
|
51
|
+
number,
|
|
52
|
+
number
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
number,
|
|
56
|
+
number,
|
|
57
|
+
number,
|
|
58
|
+
number,
|
|
59
|
+
number
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
number,
|
|
63
|
+
number,
|
|
64
|
+
number,
|
|
65
|
+
number,
|
|
66
|
+
number
|
|
67
|
+
]
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
* Tensor score result
|
|
71
|
+
*
|
|
72
|
+
* Dual-metric approach inspired by CDR (Clinical Dementia Rating):
|
|
73
|
+
* - tensorScore (CDR Global style): Algorithm-based, captures interactions
|
|
74
|
+
* - rawSum (CDR-SOB style): Simple sum, better for tracking changes
|
|
75
|
+
*/
|
|
76
|
+
export interface TensorScore {
|
|
77
|
+
/** Linear component: <v, w> */
|
|
78
|
+
linear: number;
|
|
79
|
+
/** Quadratic component: v^T M v */
|
|
80
|
+
quadratic: number;
|
|
81
|
+
/** Raw score: linear + quadratic */
|
|
82
|
+
raw: number;
|
|
83
|
+
/** Regularization term: ε‖v‖² */
|
|
84
|
+
regularization: number;
|
|
85
|
+
/** Final regularized score (CDR Global style) */
|
|
86
|
+
regularized: number;
|
|
87
|
+
/** Epsilon value used */
|
|
88
|
+
epsilon: number;
|
|
89
|
+
/** Module type used */
|
|
90
|
+
moduleType: ModuleType;
|
|
91
|
+
/** Complexity vector */
|
|
92
|
+
vector: Vector5D;
|
|
93
|
+
/** Simple sum of dimensions: C + N + S + A + Λ (CDR-SOB style) */
|
|
94
|
+
rawSum: number;
|
|
95
|
+
/** Threshold for rawSum based on canonical upper bounds */
|
|
96
|
+
rawSumThreshold: number;
|
|
97
|
+
/** rawSum / rawSumThreshold ratio (0-1 = safe, >1 = violation) */
|
|
98
|
+
rawSumRatio: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Convergence status
|
|
102
|
+
*/
|
|
103
|
+
export type ConvergenceStatus = 'safe' | 'review' | 'violation' | 'oscillating';
|
|
104
|
+
/**
|
|
105
|
+
* Convergence analysis result
|
|
106
|
+
*/
|
|
107
|
+
export interface ConvergenceAnalysis {
|
|
108
|
+
/** Current score */
|
|
109
|
+
score: number;
|
|
110
|
+
/** Threshold value */
|
|
111
|
+
threshold: number;
|
|
112
|
+
/** Epsilon value */
|
|
113
|
+
epsilon: number;
|
|
114
|
+
/** Convergence score: (score - target) / ε */
|
|
115
|
+
convergenceScore: number;
|
|
116
|
+
/** Status based on convergence score */
|
|
117
|
+
status: ConvergenceStatus;
|
|
118
|
+
/** Distance to target (threshold - ε) */
|
|
119
|
+
distanceToTarget: number;
|
|
120
|
+
/** Distance to threshold */
|
|
121
|
+
distanceToThreshold: number;
|
|
122
|
+
/** Lipschitz constant estimate */
|
|
123
|
+
lipschitzEstimate: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Hodge decomposition result
|
|
127
|
+
*
|
|
128
|
+
* H^k(Code) = ⊕_{p+q=k} H^{p,q}(Code)
|
|
129
|
+
*/
|
|
130
|
+
export interface HodgeDecomposition {
|
|
131
|
+
/** H^{2,0}: Control + Nesting (algorithmic) */
|
|
132
|
+
algorithmic: number;
|
|
133
|
+
/** H^{0,2}: State + Coupling (architectural) */
|
|
134
|
+
architectural: number;
|
|
135
|
+
/** H^{1,1}: Async (balanced/harmonic) */
|
|
136
|
+
balanced: number;
|
|
137
|
+
/** Total complexity */
|
|
138
|
+
total: number;
|
|
139
|
+
/** Balance ratio: balanced / total */
|
|
140
|
+
balanceRatio: number;
|
|
141
|
+
/** Is in harmonic state (well-balanced) */
|
|
142
|
+
isHarmonic: boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Complexity level classification
|
|
146
|
+
*/
|
|
147
|
+
export type ComplexityLevel = 'minimal' | 'low' | 'medium' | 'high' | 'extreme';
|
|
148
|
+
/**
|
|
149
|
+
* Deviation from canonical form result
|
|
150
|
+
*/
|
|
151
|
+
export interface DeviationResult {
|
|
152
|
+
/** Euclidean distance to canonical centroid */
|
|
153
|
+
euclideanDistance: number;
|
|
154
|
+
/** Mahalanobis-like distance using interaction matrix */
|
|
155
|
+
mahalanobisDistance: number;
|
|
156
|
+
/** Maximum deviation in any dimension */
|
|
157
|
+
maxDimensionDeviation: number;
|
|
158
|
+
/** Normalized deviation (0-1 scale) */
|
|
159
|
+
normalizedDeviation: number;
|
|
160
|
+
/** Whether vector is within canonical bounds */
|
|
161
|
+
isCanonical: boolean;
|
|
162
|
+
/** Whether vector is outside ALL canonical regions */
|
|
163
|
+
isOrphan: boolean;
|
|
164
|
+
/** Module type used for comparison */
|
|
165
|
+
moduleType: ModuleType;
|
|
166
|
+
/** Current vector */
|
|
167
|
+
vector: Vector5D;
|
|
168
|
+
/** Dimensions that violate canonical bounds */
|
|
169
|
+
violationDimensions: string[];
|
|
170
|
+
/** Status: canonical | deviated | orphan */
|
|
171
|
+
status: 'canonical' | 'deviated' | 'orphan';
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Refactoring recommendation
|
|
175
|
+
*/
|
|
176
|
+
export interface RefactoringRecommendation {
|
|
177
|
+
/** Dimension to address */
|
|
178
|
+
dimension: string;
|
|
179
|
+
/** Priority (1-5, higher = more urgent) */
|
|
180
|
+
priority: number;
|
|
181
|
+
/** Recommended action */
|
|
182
|
+
action: string;
|
|
183
|
+
/** Expected impact on score */
|
|
184
|
+
expectedImpact: number;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tensor/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG;;GAEG;AACH,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB;QAAC,MAAM;QAAE,MAAM;QAAE,MAAM;QAAE,MAAM;QAAE,MAAM;KAAC;IACxC;QAAC,MAAM;QAAE,MAAM;QAAE,MAAM;QAAE,MAAM;QAAE,MAAM;KAAC;IACxC;QAAC,MAAM;QAAE,MAAM;QAAE,MAAM;QAAE,MAAM;QAAE,MA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v0.0.3: Tensor Types
|
|
3
|
+
*
|
|
4
|
+
* Mathematical foundation:
|
|
5
|
+
* score^(2) = v^T M v + <v, w>
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Dimension indices
|
|
9
|
+
*/
|
|
10
|
+
export const IDX_CONTROL = 0;
|
|
11
|
+
export const IDX_NESTING = 1;
|
|
12
|
+
export const IDX_STATE = 2;
|
|
13
|
+
export const IDX_ASYNC = 3;
|
|
14
|
+
export const IDX_COUPLING = 4;
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tensor/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semantic-complexity",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-e791286c",
|
|
4
4
|
"description": "Multi-dimensional code complexity analyzer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"./gates": {
|
|
34
34
|
"types": "./dist/gates/index.d.ts",
|
|
35
35
|
"import": "./dist/gates/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./tensor": {
|
|
38
|
+
"types": "./dist/tensor/index.d.ts",
|
|
39
|
+
"import": "./dist/tensor/index.js"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"files": [
|
|
@@ -61,7 +65,7 @@
|
|
|
61
65
|
"devDependencies": {
|
|
62
66
|
"@types/node": "^22.10.2",
|
|
63
67
|
"rimraf": "^6.0.1",
|
|
64
|
-
"vitest": "^
|
|
68
|
+
"vitest": "^4.0.16"
|
|
65
69
|
},
|
|
66
70
|
"peerDependencies": {
|
|
67
71
|
"typescript": ">=5.0.0"
|