Skip to content

Commit c38b9c0

Browse files
AnnatarHeclaude
andcommitted
refactor(track): split terminal field into terminal and multiplexer
Separate the combined "terminal -> multiplexer" format into two distinct fields for cleaner server-side storage and querying. - Change ResolveTerminal to return (terminal, multiplexer) tuple - Add Multiplexer field to TrackingMetaData struct - Update sync handler to populate both fields 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0aa8267 commit c38b9c0

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

daemon/handlers.sync.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ func handlePubSubSync(ctx context.Context, socketMsgPayload interface{}) error {
3636

3737
// Resolve terminal from PPID (use first data item's PPID)
3838
if len(syncMsg.Data) > 0 && syncMsg.Data[0].PPID > 0 {
39-
terminal := ResolveTerminal(syncMsg.Data[0].PPID)
39+
terminal, multiplexer := ResolveTerminal(syncMsg.Data[0].PPID)
4040
syncMsg.Meta.Terminal = terminal
41-
slog.Debug("Resolved terminal", slog.String("terminal", terminal), slog.Int("ppid", syncMsg.Data[0].PPID))
41+
syncMsg.Meta.Multiplexer = multiplexer
42+
slog.Debug("Resolved terminal", slog.String("terminal", terminal), slog.String("multiplexer", multiplexer), slog.Int("ppid", syncMsg.Data[0].PPID))
4243
}
4344

4445
// set as daemon

daemon/terminal_resolver.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,13 @@ var knownRemote = map[string]bool{
5858
}
5959

6060
// ResolveTerminal walks up the process tree starting from ppid
61-
// to find the terminal emulator. Returns raw process names.
62-
// Format: "terminal" or "terminal -> multiplexer" for multiplexed sessions
63-
func ResolveTerminal(ppid int) string {
61+
// to find the terminal emulator and multiplexer separately.
62+
// Returns (terminal, multiplexer) as separate values.
63+
func ResolveTerminal(ppid int) (terminal string, multiplexer string) {
6464
if ppid <= 0 {
65-
return ""
65+
return "", ""
6666
}
6767

68-
var terminal string
69-
var multiplexer string
70-
7168
currentPID := ppid
7269
visited := make(map[int]bool)
7370

@@ -111,20 +108,12 @@ func ResolveTerminal(ppid int) string {
111108
currentPID = parentPID
112109
}
113110

114-
// Build result string
111+
// If neither found, return "unknown" for terminal
115112
if terminal == "" && multiplexer == "" {
116-
return "unknown"
117-
}
118-
119-
if terminal != "" && multiplexer != "" {
120-
return terminal + " -> " + multiplexer
121-
}
122-
123-
if terminal != "" {
124-
return terminal
113+
return "unknown", ""
125114
}
126115

127-
return multiplexer
116+
return terminal, multiplexer
128117
}
129118

130119
// getProcessName returns the process name for the given PID

model/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type TrackingMetaData struct {
2929
OS string `json:"os"`
3030
OSVersion string `json:"osVersion"`
3131
Shell string `json:"shell"`
32-
Terminal string `json:"terminal,omitempty"`
32+
Terminal string `json:"terminal,omitempty"`
33+
Multiplexer string `json:"multiplexer,omitempty"`
3334

3435
// 0: cli, 1: daemon
3536
Source int `json:"source"`

0 commit comments

Comments
 (0)