loop: use stringer for State.String, use String in slogs

diff --git a/loop/state_string.go b/loop/state_string.go
new file mode 100644
index 0000000..4556a73
--- /dev/null
+++ b/loop/state_string.go
@@ -0,0 +1,39 @@
+// Code generated by "stringer -type=State -trimprefix=State"; DO NOT EDIT.
+
+package loop
+
+import "strconv"
+
+func _() {
+	// An "invalid array index" compiler error signifies that the constant values have changed.
+	// Re-run the stringer command to generate them again.
+	var x [1]struct{}
+	_ = x[StateUnknown-0]
+	_ = x[StateReady-1]
+	_ = x[StateWaitingForUserInput-2]
+	_ = x[StateSendingToLLM-3]
+	_ = x[StateProcessingLLMResponse-4]
+	_ = x[StateEndOfTurn-5]
+	_ = x[StateToolUseRequested-6]
+	_ = x[StateCheckingForCancellation-7]
+	_ = x[StateRunningTool-8]
+	_ = x[StateCheckingGitCommits-9]
+	_ = x[StateRunningAutoformatters-10]
+	_ = x[StateCheckingBudget-11]
+	_ = x[StateGatheringAdditionalMessages-12]
+	_ = x[StateSendingToolResults-13]
+	_ = x[StateCancelled-14]
+	_ = x[StateBudgetExceeded-15]
+	_ = x[StateError-16]
+}
+
+const _State_name = "UnknownReadyWaitingForUserInputSendingToLLMProcessingLLMResponseEndOfTurnToolUseRequestedCheckingForCancellationRunningToolCheckingGitCommitsRunningAutoformattersCheckingBudgetGatheringAdditionalMessagesSendingToolResultsCancelledBudgetExceededError"
+
+var _State_index = [...]uint8{0, 7, 12, 31, 43, 64, 73, 89, 112, 123, 141, 162, 176, 203, 221, 230, 244, 249}
+
+func (i State) String() string {
+	if i < 0 || i >= State(len(_State_index)-1) {
+		return "State(" + strconv.FormatInt(int64(i), 10) + ")"
+	}
+	return _State_name[_State_index[i]:_State_index[i+1]]
+}
diff --git a/loop/statemachine.go b/loop/statemachine.go
index 9a520f6..284c13f 100644
--- a/loop/statemachine.go
+++ b/loop/statemachine.go
@@ -11,6 +11,7 @@
 // State represents the possible states of the Agent state machine
 type State int
 
+//go:generate go tool golang.org/x/tools/cmd/stringer -type=State -trimprefix=State
 const (
 	// StateUnknown is the default state
 	StateUnknown State = iota
@@ -48,48 +49,6 @@
 	StateError
 )
 
-// String returns a string representation of the State for logging and debugging
-func (s State) String() string {
-	switch s {
-	case StateUnknown:
-		return "Unknown"
-	case StateReady:
-		return "Ready"
-	case StateWaitingForUserInput:
-		return "WaitingForUserInput"
-	case StateSendingToLLM:
-		return "SendingToLLM"
-	case StateProcessingLLMResponse:
-		return "ProcessingLLMResponse"
-	case StateEndOfTurn:
-		return "EndOfTurn"
-	case StateToolUseRequested:
-		return "ToolUseRequested"
-	case StateCheckingForCancellation:
-		return "CheckingForCancellation"
-	case StateRunningTool:
-		return "RunningTool"
-	case StateCheckingGitCommits:
-		return "CheckingGitCommits"
-	case StateRunningAutoformatters:
-		return "RunningAutoformatters"
-	case StateCheckingBudget:
-		return "CheckingBudget"
-	case StateGatheringAdditionalMessages:
-		return "GatheringAdditionalMessages"
-	case StateSendingToolResults:
-		return "SendingToolResults"
-	case StateCancelled:
-		return "Cancelled"
-	case StateBudgetExceeded:
-		return "BudgetExceeded"
-	case StateError:
-		return "Error"
-	default:
-		return fmt.Sprintf("Unknown(%d)", int(s))
-	}
-}
-
 // TransitionEvent represents an event that causes a state transition
 type TransitionEvent struct {
 	// Description provides a human-readable description of the event
@@ -329,8 +288,8 @@
 
 	// Log the transition
 	slog.InfoContext(ctx, "State transition",
-		"from", sm.previousState,
-		"to", sm.currentState,
+		"from", sm.previousState.String(),
+		"to", sm.currentState.String(),
 		"event", event.Description,
 		"duration", duration)
 
@@ -483,8 +442,8 @@
 
 	// Log the transition
 	slog.WarnContext(ctx, "Forced state transition",
-		"from", sm.previousState,
-		"to", sm.currentState,
+		"from", sm.previousState.String(),
+		"to", sm.currentState.String(),
 		"reason", reason,
 		"duration", duration)