@@ -3,7 +3,6 @@ package cc.unitmesh.devins.ui.compose.runconfig
33import androidx.compose.runtime.getValue
44import androidx.compose.runtime.mutableStateOf
55import androidx.compose.runtime.setValue
6- import cc.unitmesh.agent.Platform
76import cc.unitmesh.agent.runconfig.*
87import cc.unitmesh.agent.tool.filesystem.DefaultToolFileSystem
98import cc.unitmesh.agent.tool.shell.DefaultShellExecutor
@@ -38,51 +37,34 @@ class RunConfigViewModel(
3837 llmService = llmService
3938 )
4039
41- // State exposed to UI
4240 val state: StateFlow <RunConfigState > = service.state
4341 val configs: StateFlow <List <RunConfig >> = service.configs
4442 val defaultConfig: StateFlow <RunConfig ?> = service.defaultConfig
4543 val isRunning: StateFlow <Boolean > = service.isRunning
4644 val runningConfigId: StateFlow <String ?> = service.runningConfigId
4745
48- // Output from running commands
4946 private val _output = MutableStateFlow <String >(" " )
5047 val output: StateFlow <String > = _output .asStateFlow()
5148
52- // Streaming analysis log (shows LLM reasoning)
5349 private val _analysisLog = MutableStateFlow <String >(" " )
5450 val analysisLog: StateFlow <String > = _analysisLog .asStateFlow()
5551
56- // Progress message during analysis
5752 var progressMessage by mutableStateOf<String ?>(null )
5853 private set
5954
60- // Error message
6155 var errorMessage by mutableStateOf<String ?>(null )
6256 private set
6357
64- init {
65- // Initialize on creation
66- // scope.launch {
67- // service.initialize()
68- // }
69- }
70-
71- /* *
72- * Analyze project to discover run configurations using LLM streaming.
73- */
7458 fun analyzeProject () {
7559 scope.launch {
7660 errorMessage = null
7761 _analysisLog .value = " 🔍 Starting project analysis...\n\n "
7862 progressMessage = " Analyzing with AI..."
79- println (" [RunConfigViewModel] Starting project analysis..." )
8063
8164 service.analyzeProject { progress ->
8265 progressMessage = progress.take(50 )
8366 // Append progress directly (streaming style)
8467 _analysisLog .value = _analysisLog .value + progress
85- println (" [RunConfigViewModel] Progress: $progress " )
8668 }
8769
8870 // Check for errors from service
@@ -94,14 +76,12 @@ class RunConfigViewModel(
9476 progressMessage = null
9577 val configCount = configs.value.size
9678 if (configCount > 0 ) {
97- // Show discovered configs summary
9879 val configSummary = configs.value.take(5 ).joinToString(" \n " ) { " • ${it.name} : ${it.command} " }
99- _analysisLog .value = _analysisLog .value + " \n\n 📋 Discovered configurations:\n $configSummary "
80+ _analysisLog .value + = " \n\n 📋 Discovered configurations:\n $configSummary "
10081 if (configCount > 5 ) {
101- _analysisLog .value = _analysisLog .value + " \n ... and ${configCount - 5 } more"
82+ _analysisLog .value + = " \n ... and ${configCount - 5 } more"
10283 }
10384 }
104- println (" [RunConfigViewModel] Analysis complete. Found $configCount configs, default=${defaultConfig.value?.name} " )
10585 }
10686 }
10787
@@ -125,64 +105,23 @@ class RunConfigViewModel(
125105
126106 if (! result.success) {
127107 errorMessage = result.error ? : " Command failed"
128- _output .value = _output .value + " \n\n [FAILED] ${result.error ? : " Command failed" } \n "
108+ _output .value + = " \n\n [FAILED] ${result.error ? : " Command failed" } \n "
129109 } else {
130- _output .value = _output .value + " \n\n [DONE] Exit code: ${result.exitCode ? : 0 } \n "
110+ _output .value + = " \n\n [DONE] Exit code: ${result.exitCode ? : 0 } \n "
131111 }
132112 }
133113 }
134114
135- /* *
136- * Run the default configuration
137- */
138- fun runDefault () {
139- defaultConfig.value?.let { runConfig(it) }
140- }
141-
142115 /* *
143116 * Stop the currently running command
144117 */
145118 fun stopRunning () {
146119 scope.launch {
147120 service.stopRunning()
148- _output .value = _output .value + " \n [STOPPED] Command cancelled by user\n "
121+ _output .value + = " \n [STOPPED] Command cancelled by user\n "
149122 }
150123 }
151124
152- /* *
153- * Set a config as the default
154- */
155- fun setDefaultConfig (configId : String ) {
156- service.setDefaultConfig(configId)
157- }
158-
159- /* *
160- * Add a custom configuration
161- */
162- fun addCustomConfig (
163- name : String ,
164- command : String ,
165- type : RunConfigType = RunConfigType .CUSTOM ,
166- description : String = ""
167- ) {
168- val config = RunConfig (
169- id = " custom-${Platform .getCurrentTimestamp()} " ,
170- name = name,
171- type = type,
172- command = command,
173- description = description,
174- source = RunConfigSource .USER_DEFINED
175- )
176- service.addConfig(config)
177- }
178-
179- /* *
180- * Remove a configuration
181- */
182- fun removeConfig (configId : String ) {
183- service.removeConfig(configId)
184- }
185-
186125 /* *
187126 * Clear output
188127 */
0 commit comments