sf-agentpmd 0.1.0 → 0.1.1
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/NOTICE +7 -5
- package/dist/commands/agentpmd/analyze.js +4141 -109
- package/dist/commands/agentpmd/analyze.js.map +7 -1
- package/dist/commands/agentpmd/install-skill.js +27 -30
- package/dist/commands/agentpmd/install-skill.js.map +7 -1
- package/dist/index.js +4155 -3
- package/dist/index.js.map +7 -1
- package/oclif.manifest.json +1 -1
- package/package.json +7 -8
- package/dist/analyzer/action-references.d.ts +0 -21
- package/dist/analyzer/action-references.js +0 -130
- package/dist/analyzer/action-references.js.map +0 -1
- package/dist/analyzer/analyze.d.ts +0 -43
- package/dist/analyzer/analyze.js +0 -222
- package/dist/analyzer/analyze.js.map +0 -1
- package/dist/analyzer/apex-analyze.d.ts +0 -14
- package/dist/analyzer/apex-analyze.js +0 -60
- package/dist/analyzer/apex-analyze.js.map +0 -1
- package/dist/analyzer/apex-complexity.d.ts +0 -27
- package/dist/analyzer/apex-complexity.js +0 -133
- package/dist/analyzer/apex-complexity.js.map +0 -1
- package/dist/analyzer/apex-parse.d.ts +0 -39
- package/dist/analyzer/apex-parse.js +0 -32
- package/dist/analyzer/apex-parse.js.map +0 -1
- package/dist/analyzer/apex-resolve.d.ts +0 -32
- package/dist/analyzer/apex-resolve.js +0 -59
- package/dist/analyzer/apex-resolve.js.map +0 -1
- package/dist/analyzer/complexity.d.ts +0 -30
- package/dist/analyzer/complexity.js +0 -126
- package/dist/analyzer/complexity.js.map +0 -1
- package/dist/analyzer/parse.d.ts +0 -51
- package/dist/analyzer/parse.js +0 -143
- package/dist/analyzer/parse.js.map +0 -1
- package/dist/analyzer/project.d.ts +0 -12
- package/dist/analyzer/project.js +0 -51
- package/dist/analyzer/project.js.map +0 -1
- package/dist/analyzer/types.d.ts +0 -76
- package/dist/analyzer/types.js +0 -2
- package/dist/analyzer/types.js.map +0 -1
- package/dist/commands/agentpmd/analyze.d.ts +0 -20
- package/dist/commands/agentpmd/install-skill.d.ts +0 -11
- package/dist/index.d.ts +0 -3
- package/dist/renderers/csv.d.ts +0 -6
- package/dist/renderers/csv.js +0 -78
- package/dist/renderers/csv.js.map +0 -1
- package/dist/renderers/index.d.ts +0 -8
- package/dist/renderers/index.js +0 -25
- package/dist/renderers/index.js.map +0 -1
- package/dist/renderers/markdown.d.ts +0 -12
- package/dist/renderers/markdown.js +0 -233
- package/dist/renderers/markdown.js.map +0 -1
- package/dist/renderers/options.d.ts +0 -20
- package/dist/renderers/options.js +0 -2
- package/dist/renderers/options.js.map +0 -1
- package/dist/renderers/sarif.d.ts +0 -3
- package/dist/renderers/sarif.js +0 -131
- package/dist/renderers/sarif.js.map +0 -1
- package/dist/renderers/text.d.ts +0 -3
- package/dist/renderers/text.js +0 -243
- package/dist/renderers/text.js.map +0 -1
- package/vendor/agentscript-parser-javascript/dist/cst-node.d.ts +0 -83
- package/vendor/agentscript-parser-javascript/dist/cst-node.js +0 -238
- package/vendor/agentscript-parser-javascript/dist/errors.d.ts +0 -34
- package/vendor/agentscript-parser-javascript/dist/errors.js +0 -74
- package/vendor/agentscript-parser-javascript/dist/expressions.d.ts +0 -36
- package/vendor/agentscript-parser-javascript/dist/expressions.js +0 -682
- package/vendor/agentscript-parser-javascript/dist/highlighter.d.ts +0 -24
- package/vendor/agentscript-parser-javascript/dist/highlighter.js +0 -260
- package/vendor/agentscript-parser-javascript/dist/index.d.ts +0 -29
- package/vendor/agentscript-parser-javascript/dist/index.js +0 -35
- package/vendor/agentscript-parser-javascript/dist/lexer.d.ts +0 -60
- package/vendor/agentscript-parser-javascript/dist/lexer.js +0 -630
- package/vendor/agentscript-parser-javascript/dist/parse-mapping.d.ts +0 -46
- package/vendor/agentscript-parser-javascript/dist/parse-mapping.js +0 -549
- package/vendor/agentscript-parser-javascript/dist/parse-sequence.d.ts +0 -10
- package/vendor/agentscript-parser-javascript/dist/parse-sequence.js +0 -118
- package/vendor/agentscript-parser-javascript/dist/parse-statements.d.ts +0 -15
- package/vendor/agentscript-parser-javascript/dist/parse-statements.js +0 -519
- package/vendor/agentscript-parser-javascript/dist/parse-templates.d.ts +0 -15
- package/vendor/agentscript-parser-javascript/dist/parse-templates.js +0 -323
- package/vendor/agentscript-parser-javascript/dist/parser.d.ts +0 -65
- package/vendor/agentscript-parser-javascript/dist/parser.js +0 -163
- package/vendor/agentscript-parser-javascript/dist/recovery.d.ts +0 -51
- package/vendor/agentscript-parser-javascript/dist/recovery.js +0 -199
- package/vendor/agentscript-parser-javascript/dist/token.d.ts +0 -58
- package/vendor/agentscript-parser-javascript/dist/token.js +0 -62
- package/vendor/agentscript-parser-javascript/package.json +0 -19
- package/vendor/agentscript-types/dist/comment.d.ts +0 -11
- package/vendor/agentscript-types/dist/comment.js +0 -10
- package/vendor/agentscript-types/dist/cst.d.ts +0 -7
- package/vendor/agentscript-types/dist/cst.js +0 -8
- package/vendor/agentscript-types/dist/diagnostic.d.ts +0 -34
- package/vendor/agentscript-types/dist/diagnostic.js +0 -23
- package/vendor/agentscript-types/dist/index.d.ts +0 -9
- package/vendor/agentscript-types/dist/index.js +0 -10
- package/vendor/agentscript-types/dist/position.d.ts +0 -11
- package/vendor/agentscript-types/dist/position.js +0 -16
- package/vendor/agentscript-types/dist/syntax-node.d.ts +0 -39
- package/vendor/agentscript-types/dist/syntax-node.js +0 -8
- package/vendor/agentscript-types/package.json +0 -15
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { CatchClauseContext, CondExpressionContext, ConstructorDeclarationContext, DoWhileStatementContext, ForStatementContext, IfStatementContext, LogAndExpressionContext, LogOrExpressionContext, MethodDeclarationContext, WhenControlContext, WhileStatementContext, } from '@apexdevtools/apex-parser';
|
|
2
|
-
import { locOfCtx, walkParseTree } from './apex-parse.js';
|
|
3
|
-
/**
|
|
4
|
-
* Standard McCabe Cyclomatic Complexity for Apex, per the SonarQube /
|
|
5
|
-
* PMD CyclomaticComplexity convention used in the categorization
|
|
6
|
-
* whitepaper § 7:
|
|
7
|
-
*
|
|
8
|
-
* CC = 1
|
|
9
|
-
* + count(if)
|
|
10
|
-
* + count(for) // includes enhanced-for (for-each)
|
|
11
|
-
* + count(while)
|
|
12
|
-
* + count(do-while)
|
|
13
|
-
* + count(when arm) // each switch `when X { ... }`; `when else` excluded
|
|
14
|
-
* + count(catch) // each catch clause
|
|
15
|
-
* + count(ternary ?:)
|
|
16
|
-
* + count(&&)
|
|
17
|
-
* + count(||)
|
|
18
|
-
*
|
|
19
|
-
* Not counted: else, when else, finally, try itself.
|
|
20
|
-
*/
|
|
21
|
-
export function complexityOfMethod(methodCtx) {
|
|
22
|
-
const body = methodCtx.block();
|
|
23
|
-
const contributors = [];
|
|
24
|
-
if (body) {
|
|
25
|
-
walkParseTree(body, node => {
|
|
26
|
-
// Don't descend into nested methods/constructors — they have their
|
|
27
|
-
// own CC counted separately.
|
|
28
|
-
if (node !== methodCtx &&
|
|
29
|
-
(node instanceof MethodDeclarationContext ||
|
|
30
|
-
node instanceof ConstructorDeclarationContext)) {
|
|
31
|
-
// walkParseTree will still recurse into this node's subtree.
|
|
32
|
-
// We can't easily prune, so we filter by parentage: skip
|
|
33
|
-
// contributors whose nearest enclosing method/ctor is not us.
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const kind = classifyContributor(node);
|
|
37
|
-
if (kind !== undefined && enclosingMethod(node) === methodCtx) {
|
|
38
|
-
contributors.push({ kind, location: locOfCtx(node) });
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const name = methodCtx instanceof ConstructorDeclarationContext
|
|
43
|
-
? methodCtx.qualifiedName()?.getText() ?? '<ctor>'
|
|
44
|
-
: methodCtx.id()?.getText() ?? '<anon>';
|
|
45
|
-
const signature = renderSignature(methodCtx, name);
|
|
46
|
-
return {
|
|
47
|
-
complexity: 1 + contributors.length,
|
|
48
|
-
contributors,
|
|
49
|
-
kind: methodCtx instanceof ConstructorDeclarationContext ? 'constructor' : 'method',
|
|
50
|
-
location: locOfCtx(methodCtx),
|
|
51
|
-
name,
|
|
52
|
-
signature,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function classifyContributor(node) {
|
|
56
|
-
if (node instanceof IfStatementContext)
|
|
57
|
-
return 'if_statement';
|
|
58
|
-
if (node instanceof ForStatementContext)
|
|
59
|
-
return 'for_statement';
|
|
60
|
-
if (node instanceof WhileStatementContext)
|
|
61
|
-
return 'while_statement';
|
|
62
|
-
if (node instanceof DoWhileStatementContext)
|
|
63
|
-
return 'do_while_statement';
|
|
64
|
-
if (node instanceof WhenControlContext) {
|
|
65
|
-
// `when else { ... }` is the default arm → don't count it.
|
|
66
|
-
const wv = node.whenValue();
|
|
67
|
-
const elseTok = wv && typeof wv.ELSE === 'function' ? wv.ELSE() : undefined;
|
|
68
|
-
return elseTok ? undefined : 'when_arm';
|
|
69
|
-
}
|
|
70
|
-
if (node instanceof CatchClauseContext)
|
|
71
|
-
return 'catch_clause';
|
|
72
|
-
if (node instanceof CondExpressionContext)
|
|
73
|
-
return 'ternary';
|
|
74
|
-
if (node instanceof LogAndExpressionContext)
|
|
75
|
-
return 'short_circuit_and';
|
|
76
|
-
if (node instanceof LogOrExpressionContext)
|
|
77
|
-
return 'short_circuit_or';
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
function enclosingMethod(node) {
|
|
81
|
-
let p = node.parentCtx;
|
|
82
|
-
while (p) {
|
|
83
|
-
if (p instanceof MethodDeclarationContext || p instanceof ConstructorDeclarationContext) {
|
|
84
|
-
return p;
|
|
85
|
-
}
|
|
86
|
-
p = p.parentCtx;
|
|
87
|
-
}
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
function renderSignature(ctx, name) {
|
|
91
|
-
const paramsText = renderFormalParameters(ctx.formalParameters());
|
|
92
|
-
if (ctx instanceof MethodDeclarationContext) {
|
|
93
|
-
const retType = ctx.typeRef()?.getText() ?? (ctx.VOID() ? 'void' : '');
|
|
94
|
-
return `${retType ? retType + ' ' : ''}${name}${paramsText}`;
|
|
95
|
-
}
|
|
96
|
-
return `${name}${paramsText}`;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* ANTLR's `getText()` concatenates child tokens with no whitespace, which
|
|
100
|
-
* mangles parameter lists like `List<Request> requests` into
|
|
101
|
-
* `List<Request>requests`. Walk the structured children and rebuild a
|
|
102
|
-
* properly-spaced signature.
|
|
103
|
-
*/
|
|
104
|
-
function renderFormalParameters(params) {
|
|
105
|
-
if (!params)
|
|
106
|
-
return '()';
|
|
107
|
-
const list = params.formalParameterList();
|
|
108
|
-
if (!list)
|
|
109
|
-
return '()';
|
|
110
|
-
const parts = list.formalParameter_list().map(p => {
|
|
111
|
-
const type = p.typeRef()?.getText() ?? '';
|
|
112
|
-
const id = p.id()?.getText() ?? '';
|
|
113
|
-
return type && id ? `${type} ${id}` : type || id;
|
|
114
|
-
});
|
|
115
|
-
return `(${parts.join(', ')})`;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Enumerate every method and constructor in a compilation unit, including
|
|
119
|
-
* those nested inside inner classes. Each gets its own CC entry per the
|
|
120
|
-
* v2 scope ("all methods in any class touched by apex://").
|
|
121
|
-
*/
|
|
122
|
-
export function methodsInCompilationUnit(cu) {
|
|
123
|
-
const out = [];
|
|
124
|
-
walkParseTree(cu, node => {
|
|
125
|
-
if ((node instanceof MethodDeclarationContext ||
|
|
126
|
-
node instanceof ConstructorDeclarationContext) &&
|
|
127
|
-
node.block()) {
|
|
128
|
-
out.push(node);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
return out;
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=apex-complexity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apex-complexity.js","sourceRoot":"","sources":["../../src/analyzer/apex-complexity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,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AG,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,EAA0B;IAGjE,MAAM,GAAG,GAAoE,EAAE,CAAC;IAChF,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE;QACvB,IACE,CAAC,IAAI,YAAY,wBAAwB;YACvC,IAAI,YAAY,6BAA6B,CAAC;YAChD,IAAI,CAAC,KAAK,EAAE,EACZ,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { CompilationUnitContext } from '@apexdevtools/apex-parser';
|
|
2
|
-
/**
|
|
3
|
-
* Structural view of an ANTLR parse-tree node covering only the members this
|
|
4
|
-
* analyzer touches. `@apexdevtools/apex-parser` 5.x ships generated context
|
|
5
|
-
* types that extend antlr4's `ParserRuleContext`, but antlr4 4.13.x does not
|
|
6
|
-
* surface `ParserRuleContext` (nor its inherited `getText`/`getChild`) through
|
|
7
|
-
* its NodeNext `.d.cts` re-export chain, so importing it directly fails to
|
|
8
|
-
* resolve. We model the contract locally instead — the runtime objects carry
|
|
9
|
-
* all of these methods.
|
|
10
|
-
*/
|
|
11
|
-
export interface ApexRuleNode {
|
|
12
|
-
getChild(i: number): unknown;
|
|
13
|
-
getChildCount(): number;
|
|
14
|
-
getText(): string;
|
|
15
|
-
parentCtx?: ApexRuleNode | undefined;
|
|
16
|
-
start?: {
|
|
17
|
-
column?: number;
|
|
18
|
-
line?: number;
|
|
19
|
-
text?: string;
|
|
20
|
-
};
|
|
21
|
-
stop?: {
|
|
22
|
-
column?: number;
|
|
23
|
-
line?: number;
|
|
24
|
-
text?: string;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export declare function parseApexSource(source: string): CompilationUnitContext;
|
|
28
|
-
export declare function locOfCtx(ctx: ApexRuleNode): {
|
|
29
|
-
endCol: number;
|
|
30
|
-
endRow: number;
|
|
31
|
-
startCol: number;
|
|
32
|
-
startRow: number;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Walk an ANTLR parse-tree node depth-first, invoking the visitor on every
|
|
36
|
-
* descendant (including the start node). Terminal/error nodes have no
|
|
37
|
-
* children and are visited like any other node — caller filters by type.
|
|
38
|
-
*/
|
|
39
|
-
export declare function walkParseTree(node: ApexRuleNode, visit: (n: ApexRuleNode) => void): void;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ApexParserFactory, } from '@apexdevtools/apex-parser';
|
|
2
|
-
export function parseApexSource(source) {
|
|
3
|
-
const parser = ApexParserFactory.createParser(source);
|
|
4
|
-
return parser.compilationUnit();
|
|
5
|
-
}
|
|
6
|
-
export function locOfCtx(ctx) {
|
|
7
|
-
const { start } = ctx;
|
|
8
|
-
const stop = ctx.stop ?? ctx.start;
|
|
9
|
-
return {
|
|
10
|
-
endCol: (stop?.column ?? 0) + (stop?.text?.length ?? 0),
|
|
11
|
-
endRow: stop?.line ?? 0,
|
|
12
|
-
startCol: start?.column ?? 0,
|
|
13
|
-
startRow: start?.line ?? 0,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Walk an ANTLR parse-tree node depth-first, invoking the visitor on every
|
|
18
|
-
* descendant (including the start node). Terminal/error nodes have no
|
|
19
|
-
* children and are visited like any other node — caller filters by type.
|
|
20
|
-
*/
|
|
21
|
-
export function walkParseTree(node, visit) {
|
|
22
|
-
visit(node);
|
|
23
|
-
const childCount = typeof node.getChildCount === 'function' ? node.getChildCount() : 0;
|
|
24
|
-
for (let i = 0; i < childCount; i++) {
|
|
25
|
-
const c = node.getChild(i);
|
|
26
|
-
// Filter to ParserRuleContext children only — terminals don't carry rules.
|
|
27
|
-
if (c && typeof c.getChildCount === 'function') {
|
|
28
|
-
walkParseTree(c, visit);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=apex-parse.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apex-parse.js","sourceRoot":"","sources":["../../src/analyzer/apex-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,2BAA2B,CAAC;AAoBnC,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,eAAe,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAiB;IACxC,MAAM,EAAC,KAAK,EAAC,GAAG,GAAG,CAAC;IACpB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC;IACnC,OAAO;QACL,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;QACvD,MAAM,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC;QACvB,QAAQ,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;QAC5B,QAAQ,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC;KAC3B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAkB,EAClB,KAAgC;IAEhC,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,MAAM,UAAU,GACd,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACtE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3B,2EAA2E;QAC3E,IAAI,CAAC,IAAI,OAAQ,CAAkB,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;YACjE,aAAa,CAAC,CAAiB,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare function extractApexClassName(uri: string): string | undefined;
|
|
2
|
-
export interface ResolveOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The .agent file that holds the apex:// reference. Used as the seed for
|
|
5
|
-
* the upward walk.
|
|
6
|
-
*/
|
|
7
|
-
agentFilePath: string;
|
|
8
|
-
/**
|
|
9
|
-
* Optional `--apex-source` override. When set, classes are looked up here
|
|
10
|
-
* before falling back to the upward walk.
|
|
11
|
-
*/
|
|
12
|
-
apexSourceOverride?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The CLI `--source-dir` value. We never walk above this directory.
|
|
15
|
-
*/
|
|
16
|
-
sourceDirRoot: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Find `classes/<ClassName>.cls` by walking up from the .agent file. The walk
|
|
20
|
-
* stops at the CLI's source-dir root so we never escape it. Returns the
|
|
21
|
-
* absolute path or undefined.
|
|
22
|
-
*
|
|
23
|
-
* Path conventions covered:
|
|
24
|
-
* - sfdx default: <pkg>/main/default/classes/<X>.cls, with the .agent in
|
|
25
|
-
* <pkg>/main/default/aiAuthoringBundles/<Bundle>/<X>.agent
|
|
26
|
-
* - flat fixtures: <root>/classes/<X>.cls, with .agent under
|
|
27
|
-
* <root>/aiAuthoringBundles/<Bundle>/<X>.agent
|
|
28
|
-
* - explicit override: --apex-source <dir>/<X>.cls
|
|
29
|
-
*/
|
|
30
|
-
export declare function resolveApexClassPath(className: string, opts: ResolveOptions): Promise<string | undefined>;
|
|
31
|
-
/** True if `child` is the same as or a subpath of `parent` (path-segment safe). */
|
|
32
|
-
export declare function isUnder(child: string, parent: string): boolean;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { stat } from 'node:fs/promises';
|
|
2
|
-
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
3
|
-
const APEX_SCHEME = /^apex:\/\/(.+)$/;
|
|
4
|
-
export function extractApexClassName(uri) {
|
|
5
|
-
const m = APEX_SCHEME.exec(uri);
|
|
6
|
-
if (!m)
|
|
7
|
-
return undefined;
|
|
8
|
-
// `apex://Foo` or `apex://namespace__Foo`; take the trailing simple name.
|
|
9
|
-
const raw = m[1].trim();
|
|
10
|
-
const dot = raw.lastIndexOf('.');
|
|
11
|
-
return dot === -1 ? raw : raw.slice(dot + 1);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Find `classes/<ClassName>.cls` by walking up from the .agent file. The walk
|
|
15
|
-
* stops at the CLI's source-dir root so we never escape it. Returns the
|
|
16
|
-
* absolute path or undefined.
|
|
17
|
-
*
|
|
18
|
-
* Path conventions covered:
|
|
19
|
-
* - sfdx default: <pkg>/main/default/classes/<X>.cls, with the .agent in
|
|
20
|
-
* <pkg>/main/default/aiAuthoringBundles/<Bundle>/<X>.agent
|
|
21
|
-
* - flat fixtures: <root>/classes/<X>.cls, with .agent under
|
|
22
|
-
* <root>/aiAuthoringBundles/<Bundle>/<X>.agent
|
|
23
|
-
* - explicit override: --apex-source <dir>/<X>.cls
|
|
24
|
-
*/
|
|
25
|
-
export async function resolveApexClassPath(className, opts) {
|
|
26
|
-
const candidates = [];
|
|
27
|
-
if (opts.apexSourceOverride) {
|
|
28
|
-
const override = isAbsolute(opts.apexSourceOverride)
|
|
29
|
-
? opts.apexSourceOverride
|
|
30
|
-
: resolve(opts.apexSourceOverride);
|
|
31
|
-
candidates.push(join(override, `${className}.cls`), join(override, 'classes', `${className}.cls`));
|
|
32
|
-
}
|
|
33
|
-
const stop = resolve(opts.sourceDirRoot);
|
|
34
|
-
let dir = dirname(resolve(opts.agentFilePath));
|
|
35
|
-
while (true) {
|
|
36
|
-
candidates.push(join(dir, 'classes', `${className}.cls`));
|
|
37
|
-
if (dir === stop)
|
|
38
|
-
break;
|
|
39
|
-
const parent = dirname(dir);
|
|
40
|
-
if (parent === dir)
|
|
41
|
-
break;
|
|
42
|
-
dir = parent;
|
|
43
|
-
}
|
|
44
|
-
for (const c of candidates) {
|
|
45
|
-
const s = await stat(c).catch(() => { });
|
|
46
|
-
if (s?.isFile())
|
|
47
|
-
return c;
|
|
48
|
-
}
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
/** True if `child` is the same as or a subpath of `parent` (path-segment safe). */
|
|
52
|
-
export function isUnder(child, parent) {
|
|
53
|
-
const c = resolve(child);
|
|
54
|
-
const p = resolve(parent);
|
|
55
|
-
if (c === p)
|
|
56
|
-
return true;
|
|
57
|
-
return c.startsWith(p.endsWith(sep) ? p : p + sep);
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=apex-resolve.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apex-resolve.js","sourceRoot":"","sources":["../../src/analyzer/apex-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEpE,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,0EAA0E;IAC1E,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAA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AE,CAAC;QAC3B,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,EAAE,MAAM,EAAE;YAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,MAAc;IACnD,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { SyntaxNode } from '@agentscript/types';
|
|
2
|
-
import type { ProcedureCC, SourceLocation } from './types.js';
|
|
3
|
-
export declare function complexityOf(body: SyntaxNode, scope: string, kind: ProcedureCC['kind']): ProcedureCC;
|
|
4
|
-
/**
|
|
5
|
-
* Identify the procedure-bearing blocks in a single topic / start_agent /
|
|
6
|
-
* subagent scope. AgentScript's three control-flow surfaces are:
|
|
7
|
-
* • before_reasoning: <procedure> (deterministic, pre-LLM)
|
|
8
|
-
* • after_reasoning: <procedure> (deterministic, post-LLM)
|
|
9
|
-
* • reasoning.instructions: -> <template body> (LLM-evaluated)
|
|
10
|
-
*
|
|
11
|
-
* v1 walks all three for CC. (instructions: -> body holds Reasoning Logic per
|
|
12
|
-
* whitepaper § 4 but the CC convention itself is language-neutral.)
|
|
13
|
-
*/
|
|
14
|
-
export declare function collectProcedures(scopeBody: SyntaxNode, scopeLabel: string): ProcedureCC[];
|
|
15
|
-
export interface AgentScope {
|
|
16
|
-
body: SyntaxNode;
|
|
17
|
-
kind: string;
|
|
18
|
-
label: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Find topic/start_agent/subagent scopes anywhere in the tree. They appear
|
|
22
|
-
* at the source-file level as mapping_elements whose key kind matches.
|
|
23
|
-
*/
|
|
24
|
-
export declare function collectScopes(root: SyntaxNode): AgentScope[];
|
|
25
|
-
export interface FileComplexity {
|
|
26
|
-
procedures: ProcedureCC[];
|
|
27
|
-
total: number;
|
|
28
|
-
}
|
|
29
|
-
export declare function complexityForFile(root: SyntaxNode): FileComplexity;
|
|
30
|
-
export declare function dummyLoc(): SourceLocation;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { bodyOf, descendants, findMappingEntry, keyHeader, locOf } from './parse.js';
|
|
2
|
-
/**
|
|
3
|
-
* Standard McCabe CC, applied to AgentScript control-flow nodes.
|
|
4
|
-
*
|
|
5
|
-
* Per the categorization whitepaper (§ 7) the convention mirrors
|
|
6
|
-
* SonarQube/PMD/Checkstyle for the relevant language:
|
|
7
|
-
*
|
|
8
|
-
* CC = 1
|
|
9
|
-
* + count(if_statement)
|
|
10
|
-
* + count(elif_clause)
|
|
11
|
-
* + count(ternary_expression)
|
|
12
|
-
* + count(binary_expression where operator ∈ {and, or})
|
|
13
|
-
*
|
|
14
|
-
* We do NOT count: else_clause, comparison_expression, set/run/transition,
|
|
15
|
-
* try/catch (AgentScript has none), default branches.
|
|
16
|
-
*/
|
|
17
|
-
const SHORT_CIRCUIT_OPS = new Set(['and', 'or']);
|
|
18
|
-
export function complexityOf(body, scope, kind) {
|
|
19
|
-
const contributors = [];
|
|
20
|
-
for (const n of descendants(body)) {
|
|
21
|
-
switch (n.type) {
|
|
22
|
-
case 'binary_expression': {
|
|
23
|
-
const op = binaryOperator(n);
|
|
24
|
-
if (op === 'and')
|
|
25
|
-
contributors.push({ kind: 'short_circuit_and', location: locOf(n) });
|
|
26
|
-
else if (op === 'or')
|
|
27
|
-
contributors.push({ kind: 'short_circuit_or', location: locOf(n) });
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
case 'elif_clause': {
|
|
31
|
-
contributors.push({ kind: 'elif_clause', location: locOf(n) });
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
case 'if_statement': {
|
|
35
|
-
contributors.push({ kind: 'if_statement', location: locOf(n) });
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 'ternary_expression': {
|
|
39
|
-
contributors.push({ kind: 'ternary_expression', location: locOf(n) });
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
complexity: 1 + contributors.length,
|
|
46
|
-
contributors,
|
|
47
|
-
kind,
|
|
48
|
-
location: locOf(body),
|
|
49
|
-
scope,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function binaryOperator(n) {
|
|
53
|
-
for (const c of n.children) {
|
|
54
|
-
if (!c.isNamed && SHORT_CIRCUIT_OPS.has(c.type))
|
|
55
|
-
return c.type;
|
|
56
|
-
if (!c.isNamed && (c.type === '+' || c.type === '-' || c.type === '*' || c.type === '/'))
|
|
57
|
-
return c.type;
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Identify the procedure-bearing blocks in a single topic / start_agent /
|
|
63
|
-
* subagent scope. AgentScript's three control-flow surfaces are:
|
|
64
|
-
* • before_reasoning: <procedure> (deterministic, pre-LLM)
|
|
65
|
-
* • after_reasoning: <procedure> (deterministic, post-LLM)
|
|
66
|
-
* • reasoning.instructions: -> <template body> (LLM-evaluated)
|
|
67
|
-
*
|
|
68
|
-
* v1 walks all three for CC. (instructions: -> body holds Reasoning Logic per
|
|
69
|
-
* whitepaper § 4 but the CC convention itself is language-neutral.)
|
|
70
|
-
*/
|
|
71
|
-
export function collectProcedures(scopeBody, scopeLabel) {
|
|
72
|
-
const out = [];
|
|
73
|
-
const before = findMappingEntry(scopeBody, 'before_reasoning');
|
|
74
|
-
if (before)
|
|
75
|
-
out.push(complexityOf(before, scopeLabel, 'before_reasoning'));
|
|
76
|
-
const after = findMappingEntry(scopeBody, 'after_reasoning');
|
|
77
|
-
if (after)
|
|
78
|
-
out.push(complexityOf(after, scopeLabel, 'after_reasoning'));
|
|
79
|
-
const reasoning = findMappingEntry(scopeBody, 'reasoning');
|
|
80
|
-
if (reasoning) {
|
|
81
|
-
const instructions = findMappingEntry(reasoning, 'instructions');
|
|
82
|
-
if (instructions) {
|
|
83
|
-
out.push(complexityOf(instructions, scopeLabel, 'reasoning_instructions'));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
|
-
/** Scopes that contain procedure-bearing blocks. */
|
|
89
|
-
const PROCEDURE_SCOPES = new Set(['start_agent', 'subagent', 'topic']);
|
|
90
|
-
/**
|
|
91
|
-
* Find topic/start_agent/subagent scopes anywhere in the tree. They appear
|
|
92
|
-
* at the source-file level as mapping_elements whose key kind matches.
|
|
93
|
-
*/
|
|
94
|
-
export function collectScopes(root) {
|
|
95
|
-
const scopes = [];
|
|
96
|
-
// The source_file has a single top-level `mapping` child holding the agent
|
|
97
|
-
// declarations (system, config, variables, start_agent X, topic Y, …).
|
|
98
|
-
const topMapping = root.namedChildren.find(c => c.type === 'mapping') ?? root;
|
|
99
|
-
for (const c of topMapping.namedChildren) {
|
|
100
|
-
if (c.type !== 'mapping_element')
|
|
101
|
-
continue;
|
|
102
|
-
const keyNode = c.childForFieldName('key') ?? c.namedChildren.find(n => n.type === 'key');
|
|
103
|
-
if (!keyNode)
|
|
104
|
-
continue;
|
|
105
|
-
const h = keyHeader(keyNode);
|
|
106
|
-
if (!h || !PROCEDURE_SCOPES.has(h.kind))
|
|
107
|
-
continue;
|
|
108
|
-
const body = bodyOf(keyNode);
|
|
109
|
-
if (!body)
|
|
110
|
-
continue;
|
|
111
|
-
scopes.push({ body, kind: h.kind, label: `${h.kind} ${h.label ?? ''}`.trim() });
|
|
112
|
-
}
|
|
113
|
-
return scopes;
|
|
114
|
-
}
|
|
115
|
-
export function complexityForFile(root) {
|
|
116
|
-
const procedures = [];
|
|
117
|
-
for (const s of collectScopes(root)) {
|
|
118
|
-
procedures.push(...collectProcedures(s.body, s.label));
|
|
119
|
-
}
|
|
120
|
-
const total = procedures.reduce((acc, p) => acc + p.complexity, 0);
|
|
121
|
-
return { procedures, total };
|
|
122
|
-
}
|
|
123
|
-
export function dummyLoc() {
|
|
124
|
-
return { endCol: 0, endRow: 0, startCol: 0, startRow: 0 };
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=complexity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"complexity.js","sourceRoot":"","sources":["../../src/analyzer/complexity.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAEjD,MAAM,UAAU,YAAY,CAAC,IAAgB,EAAE,KAAa,EAAE,IAAyB;IACrF,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;YACf,KAAK,mBAAmB,CAAC,CAAC,CAAC;gBACzB,MAAM,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;gBAC7B,IAAI,EAAE,KAAK,KAAK;oBAAE,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;qBAClF,IAAI,EAAE,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CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACnE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC5D,CAAC"}
|
package/dist/analyzer/parse.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { SyntaxNode } from '@agentscript/types';
|
|
2
|
-
export declare function parseAgentSource(source: string): SyntaxNode;
|
|
3
|
-
export declare function locOf(n: SyntaxNode): {
|
|
4
|
-
endCol: number;
|
|
5
|
-
endRow: number;
|
|
6
|
-
startCol: number;
|
|
7
|
-
startRow: number;
|
|
8
|
-
};
|
|
9
|
-
export declare function walk(node: SyntaxNode, visit: (n: SyntaxNode) => void): void;
|
|
10
|
-
export declare function descendants(node: SyntaxNode): Generator<SyntaxNode>;
|
|
11
|
-
/**
|
|
12
|
-
* The block header for a `key` node. AgentScript keys can be plain (`config`)
|
|
13
|
-
* or named (`topic case_creation`, `start_agent customer_verification`).
|
|
14
|
-
* We return the first whitespace-delimited token as the key kind, and the
|
|
15
|
-
* remainder (if any) as the instance label.
|
|
16
|
-
*/
|
|
17
|
-
export declare function keyHeader(n: SyntaxNode): null | {
|
|
18
|
-
kind: string;
|
|
19
|
-
label?: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* The CST shapes a key/value pair as `mapping_element { key, ':', value }`.
|
|
23
|
-
* Given the mapping_element node, return its key kind + label.
|
|
24
|
-
*/
|
|
25
|
-
export declare function mappingKeyHeader(m: SyntaxNode): null | {
|
|
26
|
-
kind: string;
|
|
27
|
-
label?: string;
|
|
28
|
-
};
|
|
29
|
-
export declare function mappingValue(m: SyntaxNode): SyntaxNode | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* Within a scope whose body is a `mapping` (the typical case for topic/
|
|
32
|
-
* start_agent/subagent blocks), find the mapping_element whose key matches
|
|
33
|
-
* `kind`, and return its value subtree.
|
|
34
|
-
*/
|
|
35
|
-
export declare function findMappingEntry(parentBody: SyntaxNode, kind: string): SyntaxNode | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Walk a scope-key node (topic / start_agent / subagent at top level) and
|
|
38
|
-
* return its body — the `mapping` that holds before_reasoning, after_reasoning,
|
|
39
|
-
* reasoning, actions, etc. The scope-key itself lives inside a mapping_element
|
|
40
|
-
* at the source-file level; the body is the sibling value.
|
|
41
|
-
*/
|
|
42
|
-
export declare function bodyOf(scopeKey: SyntaxNode): SyntaxNode | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Read the `developer_name:` value from the `config:` block of a parsed
|
|
45
|
-
* .agent file. This is the canonical API name of the agent (matches what
|
|
46
|
-
* `sf agent generate authoring-bundle --api-name X` produces). Returns
|
|
47
|
-
* undefined when the field is absent or empty.
|
|
48
|
-
*/
|
|
49
|
-
export declare function extractDeveloperName(root: SyntaxNode): string | undefined;
|
|
50
|
-
/** Convenience: extract a leaf string literal text (without surrounding quotes). */
|
|
51
|
-
export declare function extractStringLiteral(n: SyntaxNode): string | undefined;
|