fix(hook): fall back to GT_ROLE when cwd detection fails
gt hook status failed with "cannot determine agent identity (role: unknown)" when run from rig root directories like ~/gt/beads. The cwd-based detection only recognizes specific agent directories (witness/, polecats/foo/, etc.) but not rig roots. Now falls back to GT_ROLE env var when detectRole returns unknown, matching the pattern used by GetRoleWithContext and other role detection code. Fixes gt-6pg Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -331,6 +331,11 @@ func runMoleculeStatus(cmd *cobra.Command, args []string) error {
|
||||
// not the agent from the GT_ROLE env var (which might be different if
|
||||
// we cd'd into another rig's crew/polecat directory)
|
||||
roleCtx = detectRole(cwd, townRoot)
|
||||
if roleCtx.Role == RoleUnknown {
|
||||
// Fall back to GT_ROLE when cwd doesn't identify an agent
|
||||
// (e.g., at rig root like ~/gt/beads instead of ~/gt/beads/witness)
|
||||
roleCtx, _ = GetRoleWithContext(cwd, townRoot)
|
||||
}
|
||||
target = buildAgentIdentity(roleCtx)
|
||||
if target == "" {
|
||||
return fmt.Errorf("cannot determine agent identity (role: %s)", roleCtx.Role)
|
||||
@@ -760,6 +765,11 @@ func runMoleculeCurrent(cmd *cobra.Command, args []string) error {
|
||||
// not the agent from the GT_ROLE env var (which might be different if
|
||||
// we cd'd into another rig's crew/polecat directory)
|
||||
roleCtx = detectRole(cwd, townRoot)
|
||||
if roleCtx.Role == RoleUnknown {
|
||||
// Fall back to GT_ROLE when cwd doesn't identify an agent
|
||||
// (e.g., at rig root like ~/gt/beads instead of ~/gt/beads/witness)
|
||||
roleCtx, _ = GetRoleWithContext(cwd, townRoot)
|
||||
}
|
||||
target = buildAgentIdentity(roleCtx)
|
||||
if target == "" {
|
||||
return fmt.Errorf("cannot determine agent identity (role: %s)", roleCtx.Role)
|
||||
|
||||
Reference in New Issue
Block a user