-
Notifications
You must be signed in to change notification settings - Fork 1
feat(backend): wire Session Manager into the daemon (real tmux + gitworktree, stub Agent) #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
27fb82d
feat(backend): wire Session Manager into the daemon (real tmux + gitw…
harshitsinghbhandari c1b9e7e
chore(backend): name startSession's ctx param for forward use
harshitsinghbhandari 7b9a9f5
fix(backend): drain reaper + cdc poller when startSession fails
harshitsinghbhandari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Package wiring bridges *sqlite.Store to the engine's outbound ports. It | ||
| // embeds the store (so the SessionStore reads/writes and PRWriter.RecentCheckStatuses | ||
| // promote directly) and supplies the PR conversions plus the PRFacts read-model | ||
| // that drives the derived display status. | ||
| // | ||
| // The adapter lives in its own package so the daemon's composition root and any | ||
| // in-process integration tests (e.g. backend/internal/integration) can share the | ||
| // same bridge instead of redefining it. | ||
| package wiring | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/ports" | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/storage/sqlite" | ||
| ) | ||
|
|
||
| // Adapter wraps *sqlite.Store and implements ports.SessionStore + ports.PRWriter. | ||
| // The embedded *sqlite.Store promotes CreateSession / UpdateSession / GetSession | ||
| // / ListSessions / ListAllSessions and RecentCheckStatuses verbatim; the two | ||
| // methods defined here are the ones that need shape translation between the port | ||
| // types and the sqlite row types. | ||
| type Adapter struct{ *sqlite.Store } | ||
|
|
||
| var ( | ||
| _ ports.SessionStore = Adapter{} | ||
| _ ports.PRWriter = Adapter{} | ||
| ) | ||
|
|
||
| // PRFactsForSession picks the PR that drives display status — the most-recently | ||
| // updated non-closed PR, else the most recent — and folds in whether it has | ||
| // unresolved review comments. | ||
| func (a Adapter) PRFactsForSession(ctx context.Context, id domain.SessionID) (domain.PRFacts, error) { | ||
| rows, err := a.Store.ListPRsBySession(ctx, string(id)) // newest first | ||
| if err != nil { | ||
| return domain.PRFacts{}, err | ||
| } | ||
| if len(rows) == 0 { | ||
| return domain.PRFacts{}, nil | ||
| } | ||
| pick := rows[0] | ||
| for _, r := range rows { | ||
| if r.State == "draft" || r.State == "open" { | ||
| pick = r | ||
| break | ||
| } | ||
| } | ||
| facts := domain.PRFacts{ | ||
| URL: pick.URL, Number: int(pick.Number), Exists: true, | ||
| Draft: pick.State == "draft", Merged: pick.State == "merged", Closed: pick.State == "closed", | ||
| CI: domain.CIState(pick.CIState), | ||
| Review: domain.ReviewDecision(pick.ReviewDecision), | ||
| Mergeability: domain.Mergeability(pick.Mergeability), | ||
| } | ||
| comments, err := a.Store.ListPRComments(ctx, pick.URL) | ||
| if err != nil { | ||
| return domain.PRFacts{}, err | ||
| } | ||
| for _, c := range comments { | ||
| if !c.Resolved { | ||
| facts.ReviewComments = true | ||
| break | ||
| } | ||
| } | ||
| return facts, nil | ||
| } | ||
|
|
||
| func (a Adapter) WritePR(ctx context.Context, pr ports.PRRow, checks []ports.PRCheckRow, comments []ports.PRComment) error { | ||
| row := sqlite.PRRow{ | ||
| URL: pr.URL, SessionID: pr.SessionID, Number: int64(pr.Number), | ||
| State: prState(pr), | ||
| ReviewDecision: string(pr.Review), | ||
| CIState: string(pr.CI), | ||
| Mergeability: string(pr.Mergeability), | ||
| UpdatedAt: pr.UpdatedAt, | ||
| } | ||
| checkRows := make([]sqlite.PRCheckRow, len(checks)) | ||
| for i, c := range checks { | ||
| checkRows[i] = sqlite.PRCheckRow{ | ||
| PRURL: c.PRURL, Name: c.Name, CommitHash: c.CommitHash, | ||
| Status: c.Status, URL: c.URL, LogTail: c.LogTail, CreatedAt: c.CreatedAt, | ||
| } | ||
| } | ||
| commentRows := make([]sqlite.PRCommentRow, len(comments)) | ||
| for i, c := range comments { | ||
| commentRows[i] = sqlite.PRCommentRow{ | ||
| PRURL: pr.URL, CommentID: c.ID, Author: c.Author, File: c.File, | ||
| Line: int64(c.Line), Body: c.Body, Resolved: c.Resolved, CreatedAt: c.CreatedAt, | ||
| } | ||
| } | ||
| return a.Store.WritePRObservation(ctx, row, checkRows, commentRows) | ||
| } | ||
|
|
||
| // prState collapses the PR's bools into the single pr.state column value. | ||
| func prState(r ports.PRRow) string { | ||
| switch { | ||
| case r.Merged: | ||
| return "merged" | ||
| case r.Closed: | ||
| return "closed" | ||
| case r.Draft: | ||
| return "draft" | ||
| default: | ||
| return "open" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.