Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion jetbrains_plugin/README_EXTENSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ RunVSAgent now supports a modular extension system that allows you to use differ
- **Publisher**: Kilo-AI
- **Directory**: `kilo-code/`

### 4. Costrict
- **ID**: `costrict`
- **Description**: AI-powered code assistant with advanced capabilities
- **Publisher**: zgsm-ai
- **Directory**: `costrict/`

## Quick Start

### For Users
Expand All @@ -40,7 +46,7 @@ RunVSAgent now supports a modular extension system that allows you to use differ
```properties
extension.type=roo-code
```
- Supported values: `roo-code`, `cline`, `kilo-code`
- Supported values: `roo-code`, `cline`, `kilo-code`, `costrict`

3. **Extension Directory Structure**:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum class ExtensionType(val code: String, val displayName: String, val descript
ROO_CODE("roo-code", "Roo Code", "AI-powered code assistant"),
CLINE("cline", "Cline AI", "AI-powered coding assistant with advanced features"),
KILO_CODE("kilo-code", "Kilo Code", "AI-powered code assistant with advanced capabilities"),
COSTRICT("costrict", "Costrict", "AI-powered code assistant with advanced capabilities"),

Choose a reason for hiding this comment

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

在ExtensionType.kt文件中,枚举值的命名可能有拼写错误。应该使用COSTRICT还是COCONSTRICT?

Suggested change
COSTRICT("costrict", "Costrict", "AI-powered code assistant with advanced capabilities"),
ROO_CODE("roo-code", "Roo Code", "AI-powered code assistant"),
CLINE("cline", "Cline AI", "AI-powered coding assistant with advanced features"),
KILO_CODE("kilo-code", "Kilo Code", "AI-powered code assistant with advanced capabilities"),
COCONSTRICT("costrict", "Costrict", "AI-powered code assistant with advanced capabilities"),

;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ data class ExtensionConfig(
capabilities = emptyMap(),
extensionDependencies = emptyList()
)
ExtensionType.COSTRICT -> ExtensionConfig(

Choose a reason for hiding this comment

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

在ExtensionConfiguration.kt文件中,应该使用修正后的枚举值COCONSTRICT而不是COSTRICT。

Suggested change
ExtensionType.COSTRICT -> ExtensionConfig(
ExtensionType.ROO_CODE -> ExtensionConfig(
extensionType = extensionType,
codeDir = "roo-code",
displayName = "Roo Code",
description = "AI-powered code assistant",
publisher = "WeCode-AI",
version = "1.0.0",
mainFile = "./dist/extension.js",
activationEvents = listOf("onStartupFinished"),
engines = mapOf("vscode" to "^1.0.0"),
capabilities = emptyMap(),
extensionDependencies = emptyList()
)
ExtensionType.CLINE -> ExtensionConfig(
extensionType = extensionType,
codeDir = "cline",
displayName = "Cline",
description = "AI-powered coding assistant with advanced features",
publisher = "Cline-AI",
version = "1.0.0",
mainFile = "./dist/extension.js",
activationEvents = listOf("onStartupFinished"),
engines = mapOf("vscode" to "^1.0.0"),
capabilities = emptyMap(),
extensionDependencies = emptyList()
)
ExtensionType.KILO_CODE -> ExtensionConfig(
extensionType = extensionType,
codeDir = "kilo-code",
displayName = "Kilo Code",
description = "AI-powered code assistant with advanced capabilities",
publisher = "Kilo-AI",
version = "1.0.0",
mainFile = "./dist/extension.js",
activationEvents = listOf("onStartupFinished"),
engines = mapOf("vscode" to "^1.0.0"),
capabilities = emptyMap(),
extensionDependencies = emptyList()
)
ExtensionType.COCONSTRICT -> ExtensionConfig(
extensionType = extensionType,
codeDir = "costrict",
displayName = "Costrict",
description = "AI-powered code assistant with advanced capabilities",
publisher = "zgsm-ai",
version = "1.0.0",
mainFile = "./dist/extension.js",
activationEvents = listOf("onStartupFinished"),
engines = mapOf("vscode" to "^1.0.0"),
capabilities = emptyMap(),
extensionDependencies = emptyList()
)

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()
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.sina.weibo.agent.extensions.config.ExtensionProvider
import com.sina.weibo.agent.extensions.plugin.cline.ClineExtensionProvider
import com.sina.weibo.agent.extensions.plugin.roo.RooExtensionProvider
import com.sina.weibo.agent.extensions.plugin.kilo.KiloCodeExtensionProvider
import com.sina.weibo.agent.extensions.plugin.costrict.CostrictExtensionProvider
import com.sina.weibo.agent.extensions.ui.buttons.DynamicButtonManager
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -109,6 +110,7 @@ class ExtensionManager(private val project: Project) {
add(RooExtensionProvider())
add(ClineExtensionProvider())
add(KiloCodeExtensionProvider())
add(CostrictExtensionProvider())
}
}

Expand Down
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}"""
)

/**

Choose a reason for hiding this comment

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

在CostrictCodeActionConstants.kt文件中,有一些TODO注释和未完成的实现,需要进一步完善。

Suggested change
/**
// 移除空的TODO注释
// TODO: Add more prompt types as needed
// 在注释中明确说明这个文件是Costrict扩展的一部分
/**
* Collection of predefined prompt configurations for different use cases.
* Each configuration contains a template with placeholders for dynamic content.
*
* These configurations are now organized under the Costrict extension.
*/

* 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)
}
}
Loading