1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package cmd
6
7import (
8 "fmt"
9 "strings"
10
11 "git.secluded.site/np/cmd/shared"
12 "git.secluded.site/np/internal/task"
13 "github.com/spf13/cobra"
14)
15
16var rCmd = &cobra.Command{
17 Use: "r",
18 Short: "Resume session",
19 Long: `Resume an interrupted session in a new context window`,
20 RunE: runResume,
21}
22
23func runResume(cmd *cobra.Command, args []string) error {
24 env, err := shared.Environment(cmd)
25 if err != nil {
26 return err
27 }
28
29 sessionDoc, found, err := shared.ActiveSession(cmd, env)
30 if err != nil {
31 return err
32 }
33 if !found {
34 return nil
35 }
36
37 state, err := shared.PrintPlan(cmd, env, sessionDoc.SID)
38 if err != nil {
39 return err
40 }
41
42 // Print instructions for resuming work
43 _, _ = fmt.Fprintln(cmd.OutOrStdout(), strings.Repeat("-", 80))
44 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "\nResuming session. To continue:")
45 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "1. Check the goal description above for any bug/issue/ticket ID. If present, read that ticket for full context.")
46 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "2. Read the files and symbols referenced in the pending tasks to understand what work remains.")
47 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "3. Update task status as you work:")
48 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " Single: `np t u -i <task-id> -s <status>`")
49 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " Batch: `np t u -i <id1> -s <status1> -i <id2> -s <status2>`")
50 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " Statuses: pending, in_progress, completed, failed, cancelled")
51
52 // Provide context about pending work
53 pendingCount := 0
54 inProgressCount := 0
55 for _, t := range state.Tasks {
56 switch t.Status {
57 case task.StatusPending:
58 pendingCount++
59 case task.StatusInProgress:
60 inProgressCount++
61 }
62 }
63
64 if inProgressCount > 0 {
65 _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\n%d task(s) are in progress.\n", inProgressCount)
66 }
67 if pendingCount > 0 {
68 _, _ = fmt.Fprintf(cmd.OutOrStdout(), "%d task(s) are pending.\n", pendingCount)
69 }
70
71 return nil
72}