feat(cmd/r): implement session resumption

Amolith and Crush created

Co-Authored-By: Crush <crush@charm.land>

Change summary

cmd/r.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 53 insertions(+), 3 deletions(-)

Detailed changes

cmd/r.go 🔗

@@ -6,7 +6,10 @@ package cmd
 
 import (
 	"fmt"
+	"strings"
 
+	"git.secluded.site/np/cmd/shared"
+	"git.secluded.site/np/internal/task"
 	"github.com/spf13/cobra"
 )
 
@@ -14,7 +17,54 @@ var rCmd = &cobra.Command{
 	Use:   "r",
 	Short: "Resume session",
 	Long:  `Resume an interrupted session in a new context window`,
-	Run: func(cmd *cobra.Command, args []string) {
-		fmt.Println("[STUB] Resume interrupted session from database")
-	},
+	RunE:  runResume,
+}
+
+func runResume(cmd *cobra.Command, args []string) error {
+	env, err := shared.Environment(cmd)
+	if err != nil {
+		return err
+	}
+
+	sessionDoc, found, err := shared.ActiveSession(cmd, env)
+	if err != nil {
+		return err
+	}
+	if !found {
+		return nil
+	}
+
+	state, err := shared.PrintPlan(cmd, env, sessionDoc.SID)
+	if err != nil {
+		return err
+	}
+
+	// Print instructions for resuming work
+	fmt.Fprintln(cmd.OutOrStdout(), strings.Repeat("-", 80))
+	fmt.Fprintln(cmd.OutOrStdout(), "\nResuming session. To continue:")
+	fmt.Fprintln(cmd.OutOrStdout(), "1. Check the goal description above for any bug/issue/ticket ID. If present, read that ticket for full context.")
+	fmt.Fprintln(cmd.OutOrStdout(), "2. Read the files and symbols referenced in the pending tasks to understand what work remains.")
+	fmt.Fprintln(cmd.OutOrStdout(), "3. Update task status as you work: `np t u -i <task-id> -s <status>`")
+	fmt.Fprintln(cmd.OutOrStdout(), "   Statuses: pending, in_progress, completed, failed, cancelled")
+
+	// Provide context about pending work
+	pendingCount := 0
+	inProgressCount := 0
+	for _, t := range state.Tasks {
+		switch t.Status {
+		case task.StatusPending:
+			pendingCount++
+		case task.StatusInProgress:
+			inProgressCount++
+		}
+	}
+
+	if inProgressCount > 0 {
+		fmt.Fprintf(cmd.OutOrStdout(), "\n%d task(s) are in progress.\n", inProgressCount)
+	}
+	if pendingCount > 0 {
+		fmt.Fprintf(cmd.OutOrStdout(), "%d task(s) are pending.\n", pendingCount)
+	}
+
+	return nil
 }