Skip to content

Commit c5c273f

Browse files
authored
Merge PR #2591: fix: read rig beads prefix from rigs.json instead of missing config.json
Fixes rig bead label lookups (parked/docked state) to read prefix from rigs.json instead of non-existent config.json. Affects rig_helpers.go and daemon.go. PR: #2591 Author: Cdfghglz
2 parents ef49140 + 98b748d commit c5c273f

2 files changed

Lines changed: 54 additions & 9 deletions

File tree

internal/cmd/rig_helpers.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ func getRig(rigName string) (string, *rig.Rig, error) {
6868
// Returns false if the rig config or bead can't be loaded (safe default).
6969
func hasRigBeadLabel(townRoot, rigName, label string) bool {
7070
rigPath := filepath.Join(townRoot, rigName)
71-
rigCfg, err := rig.LoadRigConfig(rigPath)
72-
if err != nil || rigCfg.Beads == nil {
71+
prefix := ""
72+
rigsConfigPath := constants.MayorRigsPath(townRoot)
73+
if rigsConfig, err := config.LoadRigsConfig(rigsConfigPath); err == nil {
74+
if entry, ok := rigsConfig.Rigs[rigName]; ok && entry.BeadsConfig != nil {
75+
prefix = entry.BeadsConfig.Prefix
76+
}
77+
}
78+
if prefix == "" {
7379
return false
7480
}
7581

@@ -79,7 +85,7 @@ func hasRigBeadLabel(townRoot, rigName, label string) bool {
7985
}
8086

8187
bd := beads.New(beadsPath)
82-
rigBeadID := beads.RigBeadIDWithPrefix(rigCfg.Beads.Prefix, rigName)
88+
rigBeadID := beads.RigBeadIDWithPrefix(prefix, rigName)
8389

8490
rigBead, err := bd.Show(rigBeadID)
8591
if err != nil {
@@ -111,10 +117,18 @@ func IsRigParkedOrDocked(townRoot, rigName string) (bool, string) {
111117
return true, "parked"
112118
}
113119

114-
// Single bead lookup for both parked and docked labels
120+
// Single bead lookup for both parked and docked labels.
121+
// Look up the beads prefix from rigs.json (the rig registry) instead of
122+
// <rigPath>/config.json which doesn't exist for most rigs.
115123
rigPath := filepath.Join(townRoot, rigName)
116-
rigCfg, err := rig.LoadRigConfig(rigPath)
117-
if err != nil || rigCfg.Beads == nil {
124+
prefix := ""
125+
rigsConfigPath := constants.MayorRigsPath(townRoot)
126+
if rigsConfig, err := config.LoadRigsConfig(rigsConfigPath); err == nil {
127+
if entry, ok := rigsConfig.Rigs[rigName]; ok && entry.BeadsConfig != nil {
128+
prefix = entry.BeadsConfig.Prefix
129+
}
130+
}
131+
if prefix == "" {
118132
return false, ""
119133
}
120134

@@ -124,7 +138,7 @@ func IsRigParkedOrDocked(townRoot, rigName string) (bool, string) {
124138
}
125139

126140
bd := beads.New(beadsPath)
127-
rigBeadID := beads.RigBeadIDWithPrefix(rigCfg.Beads.Prefix, rigName)
141+
rigBeadID := beads.RigBeadIDWithPrefix(prefix, rigName)
128142
rigBead, err := bd.Show(rigBeadID)
129143
if err != nil {
130144
return false, ""

internal/daemon/daemon.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,33 @@ func (d *Daemon) getKnownRigs() []string {
13811381
return rigs
13821382
}
13831383

1384+
// getRigBeadsPrefix returns the beads prefix for a rig by reading rigs.json.
1385+
// Returns "" if the prefix cannot be determined.
1386+
func (d *Daemon) getRigBeadsPrefix(rigName string) string {
1387+
rigsPath := filepath.Join(d.config.TownRoot, "mayor", "rigs.json")
1388+
data, err := os.ReadFile(rigsPath)
1389+
if err != nil {
1390+
return ""
1391+
}
1392+
1393+
var parsed struct {
1394+
Rigs map[string]struct {
1395+
Beads *struct {
1396+
Prefix string `json:"prefix"`
1397+
} `json:"beads,omitempty"`
1398+
} `json:"rigs"`
1399+
}
1400+
if err := json.Unmarshal(data, &parsed); err != nil {
1401+
return ""
1402+
}
1403+
1404+
entry, ok := parsed.Rigs[rigName]
1405+
if !ok || entry.Beads == nil {
1406+
return ""
1407+
}
1408+
return entry.Beads.Prefix
1409+
}
1410+
13841411
// getPatrolRigs returns the list of operational rigs for a patrol.
13851412
// If the patrol config specifies a rigs filter, only those rigs are returned.
13861413
// Otherwise, all known rigs are returned. In both cases, non-operational
@@ -1435,8 +1462,12 @@ func (d *Daemon) isRigOperational(rigName string) (bool, string) {
14351462
// Check rig bead labels (global/synced docked status)
14361463
// This is the persistent docked state set by 'gt rig dock'
14371464
rigPath := filepath.Join(d.config.TownRoot, rigName)
1438-
if rigCfg, err := rig.LoadRigConfig(rigPath); err == nil && rigCfg.Beads != nil {
1439-
rigBeadID := fmt.Sprintf("%s-rig-%s", rigCfg.Beads.Prefix, rigName)
1465+
// Look up the beads prefix from rigs.json (the daemon's authoritative
1466+
// rig registry). The previous code used rig.LoadRigConfig which reads
1467+
// <rigPath>/config.json — a file that doesn't exist for most rigs,
1468+
// silently skipping the bead-label check and ignoring dock state.
1469+
if prefix := d.getRigBeadsPrefix(rigName); prefix != "" {
1470+
rigBeadID := fmt.Sprintf("%s-rig-%s", prefix, rigName)
14401471
rigBeadsDir := beads.ResolveBeadsDir(rigPath)
14411472
bd := beads.NewWithBeadsDir(rigPath, rigBeadsDir)
14421473
if issue, err := bd.Show(rigBeadID); err == nil {

0 commit comments

Comments
 (0)