@arcteninc/core 0.0.94 → 0.0.96
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/package.json
CHANGED
|
@@ -87,6 +87,33 @@ async function findToolUsageFiles(projectRoot: string): Promise<string[]> {
|
|
|
87
87
|
return files;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
function unwrapExpression(expr: ts.Expression): ts.Expression {
|
|
91
|
+
let current: ts.Expression = expr;
|
|
92
|
+
// Keep unwrapping as long as we're looking at wrappers
|
|
93
|
+
while (true) {
|
|
94
|
+
if (ts.isParenthesizedExpression(current)) {
|
|
95
|
+
current = current.expression;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (ts.isAsExpression(current)) {
|
|
99
|
+
current = current.expression;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (ts.isTypeAssertionExpression(current)) {
|
|
103
|
+
current = current.expression;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// satisfies expressions exist in TS 4.9+
|
|
107
|
+
// @ts-ignore - older compiler types may not have this helper
|
|
108
|
+
if (typeof ts.isSatisfiesExpression === 'function' && ts.isSatisfiesExpression(current)) {
|
|
109
|
+
current = current.expression;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return current;
|
|
115
|
+
}
|
|
116
|
+
|
|
90
117
|
/**
|
|
91
118
|
* Extract tool names from an expression (handles arrays, variables, useMemo, etc.)
|
|
92
119
|
*/
|
|
@@ -100,6 +127,9 @@ function extractToolNamesFromExpression(
|
|
|
100
127
|
const visited = new Set<ts.Node>();
|
|
101
128
|
|
|
102
129
|
function extractFromExpr(node: ts.Node): void {
|
|
130
|
+
if (ts.isExpression(node)) {
|
|
131
|
+
node = unwrapExpression(node);
|
|
132
|
+
}
|
|
103
133
|
if (visited.has(node)) return;
|
|
104
134
|
visited.add(node);
|
|
105
135
|
|
|
@@ -217,11 +247,7 @@ function extractToolNamesFromExpression(
|
|
|
217
247
|
return;
|
|
218
248
|
}
|
|
219
249
|
|
|
220
|
-
//
|
|
221
|
-
if (ts.isParenthesizedExpression(node)) {
|
|
222
|
-
extractFromExpr(node.expression);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
250
|
+
// Parentheses handled via unwrapExpression
|
|
225
251
|
}
|
|
226
252
|
|
|
227
253
|
extractFromExpr(expr);
|
|
@@ -331,7 +357,7 @@ function extractToolNamesFromFile(
|
|
|
331
357
|
const toolNames = new Set<string>();
|
|
332
358
|
|
|
333
359
|
if (node.arguments.length > 0) {
|
|
334
|
-
const arg = node.arguments[0];
|
|
360
|
+
const arg = unwrapExpression(node.arguments[0]);
|
|
335
361
|
if (ts.isObjectLiteralExpression(arg)) {
|
|
336
362
|
for (const prop of arg.properties) {
|
|
337
363
|
if (ts.isPropertyAssignment(prop)) {
|
|
@@ -344,6 +370,18 @@ function extractToolNamesFromFile(
|
|
|
344
370
|
);
|
|
345
371
|
extracted.names.forEach(name => toolNames.add(name));
|
|
346
372
|
}
|
|
373
|
+
} else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
374
|
+
// Handle shorthand: { safeTools } instead of { safeTools: safeTools }
|
|
375
|
+
const propName = prop.name.getText(sourceFile);
|
|
376
|
+
if (propName === 'tools' || propName === 'safeTools') {
|
|
377
|
+
// For shorthand, the property name IS the identifier
|
|
378
|
+
const extracted = extractToolNamesFromExpression(
|
|
379
|
+
prop.name,
|
|
380
|
+
sourceFile,
|
|
381
|
+
variableMap
|
|
382
|
+
);
|
|
383
|
+
extracted.names.forEach(name => toolNames.add(name));
|
|
384
|
+
}
|
|
347
385
|
}
|
|
348
386
|
}
|
|
349
387
|
}
|
|
@@ -353,7 +391,7 @@ function extractToolNamesFromFile(
|
|
|
353
391
|
// Collect ordered tool names from tools and safeTools properties
|
|
354
392
|
const allToolOrder: string[] = [];
|
|
355
393
|
if (node.arguments.length > 0) {
|
|
356
|
-
const arg = node.arguments[0];
|
|
394
|
+
const arg = unwrapExpression(node.arguments[0]);
|
|
357
395
|
if (ts.isObjectLiteralExpression(arg)) {
|
|
358
396
|
for (const prop of arg.properties) {
|
|
359
397
|
if (ts.isPropertyAssignment(prop)) {
|
|
@@ -366,6 +404,18 @@ function extractToolNamesFromFile(
|
|
|
366
404
|
);
|
|
367
405
|
allToolOrder.push(...extracted.order);
|
|
368
406
|
}
|
|
407
|
+
} else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
408
|
+
// Handle shorthand: { safeTools } instead of { safeTools: safeTools }
|
|
409
|
+
const propName = prop.name.getText(sourceFile);
|
|
410
|
+
if (propName === 'tools' || propName === 'safeTools') {
|
|
411
|
+
// For shorthand, the property name IS the identifier
|
|
412
|
+
const extracted = extractToolNamesFromExpression(
|
|
413
|
+
prop.name,
|
|
414
|
+
sourceFile,
|
|
415
|
+
variableMap
|
|
416
|
+
);
|
|
417
|
+
allToolOrder.push(...extracted.order);
|
|
418
|
+
}
|
|
369
419
|
}
|
|
370
420
|
}
|
|
371
421
|
}
|