Skip to content

@W-21102094 - Add PMD XPath custom rule creation tool with AST prompt generation#381

Open
aruntyagiTutu wants to merge 28 commits intomainfrom
arun.tyagi/feature/pmd_apex_rule_creation_tool
Open

@W-21102094 - Add PMD XPath custom rule creation tool with AST prompt generation#381
aruntyagiTutu wants to merge 28 commits intomainfrom
arun.tyagi/feature/pmd_apex_rule_creation_tool

Conversation

@aruntyagiTutu
Copy link
Contributor

@aruntyagiTutu aruntyagiTutu commented Feb 11, 2026

What does this PR do?

@W-21102094@

What issues does this PR fix or reference?

This PR introduces an end‑to‑end flow for creating PMD XPath custom rules. It generates PMD AST XML from sample Apex code, extracts AST nodes and cached metadata, builds a high‑signal prompt for XPath generation, and then writes a PMD ruleset XML plus updates code-analyzer.yml (with relative custom ruleset paths). It also adds engine strategies/pipeline/adapters to keep the workflow extensible for future engines, along with tests and tool registration updates.

Notes / Future Work
The Apex AST reference JSON is cached locally in the provider to enable prompt enrichment in phase 1. This is a temporary placement and will move into the PMD engine implementation in core once the engine plugin owns AST metadata.
PMD CLI integration is used to generate AST XML in phase 1. This will be replaced by a PMD engine API in core (Java SDK or internal API) so we can avoid external process execution and share logic across tools.

@aruntyagiTutu aruntyagiTutu requested review from a team as code owners February 11, 2026 02:56
@aruntyagiTutu aruntyagiTutu changed the title @W-21102094 - Custom rule creation for PMD based on xpath @W-21102094 - [WIP] [Do not review] Custom rule creation for PMD based on xpath Feb 11, 2026
* add validation that this implementation supports pmd only for now

* update prompt - optimize for output  size

* refactor create tool

* file name santization

* updated action name

* update prompt

* update prompt optimize for simple xpath

* fix tests

* fix test with mock
…y methods (#386)

* langugae in ruleset template

* update telemetry on success

* xpath is optional

* clean chuncky methods
@stephen-carter-at-sf stephen-carter-at-sf marked this pull request as draft February 16, 2026 13:25
@aruntyagiTutu aruntyagiTutu changed the title @W-21102094 - [WIP] [Do not review] Custom rule creation for PMD based on xpath @W-21102094 - Add PMD XPath custom rule creation workflow with AST prompt generation Feb 17, 2026
@aruntyagiTutu aruntyagiTutu changed the title @W-21102094 - Add PMD XPath custom rule creation workflow with AST prompt generation @W-21102094 - Add PMD XPath custom rule creation tool with AST prompt generation Feb 17, 2026
@aruntyagiTutu aruntyagiTutu marked this pull request as ready for review February 18, 2026 11:32
@@ -0,0 +1,99 @@
import { XMLParser } from "fast-xml-parser";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing from your package.json dependencies. It is probably getting pulled in as a transitive dependency, but it is best to depend on it explicitly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make sure it is a least 5.3.5 or higher. Earlier versions have a known vuln

title: "Create Custom Rule",
description: DESCRIPTION,
inputSchema: inputSchema.shape,
outputSchema: outputSchema.shape
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add annotations here. I think this is right, confirm:

annotations: {
    readOnlyHint: false, // Writes ruleset XML and code-analyzer.yml
    destructiveHint: false, // Does not delete anything
    openWorldHint: false, // Local file operations only
},

configPath: output.configPath
});
}
return {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add isError if the response is an error
isError: output.status !== "success",

import { getApexAstNodeMetadataByNames, type ApexAstNodeMetadata } from "../ast/metadata/apex-ast-reference.js";
import { LANGUAGE_NAMES } from "../constants.js";

export type EngineName = "pmd";
Copy link
Collaborator

@iowillhoit iowillhoit Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be exported? I ask because this collides with export type EngineName = typeof ENGINE_NAMES[number]; defined in packages/mcp-provider-code-analyzer/src/constants.ts

inputSchema: inputSchema.shape,
outputSchema: outputSchema.shape,
annotations: {
readOnlyHint: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm readOnlyHint: true is correct? If I am following this correctly, it looks like this generates some temp files in PmdCliAstXmlAdapter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants