Skip to content

Commit ca32e3b

Browse files
authored
Merge pull request #121 from bulengxin/feature-costrict
add support for costrict, a branch of roo code.
2 parents 3c050a6 + dffd6b6 commit ca32e3b

File tree

12 files changed

+1021
-1
lines changed

12 files changed

+1021
-1
lines changed

jetbrains_plugin/README_EXTENSIONS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ RunVSAgent now supports a modular extension system that allows you to use differ
2424
- **Publisher**: Kilo-AI
2525
- **Directory**: `kilo-code/`
2626

27+
### 4. Costrict
28+
- **ID**: `costrict`
29+
- **Description**: AI-powered code assistant with advanced capabilities
30+
- **Publisher**: zgsm-ai
31+
- **Directory**: `costrict/`
32+
2733
## Quick Start
2834

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

4551
3. **Extension Directory Structure**:
4652
```

jetbrains_plugin/src/main/kotlin/com/sina/weibo/agent/extensions/common/ExtensionType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum class ExtensionType(val code: String, val displayName: String, val descript
88
ROO_CODE("roo-code", "Roo Code", "AI-powered code assistant"),
99
CLINE("cline", "Cline AI", "AI-powered coding assistant with advanced features"),
1010
KILO_CODE("kilo-code", "Kilo Code", "AI-powered code assistant with advanced capabilities"),
11+
COSTRICT("costrict", "Costrict", "AI-powered code assistant with advanced capabilities"),
1112
;
1213

1314
companion object {

jetbrains_plugin/src/main/kotlin/com/sina/weibo/agent/extensions/config/ExtensionConfiguration.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,19 @@ data class ExtensionConfig(
194194
capabilities = emptyMap(),
195195
extensionDependencies = emptyList()
196196
)
197+
ExtensionType.COSTRICT -> ExtensionConfig(
198+
extensionType = extensionType,
199+
codeDir = "costrict",
200+
displayName = "Costrict",
201+
description = "AI-powered code assistant with advanced capabilities",
202+
publisher = "zgsm-ai",
203+
version = "1.6.5",
204+
mainFile = "./dist/extension.js",
205+
activationEvents = listOf("onStartupFinished"),
206+
engines = mapOf("vscode" to "^1.0.0"),
207+
capabilities = emptyMap(),
208+
extensionDependencies = emptyList()
209+
)
197210
}
198211
}
199212

jetbrains_plugin/src/main/kotlin/com/sina/weibo/agent/extensions/core/ExtensionManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.sina.weibo.agent.extensions.config.ExtensionProvider
1212
import com.sina.weibo.agent.extensions.plugin.cline.ClineExtensionProvider
1313
import com.sina.weibo.agent.extensions.plugin.roo.RooExtensionProvider
1414
import com.sina.weibo.agent.extensions.plugin.kilo.KiloCodeExtensionProvider
15+
import com.sina.weibo.agent.extensions.plugin.costrict.CostrictExtensionProvider
1516
import com.sina.weibo.agent.extensions.ui.buttons.DynamicButtonManager
1617
import java.util.concurrent.CompletableFuture
1718
import java.util.concurrent.ConcurrentHashMap
@@ -109,6 +110,7 @@ class ExtensionManager(private val project: Project) {
109110
add(RooExtensionProvider())
110111
add(ClineExtensionProvider())
111112
add(KiloCodeExtensionProvider())
113+
add(CostrictExtensionProvider())
112114
}
113115
}
114116

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
// SPDX-FileCopyrightText: 2025 Weibo, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package com.sina.weibo.agent.extensions.plugin.costrict
6+
7+
/** Type alias for prompt type identifiers */
8+
typealias CostrictCodeSupportPromptType = String
9+
/** Type alias for prompt parameters map */
10+
typealias CostrictCodePromptParams = Map<String, Any?>
11+
12+
/**
13+
* Data class representing a prompt configuration with a template string.
14+
* Templates contain placeholders that will be replaced with actual values.
15+
*/
16+
data class CostrictCodeSupportPromptConfig(val template: String)
17+
18+
/**
19+
* Collection of predefined prompt configurations for different use cases.
20+
* Each configuration contains a template with placeholders for dynamic content.
21+
*
22+
* now organized under the Costrict extension.
23+
*/
24+
object CostrictCodeSupportPromptConfigs {
25+
/**
26+
* Template for enhancing user prompts.
27+
* Instructs the AI to generate an improved version of the user's input.
28+
*/
29+
val ENHANCE = CostrictCodeSupportPromptConfig(
30+
"""Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):
31+
32+
${'$'}{userInput}"""
33+
)
34+
35+
/**
36+
* Template for explaining code.
37+
* Provides structure for code explanation requests with file path and line information.
38+
*/
39+
val EXPLAIN = CostrictCodeSupportPromptConfig(
40+
"""Explain the following code from file path ${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine}
41+
${'$'}{userInput}
42+
43+
```
44+
${'$'}{selectedText}
45+
```
46+
47+
Please provide a clear and concise explanation of what this code does, including:
48+
1. The purpose and functionality
49+
2. Key components and their interactions
50+
3. Important patterns or techniques used"""
51+
)
52+
53+
/**
54+
* Template for fixing code issues.
55+
* Includes diagnostic information and structured format for issue resolution.
56+
*/
57+
val FIX = CostrictCodeSupportPromptConfig(
58+
"""Fix any issues in the following code from file path ${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine}
59+
${'$'}{diagnosticText}
60+
${'$'}{userInput}
61+
62+
```
63+
${'$'}{selectedText}
64+
```
65+
66+
Please:
67+
1. Address all detected problems listed above (if any)
68+
2. Identify any other potential bugs or issues
69+
3. Provide corrected code
70+
4. Explain what was fixed and why"""
71+
)
72+
73+
/**
74+
* Template for improving code quality.
75+
* Focuses on readability, performance, best practices, and error handling.
76+
*/
77+
val IMPROVE = CostrictCodeSupportPromptConfig(
78+
"""Improve the following code from file path ${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine}
79+
${'$'}{userInput}
80+
81+
```
82+
${'$'}{selectedText}
83+
```
84+
85+
Please suggest improvements for:
86+
1. Code readability and maintainability
87+
2. Performance optimization
88+
3. Best practices and patterns
89+
4. Error handling and edge cases
90+
91+
Provide the improved code along with explanations for each enhancement."""
92+
)
93+
94+
/**
95+
* Template for adding code to context.
96+
* Simple format that includes file path, line range, and selected code.
97+
*/
98+
val ADD_TO_CONTEXT = CostrictCodeSupportPromptConfig(
99+
"""${'$'}{filePath}:${'$'}{startLine}-${'$'}{endLine}
100+
```
101+
${'$'}{selectedText}
102+
```"""
103+
)
104+
105+
/**
106+
* Template for adding terminal output to context.
107+
* Includes user input and terminal content.
108+
*/
109+
val TERMINAL_ADD_TO_CONTEXT = CostrictCodeSupportPromptConfig(
110+
"""${'$'}{userInput}
111+
Terminal output:
112+
```
113+
${'$'}{terminalContent}
114+
```"""
115+
)
116+
117+
/**
118+
* Template for fixing terminal commands.
119+
* Structured format for identifying and resolving command issues.
120+
*/
121+
val TERMINAL_FIX = CostrictCodeSupportPromptConfig(
122+
"""${'$'}{userInput}
123+
Fix this terminal command:
124+
```
125+
${'$'}{terminalContent}
126+
```
127+
128+
Please:
129+
1. Identify any issues in the command
130+
2. Provide the corrected command
131+
3. Explain what was fixed and why"""
132+
)
133+
134+
/**
135+
* Template for explaining terminal commands.
136+
* Provides structure for command explanation with focus on functionality and behavior.
137+
*/
138+
val TERMINAL_EXPLAIN = CostrictCodeSupportPromptConfig(
139+
"""${'$'}{userInput}
140+
Explain this terminal command:
141+
```
142+
${'$'}{terminalContent}
143+
```
144+
145+
Please provide:
146+
1. What the command does
147+
2. Explanation of each part/flag
148+
3. Expected output and behavior"""
149+
)
150+
151+
/**
152+
* Template for creating a new task.
153+
* Simple format that passes through user input directly.
154+
*/
155+
val NEW_TASK = CostrictCodeSupportPromptConfig(
156+
"""${'$'}{userInput}"""
157+
)
158+
159+
/**
160+
* Map of all available prompt configurations indexed by their type identifiers.
161+
* Used for lookup when creating prompts.
162+
*/
163+
val configs = mapOf(
164+
"ENHANCE" to ENHANCE,
165+
"EXPLAIN" to EXPLAIN,
166+
"FIX" to FIX,
167+
"IMPROVE" to IMPROVE,
168+
"ADD_TO_CONTEXT" to ADD_TO_CONTEXT,
169+
"TERMINAL_ADD_TO_CONTEXT" to TERMINAL_ADD_TO_CONTEXT,
170+
"TERMINAL_FIX" to TERMINAL_FIX,
171+
"TERMINAL_EXPLAIN" to TERMINAL_EXPLAIN,
172+
"NEW_TASK" to NEW_TASK
173+
)
174+
}
175+
176+
/**
177+
* Utility object for working with Costrict Code support prompts.
178+
* Provides methods for creating and customizing prompts based on templates.
179+
*
180+
* now organized under the Costrict extension.
181+
*/
182+
object CostrictCodeSupportPrompt {
183+
/**
184+
* Generates formatted diagnostic text from a list of diagnostic items.
185+
*
186+
* @param diagnostics List of diagnostic items containing source, message, and code
187+
* @return Formatted string of diagnostic messages or empty string if no diagnostics
188+
*/
189+
private fun generateDiagnosticText(diagnostics: List<Map<String, Any?>>?): String {
190+
if (diagnostics.isNullOrEmpty()) return ""
191+
return "\nCurrent problems detected:\n" + diagnostics.joinToString("\n") { d ->
192+
val source = d["source"] as? String ?: "Error"
193+
val message = d["message"] as? String ?: ""
194+
val code = d["code"] as? String
195+
"- [$source] $message${code?.let { " ($it)" } ?: ""}"
196+
}
197+
}
198+
199+
/**
200+
* Creates a prompt by replacing placeholders in a template with actual values.
201+
*
202+
* @param template The prompt template with placeholders
203+
* @param params Map of parameter values to replace placeholders
204+
* @return The processed prompt with placeholders replaced by actual values
205+
*/
206+
private fun createPrompt(template: String, params: CostrictCodePromptParams): String {
207+
val pattern = Regex("""\$\{(.*?)}""")
208+
return pattern.replace(template) { matchResult ->
209+
val key = matchResult.groupValues[1]
210+
if (key == "diagnosticText") {
211+
generateDiagnosticText(params["diagnostics"] as? List<Map<String, Any?>>)
212+
} else if (params.containsKey(key)) {
213+
// Ensure the value is treated as a string for replacement
214+
val value = params[key]
215+
when (value) {
216+
is String -> value
217+
else -> {
218+
// Convert non-string values to string for replacement
219+
value?.toString() ?: ""
220+
}
221+
}
222+
} else {
223+
// If the placeholder key is not in params, replace with empty string
224+
""
225+
}
226+
}
227+
}
228+
229+
/**
230+
* Gets the template for a specific prompt type, with optional custom overrides.
231+
*
232+
* @param customSupportPrompts Optional map of custom prompt templates
233+
* @param type The type of prompt to retrieve
234+
* @return The template string for the specified prompt type
235+
*/
236+
fun get(customSupportPrompts: Map<String, String>?, type: CostrictCodeSupportPromptType): String {
237+
return customSupportPrompts?.get(type) ?: CostrictCodeSupportPromptConfigs.configs[type]?.template ?: ""
238+
}
239+
240+
/**
241+
* Creates a complete prompt by getting the template and replacing placeholders.
242+
*
243+
* @param type The type of prompt to create
244+
* @param params Parameters to substitute into the template
245+
* @param customSupportPrompts Optional custom prompt templates
246+
* @return The final prompt with all placeholders replaced
247+
*/
248+
fun create(type: CostrictCodeSupportPromptType, params: CostrictCodePromptParams, customSupportPrompts: Map<String, String>? = null): String {
249+
val template = get(customSupportPrompts, type)
250+
return createPrompt(template, params)
251+
}
252+
}

0 commit comments

Comments
 (0)