Add /refocus and /ontask routes and carry allowed classes

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 17:18:25 -04:00
parent 4e7676560d
commit 6ca796dee3
2 changed files with 46 additions and 4 deletions
+15 -4
View File
@@ -50,6 +50,8 @@ func (s *Server) Router() *gin.Engine {
r.POST("/commitment", s.handleCommitment)
r.POST("/complete", s.handleComplete)
r.POST("/end", s.handleEnd)
r.POST("/refocus", s.handleRefocus)
r.POST("/ontask", s.handleOnTask)
return r
}
@@ -97,9 +99,10 @@ func (s *Server) handleCoach(c *gin.Context) {
}
type commitmentRequest struct {
NextAction string `json:"next_action"`
SuccessCondition string `json:"success_condition"`
TimeboxSecs int64 `json:"timebox_secs"`
NextAction string `json:"next_action"`
SuccessCondition string `json:"success_condition"`
TimeboxSecs int64 `json:"timebox_secs"`
AllowedWindowClasses []string `json:"allowed_window_classes"`
}
func (s *Server) handleCommitment(c *gin.Context) {
@@ -108,7 +111,7 @@ func (s *Server) handleCommitment(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid json"})
return
}
err := s.ctrl.StartManualCommitment(req.NextAction, req.SuccessCondition, time.Duration(req.TimeboxSecs)*time.Second, nil)
err := s.ctrl.StartManualCommitment(req.NextAction, req.SuccessCondition, time.Duration(req.TimeboxSecs)*time.Second, req.AllowedWindowClasses)
if err == nil {
s.armExpiry()
}
@@ -124,6 +127,14 @@ func (s *Server) handleEnd(c *gin.Context) {
s.respond(c, s.ctrl.End())
}
func (s *Server) handleRefocus(c *gin.Context) {
s.respond(c, s.ctrl.Refocus())
}
func (s *Server) handleOnTask(c *gin.Context) {
s.respond(c, s.ctrl.OnTask())
}
func (s *Server) handleEvents(c *gin.Context) {
c.Header("Content-Type", "text/event-stream")
c.Header("Cache-Control", "no-cache")