You've already forked agentic-coding-workflow
bugfix
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// Package docs generates commit / PR markdown summaries on commit. A background
|
||||
// job (SummaryRunner) gathers the diffstat + log for a commit, prompts an LLM to
|
||||
// produce markdown, and upserts a commit_summaries row. Enqueued post-commit via
|
||||
// EnqueueCommitSummary (injected as a callback into gitops to avoid import cycles).
|
||||
package docs
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/jobs"
|
||||
)
|
||||
|
||||
// JobTypeCommitSummary is the jobs.JobType for an event-driven commit summary.
|
||||
const JobTypeCommitSummary jobs.JobType = "docs.commit_summary"
|
||||
|
||||
// Summary kind values mirror the commit_summaries.kind CHECK constraint.
|
||||
const (
|
||||
KindCommit = "commit"
|
||||
KindPR = "pr"
|
||||
)
|
||||
|
||||
// Status values mirror the commit_summaries.status CHECK constraint.
|
||||
const (
|
||||
StatusPending = "pending"
|
||||
StatusCompleted = "completed"
|
||||
StatusFailed = "failed"
|
||||
)
|
||||
|
||||
// Summary mirrors a commit_summaries row.
|
||||
type Summary struct {
|
||||
ID uuid.UUID
|
||||
WorkspaceID uuid.UUID
|
||||
WorktreeID *uuid.UUID
|
||||
Branch string
|
||||
CommitSHA string
|
||||
Kind string
|
||||
Title *string
|
||||
BodyMD string
|
||||
Model *string
|
||||
Status string
|
||||
Error *string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// summaryPayload is the jobs payload for JobTypeCommitSummary.
|
||||
type summaryPayload struct {
|
||||
WorkspaceID uuid.UUID `json:"workspace_id"`
|
||||
WorktreeID *uuid.UUID `json:"worktree_id,omitempty"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSHA string `json:"commit_sha"`
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
-- name: UpsertSummary :one
|
||||
INSERT INTO commit_summaries (
|
||||
id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
ON CONFLICT (workspace_id, commit_sha, kind) DO UPDATE
|
||||
SET title = EXCLUDED.title,
|
||||
body_md = EXCLUDED.body_md,
|
||||
model = EXCLUDED.model,
|
||||
status = EXCLUDED.status,
|
||||
error = EXCLUDED.error,
|
||||
branch = EXCLUDED.branch,
|
||||
worktree_id = EXCLUDED.worktree_id
|
||||
RETURNING id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error, created_at;
|
||||
|
||||
-- name: GetSummary :one
|
||||
SELECT id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error, created_at
|
||||
FROM commit_summaries
|
||||
WHERE workspace_id = $1 AND commit_sha = $2 AND kind = $3;
|
||||
|
||||
-- name: InsertPendingSummary :one
|
||||
INSERT INTO commit_summaries (
|
||||
id, workspace_id, worktree_id, branch, commit_sha, kind, body_md, status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, '', 'pending')
|
||||
ON CONFLICT (workspace_id, commit_sha, kind) DO NOTHING
|
||||
RETURNING id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error, created_at;
|
||||
@@ -0,0 +1,127 @@
|
||||
package docs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
docssqlc "github.com/yan1h/agent-coding-workflow/internal/docs/sqlc"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
)
|
||||
|
||||
// Repository is the docs persistence contract.
|
||||
type Repository interface {
|
||||
Get(ctx context.Context, wsID uuid.UUID, commitSHA, kind string) (*Summary, error)
|
||||
Upsert(ctx context.Context, in UpsertInput) (*Summary, error)
|
||||
}
|
||||
|
||||
// UpsertInput carries the fields for a commit_summaries upsert.
|
||||
type UpsertInput struct {
|
||||
WorkspaceID uuid.UUID
|
||||
WorktreeID *uuid.UUID
|
||||
Branch string
|
||||
CommitSHA string
|
||||
Kind string
|
||||
Title *string
|
||||
BodyMD string
|
||||
Model *string
|
||||
Status string
|
||||
Error *string
|
||||
}
|
||||
|
||||
// PgRepository is the production Repository on a pgxpool.Pool.
|
||||
type PgRepository struct {
|
||||
pool *pgxpool.Pool
|
||||
q *docssqlc.Queries
|
||||
}
|
||||
|
||||
// NewPostgresRepository builds a PgRepository.
|
||||
func NewPostgresRepository(pool *pgxpool.Pool) *PgRepository {
|
||||
return &PgRepository{pool: pool, q: docssqlc.New(pool)}
|
||||
}
|
||||
|
||||
var _ Repository = (*PgRepository)(nil)
|
||||
|
||||
func pgUUID(u uuid.UUID) pgtype.UUID { return pgtype.UUID{Bytes: u, Valid: true} }
|
||||
|
||||
func pgUUIDPtr(u *uuid.UUID) pgtype.UUID {
|
||||
if u == nil {
|
||||
return pgtype.UUID{}
|
||||
}
|
||||
return pgtype.UUID{Bytes: *u, Valid: true}
|
||||
}
|
||||
|
||||
func uuidPtr(p pgtype.UUID) *uuid.UUID {
|
||||
if !p.Valid {
|
||||
return nil
|
||||
}
|
||||
id := uuid.UUID(p.Bytes)
|
||||
return &id
|
||||
}
|
||||
|
||||
func summaryFromRow(r docssqlc.CommitSummary) *Summary {
|
||||
s := &Summary{
|
||||
ID: uuid.UUID(r.ID.Bytes),
|
||||
WorkspaceID: uuid.UUID(r.WorkspaceID.Bytes),
|
||||
WorktreeID: uuidPtr(r.WorktreeID),
|
||||
Branch: r.Branch,
|
||||
CommitSHA: r.CommitSha,
|
||||
Kind: r.Kind,
|
||||
Title: r.Title,
|
||||
BodyMD: r.BodyMd,
|
||||
Model: r.Model,
|
||||
Status: r.Status,
|
||||
Error: r.Error,
|
||||
}
|
||||
if r.CreatedAt.Valid {
|
||||
s.CreatedAt = r.CreatedAt.Time
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (r *PgRepository) Get(ctx context.Context, wsID uuid.UUID, commitSHA, kind string) (*Summary, error) {
|
||||
row, err := r.q.GetSummary(ctx, docssqlc.GetSummaryParams{
|
||||
WorkspaceID: pgUUID(wsID),
|
||||
CommitSha: commitSHA,
|
||||
Kind: kind,
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "get commit summary")
|
||||
}
|
||||
return summaryFromRow(row), nil
|
||||
}
|
||||
|
||||
func (r *PgRepository) Upsert(ctx context.Context, in UpsertInput) (*Summary, error) {
|
||||
kind := in.Kind
|
||||
if kind == "" {
|
||||
kind = KindCommit
|
||||
}
|
||||
status := in.Status
|
||||
if status == "" {
|
||||
status = StatusCompleted
|
||||
}
|
||||
row, err := r.q.UpsertSummary(ctx, docssqlc.UpsertSummaryParams{
|
||||
ID: pgUUID(uuid.New()),
|
||||
WorkspaceID: pgUUID(in.WorkspaceID),
|
||||
WorktreeID: pgUUIDPtr(in.WorktreeID),
|
||||
Branch: in.Branch,
|
||||
CommitSha: in.CommitSHA,
|
||||
Kind: kind,
|
||||
Title: in.Title,
|
||||
BodyMd: in.BodyMD,
|
||||
Model: in.Model,
|
||||
Status: status,
|
||||
Error: in.Error,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInternal, "upsert commit summary")
|
||||
}
|
||||
return summaryFromRow(row), nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package docs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/errs"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/jobs"
|
||||
)
|
||||
|
||||
// Enqueuer is the subset of jobs.Repository the service needs.
|
||||
type Enqueuer interface {
|
||||
Enqueue(ctx context.Context, typ jobs.JobType, payload json.RawMessage, scheduledAt time.Time, maxAttempts int32) (*jobs.Job, error)
|
||||
}
|
||||
|
||||
// Service is the docs application service.
|
||||
type Service interface {
|
||||
// EnqueueCommitSummary enqueues a docs.commit_summary job for the given
|
||||
// commit. Idempotent at the data layer via UNIQUE(workspace, commit, kind).
|
||||
EnqueueCommitSummary(ctx context.Context, wsID uuid.UUID, worktreeID *uuid.UUID, branch, commitSHA string) error
|
||||
}
|
||||
|
||||
type service struct {
|
||||
jobs Enqueuer
|
||||
enabled bool
|
||||
}
|
||||
|
||||
// NewService constructs the docs Service. When enabled is false, EnqueueCommitSummary
|
||||
// is a no-op so the commit path stays free of doc-gen overhead.
|
||||
func NewService(jobsRepo Enqueuer, enabled bool) Service {
|
||||
return &service{jobs: jobsRepo, enabled: enabled}
|
||||
}
|
||||
|
||||
func (s *service) EnqueueCommitSummary(ctx context.Context, wsID uuid.UUID, worktreeID *uuid.UUID, branch, commitSHA string) error {
|
||||
if !s.enabled {
|
||||
return nil
|
||||
}
|
||||
if commitSHA == "" {
|
||||
return errs.New(errs.CodeInvalidInput, "commit_sha required")
|
||||
}
|
||||
payload, _ := json.Marshal(summaryPayload{
|
||||
WorkspaceID: wsID,
|
||||
WorktreeID: worktreeID,
|
||||
Branch: branch,
|
||||
CommitSHA: commitSHA,
|
||||
})
|
||||
if _, err := s.jobs.Enqueue(ctx, JobTypeCommitSummary, payload, time.Now(), 3); err != nil {
|
||||
return errs.Wrap(err, errs.CodeInternal, "enqueue docs.commit_summary")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package docs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/jobs"
|
||||
)
|
||||
|
||||
type fakeEnqueuer struct {
|
||||
count int
|
||||
lastType jobs.JobType
|
||||
}
|
||||
|
||||
func (f *fakeEnqueuer) Enqueue(_ context.Context, typ jobs.JobType, _ json.RawMessage, _ time.Time, _ int32) (*jobs.Job, error) {
|
||||
f.count++
|
||||
f.lastType = typ
|
||||
return &jobs.Job{ID: uuid.New(), Type: typ}, nil
|
||||
}
|
||||
|
||||
func TestService_EnqueueCommitSummary_Enabled(t *testing.T) {
|
||||
enq := &fakeEnqueuer{}
|
||||
svc := NewService(enq, true)
|
||||
require.NoError(t, svc.EnqueueCommitSummary(context.Background(), uuid.New(), nil, "main", "abc"))
|
||||
require.Equal(t, 1, enq.count)
|
||||
require.Equal(t, JobTypeCommitSummary, enq.lastType)
|
||||
}
|
||||
|
||||
func TestService_EnqueueCommitSummary_Disabled(t *testing.T) {
|
||||
enq := &fakeEnqueuer{}
|
||||
svc := NewService(enq, false)
|
||||
require.NoError(t, svc.EnqueueCommitSummary(context.Background(), uuid.New(), nil, "main", "abc"))
|
||||
require.Equal(t, 0, enq.count, "disabled: no enqueue")
|
||||
}
|
||||
|
||||
func TestService_EnqueueCommitSummary_RequiresSHA(t *testing.T) {
|
||||
svc := NewService(&fakeEnqueuer{}, true)
|
||||
require.Error(t, svc.EnqueueCommitSummary(context.Background(), uuid.New(), nil, "main", ""))
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package docssqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,593 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package docssqlc
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pgvector/pgvector-go"
|
||||
)
|
||||
|
||||
type AcpAgentKind struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
BinaryPath string `json:"binary_path"`
|
||||
Args []string `json:"args"`
|
||||
EncryptedEnv []byte `json:"encrypted_env"`
|
||||
Enabled bool `json:"enabled"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ToolAllowlist []string `json:"tool_allowlist"`
|
||||
ClientType string `json:"client_type"`
|
||||
EncryptedMcpServers []byte `json:"encrypted_mcp_servers"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
MaxCostUsd pgtype.Numeric `json:"max_cost_usd"`
|
||||
MaxTokens *int64 `json:"max_tokens"`
|
||||
MaxWallClockSeconds *int32 `json:"max_wall_clock_seconds"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type AcpAgentKindConfigFile struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
RelPath string `json:"rel_path"`
|
||||
EncryptedContent []byte `json:"encrypted_content"`
|
||||
UpdatedBy pgtype.UUID `json:"updated_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type AcpEvent struct {
|
||||
ID int64 `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
Direction string `json:"direction"`
|
||||
RpcKind string `json:"rpc_kind"`
|
||||
Method *string `json:"method"`
|
||||
Payload []byte `json:"payload"`
|
||||
PayloadSize int32 `json:"payload_size"`
|
||||
Truncated bool `json:"truncated"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcpPermissionRequest struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
AgentRequestID string `json:"agent_request_id"`
|
||||
ToolName string `json:"tool_name"`
|
||||
ToolCall []byte `json:"tool_call"`
|
||||
Options []byte `json:"options"`
|
||||
Status string `json:"status"`
|
||||
ChosenOptionID *string `json:"chosen_option_id"`
|
||||
DecidedBy pgtype.UUID `json:"decided_by"`
|
||||
DecidedAt pgtype.Timestamptz `json:"decided_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcpSession 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"`
|
||||
AgentSessionID *string `json:"agent_session_id"`
|
||||
Branch string `json:"branch"`
|
||||
CwdPath string `json:"cwd_path"`
|
||||
IsMainWorktree bool `json:"is_main_worktree"`
|
||||
Status string `json:"status"`
|
||||
Pid *int32 `json:"pid"`
|
||||
ExitCode *int32 `json:"exit_code"`
|
||||
LastError *string `json:"last_error"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
EndedAt pgtype.Timestamptz `json:"ended_at"`
|
||||
LastStopReason *string `json:"last_stop_reason"`
|
||||
OrchestratorStepID pgtype.UUID `json:"orchestrator_step_id"`
|
||||
PromptTokens int64 `json:"prompt_tokens"`
|
||||
CompletionTokens int64 `json:"completion_tokens"`
|
||||
ThinkingTokens int64 `json:"thinking_tokens"`
|
||||
TotalCostUsd pgtype.Numeric `json:"total_cost_usd"`
|
||||
LastActivityAt pgtype.Timestamptz `json:"last_activity_at"`
|
||||
BudgetMaxCostUsd pgtype.Numeric `json:"budget_max_cost_usd"`
|
||||
BudgetMaxTokens *int64 `json:"budget_max_tokens"`
|
||||
BudgetMaxWallClockSeconds *int32 `json:"budget_max_wall_clock_seconds"`
|
||||
TerminatedReason *string `json:"terminated_reason"`
|
||||
SandboxMode *string `json:"sandbox_mode"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
TokensTotal int64 `json:"tokens_total"`
|
||||
}
|
||||
|
||||
type AcpSessionUsage struct {
|
||||
ID int64 `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
PromptTokens int64 `json:"prompt_tokens"`
|
||||
CompletionTokens int64 `json:"completion_tokens"`
|
||||
ThinkingTokens int64 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
SourceEventID *int64 `json:"source_event_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type AcpTurn struct {
|
||||
ID int64 `json:"id"`
|
||||
SessionID pgtype.UUID `json:"session_id"`
|
||||
TurnIndex int32 `json:"turn_index"`
|
||||
PromptRequestID *string `json:"prompt_request_id"`
|
||||
Status string `json:"status"`
|
||||
StopReason *string `json:"stop_reason"`
|
||||
UpdateCount int32 `json:"update_count"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
||||
}
|
||||
|
||||
type AuditLog struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Action string `json:"action"`
|
||||
TargetType *string `json:"target_type"`
|
||||
TargetID *string `json:"target_id"`
|
||||
Ip *netip.Addr `json:"ip"`
|
||||
Metadata []byte `json:"metadata"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type ChangeRequest struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
SourceBranch string `json:"source_branch"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
State string `json:"state"`
|
||||
ReviewVerdict string `json:"review_verdict"`
|
||||
CiState string `json:"ci_state"`
|
||||
Provider string `json:"provider"`
|
||||
ExternalID *int64 `json:"external_id"`
|
||||
ExternalUrl string `json:"external_url"`
|
||||
MergeCommitSha string `json:"merge_commit_sha"`
|
||||
ReviewedBy pgtype.UUID `json:"reviewed_by"`
|
||||
ReviewedAt pgtype.Timestamptz `json:"reviewed_at"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
MergedAt pgtype.Timestamptz `json:"merged_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type CodeChunk struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
RunID pgtype.UUID `json:"run_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
FilePath string `json:"file_path"`
|
||||
Lang *string `json:"lang"`
|
||||
StartLine int32 `json:"start_line"`
|
||||
EndLine int32 `json:"end_line"`
|
||||
Content string `json:"content"`
|
||||
ContentSha []byte `json:"content_sha"`
|
||||
TokenCount *int32 `json:"token_count"`
|
||||
Embedding *pgvector.Vector `json:"embedding"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type CodeIndexRun struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
WorktreeID pgtype.UUID `json:"worktree_id"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Status string `json:"status"`
|
||||
EmbeddingEndpointID pgtype.UUID `json:"embedding_endpoint_id"`
|
||||
EmbeddingModel string `json:"embedding_model"`
|
||||
Dims int32 `json:"dims"`
|
||||
FilesIndexed int32 `json:"files_indexed"`
|
||||
ChunksIndexed int32 `json:"chunks_indexed"`
|
||||
Error *string `json:"error"`
|
||||
StartedAt pgtype.Timestamptz `json:"started_at"`
|
||||
FinishedAt pgtype.Timestamptz `json:"finished_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type CommitSummary struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
WorktreeID pgtype.UUID `json:"worktree_id"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Kind string `json:"kind"`
|
||||
Title *string `json:"title"`
|
||||
BodyMd string `json:"body_md"`
|
||||
Model *string `json:"model"`
|
||||
Status string `json:"status"`
|
||||
Error *string `json:"error"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Conversation struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
IssueID pgtype.UUID `json:"issue_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
SystemPrompt string `json:"system_prompt"`
|
||||
Title *string `json:"title"`
|
||||
TitleGeneratedAt pgtype.Timestamptz `json:"title_generated_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
}
|
||||
|
||||
type CryptoKey struct {
|
||||
Version int32 `json:"version"`
|
||||
Provider string `json:"provider"`
|
||||
KeyRef *string `json:"key_ref"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type GitCredential struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Kind string `json:"kind"`
|
||||
Username *string `json:"username"`
|
||||
EncryptedSecret []byte `json:"encrypted_secret"`
|
||||
Fingerprint *string `json:"fingerprint"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status"`
|
||||
AssigneeID pgtype.UUID `json:"assignee_id"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
ClosedAt pgtype.Timestamptz `json:"closed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
ParentID pgtype.UUID `json:"parent_id"`
|
||||
Priority int32 `json:"priority"`
|
||||
}
|
||||
|
||||
type IssueDependency struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
BlockedID pgtype.UUID `json:"blocked_id"`
|
||||
BlockerID pgtype.UUID `json:"blocker_id"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Payload []byte `json:"payload"`
|
||||
Status string `json:"status"`
|
||||
ScheduledAt pgtype.Timestamptz `json:"scheduled_at"`
|
||||
Attempts int32 `json:"attempts"`
|
||||
MaxAttempts int32 `json:"max_attempts"`
|
||||
LeasedAt pgtype.Timestamptz `json:"leased_at"`
|
||||
LeasedBy *string `json:"leased_by"`
|
||||
LastError *string `json:"last_error"`
|
||||
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LlmEndpoint struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
DisplayName string `json:"display_name"`
|
||||
BaseUrl string `json:"base_url"`
|
||||
ApiKeyEncrypted []byte `json:"api_key_encrypted"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type LlmModel struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EndpointID pgtype.UUID `json:"endpoint_id"`
|
||||
ModelID string `json:"model_id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Capabilities []byte `json:"capabilities"`
|
||||
ContextWindow int32 `json:"context_window"`
|
||||
MaxOutputTokens int32 `json:"max_output_tokens"`
|
||||
PromptPricePerMillionUsd pgtype.Numeric `json:"prompt_price_per_million_usd"`
|
||||
CompletionPricePerMillionUsd pgtype.Numeric `json:"completion_price_per_million_usd"`
|
||||
ThinkingPricePerMillionUsd pgtype.Numeric `json:"thinking_price_per_million_usd"`
|
||||
IsTitleGenerator bool `json:"is_title_generator"`
|
||||
Enabled bool `json:"enabled"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type LlmUsage struct {
|
||||
ID int64 `json:"id"`
|
||||
ConversationID pgtype.UUID `json:"conversation_id"`
|
||||
MessageID int64 `json:"message_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EndpointID pgtype.UUID `json:"endpoint_id"`
|
||||
ModelID pgtype.UUID `json:"model_id"`
|
||||
PromptTokens int32 `json:"prompt_tokens"`
|
||||
CompletionTokens int32 `json:"completion_tokens"`
|
||||
ThinkingTokens int32 `json:"thinking_tokens"`
|
||||
CostUsd pgtype.Numeric `json:"cost_usd"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type McpToken struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
TokenHash []byte `json:"token_hash"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
Issuer string `json:"issuer"`
|
||||
Scope []byte `json:"scope"`
|
||||
AcpSessionID pgtype.UUID `json:"acp_session_id"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
|
||||
RevokedAt pgtype.Timestamptz `json:"revoked_at"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
ID int64 `json:"id"`
|
||||
ConversationID pgtype.UUID `json:"conversation_id"`
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
Thinking *string `json:"thinking"`
|
||||
ToolCalls []byte `json:"tool_calls"`
|
||||
Status string `json:"status"`
|
||||
ErrorMessage *string `json:"error_message"`
|
||||
PromptTokens *int32 `json:"prompt_tokens"`
|
||||
CompletionTokens *int32 `json:"completion_tokens"`
|
||||
ThinkingTokens *int32 `json:"thinking_tokens"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type MessageAttachment struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
MessageID *int64 `json:"message_id"`
|
||||
Filename string `json:"filename"`
|
||||
MimeType string `json:"mime_type"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
Sha256 string `json:"sha256"`
|
||||
StoragePath string `json:"storage_path"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Topic string `json:"topic"`
|
||||
Severity string `json:"severity"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Link *string `json:"link"`
|
||||
Metadata []byte `json:"metadata"`
|
||||
ReadAt pgtype.Timestamptz `json:"read_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type NotificationPref struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
EmailEnabled bool `json:"email_enabled"`
|
||||
ImEnabled bool `json:"im_enabled"`
|
||||
ImWebhookUrlEnc []byte `json:"im_webhook_url_enc"`
|
||||
MinSeverity string `json:"min_severity"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type OrchestratorRun struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Status string `json:"status"`
|
||||
CurrentPhase string `json:"current_phase"`
|
||||
Config []byte `json:"config"`
|
||||
LastError *string `json:"last_error"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
EndedAt pgtype.Timestamptz `json:"ended_at"`
|
||||
}
|
||||
|
||||
type OrchestratorStep struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
RunID pgtype.UUID `json:"run_id"`
|
||||
Phase string `json:"phase"`
|
||||
Attempt int32 `json:"attempt"`
|
||||
ParentStepID pgtype.UUID `json:"parent_step_id"`
|
||||
Depth int32 `json:"depth"`
|
||||
Status string `json:"status"`
|
||||
AgentKindID pgtype.UUID `json:"agent_kind_id"`
|
||||
AcpSessionID pgtype.UUID `json:"acp_session_id"`
|
||||
Prompt string `json:"prompt"`
|
||||
StopReason *string `json:"stop_reason"`
|
||||
GateResult []byte `json:"gate_result"`
|
||||
LastError *string `json:"last_error"`
|
||||
JobID pgtype.UUID `json:"job_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
EndedAt pgtype.Timestamptz `json:"ended_at"`
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Visibility string `json:"visibility"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
ArchivedAt pgtype.Timestamptz `json:"archived_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ProjectMember struct {
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
AddedBy pgtype.UUID `json:"added_by"`
|
||||
}
|
||||
|
||||
type ProjectMemory struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Kind string `json:"kind"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Tags []string `json:"tags"`
|
||||
Source string `json:"source"`
|
||||
Embedding *pgvector.Vector `json:"embedding"`
|
||||
EmbeddingModel *string `json:"embedding_model"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type PromptTemplate struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
Scope string `json:"scope"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Requirement struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Number int32 `json:"number"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Phase string `json:"phase"`
|
||||
Status string `json:"status"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
ClosedAt pgtype.Timestamptz `json:"closed_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
}
|
||||
|
||||
type RequirementArtifact struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
Phase string `json:"phase"`
|
||||
Version int32 `json:"version"`
|
||||
Content string `json:"content"`
|
||||
Note string `json:"note"`
|
||||
SourceMessageID *int64 `json:"source_message_id"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
Verdict string `json:"verdict"`
|
||||
}
|
||||
|
||||
type RequirementPhasePointer struct {
|
||||
RequirementID pgtype.UUID `json:"requirement_id"`
|
||||
Phase string `json:"phase"`
|
||||
ApprovedArtifactID pgtype.UUID `json:"approved_artifact_id"`
|
||||
ApprovedBy pgtype.UUID `json:"approved_by"`
|
||||
ApprovedAt pgtype.Timestamptz `json:"approved_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
DisplayName string `json:"display_name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type UserSession struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
TokenHash []byte `json:"token_hash"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
LastSeenAt pgtype.Timestamptz `json:"last_seen_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
GitRemoteUrl string `json:"git_remote_url"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
MainPath string `json:"main_path"`
|
||||
SyncStatus string `json:"sync_status"`
|
||||
LastSyncedAt pgtype.Timestamptz `json:"last_synced_at"`
|
||||
LastSyncError *string `json:"last_sync_error"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ActiveMainSessionID pgtype.UUID `json:"active_main_session_id"`
|
||||
}
|
||||
|
||||
type WorkspaceRunProfile struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Command string `json:"command"`
|
||||
Args []string `json:"args"`
|
||||
EncryptedEnv []byte `json:"encrypted_env"`
|
||||
Enabled bool `json:"enabled"`
|
||||
LastStartedAt pgtype.Timestamptz `json:"last_started_at"`
|
||||
LastExitCode *int32 `json:"last_exit_code"`
|
||||
LastError string `json:"last_error"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
KeyVersion int16 `json:"key_version"`
|
||||
}
|
||||
|
||||
type WorkspaceWorktree struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
Branch string `json:"branch"`
|
||||
Path string `json:"path"`
|
||||
Status string `json:"status"`
|
||||
ActiveHolder *string `json:"active_holder"`
|
||||
AcquiredAt pgtype.Timestamptz `json:"acquired_at"`
|
||||
LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
PruneWarningAt pgtype.Timestamptz `json:"prune_warning_at"`
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: summaries.sql
|
||||
|
||||
package docssqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getSummary = `-- name: GetSummary :one
|
||||
SELECT id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error, created_at
|
||||
FROM commit_summaries
|
||||
WHERE workspace_id = $1 AND commit_sha = $2 AND kind = $3
|
||||
`
|
||||
|
||||
type GetSummaryParams struct {
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetSummary(ctx context.Context, arg GetSummaryParams) (CommitSummary, error) {
|
||||
row := q.db.QueryRow(ctx, getSummary, arg.WorkspaceID, arg.CommitSha, arg.Kind)
|
||||
var i CommitSummary
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.WorktreeID,
|
||||
&i.Branch,
|
||||
&i.CommitSha,
|
||||
&i.Kind,
|
||||
&i.Title,
|
||||
&i.BodyMd,
|
||||
&i.Model,
|
||||
&i.Status,
|
||||
&i.Error,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertPendingSummary = `-- name: InsertPendingSummary :one
|
||||
INSERT INTO commit_summaries (
|
||||
id, workspace_id, worktree_id, branch, commit_sha, kind, body_md, status
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, '', 'pending')
|
||||
ON CONFLICT (workspace_id, commit_sha, kind) DO NOTHING
|
||||
RETURNING id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error, created_at
|
||||
`
|
||||
|
||||
type InsertPendingSummaryParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
WorktreeID pgtype.UUID `json:"worktree_id"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Kind string `json:"kind"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertPendingSummary(ctx context.Context, arg InsertPendingSummaryParams) (CommitSummary, error) {
|
||||
row := q.db.QueryRow(ctx, insertPendingSummary,
|
||||
arg.ID,
|
||||
arg.WorkspaceID,
|
||||
arg.WorktreeID,
|
||||
arg.Branch,
|
||||
arg.CommitSha,
|
||||
arg.Kind,
|
||||
)
|
||||
var i CommitSummary
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.WorktreeID,
|
||||
&i.Branch,
|
||||
&i.CommitSha,
|
||||
&i.Kind,
|
||||
&i.Title,
|
||||
&i.BodyMd,
|
||||
&i.Model,
|
||||
&i.Status,
|
||||
&i.Error,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const upsertSummary = `-- name: UpsertSummary :one
|
||||
INSERT INTO commit_summaries (
|
||||
id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
ON CONFLICT (workspace_id, commit_sha, kind) DO UPDATE
|
||||
SET title = EXCLUDED.title,
|
||||
body_md = EXCLUDED.body_md,
|
||||
model = EXCLUDED.model,
|
||||
status = EXCLUDED.status,
|
||||
error = EXCLUDED.error,
|
||||
branch = EXCLUDED.branch,
|
||||
worktree_id = EXCLUDED.worktree_id
|
||||
RETURNING id, workspace_id, worktree_id, branch, commit_sha, kind,
|
||||
title, body_md, model, status, error, created_at
|
||||
`
|
||||
|
||||
type UpsertSummaryParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
||||
WorktreeID pgtype.UUID `json:"worktree_id"`
|
||||
Branch string `json:"branch"`
|
||||
CommitSha string `json:"commit_sha"`
|
||||
Kind string `json:"kind"`
|
||||
Title *string `json:"title"`
|
||||
BodyMd string `json:"body_md"`
|
||||
Model *string `json:"model"`
|
||||
Status string `json:"status"`
|
||||
Error *string `json:"error"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertSummary(ctx context.Context, arg UpsertSummaryParams) (CommitSummary, error) {
|
||||
row := q.db.QueryRow(ctx, upsertSummary,
|
||||
arg.ID,
|
||||
arg.WorkspaceID,
|
||||
arg.WorktreeID,
|
||||
arg.Branch,
|
||||
arg.CommitSha,
|
||||
arg.Kind,
|
||||
arg.Title,
|
||||
arg.BodyMd,
|
||||
arg.Model,
|
||||
arg.Status,
|
||||
arg.Error,
|
||||
)
|
||||
var i CommitSummary
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WorkspaceID,
|
||||
&i.WorktreeID,
|
||||
&i.Branch,
|
||||
&i.CommitSha,
|
||||
&i.Kind,
|
||||
&i.Title,
|
||||
&i.BodyMd,
|
||||
&i.Model,
|
||||
&i.Status,
|
||||
&i.Error,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package docs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/git"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/jobs"
|
||||
)
|
||||
|
||||
// maxDiffChars bounds the diffstat fed to the LLM so a huge commit can't blow the
|
||||
// prompt budget.
|
||||
const maxDiffChars = 12000
|
||||
|
||||
// WorkspaceLocator resolves the on-disk directory holding a commit's files.
|
||||
type WorkspaceLocator interface {
|
||||
LocateWorkspace(ctx context.Context, wsID uuid.UUID) (mainPath string, err error)
|
||||
LocateWorktree(ctx context.Context, worktreeID uuid.UUID) (path string, err error)
|
||||
}
|
||||
|
||||
// Summarizer turns a diffstat into a markdown summary. Implemented in app.go over
|
||||
// the llm registry (default chat endpoint); the SummaryRunner only sees this
|
||||
// narrow contract so tests can inject a canned-output fake.
|
||||
type Summarizer interface {
|
||||
// Summarize returns (title, bodyMarkdown, modelID, error).
|
||||
Summarize(ctx context.Context, branch, commitSHA, diff string) (title, bodyMD, model string, err error)
|
||||
}
|
||||
|
||||
// SummaryRunner is the jobs.Handler that generates a commit_summaries row. It is
|
||||
// event-driven (enqueued post-commit), never a periodic ticker.
|
||||
type SummaryRunner struct {
|
||||
repo Repository
|
||||
locator WorkspaceLocator
|
||||
gitr git.Runner
|
||||
summ Summarizer
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
// NewSummaryRunner constructs a SummaryRunner. log may be nil.
|
||||
func NewSummaryRunner(repo Repository, locator WorkspaceLocator, gitr git.Runner, summ Summarizer, log *slog.Logger) *SummaryRunner {
|
||||
if log == nil {
|
||||
log = slog.Default()
|
||||
}
|
||||
return &SummaryRunner{repo: repo, locator: locator, gitr: gitr, summ: summ, log: log}
|
||||
}
|
||||
|
||||
var _ jobs.Handler = (*SummaryRunner)(nil)
|
||||
|
||||
// Type returns the job type this handler processes.
|
||||
func (h *SummaryRunner) Type() jobs.JobType { return JobTypeCommitSummary }
|
||||
|
||||
// Handle generates and upserts a commit summary. Idempotent: a completed summary
|
||||
// for the same (workspace, commit, kind) is left untouched.
|
||||
func (h *SummaryRunner) Handle(ctx context.Context, job jobs.Job) error {
|
||||
var p summaryPayload
|
||||
if err := json.Unmarshal(job.Payload, &p); err != nil {
|
||||
return jobs.Permanent(fmt.Errorf("docs.commit_summary: bad payload: %w", err))
|
||||
}
|
||||
|
||||
// Skip if a completed summary already exists (idempotent re-enqueue).
|
||||
if existing, err := h.repo.Get(ctx, p.WorkspaceID, p.CommitSHA, KindCommit); err == nil && existing != nil && existing.Status == StatusCompleted {
|
||||
return nil
|
||||
}
|
||||
|
||||
dir := ""
|
||||
if p.WorktreeID != nil {
|
||||
path, lerr := h.locator.LocateWorktree(ctx, *p.WorktreeID)
|
||||
if lerr != nil {
|
||||
return fmt.Errorf("locate worktree: %w", lerr)
|
||||
}
|
||||
dir = path
|
||||
} else {
|
||||
path, lerr := h.locator.LocateWorkspace(ctx, p.WorkspaceID)
|
||||
if lerr != nil {
|
||||
return fmt.Errorf("locate workspace: %w", lerr)
|
||||
}
|
||||
dir = path
|
||||
}
|
||||
|
||||
diff, err := h.gitr.DiffStat(ctx, dir, p.CommitSHA)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git show --stat: %w", err)
|
||||
}
|
||||
if len(diff) > maxDiffChars {
|
||||
diff = diff[:maxDiffChars] + "\n...[truncated]"
|
||||
}
|
||||
|
||||
title, body, model, serr := h.summ.Summarize(ctx, p.Branch, p.CommitSHA, diff)
|
||||
if serr != nil {
|
||||
// Persist a failed row so the failure is visible, then return for retry.
|
||||
msg := serr.Error()
|
||||
if _, uerr := h.repo.Upsert(ctx, UpsertInput{
|
||||
WorkspaceID: p.WorkspaceID, WorktreeID: p.WorktreeID, Branch: p.Branch,
|
||||
CommitSHA: p.CommitSHA, Kind: KindCommit, BodyMD: "",
|
||||
Status: StatusFailed, Error: &msg,
|
||||
}); uerr != nil {
|
||||
h.log.Error("docs.summary.upsert_failed_row", "commit", p.CommitSHA, "err", uerr.Error())
|
||||
}
|
||||
return fmt.Errorf("summarize: %w", serr)
|
||||
}
|
||||
|
||||
var titlePtr, modelPtr *string
|
||||
if t := strings.TrimSpace(title); t != "" {
|
||||
titlePtr = &t
|
||||
}
|
||||
if m := strings.TrimSpace(model); m != "" {
|
||||
modelPtr = &m
|
||||
}
|
||||
if _, err := h.repo.Upsert(ctx, UpsertInput{
|
||||
WorkspaceID: p.WorkspaceID, WorktreeID: p.WorktreeID, Branch: p.Branch,
|
||||
CommitSHA: p.CommitSHA, Kind: KindCommit, Title: titlePtr,
|
||||
BodyMD: body, Model: modelPtr, Status: StatusCompleted,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("upsert summary: %w", err)
|
||||
}
|
||||
h.log.Info("docs.summary.completed", "workspace_id", p.WorkspaceID, "commit", p.CommitSHA)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package docs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/yan1h/agent-coding-workflow/internal/infra/git"
|
||||
"github.com/yan1h/agent-coding-workflow/internal/jobs"
|
||||
)
|
||||
|
||||
type fakeDocsRepo struct {
|
||||
summaries map[string]*Summary // keyed by commitSHA|kind
|
||||
upserts int
|
||||
}
|
||||
|
||||
func key(commit, kind string) string { return commit + "|" + kind }
|
||||
|
||||
func newFakeDocsRepo() *fakeDocsRepo {
|
||||
return &fakeDocsRepo{summaries: map[string]*Summary{}}
|
||||
}
|
||||
|
||||
func (r *fakeDocsRepo) Get(_ context.Context, _ uuid.UUID, commit, kind string) (*Summary, error) {
|
||||
return r.summaries[key(commit, kind)], nil
|
||||
}
|
||||
func (r *fakeDocsRepo) Upsert(_ context.Context, in UpsertInput) (*Summary, error) {
|
||||
r.upserts++
|
||||
s := &Summary{
|
||||
ID: uuid.New(), WorkspaceID: in.WorkspaceID, WorktreeID: in.WorktreeID,
|
||||
Branch: in.Branch, CommitSHA: in.CommitSHA, Kind: in.Kind, Title: in.Title,
|
||||
BodyMD: in.BodyMD, Model: in.Model, Status: in.Status, Error: in.Error,
|
||||
}
|
||||
r.summaries[key(in.CommitSHA, in.Kind)] = s
|
||||
return s, nil
|
||||
}
|
||||
|
||||
type fakeLocator struct{}
|
||||
|
||||
func (fakeLocator) LocateWorkspace(context.Context, uuid.UUID) (string, error) { return "/tmp/x", nil }
|
||||
func (fakeLocator) LocateWorktree(context.Context, uuid.UUID) (string, error) { return "/tmp/x", nil }
|
||||
|
||||
// gitShim embeds git.Runner (nil) and overrides only DiffStat, the single method
|
||||
// the SummaryRunner invokes. Any other call would panic, which never happens here.
|
||||
type gitShim struct {
|
||||
git.Runner
|
||||
diff string
|
||||
}
|
||||
|
||||
func (g gitShim) DiffStat(context.Context, string, string) (string, error) { return g.diff, nil }
|
||||
|
||||
type fakeSummarizer struct {
|
||||
title, body, model string
|
||||
err error
|
||||
}
|
||||
|
||||
func (s fakeSummarizer) Summarize(context.Context, string, string, string) (string, string, string, error) {
|
||||
return s.title, s.body, s.model, s.err
|
||||
}
|
||||
|
||||
func newRunner(repo Repository, summ Summarizer, diff string) *SummaryRunner {
|
||||
return NewSummaryRunner(repo, fakeLocator{}, gitShim{diff: diff}, summ, nil)
|
||||
}
|
||||
|
||||
func TestSummaryRunner_Success(t *testing.T) {
|
||||
repo := newFakeDocsRepo()
|
||||
wsID := uuid.New()
|
||||
r := newRunner(repo, fakeSummarizer{title: "Add feature X", body: "# Add feature X\n\n- did stuff", model: "m1"}, "f.go | 2 +-")
|
||||
|
||||
payload, _ := json.Marshal(summaryPayload{WorkspaceID: wsID, Branch: "main", CommitSHA: "abc"})
|
||||
require.NoError(t, r.Handle(context.Background(), jobs.Job{Payload: payload}))
|
||||
|
||||
s := repo.summaries[key("abc", KindCommit)]
|
||||
require.NotNil(t, s)
|
||||
require.Equal(t, StatusCompleted, s.Status)
|
||||
require.Equal(t, "# Add feature X\n\n- did stuff", s.BodyMD)
|
||||
require.NotNil(t, s.Title)
|
||||
require.Equal(t, "Add feature X", *s.Title)
|
||||
require.NotNil(t, s.Model)
|
||||
require.Equal(t, "m1", *s.Model)
|
||||
}
|
||||
|
||||
func TestSummaryRunner_IdempotentWhenCompleted(t *testing.T) {
|
||||
repo := newFakeDocsRepo()
|
||||
wsID := uuid.New()
|
||||
repo.summaries[key("abc", KindCommit)] = &Summary{CommitSHA: "abc", Kind: KindCommit, Status: StatusCompleted}
|
||||
|
||||
r := newRunner(repo, fakeSummarizer{title: "x", body: "y", model: "m"}, "stat")
|
||||
payload, _ := json.Marshal(summaryPayload{WorkspaceID: wsID, Branch: "main", CommitSHA: "abc"})
|
||||
require.NoError(t, r.Handle(context.Background(), jobs.Job{Payload: payload}))
|
||||
require.Equal(t, 0, repo.upserts, "completed summary must not be regenerated")
|
||||
}
|
||||
|
||||
func TestSummaryRunner_FailurePersistsFailedRow(t *testing.T) {
|
||||
repo := newFakeDocsRepo()
|
||||
wsID := uuid.New()
|
||||
r := newRunner(repo, fakeSummarizer{err: errors.New("llm down")}, "stat")
|
||||
payload, _ := json.Marshal(summaryPayload{WorkspaceID: wsID, Branch: "main", CommitSHA: "abc"})
|
||||
err := r.Handle(context.Background(), jobs.Job{Payload: payload})
|
||||
require.Error(t, err)
|
||||
s := repo.summaries[key("abc", KindCommit)]
|
||||
require.NotNil(t, s)
|
||||
require.Equal(t, StatusFailed, s.Status)
|
||||
require.NotNil(t, s.Error)
|
||||
}
|
||||
|
||||
var _ Repository = (*fakeDocsRepo)(nil)
|
||||
Reference in New Issue
Block a user