You've already forked agentic-coding-workflow
348 lines
8.8 KiB
Go
348 lines
8.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: sessions.sql
|
|
|
|
package acpsqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const acquireMainWorktree = `-- name: AcquireMainWorktree :execrows
|
|
UPDATE workspaces SET active_main_session_id = $1
|
|
WHERE id = $2 AND active_main_session_id IS NULL
|
|
`
|
|
|
|
type AcquireMainWorktreeParams struct {
|
|
ActiveMainSessionID pgtype.UUID `json:"active_main_session_id"`
|
|
ID pgtype.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) AcquireMainWorktree(ctx context.Context, arg AcquireMainWorktreeParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, acquireMainWorktree, arg.ActiveMainSessionID, arg.ID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const countActiveSessions = `-- name: CountActiveSessions :one
|
|
SELECT COUNT(*) FROM acp_sessions WHERE status IN ('starting', 'running')
|
|
`
|
|
|
|
func (q *Queries) CountActiveSessions(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countActiveSessions)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countActiveSessionsByUser = `-- name: CountActiveSessionsByUser :one
|
|
SELECT COUNT(*) FROM acp_sessions
|
|
WHERE user_id = $1 AND status IN ('starting', 'running')
|
|
`
|
|
|
|
func (q *Queries) CountActiveSessionsByUser(ctx context.Context, userID pgtype.UUID) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countActiveSessionsByUser, userID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const getSessionByID = `-- name: GetSessionByID :one
|
|
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
|
issue_id, requirement_id, agent_session_id,
|
|
branch, cwd_path, is_main_worktree, status,
|
|
pid, exit_code, last_error, started_at, ended_at
|
|
FROM acp_sessions
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetSessionByID(ctx context.Context, id pgtype.UUID) (AcpSession, error) {
|
|
row := q.db.QueryRow(ctx, getSessionByID, id)
|
|
var i AcpSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.ProjectID,
|
|
&i.AgentKindID,
|
|
&i.UserID,
|
|
&i.IssueID,
|
|
&i.RequirementID,
|
|
&i.AgentSessionID,
|
|
&i.Branch,
|
|
&i.CwdPath,
|
|
&i.IsMainWorktree,
|
|
&i.Status,
|
|
&i.Pid,
|
|
&i.ExitCode,
|
|
&i.LastError,
|
|
&i.StartedAt,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertSession = `-- name: InsertSession :one
|
|
INSERT INTO acp_sessions (
|
|
id, workspace_id, project_id, agent_kind_id, user_id,
|
|
issue_id, requirement_id, branch, cwd_path, is_main_worktree, status
|
|
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
|
RETURNING id, workspace_id, project_id, agent_kind_id, user_id,
|
|
issue_id, requirement_id, agent_session_id,
|
|
branch, cwd_path, is_main_worktree, status,
|
|
pid, exit_code, last_error, started_at, ended_at
|
|
`
|
|
|
|
type InsertSessionParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
ProjectID pgtype.UUID `json:"project_id"`
|
|
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
IssueID pgtype.UUID `json:"issue_id"`
|
|
RequirementID pgtype.UUID `json:"requirement_id"`
|
|
Branch string `json:"branch"`
|
|
CwdPath string `json:"cwd_path"`
|
|
IsMainWorktree bool `json:"is_main_worktree"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) (AcpSession, error) {
|
|
row := q.db.QueryRow(ctx, insertSession,
|
|
arg.ID,
|
|
arg.WorkspaceID,
|
|
arg.ProjectID,
|
|
arg.AgentKindID,
|
|
arg.UserID,
|
|
arg.IssueID,
|
|
arg.RequirementID,
|
|
arg.Branch,
|
|
arg.CwdPath,
|
|
arg.IsMainWorktree,
|
|
arg.Status,
|
|
)
|
|
var i AcpSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.ProjectID,
|
|
&i.AgentKindID,
|
|
&i.UserID,
|
|
&i.IssueID,
|
|
&i.RequirementID,
|
|
&i.AgentSessionID,
|
|
&i.Branch,
|
|
&i.CwdPath,
|
|
&i.IsMainWorktree,
|
|
&i.Status,
|
|
&i.Pid,
|
|
&i.ExitCode,
|
|
&i.LastError,
|
|
&i.StartedAt,
|
|
&i.EndedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listAllSessions = `-- name: ListAllSessions :many
|
|
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
|
issue_id, requirement_id, agent_session_id,
|
|
branch, cwd_path, is_main_worktree, status,
|
|
pid, exit_code, last_error, started_at, ended_at
|
|
FROM acp_sessions
|
|
ORDER BY started_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListAllSessions(ctx context.Context) ([]AcpSession, error) {
|
|
rows, err := q.db.Query(ctx, listAllSessions)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AcpSession
|
|
for rows.Next() {
|
|
var i AcpSession
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.ProjectID,
|
|
&i.AgentKindID,
|
|
&i.UserID,
|
|
&i.IssueID,
|
|
&i.RequirementID,
|
|
&i.AgentSessionID,
|
|
&i.Branch,
|
|
&i.CwdPath,
|
|
&i.IsMainWorktree,
|
|
&i.Status,
|
|
&i.Pid,
|
|
&i.ExitCode,
|
|
&i.LastError,
|
|
&i.StartedAt,
|
|
&i.EndedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listSessionsByUser = `-- name: ListSessionsByUser :many
|
|
SELECT id, workspace_id, project_id, agent_kind_id, user_id,
|
|
issue_id, requirement_id, agent_session_id,
|
|
branch, cwd_path, is_main_worktree, status,
|
|
pid, exit_code, last_error, started_at, ended_at
|
|
FROM acp_sessions
|
|
WHERE user_id = $1
|
|
ORDER BY started_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListSessionsByUser(ctx context.Context, userID pgtype.UUID) ([]AcpSession, error) {
|
|
rows, err := q.db.Query(ctx, listSessionsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AcpSession
|
|
for rows.Next() {
|
|
var i AcpSession
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.ProjectID,
|
|
&i.AgentKindID,
|
|
&i.UserID,
|
|
&i.IssueID,
|
|
&i.RequirementID,
|
|
&i.AgentSessionID,
|
|
&i.Branch,
|
|
&i.CwdPath,
|
|
&i.IsMainWorktree,
|
|
&i.Status,
|
|
&i.Pid,
|
|
&i.ExitCode,
|
|
&i.LastError,
|
|
&i.StartedAt,
|
|
&i.EndedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const releaseMainWorktree = `-- name: ReleaseMainWorktree :execrows
|
|
UPDATE workspaces SET active_main_session_id = NULL
|
|
WHERE id = $1 AND active_main_session_id = $2
|
|
`
|
|
|
|
type ReleaseMainWorktreeParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
ActiveMainSessionID pgtype.UUID `json:"active_main_session_id"`
|
|
}
|
|
|
|
func (q *Queries) ReleaseMainWorktree(ctx context.Context, arg ReleaseMainWorktreeParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, releaseMainWorktree, arg.ID, arg.ActiveMainSessionID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const resetStuckSessionsOnRestart = `-- name: ResetStuckSessionsOnRestart :many
|
|
UPDATE acp_sessions
|
|
SET status = 'crashed',
|
|
last_error = 'process_aborted_on_restart',
|
|
ended_at = now()
|
|
WHERE status IN ('starting', 'running')
|
|
RETURNING id, workspace_id, user_id, branch, agent_kind_id, is_main_worktree
|
|
`
|
|
|
|
type ResetStuckSessionsOnRestartRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
Branch string `json:"branch"`
|
|
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
|
IsMainWorktree bool `json:"is_main_worktree"`
|
|
}
|
|
|
|
func (q *Queries) ResetStuckSessionsOnRestart(ctx context.Context) ([]ResetStuckSessionsOnRestartRow, error) {
|
|
rows, err := q.db.Query(ctx, resetStuckSessionsOnRestart)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ResetStuckSessionsOnRestartRow
|
|
for rows.Next() {
|
|
var i ResetStuckSessionsOnRestartRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.WorkspaceID,
|
|
&i.UserID,
|
|
&i.Branch,
|
|
&i.AgentKindID,
|
|
&i.IsMainWorktree,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateSessionFinished = `-- name: UpdateSessionFinished :exec
|
|
UPDATE acp_sessions
|
|
SET status = $2, exit_code = $3, last_error = $4, ended_at = now()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateSessionFinishedParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Status string `json:"status"`
|
|
ExitCode *int32 `json:"exit_code"`
|
|
LastError *string `json:"last_error"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSessionFinished(ctx context.Context, arg UpdateSessionFinishedParams) error {
|
|
_, err := q.db.Exec(ctx, updateSessionFinished,
|
|
arg.ID,
|
|
arg.Status,
|
|
arg.ExitCode,
|
|
arg.LastError,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateSessionRunning = `-- name: UpdateSessionRunning :exec
|
|
UPDATE acp_sessions
|
|
SET status = 'running', agent_session_id = $2, pid = $3
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateSessionRunningParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
AgentSessionID *string `json:"agent_session_id"`
|
|
Pid *int32 `json:"pid"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSessionRunning(ctx context.Context, arg UpdateSessionRunningParams) error {
|
|
_, err := q.db.Exec(ctx, updateSessionRunning, arg.ID, arg.AgentSessionID, arg.Pid)
|
|
return err
|
|
}
|