fix: critical issues in wisp hook system

Code review fixes:

1. CRITICAL: Move polecat check to start of runSling
   - Previously wrote wisp THEN failed, leaving orphan
   - Now fails fast before any file operations

2. CRITICAL: Sanitize slashes in agent IDs for filenames
   - Agent IDs like 'gastown/crew/joe' were creating subdirs
   - Now converts '/' to '--' for safe filenames
   - Added sanitizeAgentID/unsanitizeAgentID helpers

3. MODERATE: Use git root instead of WorkDir in prime.go
   - Hooks are written to clone root, not cwd
   - Added getGitRoot() helper for consistency

4. MODERATE: Fix silent error swallowing
   - Now logs non-ErrNoHook errors when reading hooks
   - Warns if bead doesn't exist before burning hook
   - Preserves hook if bead is missing for debugging
This commit is contained in:
Steve Yegge
2025-12-24 16:20:04 -08:00
parent dbec2c3b88
commit 7c7b8b551d
4 changed files with 57 additions and 15 deletions

View File

@@ -50,6 +50,11 @@ func init() {
func runSling(cmd *cobra.Command, args []string) error {
beadID := args[0]
// Polecats cannot sling - check early before writing anything
if polecatName := os.Getenv("GT_POLECAT"); polecatName != "" {
return fmt.Errorf("polecats cannot sling (use gt done for handoff)")
}
// Verify the bead exists
if err := verifyBeadExists(beadID); err != nil {
return err
@@ -166,13 +171,6 @@ func detectCloneRoot() (string, error) {
// triggerHandoff restarts the agent session.
func triggerHandoff(agentID, beadID string) error {
// Check if we're a polecat
if polecatName := os.Getenv("GT_POLECAT"); polecatName != "" {
fmt.Printf("%s Polecat detected - cannot sling (use gt done instead)\n",
style.Bold.Render("⚠"))
return fmt.Errorf("polecats cannot sling - use gt done for handoff")
}
// Must be in tmux
if !tmux.IsInsideTmux() {
return fmt.Errorf("not running in tmux - cannot restart")