feat: gt mol attach auto-detects agent from cwd when single arg provided

When called with 1 arg from an agent working directory, gt mol attach
now auto-detects the pinned bead ID from the current agent's hook.

Uses the same role detection infrastructure as gt mail and bd. (gt-t7ekm)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-30 00:15:58 -08:00
parent fdea399d6f
commit 3aeaeaf845
2 changed files with 68 additions and 6 deletions

View File

@@ -55,16 +55,20 @@ Example:
} }
var moleculeAttachCmd = &cobra.Command{ var moleculeAttachCmd = &cobra.Command{
Use: "attach <pinned-bead-id> <molecule-id>", Use: "attach [pinned-bead-id] <molecule-id>",
Short: "Attach a molecule to a pinned bead", Short: "Attach a molecule to a pinned bead",
Long: `Attach a molecule to a pinned/handoff bead. Long: `Attach a molecule to a pinned/handoff bead.
This records which molecule an agent is currently working on. The attachment This records which molecule an agent is currently working on. The attachment
is stored in the pinned bead's description and visible via 'bd show'. is stored in the pinned bead's description and visible via 'bd show'.
Example: When called with a single argument from an agent working directory, the
gt molecule attach gt-abc mol-xyz`, pinned bead ID is auto-detected from the current agent's hook.
Args: cobra.ExactArgs(2),
Examples:
gt molecule attach gt-abc mol-xyz # Explicit pinned bead
gt molecule attach mol-xyz # Auto-detect from cwd`,
Args: cobra.RangeArgs(1, 2),
RunE: runMoleculeAttach, RunE: runMoleculeAttach,
} }

View File

@@ -12,8 +12,24 @@ import (
) )
func runMoleculeAttach(cmd *cobra.Command, args []string) error { func runMoleculeAttach(cmd *cobra.Command, args []string) error {
pinnedBeadID := args[0] var pinnedBeadID, moleculeID string
moleculeID := args[1]
if len(args) == 2 {
// Explicit: gt mol attach <pinned-bead-id> <molecule-id>
pinnedBeadID = args[0]
moleculeID = args[1]
} else {
// Auto-detect: gt mol attach <molecule-id>
moleculeID = args[0]
var err error
pinnedBeadID, err = detectAgentBeadID()
if err != nil {
return fmt.Errorf("auto-detecting agent: %w", err)
}
if pinnedBeadID == "" {
return fmt.Errorf("could not detect agent from current directory - provide explicit pinned bead ID")
}
}
workDir, err := findLocalBeadsDir() workDir, err := findLocalBeadsDir()
if err != nil { if err != nil {
@@ -37,6 +53,48 @@ func runMoleculeAttach(cmd *cobra.Command, args []string) error {
return nil return nil
} }
// detectAgentBeadID detects the current agent's bead ID from the working directory.
// Returns the agent bead ID (e.g., "gt-mayor", "gt-gastown-polecat-nux") or empty string if not detectable.
func detectAgentBeadID() (string, error) {
cwd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("getting current directory: %w", err)
}
townRoot, err := workspace.FindFromCwd()
if err != nil {
return "", fmt.Errorf("finding workspace: %w", err)
}
if townRoot == "" {
return "", fmt.Errorf("not in a Gas Town workspace")
}
roleInfo, err := GetRoleWithContext(cwd, townRoot)
if err != nil {
return "", fmt.Errorf("detecting role: %w", err)
}
roleCtx := RoleContext{
Role: roleInfo.Role,
Rig: roleInfo.Rig,
Polecat: roleInfo.Polecat,
TownRoot: townRoot,
WorkDir: cwd,
}
identity := buildAgentIdentity(roleCtx)
if identity == "" {
return "", fmt.Errorf("cannot determine agent identity (role: %s)", roleCtx.Role)
}
beadID := buildAgentBeadID(identity, roleCtx.Role)
if beadID == "" {
return "", fmt.Errorf("cannot build agent bead ID for identity: %s", identity)
}
return beadID, nil
}
func runMoleculeDetach(cmd *cobra.Command, args []string) error { func runMoleculeDetach(cmd *cobra.Command, args []string) error {
pinnedBeadID := args[0] pinnedBeadID := args[0]