sf-agentpmd 0.1.0

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.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +26 -0
  3. package/README.md +204 -0
  4. package/bin/dev.js +5 -0
  5. package/bin/run.js +3 -0
  6. package/dist/analyzer/action-references.d.ts +21 -0
  7. package/dist/analyzer/action-references.js +130 -0
  8. package/dist/analyzer/action-references.js.map +1 -0
  9. package/dist/analyzer/analyze.d.ts +43 -0
  10. package/dist/analyzer/analyze.js +222 -0
  11. package/dist/analyzer/analyze.js.map +1 -0
  12. package/dist/analyzer/apex-analyze.d.ts +14 -0
  13. package/dist/analyzer/apex-analyze.js +60 -0
  14. package/dist/analyzer/apex-analyze.js.map +1 -0
  15. package/dist/analyzer/apex-complexity.d.ts +27 -0
  16. package/dist/analyzer/apex-complexity.js +133 -0
  17. package/dist/analyzer/apex-complexity.js.map +1 -0
  18. package/dist/analyzer/apex-parse.d.ts +39 -0
  19. package/dist/analyzer/apex-parse.js +32 -0
  20. package/dist/analyzer/apex-parse.js.map +1 -0
  21. package/dist/analyzer/apex-resolve.d.ts +32 -0
  22. package/dist/analyzer/apex-resolve.js +59 -0
  23. package/dist/analyzer/apex-resolve.js.map +1 -0
  24. package/dist/analyzer/complexity.d.ts +30 -0
  25. package/dist/analyzer/complexity.js +126 -0
  26. package/dist/analyzer/complexity.js.map +1 -0
  27. package/dist/analyzer/parse.d.ts +51 -0
  28. package/dist/analyzer/parse.js +143 -0
  29. package/dist/analyzer/parse.js.map +1 -0
  30. package/dist/analyzer/project.d.ts +12 -0
  31. package/dist/analyzer/project.js +51 -0
  32. package/dist/analyzer/project.js.map +1 -0
  33. package/dist/analyzer/types.d.ts +76 -0
  34. package/dist/analyzer/types.js +2 -0
  35. package/dist/analyzer/types.js.map +1 -0
  36. package/dist/commands/agentpmd/analyze.d.ts +20 -0
  37. package/dist/commands/agentpmd/analyze.js +122 -0
  38. package/dist/commands/agentpmd/analyze.js.map +1 -0
  39. package/dist/commands/agentpmd/install-skill.d.ts +11 -0
  40. package/dist/commands/agentpmd/install-skill.js +33 -0
  41. package/dist/commands/agentpmd/install-skill.js.map +1 -0
  42. package/dist/index.d.ts +3 -0
  43. package/dist/index.js +3 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/renderers/csv.d.ts +6 -0
  46. package/dist/renderers/csv.js +78 -0
  47. package/dist/renderers/csv.js.map +1 -0
  48. package/dist/renderers/index.d.ts +8 -0
  49. package/dist/renderers/index.js +25 -0
  50. package/dist/renderers/index.js.map +1 -0
  51. package/dist/renderers/markdown.d.ts +12 -0
  52. package/dist/renderers/markdown.js +233 -0
  53. package/dist/renderers/markdown.js.map +1 -0
  54. package/dist/renderers/options.d.ts +20 -0
  55. package/dist/renderers/options.js +2 -0
  56. package/dist/renderers/options.js.map +1 -0
  57. package/dist/renderers/sarif.d.ts +3 -0
  58. package/dist/renderers/sarif.js +131 -0
  59. package/dist/renderers/sarif.js.map +1 -0
  60. package/dist/renderers/text.d.ts +3 -0
  61. package/dist/renderers/text.js +243 -0
  62. package/dist/renderers/text.js.map +1 -0
  63. package/oclif.manifest.json +168 -0
  64. package/package.json +97 -0
  65. package/skill/SKILL.md +103 -0
  66. package/skill/references/command-structure.md +89 -0
  67. package/skill/references/install.md +112 -0
  68. package/skill/references/output-formats.md +205 -0
  69. package/skill/references/upgrade.md +112 -0
  70. package/vendor/agentscript-parser-javascript/dist/cst-node.d.ts +83 -0
  71. package/vendor/agentscript-parser-javascript/dist/cst-node.js +238 -0
  72. package/vendor/agentscript-parser-javascript/dist/errors.d.ts +34 -0
  73. package/vendor/agentscript-parser-javascript/dist/errors.js +74 -0
  74. package/vendor/agentscript-parser-javascript/dist/expressions.d.ts +36 -0
  75. package/vendor/agentscript-parser-javascript/dist/expressions.js +682 -0
  76. package/vendor/agentscript-parser-javascript/dist/highlighter.d.ts +24 -0
  77. package/vendor/agentscript-parser-javascript/dist/highlighter.js +260 -0
  78. package/vendor/agentscript-parser-javascript/dist/index.d.ts +29 -0
  79. package/vendor/agentscript-parser-javascript/dist/index.js +35 -0
  80. package/vendor/agentscript-parser-javascript/dist/lexer.d.ts +60 -0
  81. package/vendor/agentscript-parser-javascript/dist/lexer.js +630 -0
  82. package/vendor/agentscript-parser-javascript/dist/parse-mapping.d.ts +46 -0
  83. package/vendor/agentscript-parser-javascript/dist/parse-mapping.js +549 -0
  84. package/vendor/agentscript-parser-javascript/dist/parse-sequence.d.ts +10 -0
  85. package/vendor/agentscript-parser-javascript/dist/parse-sequence.js +118 -0
  86. package/vendor/agentscript-parser-javascript/dist/parse-statements.d.ts +15 -0
  87. package/vendor/agentscript-parser-javascript/dist/parse-statements.js +519 -0
  88. package/vendor/agentscript-parser-javascript/dist/parse-templates.d.ts +15 -0
  89. package/vendor/agentscript-parser-javascript/dist/parse-templates.js +323 -0
  90. package/vendor/agentscript-parser-javascript/dist/parser.d.ts +65 -0
  91. package/vendor/agentscript-parser-javascript/dist/parser.js +163 -0
  92. package/vendor/agentscript-parser-javascript/dist/recovery.d.ts +51 -0
  93. package/vendor/agentscript-parser-javascript/dist/recovery.js +199 -0
  94. package/vendor/agentscript-parser-javascript/dist/token.d.ts +58 -0
  95. package/vendor/agentscript-parser-javascript/dist/token.js +62 -0
  96. package/vendor/agentscript-parser-javascript/package.json +19 -0
  97. package/vendor/agentscript-types/dist/comment.d.ts +11 -0
  98. package/vendor/agentscript-types/dist/comment.js +10 -0
  99. package/vendor/agentscript-types/dist/cst.d.ts +7 -0
  100. package/vendor/agentscript-types/dist/cst.js +8 -0
  101. package/vendor/agentscript-types/dist/diagnostic.d.ts +34 -0
  102. package/vendor/agentscript-types/dist/diagnostic.js +23 -0
  103. package/vendor/agentscript-types/dist/index.d.ts +9 -0
  104. package/vendor/agentscript-types/dist/index.js +10 -0
  105. package/vendor/agentscript-types/dist/position.d.ts +11 -0
  106. package/vendor/agentscript-types/dist/position.js +16 -0
  107. package/vendor/agentscript-types/dist/syntax-node.d.ts +39 -0
  108. package/vendor/agentscript-types/dist/syntax-node.js +8 -0
  109. package/vendor/agentscript-types/package.json +15 -0
