Skip to content

Commit 562103d

Browse files
committed
Remove dead code, extract shared helpers, add --config-dir flag
- Delete commands_pairing.go (move addTokenForMobile to pairing_handlers) - Delete utils.go (unused openFile) - Remove dead fields: running, cmd, inputBuffer, Available - Extract buildPairingQRData and reuse DetectSSHInfo in sendCLIInfo - Add --config-dir flag for isolated config (staging testing) - Add error handling for savePCConfig calls
1 parent f781c46 commit 562103d

11 files changed

Lines changed: 130 additions & 328 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
VERSION := $(shell cat VERSION)
22

3-
# Default relay URL (can be overridden by .env.local or environment)
3+
# Default relay URL (can be overridden by .env.local or command line)
44
RELAY_URL ?= wss://aipilot-relay.softwarity.io
55

66
# Load .env.local if it exists (for local dev)

agents.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,19 @@ const (
1717

1818
// AgentInfo contains information about a detected agent
1919
type AgentInfo struct {
20-
Command string
21-
Type AgentType
22-
Version string
23-
Available bool
20+
Command string
21+
Type AgentType
22+
Version string
2423
}
2524

2625
// knownAgents lists all known AI terminal agents to detect
2726
var knownAgents = []struct {
28-
command string
29-
agentType AgentType
30-
displayName string
27+
command string
28+
agentType AgentType
3129
}{
32-
{"claude", AgentClaude, "Claude Code"},
33-
{"gemini", AgentGemini, "Google Gemini CLI"},
34-
{"codex", AgentCodex, "OpenAI Codex"},
30+
{"claude", AgentClaude},
31+
{"gemini", AgentGemini},
32+
{"codex", AgentCodex},
3533
}
3634

3735
func checkCommand(command string) (string, error) {
@@ -85,10 +83,9 @@ func detectAvailableAgents() []AgentInfo {
8583
if _, err := exec.LookPath(agent.command); err == nil {
8684
version := getAgentVersion(agent.command, agent.agentType)
8785
available = append(available, AgentInfo{
88-
Command: agent.command,
89-
Type: agent.agentType,
90-
Version: version,
91-
Available: true,
86+
Command: agent.command,
87+
Type: agent.agentType,
88+
Version: version,
9289
})
9390
}
9491
}

commands_info.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@ package main
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"net"
7-
"os"
8-
"os/user"
96
"runtime"
107
)
118

129
// sendCLIInfo sends CLI information to mobile
1310
func (d *Daemon) sendCLIInfo() {
14-
hostname, err := os.Hostname()
15-
if err != nil {
16-
fmt.Printf("%sWarning: Could not get hostname: %v%s\n", yellow, err, reset)
17-
hostname = "unknown"
18-
}
19-
20-
currentUser := "unknown"
21-
if u, err := user.Current(); err == nil {
22-
currentUser = u.Username
23-
}
24-
11+
// Gather all non-loopback IPv4 addresses for mobile connectivity
2512
var ips []string
2613
if addrs, err := net.InterfaceAddrs(); err == nil {
2714
for _, addr := range addrs {
@@ -33,29 +20,20 @@ func (d *Daemon) sendCLIInfo() {
3320
}
3421
}
3522

36-
// Quick SSH check
37-
sshPort := DefaultSSHPort
38-
sshRunning := false
39-
if conn, err := net.DialTimeout("tcp", fmt.Sprintf("127.0.0.1:%d", DefaultSSHPort), SSHQuickCheckTimeout); err == nil {
40-
conn.Close()
41-
sshRunning = true
42-
} else if conn, err := net.DialTimeout("tcp", fmt.Sprintf("127.0.0.1:%d", AlternativeSSHPort), SSHQuickCheckTimeout); err == nil {
43-
conn.Close()
44-
sshPort = AlternativeSSHPort
45-
sshRunning = true
46-
}
23+
// Use thorough SSH detection (ss/lsof/netstat/config parsing)
24+
sshInfo := DetectSSHInfo()
4725

4826
info := map[string]interface{}{
4927
"os": runtime.GOOS,
5028
"arch": runtime.GOARCH,
51-
"hostname": hostname,
52-
"user": currentUser,
29+
"hostname": sshInfo.Hostname,
30+
"user": sshInfo.Username,
5331
"cli_version": Version,
5432
"working_dir": d.workDir,
5533
"agent": d.command,
5634
"agent_type": string(d.agentType),
57-
"ssh_running": sshRunning,
58-
"ssh_port": sshPort,
35+
"ssh_running": sshInfo.Available,
36+
"ssh_port": sshInfo.Port,
5937
"ips": ips,
6038
}
6139

commands_pairing.go

Lines changed: 0 additions & 196 deletions
This file was deleted.

commands_session.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,38 +116,25 @@ func (d *Daemon) showPairingQRRaw(onComplete func()) {
116116
return
117117
}
118118

119-
// Create QR data
120-
qrData := PairingQRData{
121-
Type: "pairing",
122-
Relay: d.relay,
123-
Token: pairingResp.Token,
124-
PCID: d.pcConfig.PCID,
125-
PCName: d.pcConfig.PCName,
126-
PublicKey: d.pcConfig.PublicKey,
127-
}
128-
129119
// Include session info if we have an active session
130120
d.mu.RLock()
131121
sessionID := d.session
132122
workDir := d.workDir
133123
agentType := d.agentType
134124
d.mu.RUnlock()
135125

126+
var sessionInfo *SessionQRInfo
136127
if sessionID != "" {
137-
qrData.SessionID = sessionID
138-
qrData.WorkingDir = workDir
139-
qrData.AgentType = string(agentType)
140-
141-
// Add SSH info
142-
sshInfo := DetectSSHInfo()
143-
if sshInfo != nil && sshInfo.Available {
144-
qrData.SSHAvailable = true
145-
qrData.SSHPort = sshInfo.Port
146-
qrData.Hostname = sshInfo.Hostname
147-
qrData.Username = sshInfo.Username
128+
sessionInfo = &SessionQRInfo{
129+
SessionID: sessionID,
130+
WorkDir: workDir,
131+
AgentType: string(agentType),
148132
}
149133
}
150134

135+
// Create QR data using shared helper
136+
qrData := buildPairingQRData(d.pcConfig, d.relay, pairingResp.Token, sessionInfo)
137+
151138
qrJSON, err := json.Marshal(qrData)
152139
if err != nil {
153140
printRaw("%sError creating QR: %v%s\n", red, err, reset)
@@ -200,7 +187,9 @@ func (d *Daemon) pollPairingCompletionRaw(token string, onComplete func()) {
200187
PairedAt: time.Now().Format(time.RFC3339),
201188
}
202189
d.pcConfig.addPairedMobile(mobile)
203-
savePCConfig(d.pcConfig)
190+
if err := savePCConfig(d.pcConfig); err != nil {
191+
fmt.Printf("%sFailed to save config: %v%s\n", red, err, reset)
192+
}
204193

205194
d.mu.RLock()
206195
oldSessionID := d.session

0 commit comments

Comments
 (0)