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:
mayor
2026-01-25 18:19:59 -08:00
committed by beads/crew/emma
parent 31bd120077
commit 809b0eb028

View File

@@ -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 // not the agent from the GT_ROLE env var (which might be different if
// we cd'd into another rig's crew/polecat directory) // we cd'd into another rig's crew/polecat directory)
roleCtx = detectRole(cwd, townRoot) 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) target = buildAgentIdentity(roleCtx)
if target == "" { if target == "" {
return fmt.Errorf("cannot determine agent identity (role: %s)", roleCtx.Role) 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 // not the agent from the GT_ROLE env var (which might be different if
// we cd'd into another rig's crew/polecat directory) // we cd'd into another rig's crew/polecat directory)
roleCtx = detectRole(cwd, townRoot) 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) target = buildAgentIdentity(roleCtx)
if target == "" { if target == "" {
return fmt.Errorf("cannot determine agent identity (role: %s)", roleCtx.Role) return fmt.Errorf("cannot determine agent identity (role: %s)", roleCtx.Role)