From 809b0eb028cb57d4c56dad8a5b1e03bfa8c1ef41 Mon Sep 17 00:00:00 2001 From: mayor Date: Sun, 25 Jan 2026 18:19:59 -0800 Subject: [PATCH] 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 --- internal/cmd/molecule_status.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/cmd/molecule_status.go b/internal/cmd/molecule_status.go index 7feb33d7..abf4500f 100644 --- a/internal/cmd/molecule_status.go +++ b/internal/cmd/molecule_status.go @@ -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)