moki 2 долоо хоног өмнө
parent
commit
8ca659fde1

+ 2 - 2
internal/discovery/discovery_darwin.go

@@ -21,7 +21,7 @@ func findByPID() []int {
 
 	var pids []int
 	for _, line := range strings.Split(string(out), "\n") {
-		if pidRegex.MatchString(line) && !strings.Contains(line, "grep") {
+		if pidRegex.MatchString(line) && !strings.Contains(line, "opencode-monitor") && !strings.Contains(line, "grep") {
 			fields := strings.Fields(line)
 			if len(fields) > 1 {
 				if pid, err := strconv.Atoi(fields[1]); err == nil {
@@ -91,7 +91,7 @@ func findByCmdline() []int {
 	}
 
 	for _, line := range strings.Split(string(out), "\n") {
-		if strings.Contains(line, "opencode") && !strings.Contains(line, "grep") {
+		if strings.Contains(line, "opencode") && !strings.Contains(line, "opencode-monitor") && !strings.Contains(line, "grep") {
 			if strings.Contains(line, "--port") {
 				fields := strings.Fields(line)
 				for i, f := range fields {

+ 1 - 1
internal/discovery/discovery_linux.go

@@ -81,7 +81,7 @@ func findByCmdline() []int {
 	}
 
 	for _, line := range strings.Split(string(out), "\n") {
-		if strings.Contains(line, "opencode") && !strings.Contains(line, "grep") {
+		if strings.Contains(line, "opencode") && !strings.Contains(line, "opencode-monitor") && !strings.Contains(line, "grep") {
 			if strings.Contains(line, "--port") {
 				fields := strings.Fields(line)
 				for i, f := range fields {

+ 3 - 3
internal/discovery/discovery_windows.go

@@ -21,7 +21,7 @@ func findByPID() []int {
 
 	var pids []int
 	for _, line := range strings.Split(string(tasklistOut), "\n") {
-		if pidRegex.MatchString(line) {
+		if pidRegex.MatchString(line) && !strings.Contains(line, "opencode-monitor") {
 			fields := strings.Split(line, ",")
 			if len(fields) >= 2 {
 				pidStr := strings.Trim(fields[1], "\"")
@@ -69,7 +69,7 @@ func findByCmdline() []int {
 	var ports []int
 
 	// 查找 opencode 进程
-	wmicOut, err := exec.Command("wmic", "process", "where", "name like '%opencode%'", "get", "commandline", "/FORMAT:LIST").Output()
+	wmicOut, err := exec.Command("wmic", "process", "where", "name like '%opencode%' and name not like '%opencode-monitor%'", "get", "commandline", "/FORMAT:LIST").Output()
 	if err == nil {
 		for _, line := range strings.Split(string(wmicOut), "\n") {
 			if strings.Contains(line, "--port") {
@@ -110,7 +110,7 @@ func findByCmdline() []int {
 
 	// 使用 PowerShell 作为后备方案
 	if len(ports) == 0 {
-		powershellOut, err := exec.Command("powershell", "-Command", "Get-CimInstance Win32_Process | Where-Object {$_.Name -like '*opencode*' -or ($_.Name -like '*bun*' -and $_.CommandLine -like '*opencode*')} | Select-Object CommandLine").Output()
+		powershellOut, err := exec.Command("powershell", "-Command", "Get-CimInstance Win32_Process | Where-Object {($_.Name -like '*opencode*' -and $_.Name -notlike '*opencode-monitor*') -or ($_.Name -like '*bun*' -and $_.CommandLine -like '*opencode*')} | Select-Object CommandLine").Output()
 		if err == nil {
 			for _, line := range strings.Split(string(powershellOut), "\n") {
 				if strings.Contains(line, "--port") {