@@ -0,0 +1 @@
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,EAAE,CAAC;IACxB,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAC/C,CAAC;AAmBD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,SAAiB,EACjB,IAAoB;IAEpB,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC;YAClD,CAAC,CAAC,IAAI,CAAC,kBAAkB;YACzB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACrC,UAAU,CAAC,IAAI,CACb,IAAI,CAAC,QAAQ,EAAE,GAA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-0,0 +1,30 @@
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;
@@ -0,0 +1,126 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complexity.js","sourceRoot":"","sources":["../../src/analyzer/complexity.ts"],"names":[],"mappings":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,CAAC,CAAC,IAAI,CAAC;YAAE,SAAS;QAClD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAOD,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAChD,MAAM,UAAU,GAAkB,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,UAAU,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,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"}
@@ -0,0 +1,51 @@
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;
@@ -0,0 +1,143 @@
1
+ import { parse as parseAgent } from '@agentscript/parser-javascript';
2
+ export function parseAgentSource(source) {
3
+ return parseAgent(source).rootNode;
4
+ }
5
+ export function locOf(n) {
6
+ return {
7
+ endCol: n.endCol,
8
+ endRow: n.endRow,
9
+ startCol: n.startCol,
10
+ startRow: n.startRow,
11
+ };
12
+ }
13
+ export function walk(node, visit) {
14
+ visit(node);
15
+ for (const c of node.namedChildren)
16
+ walk(c, visit);
17
+ }
18
+ export function* descendants(node) {
19
+ yield node;
20
+ for (const c of node.namedChildren)
21
+ yield* descendants(c);
22
+ }
23
+ /**
24
+ * The block header for a `key` node. AgentScript keys can be plain (`config`)
25
+ * or named (`topic case_creation`, `start_agent customer_verification`).
26
+ * We return the first whitespace-delimited token as the key kind, and the
27
+ * remainder (if any) as the instance label.
28
+ */
29
+ export function keyHeader(n) {
30
+ if (n.type !== 'key')
31
+ return null;
32
+ const head = n.text.split('\n', 1)[0];
33
+ const colon = head.indexOf(':');
34
+ const lhs = (colon === -1 ? head : head.slice(0, colon)).trim();
35
+ const parts = lhs.split(/\s+/);
36
+ return { kind: parts[0], label: parts.length > 1 ? parts.slice(1).join(' ') : undefined };
37
+ }
38
+ /**
39
+ * The CST shapes a key/value pair as `mapping_element { key, ':', value }`.
40
+ * Given the mapping_element node, return its key kind + label.
41
+ */
42
+ export function mappingKeyHeader(m) {
43
+ if (m.type !== 'mapping_element')
44
+ return null;
45
+ const keyNode = m.childForFieldName('key');
46
+ if (!keyNode) {
47
+ // Fall back: first namedChild of type 'key'.
48
+ for (const c of m.namedChildren) {
49
+ if (c.type === 'key')
50
+ return keyHeader(c);
51
+ }
52
+ return null;
53
+ }
54
+ return keyHeader(keyNode);
55
+ }
56
+ /**
57
+ * The value-bearing child of a mapping_element. Could be `mapping` (sub-block),
58
+ * `expression_with_to` (scalar/expression), `colinear_value`, `procedure`,
59
+ * `variable_declaration`, etc.
60
+ *
61
+ * A mapping_element can interleave leading `comment` nodes between the `:`/`->`
62
+ * markers and the actual value-bearing child. Skip them so we don't return a
63
+ * comment as the "value."
64
+ */
65
+ const NON_VALUE_NAMED_TYPES = new Set(['comment', 'key']);
66
+ export function mappingValue(m) {
67
+ if (m.type !== 'mapping_element')
68
+ return undefined;
69
+ for (const c of m.namedChildren) {
70
+ if (!NON_VALUE_NAMED_TYPES.has(c.type))
71
+ return c;
72
+ }
73
+ return undefined;
74
+ }
75
+ /**
76
+ * Within a scope whose body is a `mapping` (the typical case for topic/
77
+ * start_agent/subagent blocks), find the mapping_element whose key matches
78
+ * `kind`, and return its value subtree.
79
+ */
80
+ export function findMappingEntry(parentBody, kind) {
81
+ for (const c of parentBody.namedChildren) {
82
+ if (c.type !== 'mapping_element')
83
+ continue;
84
+ const h = mappingKeyHeader(c);
85
+ if (h && h.kind === kind)
86
+ return mappingValue(c);
87
+ }
88
+ return undefined;
89
+ }
90
+ /**
91
+ * Walk a scope-key node (topic / start_agent / subagent at top level) and
92
+ * return its body — the `mapping` that holds before_reasoning, after_reasoning,
93
+ * reasoning, actions, etc. The scope-key itself lives inside a mapping_element
94
+ * at the source-file level; the body is the sibling value.
95
+ */
96
+ export function bodyOf(scopeKey) {
97
+ const { parent } = scopeKey;
98
+ if (!parent)
99
+ return undefined;
100
+ return mappingValue(parent);
101
+ }
102
+ /**
103
+ * Read the `developer_name:` value from the `config:` block of a parsed
104
+ * .agent file. This is the canonical API name of the agent (matches what
105
+ * `sf agent generate authoring-bundle --api-name X` produces). Returns
106
+ * undefined when the field is absent or empty.
107
+ */
108
+ export function extractDeveloperName(root) {
109
+ const topMapping = root.namedChildren.find(c => c.type === 'mapping') ?? root;
110
+ for (const c of topMapping.namedChildren) {
111
+ if (c.type !== 'mapping_element')
112
+ continue;
113
+ const keyNode = c.childForFieldName('key') ?? c.namedChildren.find(n => n.type === 'key');
114
+ if (!keyNode)
115
+ continue;
116
+ const h = keyHeader(keyNode);
117
+ if (!h || h.kind !== 'config')
118
+ continue;
119
+ const body = mappingValue(c);
120
+ if (!body)
121
+ return undefined;
122
+ const devNameVal = findMappingEntry(body, 'developer_name');
123
+ if (!devNameVal)
124
+ return undefined;
125
+ return extractStringLiteral(devNameVal);
126
+ }
127
+ return undefined;
128
+ }
129
+ /** Convenience: extract a leaf string literal text (without surrounding quotes). */
130
+ export function extractStringLiteral(n) {
131
+ for (const d of descendants(n)) {
132
+ if (d.type === 'string') {
133
+ const t = d.text;
134
+ if (t.startsWith('"') && t.endsWith('"'))
135
+ return t.slice(1, -1);
136
+ if (t.startsWith("'") && t.endsWith("'"))
137
+ return t.slice(1, -1);
138
+ return t;
139
+ }
140
+ }
141
+ return undefined;
142
+ }
143
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/analyzer/parse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAErE,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,CAAa;IACjC,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;KACrB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAgB,EAAE,KAA8B;IACnE,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa;QAAE,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,SAAS,CAAC,CAAC,WAAW,CAAC,IAAgB;IAC3C,MAAM,IAAI,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa;QAAE,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,CAAa;IACrC,IAAI,CAAC,CAAC,IAAI,KAA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,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export interface SfdxProject {
2
+ /** Absolute paths of every `packageDirectories[].path`, in declaration order. */
3
+ packageDirectories: string[];
4
+ /** Absolute path of the project root (the directory containing sfdx-project.json). */
5
+ root: string;
6
+ }
7
+ /**
8
+ * Walk up from `startDir` until we find a directory containing
9
+ * `sfdx-project.json`, then return its root + resolved package directories.
10
+ * Returns undefined when no project is found.
11
+ */
12
+ export declare function discoverSfdxProject(startDir: string): Promise<SfdxProject | undefined>;
@@ -0,0 +1,51 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
3
+ /**
4
+ * Walk up from `startDir` until we find a directory containing
5
+ * `sfdx-project.json`, then return its root + resolved package directories.
6
+ * Returns undefined when no project is found.
7
+ */
8
+ export async function discoverSfdxProject(startDir) {
9
+ let dir = resolve(startDir);
10
+ while (true) {
11
+ const candidate = join(dir, 'sfdx-project.json');
12
+ const s = await stat(candidate).catch(() => { });
13
+ if (s?.isFile()) {
14
+ return readProject(dir, candidate);
15
+ }
16
+ const parent = dirname(dir);
17
+ if (parent === dir)
18
+ return undefined;
19
+ dir = parent;
20
+ }
21
+ }
22
+ async function readProject(root, jsonPath) {
23
+ const raw = await readFile(jsonPath, 'utf8');
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(raw);
27
+ }
28
+ catch (error) {
29
+ throw new Error(`failed to parse ${jsonPath}: ${error.message}`);
30
+ }
31
+ const pkgs = extractPackageDirectories(parsed, root);
32
+ return { packageDirectories: pkgs, root };
33
+ }
34
+ function extractPackageDirectories(parsed, root) {
35
+ if (!parsed || typeof parsed !== 'object')
36
+ return [];
37
+ const obj = parsed;
38
+ if (!Array.isArray(obj.packageDirectories))
39
+ return [];
40
+ const out = [];
41
+ for (const entry of obj.packageDirectories) {
42
+ if (!entry || typeof entry !== 'object')
43
+ continue;
44
+ const pathField = entry.path;
45
+ if (typeof pathField !== 'string' || pathField.length === 0)
46
+ continue;
47
+ out.push(isAbsolute(pathField) ? pathField : resolve(root, pathField));
48
+ }
49
+ return out;
50
+ }
51
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/analyzer/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAS/D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAgB;IAEhB,IAAI,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;QACjD,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;YAChB,OAAO,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,SAAS,CAAC;QACrC,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,QAAgB;IACvD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC7C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,mBAAmB,QAAQ,KAAM,KAAe,CAAC,OAAO,EAAE,CAC3D,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,yBAAyB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,yBAAyB,CAAC,MAAe,EAAE,IAAY;IAC9D,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACrD,MAAM,GAAG,GAAG,MAA0C,CAAC;IACvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAAE,OAAO,EAAE,CAAC;IACtD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,kBAAkB,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QAClD,MAAM,SAAS,GAAI,KAA4B,CAAC,IAAI,CAAC;QACrD,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACtE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,76 @@
1
+ export interface SourceLocation {
2
+ endCol: number;
3
+ endRow: number;
4
+ startCol: number;
5
+ startRow: number;
6
+ }
7
+ export interface ProcedureCC {
8
+ complexity: number;
9
+ contributors: CCContributor[];
10
+ kind: 'after_reasoning' | 'available_when' | 'before_reasoning' | 'other' | 'reasoning_instructions';
11
+ location: SourceLocation;
12
+ scope: string;
13
+ }
14
+ export interface CCContributor {
15
+ kind: 'elif_clause' | 'if_statement' | 'short_circuit_and' | 'short_circuit_or' | 'ternary_expression';
16
+ location: SourceLocation;
17
+ }
18
+ export type ActionTargetKind = 'apex' | 'flow' | 'prompt' | 'unknown' | 'utils';
19
+ export interface ActionDeclaration {
20
+ location: SourceLocation;
21
+ name: string;
22
+ scope: string;
23
+ target?: string;
24
+ targetKind: ActionTargetKind;
25
+ }
26
+ export type ActionReferenceContext = 'after_reasoning_run' | 'before_reasoning_run' | 'reasoning_actions' | 'reasoning_instructions_run' | 'transition' | 'unknown';
27
+ export interface ActionReference {
28
+ context: ActionReferenceContext;
29
+ location: SourceLocation;
30
+ name: string;
31
+ scope: string;
32
+ }
33
+ export interface FileReport {
34
+ declarations: ActionDeclaration[];
35
+ fileComplexity: number;
36
+ parseErrors: ParseDiagnostic[];
37
+ path: string;
38
+ procedures: ProcedureCC[];
39
+ references: ActionReference[];
40
+ }
41
+ export interface ParseDiagnostic {
42
+ location: SourceLocation;
43
+ message: string;
44
+ }
45
+ export interface AnalysisReport {
46
+ apexClasses: ApexClassReport[];
47
+ byTargetKind: Record<ActionTargetKind, number>;
48
+ files: FileReport[];
49
+ totalApexComplexity: number;
50
+ totalComplexity: number;
51
+ totalDeclarations: number;
52
+ totalReferences: number;
53
+ unresolvedApexTargets: string[];
54
+ }
55
+ export type ApexCCContributorKind = 'catch_clause' | 'do_while_statement' | 'for_statement' | 'if_statement' | 'short_circuit_and' | 'short_circuit_or' | 'ternary' | 'when_arm' | 'while_statement';
56
+ export interface ApexCCContributor {
57
+ kind: ApexCCContributorKind;
58
+ location: SourceLocation;
59
+ }
60
+ export interface ApexMethodCC {
61
+ complexity: number;
62
+ contributors: ApexCCContributor[];
63
+ kind: 'constructor' | 'method';
64
+ location: SourceLocation;
65
+ name: string;
66
+ signature: string;
67
+ }
68
+ export interface ApexClassReport {
69
+ classComplexity: number;
70
+ className: string;
71
+ methods: ApexMethodCC[];
72
+ parseErrors: ParseDiagnostic[];
73
+ path: string;
74
+ /** Bundles or actions whose target resolves here. */
75
+ referencedBy: string[];
76
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/analyzer/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ import type { AnalysisReport } from '../../analyzer/types.js';
3
+ export default class AgentpmdAnalyze extends SfCommand<AnalysisReport> {
4
+ static readonly description = "Walks .agent source files under --source-dir and emits per-procedure\ncyclomatic complexity totals (before_reasoning, after_reasoning, and\nreasoning.instructions blocks), plus an inventory of declared and used\n@actions.X targets. For every apex:// target, resolves the .cls file\nand computes per-method Apex CC.\n\nDefault output is human-readable text. --json emits the SF CLI envelope\nwith the full structured report. --format <markdown|sarif|csv> emits the\nnamed format on stdout for piping into PR comments, GitHub Code Scanning,\nor spreadsheet pivots.";
5
+ static readonly examples: string[];
6
+ static readonly flags: {
7
+ 'apex-source': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'api-name': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ ascii: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ 'fail-on': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'no-color': import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ 'sarif-error': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'sarif-warning': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ 'source-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ width: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
17
+ };
18
+ static readonly summary = "Compute McCabe cyclomatic complexity and action-reference inventory for AgentScript bundles and their Apex backing logic.";
19
+ run(): Promise<AnalysisReport>;
20
+ }