Skip to content

Commit b2c58eb

Browse files
authored
CAMEL-23477: camel-jbang-mcp - Stop re-embedding pomContent in migrateProject prompt (#23140)
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
1 parent e533044 commit b2c58eb

2 files changed

Lines changed: 64 additions & 53 deletions

File tree

dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/PromptDefinitions.java

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -101,62 +101,45 @@ Determine which Enterprise Integration Patterns are needed (e.g., split, aggrega
101101
+ "get OpenRewrite recipes, search migration guides, "
102102
+ "and produce a migration summary.")
103103
public List<PromptMessage> migrateProject(
104-
@PromptArg(name = "pomContent", description = "The project's pom.xml file content") String pomContent,
104+
@PromptArg(name = "pomContent",
105+
description = "Optional: project's pom.xml content. If omitted, the LLM uses the pom.xml already in its conversation context.",
106+
required = false) String pomContent,
105107
@PromptArg(name = "targetVersion", description = "Target Camel version to migrate to (e.g., 4.18.0)",
106108
required = false) String targetVersion) {
107109

108110
String versionNote = targetVersion != null && !targetVersion.isBlank()
109111
? "Target version: " + targetVersion
110112
: "Target version: latest stable (determine from camel_version_list)";
111113

112-
String instructions = """
113-
You are migrating a Camel project to a newer version.
114-
115-
## %s
116-
117-
## Project pom.xml
118-
```xml
119-
%s
120-
```
121-
122-
## Workflow
123-
124-
Follow these steps in order:
125-
126-
### Step 1: Analyze the project
127-
Call `camel_migration_analyze` with the pom.xml content above.
128-
This detects the current runtime, Camel version, Java version, and component dependencies.
129-
130-
### Step 2: Determine target version
131-
If no target version was specified, call `camel_version_list` with the detected runtime \
132-
to find the latest stable version. For LTS releases, filter with lts=true.
133-
134-
### Step 3: Check compatibility
135-
Based on the detected runtime from Step 1:
136-
- For **wildfly** or **karaf** runtimes: call `camel_migration_wildfly_karaf` with the pom.xml \
137-
content, target runtime, and target version.
138-
- For **main**, **spring-boot**, or **quarkus** runtimes: call `camel_migration_compatibility` \
139-
with the detected components, current version, target version, runtime, and Java version.
140-
141-
Review any blockers (e.g., Java version too old) and warnings.
142-
143-
### Step 4: Get migration recipes
144-
Call `camel_migration_recipes` with the runtime, current version, target version, \
145-
Java version, and dryRun=true to get the OpenRewrite Maven commands.
146-
147-
### Step 5: Search for breaking changes
148-
For each component detected in Step 1, call `camel_migration_guide_search` \
149-
with the component name to find relevant breaking changes and rename mappings.
150-
151-
### Step 6: Produce migration summary
152-
Present a structured summary:
153-
- **Current state**: runtime, Camel version, Java version, component count
154-
- **Target state**: target version, required Java version
155-
- **Blockers**: issues that must be resolved before migration
156-
- **Breaking changes**: component renames, API changes found in guides
157-
- **Migration commands**: the OpenRewrite commands from Step 4
158-
- **Manual steps**: any changes that OpenRewrite cannot automate
159-
""".formatted(versionNote, pomContent);
114+
String pomNote = pomContent != null && !pomContent.isBlank()
115+
? "A pom.xml has been supplied as the `pomContent` argument to this prompt."
116+
: "Use the project's pom.xml from your conversation context.";
117+
118+
String instructions
119+
= """
120+
You are migrating a Camel project to a newer version.
121+
122+
%s
123+
%s
124+
125+
## Workflow
126+
127+
1. **Analyze**: call `camel_migration_analyze` with the pom.xml to detect runtime, \
128+
Camel version, Java version, and component dependencies.
129+
2. **Target version**: if not specified, call `camel_version_list` with the detected runtime \
130+
(use `lts=true` for LTS releases).
131+
3. **Compatibility** (based on detected runtime):
132+
- **wildfly** or **karaf**: call `camel_migration_wildfly_karaf` with the pom, target runtime, and target version.
133+
- **main**, **spring-boot**, or **quarkus**: call `camel_migration_compatibility` \
134+
with components, current/target version, runtime, and Java version.
135+
4. **Recipes**: call `camel_migration_recipes` with runtime, versions, Java version, and `dryRun=true` \
136+
to get the OpenRewrite Maven commands.
137+
5. **Breaking changes**: for each detected component, call `camel_migration_guide_search` \
138+
to find renames and API changes.
139+
6. **Summary**: report current state, target state, blockers, breaking changes, \
140+
migration commands, and manual steps that OpenRewrite cannot automate.
141+
"""
142+
.formatted(versionNote, pomNote);
160143

161144
return List.of(PromptMessage.withUserRole(instructions));
162145
}

dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/PromptDefinitionsTest.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,40 @@ void migrateProjectReturnsNonEmptyMessages() {
9090
}
9191

9292
@Test
93-
void migrateProjectContainsPomContent() {
94-
String pom = "<project><version>3.20.0</version></project>";
95-
List<PromptMessage> result = prompts.migrateProject(pom, null);
93+
void migrateProjectDoesNotInlinePomContent() {
94+
// The prompt must not embed the full pom content; size should not scale with pomContent length.
95+
String smallPom = "<project/>";
96+
String largePom = "<project>" + "<dependency/>".repeat(1000) + "</project>";
97+
98+
int smallSize = extractText(prompts.migrateProject(smallPom, "4.18.0")).length();
99+
int largeSize = extractText(prompts.migrateProject(largePom, "4.18.0")).length();
100+
101+
assertThat(largeSize).isEqualTo(smallSize);
102+
assertThat(extractText(prompts.migrateProject(largePom, "4.18.0"))).doesNotContain(largePom);
103+
}
104+
105+
@Test
106+
void migrateProjectAcknowledgesSuppliedPom() {
107+
List<PromptMessage> result = prompts.migrateProject("<project/>", "4.18.0");
108+
109+
String text = extractText(result);
110+
assertThat(text).contains("supplied as the `pomContent` argument");
111+
}
112+
113+
@Test
114+
void migrateProjectFallsBackToContextWhenPomOmitted() {
115+
List<PromptMessage> result = prompts.migrateProject(null, "4.18.0");
116+
117+
String text = extractText(result);
118+
assertThat(text).contains("conversation context");
119+
}
120+
121+
@Test
122+
void migrateProjectBlankPomFallsBackToContext() {
123+
List<PromptMessage> result = prompts.migrateProject(" ", "4.18.0");
96124

97125
String text = extractText(result);
98-
assertThat(text).contains(pom);
126+
assertThat(text).contains("conversation context");
99127
}
100128

101129
@Test

0 commit comments

Comments
 (0)