Skip to content

Commit deddcd0

Browse files
committed
refactor: move session status assembly to service (#62)
1 parent c8f6050 commit deddcd0

17 files changed

Lines changed: 912 additions & 179 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Rewrite of the agent-orchestrator: a long-running Go backend daemon (`backend/`)
44
paired with a placeholder Electron + TypeScript frontend shell (`frontend/`).
55

66
See [`docs/`](docs/README.md) for architecture and status — start with the
7-
Lifecycle Manager + Session Manager lane in [`docs/architecture.md`](docs/architecture.md).
7+
Lifecycle Manager + Session Service lane in [`docs/architecture.md`](docs/architecture.md).
88

99
## Backend daemon
1010

backend/internal/domain/status.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,3 @@ const (
1919
StatusIdle SessionStatus = "idle"
2020
StatusTerminated SessionStatus = "terminated"
2121
)
22-
23-
// DeriveStatus is the ONLY producer of display status. It is a pure function of
24-
// persisted session facts and PR facts: is_terminated, activity_state, and the PR
25-
// table are the durable facts that tell the UI what it needs to know.
26-
func DeriveStatus(rec SessionRecord, pr *PRFacts) SessionStatus {
27-
if rec.IsTerminated {
28-
if pr != nil && pr.Merged {
29-
return StatusMerged
30-
}
31-
return StatusTerminated
32-
}
33-
34-
if rec.Activity.State == ActivityWaitingInput {
35-
return StatusNeedsInput
36-
}
37-
38-
if pr != nil {
39-
if pr.Merged {
40-
return StatusMerged
41-
}
42-
if !pr.Closed {
43-
return prPipelineStatus(*pr)
44-
}
45-
}
46-
47-
if rec.Activity.State == ActivityActive {
48-
return StatusWorking
49-
}
50-
return StatusIdle
51-
}
52-
53-
func prPipelineStatus(pr PRFacts) SessionStatus {
54-
switch {
55-
case pr.CI == CIFailing:
56-
return StatusCIFailed
57-
case pr.Draft:
58-
return StatusDraft
59-
case pr.Review == ReviewChangesRequest || pr.ReviewComments:
60-
return StatusChangesRequested
61-
case pr.Mergeability == MergeMergeable:
62-
return StatusMergeable
63-
case pr.Review == ReviewApproved:
64-
return StatusApproved
65-
case pr.Review == ReviewRequired:
66-
return StatusReviewPending
67-
default:
68-
return StatusPROpen
69-
}
70-
}

backend/internal/domain/status_test.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

backend/internal/httpd/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ import (
1919
// registered but returns the OpenAPI-backed 501 response.
2020
type APIDeps struct {
2121
Projects project.Manager
22+
Sessions controllers.SessionService
2223
}
2324

2425
// API owns one controller per resource and is the single Register call the
2526
// router invokes to mount the /api/v1 surface.
2627
type API struct {
2728
cfg config.Config
2829
projects *controllers.ProjectsController
30+
sessions *controllers.SessionsController
2931
}
3032

3133
// NewAPI constructs the API surface from its dependencies. cfg carries the
@@ -37,6 +39,9 @@ func NewAPI(cfg config.Config, deps APIDeps) *API {
3739
projects: &controllers.ProjectsController{
3840
Mgr: deps.Projects,
3941
},
42+
sessions: &controllers.SessionsController{
43+
Svc: deps.Sessions,
44+
},
4045
}
4146
}
4247

@@ -55,6 +60,7 @@ func (a *API) Register(root chi.Router) {
5560
r.Group(func(r chi.Router) {
5661
r.Use(middleware.Timeout(timeout))
5762
a.projects.Register(r)
63+
a.sessions.Register(r)
5864
// Sibling REST controllers plug in here.
5965
})
6066
// Surfaces that intentionally bypass the REST timeout register at this level.

0 commit comments

Comments
 (0)