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(), "")
45 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "Resuming session. To continue:")
46 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "1. Thoroughly consider the goal and its description.")
47 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "2. Read the referenced files and symbols, especially in the pending tasks, to understand what work remains.")
48 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "3. Add more tasks if needed. For multi-line descriptions, use literal newlines:")
49 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " # Single")
50 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " np t a -t \"task title\" -d \"details\"")
51 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "")
52 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " # Batch (preferred for multiple additions)")
53 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " np t a -t \"first\" -d \"step 1 details\" -t \"second\" -d \"step 2 with")
54 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " more details\" -t \"third\" -d \"step three\"`")
55 _, _ = fmt.Fprintln(cmd.OutOrStdout(), "4. Update task status as you work:")
56 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " Single: `np t u -i <task-id> -s <status>`")
57 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " Batch: `np t u -i <id1> -s <status1> -i <id2> -s <status2>`")
58 _, _ = fmt.Fprintln(cmd.OutOrStdout(), " Statuses: pending, in_progress, completed, failed, cancelled")
59
60 // Provide context about pending work
61 pendingCount := 0
62 inProgressCount := 0
63 for _, t := range state.Tasks {
64 switch t.Status {
65 case task.StatusPending:
66 pendingCount++
67 case task.StatusInProgress:
68 inProgressCount++
69 }
70 }
71
72 if inProgressCount > 0 {
73 _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\n%d task(s) are in progress.\n", inProgressCount)
74 }
75 if pendingCount > 0 {
76 _, _ = fmt.Fprintf(cmd.OutOrStdout(), "%d task(s) are pending.\n", pendingCount)
77 }
78
79 return nil
80}