-
Notifications
You must be signed in to change notification settings - Fork 83
Code Indexing Support for WSO2 Integrator Copilot #2310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ import { FILE_BATCH_EDIT_TOOL_NAME, FILE_READ_TOOL_NAME, FILE_SINGLE_EDIT_TOOL_N | |
| import { CONNECTOR_GENERATOR_TOOL } from "./tools/connector-generator"; | ||
| import { CONFIG_COLLECTOR_TOOL } from "./tools/config-collector"; | ||
| import { CLARIFY_TOOL } from "./tools/clarify"; | ||
| import { GREP_TOOL_NAME } from "./tools/grep"; | ||
| import { GLOB_TOOL_NAME } from "./tools/glob"; | ||
| import { TEST_RUNNER_TOOL_NAME } from "./tools/test-runner"; | ||
| import { getLanglibInstructions } from "../utils/libs/langlibs"; | ||
| import { formatCodebaseStructure, formatCodeContext } from "./utils"; | ||
|
|
@@ -53,7 +55,7 @@ Create a very high-level and concise design plan for the given user requirement. | |
| You must use ${TASK_WRITE_TOOL_NAME} tool to create and manage tasks. | ||
| This plan will be visible to the user and the execution will be guided on the tasks you create. | ||
|
|
||
| - Break down the implementation into specific, actionable tasks. Each task should be concise and high level as they are visible to a very high level user. | ||
| - Break down the implementation into specific, actionable tasks. Each task should be concise and high level as they are visible to a very high level user. | ||
| - Each task should have a type. This type will be used to guide the user through the generation proccess. | ||
| - Track each task as you work through them and mark tasks as you start and complete them | ||
|
|
||
|
|
@@ -114,7 +116,7 @@ Plan the implementation approach in your reasoning. Keep output minimal — no d | |
| Identify the libraries required to implement the user requirement. Use ${LIBRARY_SEARCH_TOOL} to discover relevant libraries, then use ${LIBRARY_GET_TOOL} to fetch their full details. | ||
|
|
||
| ### Step 3: Write the code | ||
| Write/modify the Ballerina code to implement the user requirement. Use the ${FILE_BATCH_EDIT_TOOL_NAME}, ${FILE_SINGLE_EDIT_TOOL_NAME}, ${FILE_WRITE_TOOL_NAME} tools to write/modify the code. | ||
| Write/modify the Ballerina code to implement the user requirement. Use the ${FILE_BATCH_EDIT_TOOL_NAME}, ${FILE_SINGLE_EDIT_TOOL_NAME}, ${FILE_WRITE_TOOL_NAME} tools to write/modify the code. | ||
|
|
||
| ### Step 4: Validate the code | ||
| Once the code is written, always use ${DIAGNOSTICS_TOOL_NAME} to check for compilation errors and fix them. You may call it multiple times after making changes. | ||
|
|
@@ -143,8 +145,6 @@ When generating Ballerina code strictly follow these syntax and structure guidel | |
| - A submodule MUST BE imported before being used. The import statement should only contain the package name and submodule name. For package my_pkg, folder structure generated/fooApi, the import should be \`import my_pkg.fooApi;\`. | ||
| - For GraphQL service related queries, if the user hasn't specified their own GraphQL Schema, write the proposed GraphQL schema for the user query right after the explanation before generating the Ballerina code. Use the same names as the GraphQL Schema when defining record types. | ||
| - Some libaries has instructions fields in their API documentation. Follow those instructions strictly when using those libraries. | ||
| - You should only generate tests if the user explicitly asks for them in the query. You must use the 'ballerina/test' and whatever services associated when writing tests. Respect the instructions field in ballerina/test library and testGenerationInstruction field in whatever library associated with the service in the library API documentation when writing tests. | ||
| - For workflow-based requirements involving long-running processes, state management, or orchestration of multiple steps, use the 'ballerina/workflow' module. | ||
| - When writing tests, use the 'ballerina/test' module and any service-specific test libraries. Respect the instructions field in ballerina/test library and the testGenerationInstruction field in the associated service library API documentation when writing tests. | ||
| - Some libraries may contain Readme field. This is generic information about the library. Avoid following links from the readme contents. | ||
| ${getLanglibInstructions()} | ||
|
|
@@ -176,14 +176,27 @@ ${getLanglibInstructions()} | |
| - Mention types EXPLICITLY in variable declarations and foreach statements. (Avoid var at all costs) | ||
| - To narrow down a union type(or optional type), always declare a separate variable and then use that variable in the if condition. | ||
|
|
||
| ## File modifications | ||
| # Codebase Exploration | ||
| - When the user submits a query, you will receive either **Codebase High Level Overview** or **Complete Structure of the Codebase**. Identify which one you have received before proceeding. | ||
| - If you received Codebase High Level Overview, use it as a navigation map to locate the relevant components to the user query, in the codebase, but the actual source must be read separately when needed. | ||
| - Codebase High Level Overview lists, for each Ballerina file, all of its components (imports, configurables, variables, types, functions, services, listeners, classes) with their signatures and line ranges, but excludes implementation bodies, test files, and resource files. | ||
| - If you receive complete structure of the codebase, it contains the complete source of all .bal files (test and resource files excluded) provided directly in your context. | ||
|
|
||
| ## Context Retrieval | ||
| - Explore the codebase with ${GREP_TOOL_NAME}, ${FILE_READ_TOOL_NAME}, and ${GLOB_TOOL_NAME}, and keep exploring until you have all the context required to answer confidently. | ||
|
|
||
| ### Rules for exploration | ||
| - **DO NOT** guess the implementation based on signatures from Codebase High Level Overview or excerpts you retrieved. Always read the actual source code before using any information about a component in the codebase. This is critical to avoid hallucinations and wrong assumptions. | ||
| - When you update or write code, Codebase High Level Overview will become outdated. | ||
|
|
||
| ## File Modifications and Component Modifications | ||
| - You must apply changes to the existing source code using the provided ${[ | ||
| FILE_BATCH_EDIT_TOOL_NAME, | ||
| FILE_SINGLE_EDIT_TOOL_NAME, | ||
| FILE_WRITE_TOOL_NAME, | ||
| ].join( | ||
| ", " | ||
| )} tools. The complete existing source code will be provided in the <existing_code> section of the user prompt. | ||
| )} tools. The complete existing source code will be provided in the <codebase_structure> section of the user prompt. | ||
| - When making replacements inside an existing file, provide the **exact old string** and the **exact new string** with all newlines, spaces, and indentation, being mindful to replace nearby occurrences together to minimize the number of tool calls. | ||
| - Do NOT create a new markdown file to document each change or summarize your work unless specifically requested by the user. | ||
| - Do not manually add/modify Dependencies.toml. For Config.toml configuration management, use ${CONFIG_COLLECTOR_TOOL}. | ||
|
|
@@ -241,13 +254,21 @@ System context: | |
| </system-reminder>`; | ||
| } | ||
|
|
||
| export function getUserPrompt(params: GenerateAgentCodeRequest, tempProjectPath: string, projects: ProjectSource[]) { | ||
| export function getUserPrompt(params: GenerateAgentCodeRequest, tempProjectPath: string, projects: ProjectSource[], codeMapMarkdown?: string) { | ||
| const content = []; | ||
|
|
||
| content.push({ | ||
| type: 'text' as const, | ||
| text: formatCodebaseStructure(projects, tempProjectPath) | ||
| }); | ||
| // Add codebase high level summary if available, otherwise fall back to full project structure | ||
| if (codeMapMarkdown) { | ||
| content.push({ | ||
| type: 'text' as const, | ||
| text: `<Codebase High Level Summary>\n${codeMapMarkdown}\n</Codebase High Level Summary>` | ||
| }); | ||
| } else { | ||
| content.push({ | ||
| type: 'text' as const, | ||
| text: formatCodebaseStructure(projects, tempProjectPath) | ||
| }); | ||
| } | ||
|
Comment on lines
+257
to
+271
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the prompt contract with the new Code Map path. When 🤖 Prompt for AI Agents |
||
|
|
||
| // Add code context if available | ||
| if (params.codeContext) { | ||
|
|
@@ -262,25 +283,16 @@ export function getUserPrompt(params: GenerateAgentCodeRequest, tempProjectPath: | |
|
|
||
| // Add file attachments if available | ||
| if (params.fileAttachmentContents && params.fileAttachmentContents.length > 0) { | ||
| for (const attachment of params.fileAttachmentContents) { | ||
| if (attachment.mimeType?.startsWith('image/')) { | ||
| // Add image attachment | ||
| content.push({ | ||
| type: 'image' as const, | ||
| image: attachment.content, | ||
| }); | ||
| } else { | ||
| // Add text file attachment | ||
| const attachmentsText = params.fileAttachmentContents.map((attachment) => | ||
| `## File: ${attachment.fileName}\n\`\`\`\n${attachment.content}\n\`\`\``).join('\n\n'); | ||
| content.push({ | ||
| type: 'text' as const, | ||
| text: `<User Attachments> | ||
| ${attachmentsText} | ||
| </User Attachments>` | ||
| }); | ||
| } | ||
| } | ||
| const attachmentsText = params.fileAttachmentContents.map((attachment) => | ||
| `## File: ${attachment.fileName}\n\`\`\`\n${attachment.content}\n\`\`\`` | ||
| ).join('\n\n'); | ||
|
|
||
| content.push({ | ||
| type: 'text' as const, | ||
| text: `<User Attachments> | ||
| ${attachmentsText} | ||
| </User Attachments>` | ||
| }); | ||
| } | ||
|
|
||
| const queryParts = [params.usecase]; | ||
|
|
@@ -336,5 +348,4 @@ function getNPSuffix(projects: ProjectSource[], op?: OperationType): string { | |
| basePrompt += getRequirementAnalysisTestGenPrefix(extractResourceDocumentContent(flattenProjectToFiles(projects))); | ||
| } | ||
| return basePrompt; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetch the Code Map from the reused temp project during review continuation.
When
pendingReview?.reviewState.tempProjectPathexists, the executor will edit that temp snapshot, but this fetch still targetsworkspacePath/projectPath. Follow-up prompts can therefore be built from stale project state and miss previously generated review changes. PreferpendingReview?.reviewState.tempProjectPath ?? workspacePath ?? StateMachine.context().projectPathhere, or move Code Map generation after temp-project initialization.🤖 Prompt for AI Agents