-
Notifications
You must be signed in to change notification settings - Fork 59
add support for costrict, a branch of roo code. #121
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
Open
bulengxin
wants to merge
2
commits into
wecode-ai:main
Choose a base branch
from
bulengxin:feature-costrict
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -194,6 +194,19 @@ data class ExtensionConfig( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
capabilities = emptyMap(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensionDependencies = emptyList() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ExtensionType.COSTRICT -> ExtensionConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. 在ExtensionConfiguration.kt文件中,应该使用修正后的枚举值COCONSTRICT而不是COSTRICT。
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensionType = extensionType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
codeDir = "costrict", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
displayName = "Costrict", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "AI-powered code assistant with advanced capabilities", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
publisher = "zgsm-ai", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
version = "1.6.5", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mainFile = "./dist/extension.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
activationEvents = listOf("onStartupFinished"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
engines = mapOf("vscode" to "^1.0.0"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
capabilities = emptyMap(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
extensionDependencies = emptyList() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
252 changes: 252 additions & 0 deletions
252
...ain/kotlin/com/sina/weibo/agent/extensions/plugin/costrict/CostrictCodeActionConstants.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,252 @@ | ||||||||||||||||||||||||
// SPDX-FileCopyrightText: 2025 Weibo, Inc. | ||||||||||||||||||||||||
// | ||||||||||||||||||||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
package com.sina.weibo.agent.extensions.plugin.costrict | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** Type alias for prompt type identifiers */ | ||||||||||||||||||||||||
typealias CostrictCodeSupportPromptType = String | ||||||||||||||||||||||||
/** Type alias for prompt parameters map */ | ||||||||||||||||||||||||
typealias CostrictCodePromptParams = Map<String, Any?> | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Data class representing a prompt configuration with a template string. | ||||||||||||||||||||||||
* Templates contain placeholders that will be replaced with actual values. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
data class CostrictCodeSupportPromptConfig(val template: String) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Collection of predefined prompt configurations for different use cases. | ||||||||||||||||||||||||
* Each configuration contains a template with placeholders for dynamic content. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* now organized under the Costrict extension. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
object CostrictCodeSupportPromptConfigs { | ||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for enhancing user prompts. | ||||||||||||||||||||||||
* Instructs the AI to generate an improved version of the user's input. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val ENHANCE = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes): | ||||||||||||||||||||||||
${'$'}{userInput}""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
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. 在CostrictCodeActionConstants.kt文件中,有一些TODO注释和未完成的实现,需要进一步完善。
Suggested change
|
||||||||||||||||||||||||
* Template for explaining code. | ||||||||||||||||||||||||
* Provides structure for code explanation requests with file path and line information. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val EXPLAIN = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""Explain the following code from file path ${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine} | ||||||||||||||||||||||||
${'$'}{userInput} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{selectedText} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
Please provide a clear and concise explanation of what this code does, including: | ||||||||||||||||||||||||
1. The purpose and functionality | ||||||||||||||||||||||||
2. Key components and their interactions | ||||||||||||||||||||||||
3. Important patterns or techniques used""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for fixing code issues. | ||||||||||||||||||||||||
* Includes diagnostic information and structured format for issue resolution. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val FIX = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""Fix any issues in the following code from file path ${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine} | ||||||||||||||||||||||||
${'$'}{diagnosticText} | ||||||||||||||||||||||||
${'$'}{userInput} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{selectedText} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
Please: | ||||||||||||||||||||||||
1. Address all detected problems listed above (if any) | ||||||||||||||||||||||||
2. Identify any other potential bugs or issues | ||||||||||||||||||||||||
3. Provide corrected code | ||||||||||||||||||||||||
4. Explain what was fixed and why""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for improving code quality. | ||||||||||||||||||||||||
* Focuses on readability, performance, best practices, and error handling. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val IMPROVE = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""Improve the following code from file path ${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine} | ||||||||||||||||||||||||
${'$'}{userInput} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{selectedText} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
Please suggest improvements for: | ||||||||||||||||||||||||
1. Code readability and maintainability | ||||||||||||||||||||||||
2. Performance optimization | ||||||||||||||||||||||||
3. Best practices and patterns | ||||||||||||||||||||||||
4. Error handling and edge cases | ||||||||||||||||||||||||
Provide the improved code along with explanations for each enhancement.""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for adding code to context. | ||||||||||||||||||||||||
* Simple format that includes file path, line range, and selected code. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val ADD_TO_CONTEXT = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{selectedText} | ||||||||||||||||||||||||
```""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for adding terminal output to context. | ||||||||||||||||||||||||
* Includes user input and terminal content. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val TERMINAL_ADD_TO_CONTEXT = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""${'$'}{userInput} | ||||||||||||||||||||||||
Terminal output: | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{terminalContent} | ||||||||||||||||||||||||
```""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for fixing terminal commands. | ||||||||||||||||||||||||
* Structured format for identifying and resolving command issues. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val TERMINAL_FIX = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""${'$'}{userInput} | ||||||||||||||||||||||||
Fix this terminal command: | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{terminalContent} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
Please: | ||||||||||||||||||||||||
1. Identify any issues in the command | ||||||||||||||||||||||||
2. Provide the corrected command | ||||||||||||||||||||||||
3. Explain what was fixed and why""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for explaining terminal commands. | ||||||||||||||||||||||||
* Provides structure for command explanation with focus on functionality and behavior. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val TERMINAL_EXPLAIN = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""${'$'}{userInput} | ||||||||||||||||||||||||
Explain this terminal command: | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
${'$'}{terminalContent} | ||||||||||||||||||||||||
``` | ||||||||||||||||||||||||
Please provide: | ||||||||||||||||||||||||
1. What the command does | ||||||||||||||||||||||||
2. Explanation of each part/flag | ||||||||||||||||||||||||
3. Expected output and behavior""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Template for creating a new task. | ||||||||||||||||||||||||
* Simple format that passes through user input directly. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val NEW_TASK = CostrictCodeSupportPromptConfig( | ||||||||||||||||||||||||
"""${'$'}{userInput}""" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Map of all available prompt configurations indexed by their type identifiers. | ||||||||||||||||||||||||
* Used for lookup when creating prompts. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
val configs = mapOf( | ||||||||||||||||||||||||
"ENHANCE" to ENHANCE, | ||||||||||||||||||||||||
"EXPLAIN" to EXPLAIN, | ||||||||||||||||||||||||
"FIX" to FIX, | ||||||||||||||||||||||||
"IMPROVE" to IMPROVE, | ||||||||||||||||||||||||
"ADD_TO_CONTEXT" to ADD_TO_CONTEXT, | ||||||||||||||||||||||||
"TERMINAL_ADD_TO_CONTEXT" to TERMINAL_ADD_TO_CONTEXT, | ||||||||||||||||||||||||
"TERMINAL_FIX" to TERMINAL_FIX, | ||||||||||||||||||||||||
"TERMINAL_EXPLAIN" to TERMINAL_EXPLAIN, | ||||||||||||||||||||||||
"NEW_TASK" to NEW_TASK | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Utility object for working with Costrict Code support prompts. | ||||||||||||||||||||||||
* Provides methods for creating and customizing prompts based on templates. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* now organized under the Costrict extension. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
object CostrictCodeSupportPrompt { | ||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Generates formatted diagnostic text from a list of diagnostic items. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @param diagnostics List of diagnostic items containing source, message, and code | ||||||||||||||||||||||||
* @return Formatted string of diagnostic messages or empty string if no diagnostics | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
private fun generateDiagnosticText(diagnostics: List<Map<String, Any?>>?): String { | ||||||||||||||||||||||||
if (diagnostics.isNullOrEmpty()) return "" | ||||||||||||||||||||||||
return "\nCurrent problems detected:\n" + diagnostics.joinToString("\n") { d -> | ||||||||||||||||||||||||
val source = d["source"] as? String ?: "Error" | ||||||||||||||||||||||||
val message = d["message"] as? String ?: "" | ||||||||||||||||||||||||
val code = d["code"] as? String | ||||||||||||||||||||||||
"- [$source] $message${code?.let { " ($it)" } ?: ""}" | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Creates a prompt by replacing placeholders in a template with actual values. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @param template The prompt template with placeholders | ||||||||||||||||||||||||
* @param params Map of parameter values to replace placeholders | ||||||||||||||||||||||||
* @return The processed prompt with placeholders replaced by actual values | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
private fun createPrompt(template: String, params: CostrictCodePromptParams): String { | ||||||||||||||||||||||||
val pattern = Regex("""\$\{(.*?)}""") | ||||||||||||||||||||||||
return pattern.replace(template) { matchResult -> | ||||||||||||||||||||||||
val key = matchResult.groupValues[1] | ||||||||||||||||||||||||
if (key == "diagnosticText") { | ||||||||||||||||||||||||
generateDiagnosticText(params["diagnostics"] as? List<Map<String, Any?>>) | ||||||||||||||||||||||||
} else if (params.containsKey(key)) { | ||||||||||||||||||||||||
// Ensure the value is treated as a string for replacement | ||||||||||||||||||||||||
val value = params[key] | ||||||||||||||||||||||||
when (value) { | ||||||||||||||||||||||||
is String -> value | ||||||||||||||||||||||||
else -> { | ||||||||||||||||||||||||
// Convert non-string values to string for replacement | ||||||||||||||||||||||||
value?.toString() ?: "" | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||
// If the placeholder key is not in params, replace with empty string | ||||||||||||||||||||||||
"" | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Gets the template for a specific prompt type, with optional custom overrides. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @param customSupportPrompts Optional map of custom prompt templates | ||||||||||||||||||||||||
* @param type The type of prompt to retrieve | ||||||||||||||||||||||||
* @return The template string for the specified prompt type | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
fun get(customSupportPrompts: Map<String, String>?, type: CostrictCodeSupportPromptType): String { | ||||||||||||||||||||||||
return customSupportPrompts?.get(type) ?: CostrictCodeSupportPromptConfigs.configs[type]?.template ?: "" | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* Creates a complete prompt by getting the template and replacing placeholders. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @param type The type of prompt to create | ||||||||||||||||||||||||
* @param params Parameters to substitute into the template | ||||||||||||||||||||||||
* @param customSupportPrompts Optional custom prompt templates | ||||||||||||||||||||||||
* @return The final prompt with all placeholders replaced | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
fun create(type: CostrictCodeSupportPromptType, params: CostrictCodePromptParams, customSupportPrompts: Map<String, String>? = null): String { | ||||||||||||||||||||||||
val template = get(customSupportPrompts, type) | ||||||||||||||||||||||||
return createPrompt(template, params) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
在ExtensionType.kt文件中,枚举值的命名可能有拼写错误。应该使用COSTRICT还是COCONSTRICT?