mirror of
https://github.com/cheikh2shift/godex.git
synced 2026-10-19 01:29:53 -05:00
Add /schedule-clear command and enhance scheduler status handling
This commit is contained in:
1 parent
6829203b9d
commit
5b771b1b52
4 files changed
+65
-14
No files matched your search
+9
-1
@@ -63,7 +63,7 @@ type MCPServer interface {
|
||||
Close() error
|
||||
}
|
||||
|
||||
var slashCommands = []string{"/add-path ", "/remove-path ", "/paths", "/tools", "/clear-context", "/commit ", "/commit-pull ", "/commit-merge ", "/commit-search ", "/exit", "/quit", "/q", "/save", "/save-exit", "/kill ", "/killbg", "/bg", "/clear", "/help", "/model", "/model-persist", "/schedule"}
|
||||
var slashCommands = []string{"/add-path ", "/remove-path ", "/paths", "/tools", "/clear-context", "/commit ", "/commit-pull ", "/commit-merge ", "/commit-search ", "/exit", "/quit", "/q", "/save", "/save-exit", "/kill ", "/killbg", "/bg", "/clear", "/help", "/model", "/model-persist", "/schedule", "/schedule-clear"}
|
||||
|
||||
var (
|
||||
greenOrb = lipgloss.NewStyle().Foreground(lipgloss.Color("82")).Render("●")
|
||||
@@ -334,6 +334,10 @@ func main() {
|
||||
if err != nil {
|
||||
log.Printf("[Scheduler] Failed to initialize: %v", err)
|
||||
} else {
|
||||
sched.SetStatusChannel(statusCh)
|
||||
if debugMode {
|
||||
fmt.Println(muted.Render("[Scheduler] Initialized with statusCh"))
|
||||
}
|
||||
sched.SetOnTaskFinished(func(*scheduler.ScheduledTask) {
|
||||
playSound()
|
||||
})
|
||||
@@ -897,6 +901,10 @@ promptLoop:
|
||||
}
|
||||
continue
|
||||
}
|
||||
if input == "/schedule-clear" {
|
||||
handleSchedule("/schedule clear")
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(input, "/schedule") {
|
||||
handleSchedule(input)
|
||||
continue
|
||||
|
||||
+37
-8
@@ -257,6 +257,12 @@ func (m promptModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.applyStatusMessage(msg)
|
||||
return m, waitStatusCmd(m.statusCh)
|
||||
}
|
||||
if _, ok := msg.(statusMsgPoll); ok {
|
||||
return m, waitStatusCmd(m.statusCh)
|
||||
}
|
||||
if _, ok := msg.(delegateMsgPoll); ok {
|
||||
return m, waitDelegateCmd(m.delegateCh)
|
||||
}
|
||||
if msg, ok := msg.(delegateMsg); ok {
|
||||
m.delegateCount = msg.Count
|
||||
m.delegateLatest = msg.Latest
|
||||
@@ -935,27 +941,50 @@ func waitStatusCmd(ch <-chan string) tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
return func() tea.Msg {
|
||||
msg, ok := <-ch
|
||||
if !ok {
|
||||
return nil
|
||||
select {
|
||||
case msg, ok := <-ch:
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
//fmt.Printf("DEBUG waitStatusCmd received: %s\n", msg)
|
||||
return statusMsg(msg)
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
return statusMsgPoll{}
|
||||
}
|
||||
return statusMsg(msg)
|
||||
}
|
||||
}
|
||||
|
||||
type statusMsgPoll struct{}
|
||||
|
||||
func (statusMsgPoll) Init() {}
|
||||
func (p statusMsgPoll) Update(msg tea.Msg) (tea.Msg, tea.Cmd) {
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func waitDelegateCmd(ch <-chan hive.HiveStats) tea.Cmd {
|
||||
if ch == nil {
|
||||
return nil
|
||||
}
|
||||
return func() tea.Msg {
|
||||
msg, ok := <-ch
|
||||
if !ok {
|
||||
return nil
|
||||
select {
|
||||
case msg, ok := <-ch:
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return delegateMsg{Count: msg.DelegatedCount, Latest: msg.LatestCommand}
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
return delegateMsgPoll{}
|
||||
}
|
||||
return delegateMsg{Count: msg.DelegatedCount, Latest: msg.LatestCommand}
|
||||
}
|
||||
}
|
||||
|
||||
type delegateMsgPoll struct{}
|
||||
|
||||
func (delegateMsgPoll) Init() {}
|
||||
func (p delegateMsgPoll) Update(msg tea.Msg) (tea.Msg, tea.Cmd) {
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
type commitRow struct {
|
||||
primary string
|
||||
secondary string
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -51,6 +51,7 @@ type Scheduler struct {
|
||||
toolTimeout int
|
||||
wd string
|
||||
os string
|
||||
statusCh chan string
|
||||
}
|
||||
|
||||
type ProviderGetter interface {
|
||||
@@ -97,11 +98,12 @@ func New(dbPath string) (*Scheduler, error) {
|
||||
}
|
||||
|
||||
s := &Scheduler{
|
||||
db: db,
|
||||
tasks: make(map[string]*ScheduledTask),
|
||||
running: make(map[string]context.CancelFunc),
|
||||
stopCh: make(chan struct{}),
|
||||
wd: wd,
|
||||
db: db,
|
||||
tasks: make(map[string]*ScheduledTask),
|
||||
running: make(map[string]context.CancelFunc),
|
||||
stopCh: make(chan struct{}),
|
||||
wd: wd,
|
||||
statusCh: make(chan string, 8),
|
||||
}
|
||||
|
||||
if err := s.initSchema(); err != nil {
|
||||
@@ -133,6 +135,10 @@ func NewDefault() (*Scheduler, error) {
|
||||
return New("")
|
||||
}
|
||||
|
||||
func (s *Scheduler) SetStatusChannel(ch chan string) {
|
||||
s.statusCh = ch
|
||||
}
|
||||
|
||||
func (s *Scheduler) initSchema() error {
|
||||
schema := `
|
||||
CREATE TABLE IF NOT EXISTS scheduled_tasks (
|
||||
@@ -579,6 +585,14 @@ func (s *Scheduler) executeWithTools(ctx context.Context, task *ScheduledTask) (
|
||||
}
|
||||
seenThisRound[sig] = true
|
||||
|
||||
if s.statusCh != nil {
|
||||
select {
|
||||
case s.statusCh <- fmt.Sprintf("[%s] Calling tool: %s", task.ID, toolName):
|
||||
//fmt.Printf("DEBUG: Sent status: [%s] Calling tool: %s\n", task.ID, toolName)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
result, err := s.callTool(ctx, toolName, args, toolTimeout)
|
||||
if err != nil {
|
||||
toolResults = append(toolResults, fmt.Sprintf("ERROR: %v", err))
|
||||
|
||||
Reference in new issue
Block a user