@aiready/context-analyzer 0.19.9 → 0.19.11
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/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-test.log +20 -20
- package/dist/chunk-P5YV5WIX.mjs +1803 -0
- package/dist/cli.js +164 -155
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +158 -149
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/provider.ts +1 -1
- package/src/summary.ts +13 -1
- package/src/types.ts +1 -0
package/dist/cli.js
CHANGED
|
@@ -37,7 +37,7 @@ __export(python_context_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
async function analyzePythonContext(files, rootDir) {
|
|
39
39
|
const results = [];
|
|
40
|
-
const parser = (0,
|
|
40
|
+
const parser = (0, import_core9.getParser)("dummy.py");
|
|
41
41
|
if (!parser) {
|
|
42
42
|
console.warn("Python parser not available");
|
|
43
43
|
return results;
|
|
@@ -101,7 +101,7 @@ async function analyzePythonContext(files, rootDir) {
|
|
|
101
101
|
}
|
|
102
102
|
async function buildPythonDependencyGraph(files, rootDir) {
|
|
103
103
|
const graph = /* @__PURE__ */ new Map();
|
|
104
|
-
const parser = (0,
|
|
104
|
+
const parser = (0, import_core9.getParser)("dummy.py");
|
|
105
105
|
if (!parser) return graph;
|
|
106
106
|
for (const file of files) {
|
|
107
107
|
try {
|
|
@@ -181,7 +181,7 @@ async function calculatePythonImportDepth(file, dependencyGraph, visited, depth
|
|
|
181
181
|
}
|
|
182
182
|
function estimateContextBudget(code, imports, dependencyGraph) {
|
|
183
183
|
void dependencyGraph;
|
|
184
|
-
let budget = (0,
|
|
184
|
+
let budget = (0, import_core9.estimateTokens)(code);
|
|
185
185
|
const avgTokensPerDep = 500;
|
|
186
186
|
budget += imports.length * avgTokensPerDep;
|
|
187
187
|
return budget;
|
|
@@ -231,11 +231,11 @@ function detectCircularDependencies2(file, dependencyGraph) {
|
|
|
231
231
|
dfs(file, []);
|
|
232
232
|
return [...new Set(circular)];
|
|
233
233
|
}
|
|
234
|
-
var
|
|
234
|
+
var import_core9, import_path, import_fs;
|
|
235
235
|
var init_python_context = __esm({
|
|
236
236
|
"src/analyzers/python-context.ts"() {
|
|
237
237
|
"use strict";
|
|
238
|
-
|
|
238
|
+
import_core9 = require("@aiready/core");
|
|
239
239
|
import_path = require("path");
|
|
240
240
|
import_fs = __toESM(require("fs"));
|
|
241
241
|
}
|
|
@@ -245,7 +245,7 @@ var init_python_context = __esm({
|
|
|
245
245
|
var import_commander = require("commander");
|
|
246
246
|
|
|
247
247
|
// src/index.ts
|
|
248
|
-
var
|
|
248
|
+
var import_core10 = require("@aiready/core");
|
|
249
249
|
|
|
250
250
|
// src/analyzer.ts
|
|
251
251
|
var import_core4 = require("@aiready/core");
|
|
@@ -1329,11 +1329,146 @@ function isBuildArtifact(filePath) {
|
|
|
1329
1329
|
return lower.includes("/node_modules/") || lower.includes("/dist/") || lower.includes("/build/") || lower.includes("/out/") || lower.includes("/.next/");
|
|
1330
1330
|
}
|
|
1331
1331
|
|
|
1332
|
+
// src/summary.ts
|
|
1333
|
+
var import_core5 = require("@aiready/core");
|
|
1334
|
+
function generateSummary(results, options) {
|
|
1335
|
+
const config = options ? Object.fromEntries(
|
|
1336
|
+
Object.entries(options).filter(
|
|
1337
|
+
([key]) => !import_core5.GLOBAL_SCAN_OPTIONS.includes(key) || key === "rootDir"
|
|
1338
|
+
)
|
|
1339
|
+
) : void 0;
|
|
1340
|
+
if (results.length === 0) {
|
|
1341
|
+
return {
|
|
1342
|
+
totalFiles: 0,
|
|
1343
|
+
totalTokens: 0,
|
|
1344
|
+
avgContextBudget: 0,
|
|
1345
|
+
maxContextBudget: 0,
|
|
1346
|
+
avgImportDepth: 0,
|
|
1347
|
+
maxImportDepth: 0,
|
|
1348
|
+
deepFiles: [],
|
|
1349
|
+
avgFragmentation: 0,
|
|
1350
|
+
fragmentedModules: [],
|
|
1351
|
+
avgCohesion: 0,
|
|
1352
|
+
lowCohesionFiles: [],
|
|
1353
|
+
criticalIssues: 0,
|
|
1354
|
+
majorIssues: 0,
|
|
1355
|
+
minorIssues: 0,
|
|
1356
|
+
totalPotentialSavings: 0,
|
|
1357
|
+
topExpensiveFiles: [],
|
|
1358
|
+
config
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
const totalFiles = results.length;
|
|
1362
|
+
const totalTokens = results.reduce((sum, r) => sum + r.tokenCost, 0);
|
|
1363
|
+
const totalContextBudget = results.reduce(
|
|
1364
|
+
(sum, r) => sum + r.contextBudget,
|
|
1365
|
+
0
|
|
1366
|
+
);
|
|
1367
|
+
const avgContextBudget = totalContextBudget / totalFiles;
|
|
1368
|
+
const maxContextBudget = Math.max(...results.map((r) => r.contextBudget));
|
|
1369
|
+
const avgImportDepth = results.reduce((sum, r) => sum + r.importDepth, 0) / totalFiles;
|
|
1370
|
+
const maxImportDepth = Math.max(...results.map((r) => r.importDepth));
|
|
1371
|
+
const deepFiles = results.filter((r) => r.importDepth >= 5).map((r) => ({ file: r.file, depth: r.importDepth })).sort((a, b) => b.depth - a.depth).slice(0, 10);
|
|
1372
|
+
const avgFragmentation = results.reduce((sum, r) => sum + r.fragmentationScore, 0) / totalFiles;
|
|
1373
|
+
const moduleMap = /* @__PURE__ */ new Map();
|
|
1374
|
+
for (const result of results) {
|
|
1375
|
+
for (const domain of result.domains) {
|
|
1376
|
+
if (!moduleMap.has(domain)) moduleMap.set(domain, []);
|
|
1377
|
+
moduleMap.get(domain).push(result);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
const fragmentedModules = [];
|
|
1381
|
+
for (const [domain, files] of moduleMap.entries()) {
|
|
1382
|
+
let jaccard2 = function(a, b) {
|
|
1383
|
+
const s1 = new Set(a || []);
|
|
1384
|
+
const s2 = new Set(b || []);
|
|
1385
|
+
if (s1.size === 0 && s2.size === 0) return 0;
|
|
1386
|
+
const inter = new Set([...s1].filter((x) => s2.has(x)));
|
|
1387
|
+
const uni = /* @__PURE__ */ new Set([...s1, ...s2]);
|
|
1388
|
+
return uni.size === 0 ? 0 : inter.size / uni.size;
|
|
1389
|
+
};
|
|
1390
|
+
var jaccard = jaccard2;
|
|
1391
|
+
if (files.length < 2) continue;
|
|
1392
|
+
const fragmentationScore = files.reduce((sum, f) => sum + f.fragmentationScore, 0) / files.length;
|
|
1393
|
+
if (fragmentationScore < 0.3) continue;
|
|
1394
|
+
const totalTokens2 = files.reduce((sum, f) => sum + f.tokenCost, 0);
|
|
1395
|
+
const avgCohesion2 = files.reduce((sum, f) => sum + f.cohesionScore, 0) / files.length;
|
|
1396
|
+
const targetFiles = Math.max(1, Math.ceil(files.length / 3));
|
|
1397
|
+
const filePaths = files.map((f) => f.file);
|
|
1398
|
+
const pathEntropy = calculatePathEntropy(filePaths);
|
|
1399
|
+
const directoryDistance = calculateDirectoryDistance(filePaths);
|
|
1400
|
+
let importSimTotal = 0;
|
|
1401
|
+
let importPairs = 0;
|
|
1402
|
+
for (let i = 0; i < files.length; i++) {
|
|
1403
|
+
for (let j = i + 1; j < files.length; j++) {
|
|
1404
|
+
importSimTotal += jaccard2(
|
|
1405
|
+
files[i].dependencyList || [],
|
|
1406
|
+
files[j].dependencyList || []
|
|
1407
|
+
);
|
|
1408
|
+
importPairs++;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
const importCohesion = importPairs > 0 ? importSimTotal / importPairs : 0;
|
|
1412
|
+
fragmentedModules.push({
|
|
1413
|
+
domain,
|
|
1414
|
+
files: files.map((f) => f.file),
|
|
1415
|
+
totalTokens: totalTokens2,
|
|
1416
|
+
fragmentationScore,
|
|
1417
|
+
avgCohesion: avgCohesion2,
|
|
1418
|
+
importCohesion,
|
|
1419
|
+
pathEntropy,
|
|
1420
|
+
directoryDistance,
|
|
1421
|
+
suggestedStructure: {
|
|
1422
|
+
targetFiles,
|
|
1423
|
+
consolidationPlan: [
|
|
1424
|
+
`Consolidate ${files.length} files across ${new Set(files.map((f) => f.file.split("/").slice(0, -1).join("/"))).size} directories`,
|
|
1425
|
+
`Target ~${targetFiles} core modules to reduce context switching`
|
|
1426
|
+
]
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
const avgCohesion = results.reduce((sum, r) => sum + r.cohesionScore, 0) / totalFiles;
|
|
1431
|
+
const lowCohesionFiles = results.filter((r) => r.cohesionScore < 0.4).map((r) => ({ file: r.file, score: r.cohesionScore })).sort((a, b) => a.score - b.score).slice(0, 10);
|
|
1432
|
+
const criticalIssues = results.filter(
|
|
1433
|
+
(r) => r.severity === "critical"
|
|
1434
|
+
).length;
|
|
1435
|
+
const majorIssues = results.filter((r) => r.severity === "major").length;
|
|
1436
|
+
const minorIssues = results.filter((r) => r.severity === "minor").length;
|
|
1437
|
+
const totalPotentialSavings = results.reduce(
|
|
1438
|
+
(sum, r) => sum + r.potentialSavings,
|
|
1439
|
+
0
|
|
1440
|
+
);
|
|
1441
|
+
const topExpensiveFiles = results.sort((a, b) => b.contextBudget - a.contextBudget).slice(0, 10).map((r) => ({
|
|
1442
|
+
file: r.file,
|
|
1443
|
+
contextBudget: r.contextBudget,
|
|
1444
|
+
severity: r.severity
|
|
1445
|
+
}));
|
|
1446
|
+
return {
|
|
1447
|
+
totalFiles,
|
|
1448
|
+
totalTokens,
|
|
1449
|
+
avgContextBudget,
|
|
1450
|
+
maxContextBudget,
|
|
1451
|
+
avgImportDepth,
|
|
1452
|
+
maxImportDepth,
|
|
1453
|
+
deepFiles,
|
|
1454
|
+
avgFragmentation,
|
|
1455
|
+
fragmentedModules,
|
|
1456
|
+
avgCohesion,
|
|
1457
|
+
lowCohesionFiles,
|
|
1458
|
+
criticalIssues,
|
|
1459
|
+
majorIssues,
|
|
1460
|
+
minorIssues,
|
|
1461
|
+
totalPotentialSavings,
|
|
1462
|
+
topExpensiveFiles,
|
|
1463
|
+
config
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1332
1467
|
// src/provider.ts
|
|
1333
|
-
var
|
|
1468
|
+
var import_core7 = require("@aiready/core");
|
|
1334
1469
|
|
|
1335
1470
|
// src/scoring.ts
|
|
1336
|
-
var
|
|
1471
|
+
var import_core6 = require("@aiready/core");
|
|
1337
1472
|
function calculateContextScore(summary, costConfig) {
|
|
1338
1473
|
const {
|
|
1339
1474
|
avgContextBudget,
|
|
@@ -1429,8 +1564,8 @@ function calculateContextScore(summary, costConfig) {
|
|
|
1429
1564
|
priority: "high"
|
|
1430
1565
|
});
|
|
1431
1566
|
}
|
|
1432
|
-
const cfg = { ...
|
|
1433
|
-
const estimatedMonthlyCost = (0,
|
|
1567
|
+
const cfg = { ...import_core6.DEFAULT_COST_CONFIG, ...costConfig };
|
|
1568
|
+
const estimatedMonthlyCost = (0, import_core6.calculateMonthlyCost)(
|
|
1434
1569
|
avgContextBudget * (summary.totalFiles || 1),
|
|
1435
1570
|
cfg
|
|
1436
1571
|
);
|
|
@@ -1438,9 +1573,9 @@ function calculateContextScore(summary, costConfig) {
|
|
|
1438
1573
|
...Array(criticalIssues).fill({ severity: "critical" }),
|
|
1439
1574
|
...Array(majorIssues).fill({ severity: "major" })
|
|
1440
1575
|
];
|
|
1441
|
-
const productivityImpact = (0,
|
|
1576
|
+
const productivityImpact = (0, import_core6.calculateProductivityImpact)(issues);
|
|
1442
1577
|
return {
|
|
1443
|
-
toolName:
|
|
1578
|
+
toolName: import_core6.ToolName.ContextAnalyzer,
|
|
1444
1579
|
score,
|
|
1445
1580
|
rawMetrics: {
|
|
1446
1581
|
avgContextBudget: Math.round(avgContextBudget),
|
|
@@ -1460,16 +1595,16 @@ function calculateContextScore(summary, costConfig) {
|
|
|
1460
1595
|
|
|
1461
1596
|
// src/provider.ts
|
|
1462
1597
|
var ContextAnalyzerProvider = {
|
|
1463
|
-
id:
|
|
1598
|
+
id: import_core7.ToolName.ContextAnalyzer,
|
|
1464
1599
|
alias: ["context", "fragmentation", "budget"],
|
|
1465
1600
|
async analyze(options) {
|
|
1466
1601
|
const results = await analyzeContext(options);
|
|
1467
|
-
const summary = generateSummary(results);
|
|
1602
|
+
const summary = generateSummary(results, options);
|
|
1468
1603
|
const normalizedResults = results.map(
|
|
1469
1604
|
(r) => ({
|
|
1470
1605
|
fileName: r.file,
|
|
1471
1606
|
issues: r.issues.map((msg) => ({
|
|
1472
|
-
type:
|
|
1607
|
+
type: import_core7.IssueType.ContextFragmentation,
|
|
1473
1608
|
severity: r.severity,
|
|
1474
1609
|
message: msg,
|
|
1475
1610
|
location: { file: r.file, line: 1 },
|
|
@@ -1482,13 +1617,13 @@ var ContextAnalyzerProvider = {
|
|
|
1482
1617
|
}
|
|
1483
1618
|
})
|
|
1484
1619
|
);
|
|
1485
|
-
return
|
|
1620
|
+
return import_core7.SpokeOutputSchema.parse({
|
|
1486
1621
|
results: normalizedResults,
|
|
1487
1622
|
summary: {
|
|
1488
1623
|
...summary
|
|
1489
1624
|
},
|
|
1490
1625
|
metadata: {
|
|
1491
|
-
toolName:
|
|
1626
|
+
toolName: import_core7.ToolName.ContextAnalyzer,
|
|
1492
1627
|
version: "0.17.5",
|
|
1493
1628
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1494
1629
|
}
|
|
@@ -1502,137 +1637,10 @@ var ContextAnalyzerProvider = {
|
|
|
1502
1637
|
};
|
|
1503
1638
|
|
|
1504
1639
|
// src/defaults.ts
|
|
1505
|
-
var
|
|
1506
|
-
|
|
1507
|
-
// src/summary.ts
|
|
1508
|
-
function generateSummary(results) {
|
|
1509
|
-
if (results.length === 0) {
|
|
1510
|
-
return {
|
|
1511
|
-
totalFiles: 0,
|
|
1512
|
-
totalTokens: 0,
|
|
1513
|
-
avgContextBudget: 0,
|
|
1514
|
-
maxContextBudget: 0,
|
|
1515
|
-
avgImportDepth: 0,
|
|
1516
|
-
maxImportDepth: 0,
|
|
1517
|
-
deepFiles: [],
|
|
1518
|
-
avgFragmentation: 0,
|
|
1519
|
-
fragmentedModules: [],
|
|
1520
|
-
avgCohesion: 0,
|
|
1521
|
-
lowCohesionFiles: [],
|
|
1522
|
-
criticalIssues: 0,
|
|
1523
|
-
majorIssues: 0,
|
|
1524
|
-
minorIssues: 0,
|
|
1525
|
-
totalPotentialSavings: 0,
|
|
1526
|
-
topExpensiveFiles: []
|
|
1527
|
-
};
|
|
1528
|
-
}
|
|
1529
|
-
const totalFiles = results.length;
|
|
1530
|
-
const totalTokens = results.reduce((sum, r) => sum + r.tokenCost, 0);
|
|
1531
|
-
const totalContextBudget = results.reduce(
|
|
1532
|
-
(sum, r) => sum + r.contextBudget,
|
|
1533
|
-
0
|
|
1534
|
-
);
|
|
1535
|
-
const avgContextBudget = totalContextBudget / totalFiles;
|
|
1536
|
-
const maxContextBudget = Math.max(...results.map((r) => r.contextBudget));
|
|
1537
|
-
const avgImportDepth = results.reduce((sum, r) => sum + r.importDepth, 0) / totalFiles;
|
|
1538
|
-
const maxImportDepth = Math.max(...results.map((r) => r.importDepth));
|
|
1539
|
-
const deepFiles = results.filter((r) => r.importDepth >= 5).map((r) => ({ file: r.file, depth: r.importDepth })).sort((a, b) => b.depth - a.depth).slice(0, 10);
|
|
1540
|
-
const avgFragmentation = results.reduce((sum, r) => sum + r.fragmentationScore, 0) / totalFiles;
|
|
1541
|
-
const moduleMap = /* @__PURE__ */ new Map();
|
|
1542
|
-
for (const result of results) {
|
|
1543
|
-
for (const domain of result.domains) {
|
|
1544
|
-
if (!moduleMap.has(domain)) moduleMap.set(domain, []);
|
|
1545
|
-
moduleMap.get(domain).push(result);
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
const fragmentedModules = [];
|
|
1549
|
-
for (const [domain, files] of moduleMap.entries()) {
|
|
1550
|
-
let jaccard2 = function(a, b) {
|
|
1551
|
-
const s1 = new Set(a || []);
|
|
1552
|
-
const s2 = new Set(b || []);
|
|
1553
|
-
if (s1.size === 0 && s2.size === 0) return 0;
|
|
1554
|
-
const inter = new Set([...s1].filter((x) => s2.has(x)));
|
|
1555
|
-
const uni = /* @__PURE__ */ new Set([...s1, ...s2]);
|
|
1556
|
-
return uni.size === 0 ? 0 : inter.size / uni.size;
|
|
1557
|
-
};
|
|
1558
|
-
var jaccard = jaccard2;
|
|
1559
|
-
if (files.length < 2) continue;
|
|
1560
|
-
const fragmentationScore = files.reduce((sum, f) => sum + f.fragmentationScore, 0) / files.length;
|
|
1561
|
-
if (fragmentationScore < 0.3) continue;
|
|
1562
|
-
const totalTokens2 = files.reduce((sum, f) => sum + f.tokenCost, 0);
|
|
1563
|
-
const avgCohesion2 = files.reduce((sum, f) => sum + f.cohesionScore, 0) / files.length;
|
|
1564
|
-
const targetFiles = Math.max(1, Math.ceil(files.length / 3));
|
|
1565
|
-
const filePaths = files.map((f) => f.file);
|
|
1566
|
-
const pathEntropy = calculatePathEntropy(filePaths);
|
|
1567
|
-
const directoryDistance = calculateDirectoryDistance(filePaths);
|
|
1568
|
-
let importSimTotal = 0;
|
|
1569
|
-
let importPairs = 0;
|
|
1570
|
-
for (let i = 0; i < files.length; i++) {
|
|
1571
|
-
for (let j = i + 1; j < files.length; j++) {
|
|
1572
|
-
importSimTotal += jaccard2(
|
|
1573
|
-
files[i].dependencyList || [],
|
|
1574
|
-
files[j].dependencyList || []
|
|
1575
|
-
);
|
|
1576
|
-
importPairs++;
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
const importCohesion = importPairs > 0 ? importSimTotal / importPairs : 0;
|
|
1580
|
-
fragmentedModules.push({
|
|
1581
|
-
domain,
|
|
1582
|
-
files: files.map((f) => f.file),
|
|
1583
|
-
totalTokens: totalTokens2,
|
|
1584
|
-
fragmentationScore,
|
|
1585
|
-
avgCohesion: avgCohesion2,
|
|
1586
|
-
importCohesion,
|
|
1587
|
-
pathEntropy,
|
|
1588
|
-
directoryDistance,
|
|
1589
|
-
suggestedStructure: {
|
|
1590
|
-
targetFiles,
|
|
1591
|
-
consolidationPlan: [
|
|
1592
|
-
`Consolidate ${files.length} files across ${new Set(files.map((f) => f.file.split("/").slice(0, -1).join("/"))).size} directories`,
|
|
1593
|
-
`Target ~${targetFiles} core modules to reduce context switching`
|
|
1594
|
-
]
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
const avgCohesion = results.reduce((sum, r) => sum + r.cohesionScore, 0) / totalFiles;
|
|
1599
|
-
const lowCohesionFiles = results.filter((r) => r.cohesionScore < 0.4).map((r) => ({ file: r.file, score: r.cohesionScore })).sort((a, b) => a.score - b.score).slice(0, 10);
|
|
1600
|
-
const criticalIssues = results.filter(
|
|
1601
|
-
(r) => r.severity === "critical"
|
|
1602
|
-
).length;
|
|
1603
|
-
const majorIssues = results.filter((r) => r.severity === "major").length;
|
|
1604
|
-
const minorIssues = results.filter((r) => r.severity === "minor").length;
|
|
1605
|
-
const totalPotentialSavings = results.reduce(
|
|
1606
|
-
(sum, r) => sum + r.potentialSavings,
|
|
1607
|
-
0
|
|
1608
|
-
);
|
|
1609
|
-
const topExpensiveFiles = results.sort((a, b) => b.contextBudget - a.contextBudget).slice(0, 10).map((r) => ({
|
|
1610
|
-
file: r.file,
|
|
1611
|
-
contextBudget: r.contextBudget,
|
|
1612
|
-
severity: r.severity
|
|
1613
|
-
}));
|
|
1614
|
-
return {
|
|
1615
|
-
totalFiles,
|
|
1616
|
-
totalTokens,
|
|
1617
|
-
avgContextBudget,
|
|
1618
|
-
maxContextBudget,
|
|
1619
|
-
avgImportDepth,
|
|
1620
|
-
maxImportDepth,
|
|
1621
|
-
deepFiles,
|
|
1622
|
-
avgFragmentation,
|
|
1623
|
-
fragmentedModules,
|
|
1624
|
-
avgCohesion,
|
|
1625
|
-
lowCohesionFiles,
|
|
1626
|
-
criticalIssues,
|
|
1627
|
-
majorIssues,
|
|
1628
|
-
minorIssues,
|
|
1629
|
-
totalPotentialSavings,
|
|
1630
|
-
topExpensiveFiles
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1640
|
+
var import_core8 = require("@aiready/core");
|
|
1633
1641
|
|
|
1634
1642
|
// src/index.ts
|
|
1635
|
-
|
|
1643
|
+
import_core10.ToolRegistry.register(ContextAnalyzerProvider);
|
|
1636
1644
|
async function analyzeContext(options) {
|
|
1637
1645
|
const {
|
|
1638
1646
|
maxDepth = 5,
|
|
@@ -1643,7 +1651,7 @@ async function analyzeContext(options) {
|
|
|
1643
1651
|
includeNodeModules = false,
|
|
1644
1652
|
...scanOptions
|
|
1645
1653
|
} = options;
|
|
1646
|
-
const files = await (0,
|
|
1654
|
+
const files = await (0, import_core10.scanFiles)({
|
|
1647
1655
|
...scanOptions,
|
|
1648
1656
|
exclude: includeNodeModules && scanOptions.exclude ? scanOptions.exclude.filter(
|
|
1649
1657
|
(pattern) => pattern !== "**/node_modules/**"
|
|
@@ -1653,7 +1661,7 @@ async function analyzeContext(options) {
|
|
|
1653
1661
|
const fileContents = await Promise.all(
|
|
1654
1662
|
files.map(async (file) => ({
|
|
1655
1663
|
file,
|
|
1656
|
-
content: await (0,
|
|
1664
|
+
content: await (0, import_core10.readFileContent)(file)
|
|
1657
1665
|
}))
|
|
1658
1666
|
);
|
|
1659
1667
|
const graph = buildDependencyGraph(
|
|
@@ -1808,6 +1816,7 @@ async function analyzeContext(options) {
|
|
|
1808
1816
|
});
|
|
1809
1817
|
}
|
|
1810
1818
|
const allResults = [...results, ...pythonResults];
|
|
1819
|
+
const finalSummary = generateSummary(allResults, options);
|
|
1811
1820
|
return allResults.sort((a, b) => {
|
|
1812
1821
|
const severityOrder = { critical: 0, major: 1, minor: 2, info: 3 };
|
|
1813
1822
|
const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
|
|
@@ -1820,7 +1829,7 @@ async function analyzeContext(options) {
|
|
|
1820
1829
|
var import_chalk = __toESM(require("chalk"));
|
|
1821
1830
|
var import_fs2 = require("fs");
|
|
1822
1831
|
var import_path2 = require("path");
|
|
1823
|
-
var
|
|
1832
|
+
var import_core11 = require("@aiready/core");
|
|
1824
1833
|
var import_prompts = __toESM(require("prompts"));
|
|
1825
1834
|
var program = new import_commander.Command();
|
|
1826
1835
|
program.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText(
|
|
@@ -1860,7 +1869,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
|
|
|
1860
1869
|
exclude: void 0,
|
|
1861
1870
|
maxResults: 10
|
|
1862
1871
|
};
|
|
1863
|
-
let finalOptions = await (0,
|
|
1872
|
+
let finalOptions = await (0, import_core11.loadMergedConfig)(directory, defaults, {
|
|
1864
1873
|
maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
|
|
1865
1874
|
maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
|
|
1866
1875
|
minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
|
|
@@ -1875,7 +1884,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
|
|
|
1875
1884
|
finalOptions = await runInteractiveSetup(directory, finalOptions);
|
|
1876
1885
|
}
|
|
1877
1886
|
const results = await analyzeContext(finalOptions);
|
|
1878
|
-
const elapsedTime = (0,
|
|
1887
|
+
const elapsedTime = (0, import_core11.getElapsedTime)(startTime);
|
|
1879
1888
|
const summary = generateSummary(results);
|
|
1880
1889
|
if (options.output === "json") {
|
|
1881
1890
|
const jsonOutput = {
|
|
@@ -1884,12 +1893,12 @@ program.name("aiready-context").description("Analyze AI context window cost and
|
|
|
1884
1893
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1885
1894
|
analysisTime: elapsedTime
|
|
1886
1895
|
};
|
|
1887
|
-
const outputPath = (0,
|
|
1896
|
+
const outputPath = (0, import_core11.resolveOutputPath)(
|
|
1888
1897
|
options.outputFile,
|
|
1889
1898
|
`context-report-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.json`,
|
|
1890
1899
|
directory
|
|
1891
1900
|
);
|
|
1892
|
-
(0,
|
|
1901
|
+
(0, import_core11.handleJSONOutput)(
|
|
1893
1902
|
jsonOutput,
|
|
1894
1903
|
outputPath,
|
|
1895
1904
|
`
|
|
@@ -1899,7 +1908,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
|
|
|
1899
1908
|
}
|
|
1900
1909
|
if (options.output === "html") {
|
|
1901
1910
|
const html = generateHTMLReport(summary, results);
|
|
1902
|
-
const outputPath = (0,
|
|
1911
|
+
const outputPath = (0, import_core11.resolveOutputPath)(
|
|
1903
1912
|
options.outputFile,
|
|
1904
1913
|
`context-report-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.html`,
|
|
1905
1914
|
directory
|
|
@@ -1921,7 +1930,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
|
|
|
1921
1930
|
);
|
|
1922
1931
|
displayTuningGuidance(results, finalOptions);
|
|
1923
1932
|
} catch (error) {
|
|
1924
|
-
(0,
|
|
1933
|
+
(0, import_core11.handleCLIError)(error, "Analysis");
|
|
1925
1934
|
}
|
|
1926
1935
|
});
|
|
1927
1936
|
program.parse();
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -79,6 +79,7 @@ interface ContextSummary {
|
|
|
79
79
|
contextBudget: number;
|
|
80
80
|
severity: string;
|
|
81
81
|
}>;
|
|
82
|
+
config?: any;
|
|
82
83
|
}
|
|
83
84
|
interface DependencyGraph {
|
|
84
85
|
nodes: Map<string, DependencyNode>;
|
|
@@ -320,7 +321,7 @@ declare function getSmartDefaults(directory: string, userOptions: Partial<Contex
|
|
|
320
321
|
/**
|
|
321
322
|
* Generate summary of context analysis results
|
|
322
323
|
*/
|
|
323
|
-
declare function generateSummary(results: ContextAnalysisResult[]): ContextSummary;
|
|
324
|
+
declare function generateSummary(results: ContextAnalysisResult[], options?: any): ContextSummary;
|
|
324
325
|
|
|
325
326
|
/**
|
|
326
327
|
* Build co-usage matrix: track which files are imported together
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ interface ContextSummary {
|
|
|
79
79
|
contextBudget: number;
|
|
80
80
|
severity: string;
|
|
81
81
|
}>;
|
|
82
|
+
config?: any;
|
|
82
83
|
}
|
|
83
84
|
interface DependencyGraph {
|
|
84
85
|
nodes: Map<string, DependencyNode>;
|
|
@@ -320,7 +321,7 @@ declare function getSmartDefaults(directory: string, userOptions: Partial<Contex
|
|
|
320
321
|
/**
|
|
321
322
|
* Generate summary of context analysis results
|
|
322
323
|
*/
|
|
323
|
-
declare function generateSummary(results: ContextAnalysisResult[]): ContextSummary;
|
|
324
|
+
declare function generateSummary(results: ContextAnalysisResult[], options?: any): ContextSummary;
|
|
324
325
|
|
|
325
326
|
/**
|
|
326
327
|
* Build co-usage matrix: track which files are imported together
|