@aiready/core 0.9.22 → 0.9.23

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.
@@ -0,0 +1,357 @@
1
+ // src/types/language.ts
2
+ var Language = /* @__PURE__ */ ((Language2) => {
3
+ Language2["TypeScript"] = "typescript";
4
+ Language2["JavaScript"] = "javascript";
5
+ Language2["Python"] = "python";
6
+ Language2["Java"] = "java";
7
+ Language2["Go"] = "go";
8
+ Language2["Rust"] = "rust";
9
+ Language2["CSharp"] = "csharp";
10
+ return Language2;
11
+ })(Language || {});
12
+ var LANGUAGE_EXTENSIONS = {
13
+ ".ts": "typescript" /* TypeScript */,
14
+ ".tsx": "typescript" /* TypeScript */,
15
+ ".js": "javascript" /* JavaScript */,
16
+ ".jsx": "javascript" /* JavaScript */,
17
+ ".py": "python" /* Python */,
18
+ ".java": "java" /* Java */,
19
+ ".go": "go" /* Go */,
20
+ ".rs": "rust" /* Rust */,
21
+ ".cs": "csharp" /* CSharp */
22
+ };
23
+ var ParseError = class extends Error {
24
+ constructor(message, filePath, loc) {
25
+ super(message);
26
+ this.filePath = filePath;
27
+ this.loc = loc;
28
+ this.name = "ParseError";
29
+ }
30
+ };
31
+
32
+ // src/scoring.ts
33
+ var DEFAULT_TOOL_WEIGHTS = {
34
+ "pattern-detect": 40,
35
+ "context-analyzer": 35,
36
+ "consistency": 25,
37
+ "doc-drift": 20,
38
+ "deps": 15
39
+ };
40
+ var TOOL_NAME_MAP = {
41
+ "patterns": "pattern-detect",
42
+ "context": "context-analyzer",
43
+ "consistency": "consistency",
44
+ "doc-drift": "doc-drift",
45
+ "deps": "deps"
46
+ };
47
+ function normalizeToolName(shortName) {
48
+ return TOOL_NAME_MAP[shortName] || shortName;
49
+ }
50
+ function getToolWeight(toolName, toolConfig, cliOverride) {
51
+ if (cliOverride !== void 0) {
52
+ return cliOverride;
53
+ }
54
+ if (toolConfig?.scoreWeight !== void 0) {
55
+ return toolConfig.scoreWeight;
56
+ }
57
+ return DEFAULT_TOOL_WEIGHTS[toolName] || 10;
58
+ }
59
+ function parseWeightString(weightStr) {
60
+ const weights = /* @__PURE__ */ new Map();
61
+ if (!weightStr) {
62
+ return weights;
63
+ }
64
+ const pairs = weightStr.split(",");
65
+ for (const pair of pairs) {
66
+ const [toolShortName, weightStr2] = pair.split(":");
67
+ if (toolShortName && weightStr2) {
68
+ const toolName = normalizeToolName(toolShortName.trim());
69
+ const weight = parseInt(weightStr2.trim(), 10);
70
+ if (!isNaN(weight) && weight > 0) {
71
+ weights.set(toolName, weight);
72
+ }
73
+ }
74
+ }
75
+ return weights;
76
+ }
77
+ function calculateOverallScore(toolOutputs, config, cliWeights) {
78
+ if (toolOutputs.size === 0) {
79
+ throw new Error("No tool outputs provided for scoring");
80
+ }
81
+ const weights = /* @__PURE__ */ new Map();
82
+ for (const [toolName] of toolOutputs.entries()) {
83
+ const cliWeight = cliWeights?.get(toolName);
84
+ const configWeight = config?.tools?.[toolName]?.scoreWeight;
85
+ const weight = cliWeight ?? configWeight ?? DEFAULT_TOOL_WEIGHTS[toolName] ?? 10;
86
+ weights.set(toolName, weight);
87
+ }
88
+ let weightedSum = 0;
89
+ let totalWeight = 0;
90
+ const breakdown = [];
91
+ const toolsUsed = [];
92
+ const calculationWeights = {};
93
+ for (const [toolName, output] of toolOutputs.entries()) {
94
+ const weight = weights.get(toolName) || 10;
95
+ const weightedScore = output.score * weight;
96
+ weightedSum += weightedScore;
97
+ totalWeight += weight;
98
+ toolsUsed.push(toolName);
99
+ calculationWeights[toolName] = weight;
100
+ breakdown.push(output);
101
+ }
102
+ const overall = Math.round(weightedSum / totalWeight);
103
+ const rating = getRating(overall);
104
+ const formulaParts = Array.from(toolOutputs.entries()).map(([name, output]) => {
105
+ const w = weights.get(name) || 10;
106
+ return `(${output.score} \xD7 ${w})`;
107
+ });
108
+ const formulaStr = `[${formulaParts.join(" + ")}] / ${totalWeight} = ${overall}`;
109
+ return {
110
+ overall,
111
+ rating,
112
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
113
+ toolsUsed,
114
+ breakdown,
115
+ calculation: {
116
+ formula: formulaStr,
117
+ weights: calculationWeights,
118
+ normalized: formulaStr
119
+ }
120
+ };
121
+ }
122
+ function getRating(score) {
123
+ if (score >= 90) return "Excellent";
124
+ if (score >= 75) return "Good";
125
+ if (score >= 60) return "Fair";
126
+ if (score >= 40) return "Needs Work";
127
+ return "Critical";
128
+ }
129
+ function getRatingDisplay(rating) {
130
+ switch (rating) {
131
+ case "Excellent":
132
+ return { emoji: "\u2705", color: "green" };
133
+ case "Good":
134
+ return { emoji: "\u{1F44D}", color: "blue" };
135
+ case "Fair":
136
+ return { emoji: "\u26A0\uFE0F", color: "yellow" };
137
+ case "Needs Work":
138
+ return { emoji: "\u{1F528}", color: "orange" };
139
+ case "Critical":
140
+ return { emoji: "\u274C", color: "red" };
141
+ }
142
+ }
143
+ function formatScore(result) {
144
+ const { emoji, color } = getRatingDisplay(result.rating);
145
+ return `${result.overall}/100 (${result.rating}) ${emoji}`;
146
+ }
147
+ function formatToolScore(output) {
148
+ let result = ` Score: ${output.score}/100
149
+
150
+ `;
151
+ if (output.factors && output.factors.length > 0) {
152
+ result += ` Factors:
153
+ `;
154
+ output.factors.forEach((factor) => {
155
+ const impactSign = factor.impact > 0 ? "+" : "";
156
+ result += ` \u2022 ${factor.name}: ${impactSign}${factor.impact} - ${factor.description}
157
+ `;
158
+ });
159
+ result += "\n";
160
+ }
161
+ if (output.recommendations && output.recommendations.length > 0) {
162
+ result += ` Recommendations:
163
+ `;
164
+ output.recommendations.forEach((rec, i) => {
165
+ const priorityIcon = rec.priority === "high" ? "\u{1F534}" : rec.priority === "medium" ? "\u{1F7E1}" : "\u{1F535}";
166
+ result += ` ${i + 1}. ${priorityIcon} ${rec.action}
167
+ `;
168
+ result += ` Impact: +${rec.estimatedImpact} points
169
+
170
+ `;
171
+ });
172
+ }
173
+ return result;
174
+ }
175
+
176
+ // src/utils/visualization.ts
177
+ function generateHTML(graph) {
178
+ const payload = JSON.stringify(graph, null, 2);
179
+ return `<!doctype html>
180
+ <html>
181
+ <head>
182
+ <meta charset="utf-8" />
183
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
184
+ <title>AIReady Visualization</title>
185
+ <style>
186
+ html,body { height: 100%; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0f172a; color: #e2e8f0 }
187
+ #container { display:flex; height:100vh }
188
+ #panel { width: 320px; padding: 16px; background: #071130; box-shadow: -2px 0 8px rgba(0,0,0,0.3); overflow:auto }
189
+ #canvasWrap { flex:1; display:flex; align-items:center; justify-content:center }
190
+ canvas { background: #0b1220; border-radius:8px }
191
+ .stat { margin-bottom:12px }
192
+ </style>
193
+ </head>
194
+ <body>
195
+ <div id="container">
196
+ <div id="canvasWrap"><canvas id="canvas" width="1200" height="800"></canvas></div>
197
+ <div id="panel">
198
+ <h2>AIReady Visualization</h2>
199
+ <div class="stat"><strong>Files:</strong> <span id="stat-files"></span></div>
200
+ <div class="stat"><strong>Dependencies:</strong> <span id="stat-deps"></span></div>
201
+ <div class="stat"><strong>Legend</strong></div>
202
+ <div style="font-size:13px;line-height:1.3;color:#cbd5e1;margin-top:8px">
203
+ <div style="margin-bottom:8px"><span style="display:inline-block;width:12px;height:12px;background:#ff4d4f;margin-right:8px;border:1px solid rgba(255,255,255,0.06)"></span><strong>Critical</strong>: highest severity issues.</div>
204
+ <div style="margin-bottom:8px"><span style="display:inline-block;width:12px;height:12px;background:#ff9900;margin-right:8px;border:1px solid rgba(255,255,255,0.06)"></span><strong>Major</strong>: important issues.</div>
205
+ <div style="margin-bottom:8px"><span style="display:inline-block;width:12px;height:12px;background:#ffd666;margin-right:8px;border:1px solid rgba(255,255,255,0.06)"></span><strong>Minor</strong>: low priority issues.</div>
206
+ <div style="margin-bottom:8px"><span style="display:inline-block;width:12px;height:12px;background:#91d5ff;margin-right:8px;border:1px solid rgba(255,255,255,0.06)"></span><strong>Info</strong>: informational notes.</div>
207
+ <div style="margin-top:10px;color:#94a3b8"><strong>Node size</strong>: larger = higher token cost, more issues or dependency weight.</div>
208
+ <div style="margin-top:6px;color:#94a3b8"><strong>Proximity</strong>: nodes that are spatially close are more contextually related; relatedness is represented by distance and size rather than explicit edges.</div>
209
+ <div style="margin-top:6px;color:#94a3b8"><strong>Edge colors</strong>: <span style="color:#fb7e81">Similarity</span>, <span style="color:#84c1ff">Dependency</span>, <span style="color:#ffa500">Reference</span>, default <span style="color:#334155">Other</span>.</div>
210
+ </div>
211
+ </div>
212
+ </div>
213
+
214
+ <script>
215
+ const graphData = ${payload};
216
+ document.getElementById('stat-files').textContent = graphData.metadata.totalFiles;
217
+ document.getElementById('stat-deps').textContent = graphData.metadata.totalDependencies;
218
+
219
+ const canvas = document.getElementById('canvas');
220
+ const ctx = canvas.getContext('2d');
221
+
222
+ const nodes = graphData.nodes.map((n, i) => ({
223
+ ...n,
224
+ x: canvas.width / 2 + Math.cos(i / graphData.nodes.length * Math.PI * 2) * (Math.min(canvas.width, canvas.height) / 3),
225
+ y: canvas.height / 2 + Math.sin(i / graphData.nodes.length * Math.PI * 2) * (Math.min(canvas.width, canvas.height) / 3),
226
+ }));
227
+
228
+ function draw() {
229
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
230
+
231
+ graphData.edges.forEach(edge => {
232
+ const s = nodes.find(n => n.id === edge.source);
233
+ const t = nodes.find(n => n.id === edge.target);
234
+ if (!s || !t) return;
235
+ if (edge.type === 'related') return;
236
+ if (edge.type === 'similarity') {
237
+ ctx.strokeStyle = '#fb7e81';
238
+ ctx.lineWidth = 1.2;
239
+ } else if (edge.type === 'dependency') {
240
+ ctx.strokeStyle = '#84c1ff';
241
+ ctx.lineWidth = 1.0;
242
+ } else if (edge.type === 'reference') {
243
+ ctx.strokeStyle = '#ffa500';
244
+ ctx.lineWidth = 0.9;
245
+ } else {
246
+ ctx.strokeStyle = '#334155';
247
+ ctx.lineWidth = 0.8;
248
+ }
249
+ ctx.beginPath();
250
+ ctx.moveTo(s.x, s.y);
251
+ ctx.lineTo(t.x, t.y);
252
+ ctx.stroke();
253
+ });
254
+
255
+ const groups = {};
256
+ nodes.forEach(n => {
257
+ const g = n.group || '__default';
258
+ if (!groups[g]) groups[g] = { minX: n.x, minY: n.y, maxX: n.x, maxY: n.y };
259
+ groups[g].minX = Math.min(groups[g].minX, n.x);
260
+ groups[g].minY = Math.min(groups[g].minY, n.y);
261
+ groups[g].maxX = Math.max(groups[g].maxX, n.x);
262
+ groups[g].maxY = Math.max(groups[g].maxY, n.y);
263
+ });
264
+
265
+ const groupRelations = {};
266
+ graphData.edges.forEach(edge => {
267
+ const sNode = nodes.find(n => n.id === edge.source);
268
+ const tNode = nodes.find(n => n.id === edge.target);
269
+ if (!sNode || !tNode) return;
270
+ const g1 = sNode.group || '__default';
271
+ const g2 = tNode.group || '__default';
272
+ if (g1 === g2) return;
273
+ const key = g1 < g2 ? g1 + '::' + g2 : g2 + '::' + g1;
274
+ groupRelations[key] = (groupRelations[key] || 0) + 1;
275
+ });
276
+
277
+ Object.keys(groupRelations).forEach(k => {
278
+ const count = groupRelations[k];
279
+ const [ga, gb] = k.split('::');
280
+ if (!groups[ga] || !groups[gb]) return;
281
+ const ax = (groups[ga].minX + groups[ga].maxX) / 2;
282
+ const ay = (groups[ga].minY + groups[ga].maxY) / 2;
283
+ const bx = (groups[gb].minX + groups[gb].maxX) / 2;
284
+ const by = (groups[gb].minY + groups[gb].maxY) / 2;
285
+ ctx.beginPath();
286
+ ctx.strokeStyle = 'rgba(148,163,184,0.25)';
287
+ ctx.lineWidth = Math.min(6, 0.6 + Math.sqrt(count));
288
+ ctx.moveTo(ax, ay);
289
+ ctx.lineTo(bx, by);
290
+ ctx.stroke();
291
+ });
292
+
293
+ Object.keys(groups).forEach(g => {
294
+ if (g === '__default') return;
295
+ const box = groups[g];
296
+ const pad = 16;
297
+ const x = box.minX - pad;
298
+ const y = box.minY - pad;
299
+ const w = (box.maxX - box.minX) + pad * 2;
300
+ const h = (box.maxY - box.minY) + pad * 2;
301
+ ctx.save();
302
+ ctx.fillStyle = 'rgba(30,64,175,0.04)';
303
+ ctx.strokeStyle = 'rgba(30,64,175,0.12)';
304
+ ctx.lineWidth = 1.2;
305
+ const r = 8;
306
+ ctx.beginPath();
307
+ ctx.moveTo(x + r, y);
308
+ ctx.arcTo(x + w, y, x + w, y + h, r);
309
+ ctx.arcTo(x + w, y + h, x, y + h, r);
310
+ ctx.arcTo(x, y + h, x, y, r);
311
+ ctx.arcTo(x, y, x + w, y, r);
312
+ ctx.closePath();
313
+ ctx.fill();
314
+ ctx.stroke();
315
+ ctx.restore();
316
+ ctx.fillStyle = '#94a3b8';
317
+ ctx.font = '11px sans-serif';
318
+ ctx.fillText(g, x + 8, y + 14);
319
+ });
320
+
321
+ nodes.forEach(n => {
322
+ const sizeVal = (n.size || n.value || 1);
323
+ const r = 6 + (sizeVal / 2);
324
+ ctx.beginPath();
325
+ ctx.fillStyle = n.color || '#60a5fa';
326
+ ctx.arc(n.x, n.y, r, 0, Math.PI * 2);
327
+ ctx.fill();
328
+
329
+ ctx.fillStyle = '#e2e8f0';
330
+ ctx.font = '11px sans-serif';
331
+ ctx.textAlign = 'center';
332
+ ctx.fillText(n.label || n.id.split('/').slice(-1)[0], n.x, n.y + r + 12);
333
+ });
334
+ }
335
+
336
+ draw();
337
+ </script>
338
+ </body>
339
+ </html>`;
340
+ }
341
+
342
+ export {
343
+ Language,
344
+ LANGUAGE_EXTENSIONS,
345
+ ParseError,
346
+ DEFAULT_TOOL_WEIGHTS,
347
+ TOOL_NAME_MAP,
348
+ normalizeToolName,
349
+ getToolWeight,
350
+ parseWeightString,
351
+ calculateOverallScore,
352
+ getRating,
353
+ getRatingDisplay,
354
+ formatScore,
355
+ formatToolScore,
356
+ generateHTML
357
+ };