返回 DeepSeek-Reasonix
goal_command.go
根目录 / internal / control / goal_command.go
1 package control
2
3 import (
4 "context"
5 "fmt"
6 "strings"
7
8 "reasonix/internal/i18n"
9 )
10
11 func (c *Controller) startGoalCommandTurnWithAdmission(cmd GoalCommand, display string, admission turnAdmission) {
12 if c.GoalStatus() != GoalStatusRunning {
13 return
14 }
15 if !c.sessionEngineEnabled() {
16 c.goals.markExplicitStart()
17 }
18 c.notice(fmt.Sprintf(i18n.M.GoalSetFmt, ShortGoalForNotice(c.Goal())))
19 if c.runner != nil {
20 c.runGuardedWithAdmission(func(ctx context.Context) error {
21 return c.runGoalLoopWithRawDisplay(ctx, "Start pursuing the active goal now.", cmd.Text, display)
22 }, admission)
23 }
24 }
25
26 func (c *Controller) applyGoalCommand(input, display string) bool {
27 return c.applyGoalCommandWithAdmission(input, display, turnAdmission{})
28 }
29
30 func (c *Controller) applyGoalCommandWithAdmission(input, display string, admission turnAdmission) bool {
31 cmd, ok := ParseGoalCommand(input)
32 if !ok {
33 return false
34 }
35 if cmd.DeprecatedBudgetFlag {
36 c.notice(GoalBudgetFlagDeprecatedNotice)
37 }
38 switch cmd.Action {
39 case GoalCommandSet:
40 if c.sessionEngineEnabled() {
41 if err := c.SetGoalDurable(cmd.Text); err != nil {
42 c.notice("goal: " + err.Error())
43 break
44 }
45 } else {
46 c.SetGoalWithResearchMode(cmd.Text, cmd.ResearchMode)
47 }
48 c.SetPlanMode(false)
49 c.GoalStrict(cmd.Strict)
50 c.startGoalCommandTurnWithAdmission(cmd, display, admission)
51 case GoalCommandClear:
52 if c.sessionEngineEnabled() {
53 if err := c.SetGoalDurable(""); err != nil {
54 c.notice("goal: " + err.Error())
55 break
56 }
57 } else {
58 c.ClearGoal()
59 }
60 c.notice(i18n.M.GoalCleared)
61 case GoalCommandPause:
62 if !c.PauseGoal() {
63 c.notice(i18n.M.GoalNotRunning)
64 }
65 case GoalCommandResume:
66 if !c.ResumeGoal() {
67 c.notice(i18n.M.GoalNotPaused)
68 }
69 default:
70 goal := c.Goal()
71 if strings.TrimSpace(goal) == "" {
72 c.notice(i18n.M.GoalEmpty)
73 break
74 }
75 rt := c.GoalRuntime()
76 c.notice(fmt.Sprintf(i18n.M.GoalCurrentFmt, goal))
77 c.notice(fmt.Sprintf(i18n.M.GoalRuntimeFmt,
78 rt.TurnsUsed, rt.RequestsUsed, rt.TokensUsed,
79 GoalWorkDurationText(rt.WorkDurationMs)))
80 if rt.LastReason != "" {
81 c.noticeDetail(i18n.M.GoalRuntimeLastReason, rt.LastReason)
82 }
83 if rt.StopCause != "" {
84 c.notice(fmt.Sprintf(i18n.M.GoalPausedFmt, rt.StopCause))
85 }
86 }
87 return true
88 }
89
89 lines GO