revise

package
v1.0.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildReplyMap added in v1.0.34

func BuildReplyMap(replies []ReviewComment) map[string][]ReviewComment

BuildReplyMap groups reply comments by their parent_comment_id.

func DetectEditor

func DetectEditor() string

DetectEditor returns the user's preferred editor from the environment. It checks $EDITOR and $VISUAL first, then falls back to common editors.

func EditPrompt

func EditPrompt(prompt string) (string, error)

EditPrompt writes prompt to a temp file, opens it in the user's editor, and returns the (possibly modified) content after the editor exits.

func EstimateTokens

func EstimateTokens(text string) int

EstimateTokens estimates the number of tokens in text using the ~3.5 chars/token heuristic. See plan.md §6 and research.md R12 for the rationale. Accuracy is within ~20%.

func PrintTokenWarnings

func PrintTokenWarnings(tokens int)

PrintTokenWarnings prints warnings when the prompt is too short or too long.

func RenderPrompt

func RenderPrompt(ctx RevisionContext) (string, error)

RenderPrompt renders the revision prompt template with the given context.

Types

type AutoFixture

type AutoFixture struct {
	Branch   string           `json:"branch"`
	Comments []FixtureComment `json:"comments"`
}

AutoFixture is the fixture file structure for non-interactive automation mode.

func ParseFixture

func ParseFixture(path string) (*AutoFixture, error)

ParseFixture reads and parses a fixture JSON file for --auto mode.

type FixtureComment

type FixtureComment struct {
	FilePath     string `json:"file_path"`
	SelectedText string `json:"selected_text"`
	Guidance     string `json:"guidance"`
}

FixtureComment is a single comment entry in the automation fixture.

type ProcessedComment

type ProcessedComment struct {
	Comment  ReviewComment
	Guidance string
	Index    int // 1-based display index
}

ProcessedComment is an in-memory struct for a comment the user chose to process.

func MatchFixtureComments

func MatchFixtureComments(fixture *AutoFixture, comments []ReviewComment) ([]ProcessedComment, []string)

MatchFixtureComments matches fixture entries to fetched review comments by file_path + selected_text. Returns matched ProcessedComments (with guidance from fixture) and warning messages for unmatched entries. Warnings are intended for stderr so they do not contaminate stdout prompt output.

type PromptComment

type PromptComment struct {
	Index    int    // 1-based display index
	ID       string // Comment UUID (internal, for resolution)
	FilePath string
	Target   string // selected_text, "Line N", or "General"
	Feedback string // Comment content
	Guidance string // Optional user guidance
	Replies  []ThreadReply
}

PromptComment is a single comment entry in the revision prompt template.

type ReviewComment

type ReviewComment struct {
	ID              string `json:"id"`
	ChangeID        string `json:"change_id"`
	FilePath        string `json:"file_path"`
	Content         string `json:"content"`
	SelectedText    string `json:"selected_text"`
	Line            *int   `json:"line"`
	StartLine       *int   `json:"start_line"`
	IsResolved      bool   `json:"is_resolved"`
	AuthorID        string `json:"author_id"`
	AuthorName      string `json:"author_name"`
	AuthorEmail     string `json:"author_email"`
	ParentCommentID string `json:"parent_comment_id"`
	CreatedAt       string `json:"created_at"`
	UpdatedAt       string `json:"updated_at"`
}

ReviewComment maps to the review_comments table in Supabase.

type ReviseClient

type ReviseClient struct {
	// contains filtered or unexported fields
}

ReviseClient handles all Supabase PostgREST calls for the revise command.

func NewReviseClient

func NewReviseClient(accessToken string) *ReviseClient

NewReviseClient creates a ReviseClient using the configured Supabase URL and anon key. The provided accessToken is used for Authorization headers; call doWithRetry to handle 401s.

func (*ReviseClient) FetchComments

func (c *ReviseClient) FetchComments(changeID string) ([]ReviewComment, error)

FetchComments fetches all unresolved top-level review comments for the given change. Results are ordered by created_at ascending (oldest first).

func (*ReviseClient) FetchReplies added in v1.0.34

func (c *ReviseClient) FetchReplies(changeID string) ([]ReviewComment, error)

FetchReplies fetches all unresolved thread replies (comments with a parent) for the given change. Results are ordered by created_at ascending (oldest first).

func (*ReviseClient) GetChange

func (c *ReviseClient) GetChange(specID string) (*apiChange, error)

GetChange fetches the open change record for the given spec.

func (*ReviseClient) GetProject

func (c *ReviseClient) GetProject(repoOwner, repoName string) (*apiProject, error)

GetProject fetches the project record for the given GitHub repo.

func (*ReviseClient) GetSpec

func (c *ReviseClient) GetSpec(projectID, specKey string) (*apiSpec, error)

GetSpec fetches the spec record for the given project and spec key (branch name).

func (*ReviseClient) ListSpecsWithComments

func (c *ReviseClient) ListSpecsWithComments(projectID string) ([]SpecWithCommentCount, error)

ListSpecsWithComments returns all specs for the project that have unresolved review comments.

Implementation: 3 sequential calls + client-side aggregation.

  1. GET /rest/v1/specs?project_id=eq.{pid}&select=id,spec_key
  2. GET /rest/v1/changes?spec_id=in.({spec_ids})&select=id,spec_id
  3. GET /rest/v1/review_comments?change_id=in.({change_ids})&is_resolved=eq.false&select=id,change_id

Client-side: group comments by change → map change to spec → count per spec_key. See contracts/postgrest-api.md §6 for the rationale.

func (*ReviseClient) ResolveComment

func (c *ReviseClient) ResolveComment(commentID string) error

ResolveComment marks a review comment as resolved via PATCH.

func (*ReviseClient) ResolveCommentWithReplies added in v1.0.34

func (c *ReviseClient) ResolveCommentWithReplies(commentID string, replyIDs []string) error

ResolveCommentWithReplies resolves a parent comment and all its thread replies in a single batch PATCH using PostgREST's `id=in.(...)` filter.

type RevisionContext

type RevisionContext struct {
	SpecKey  string
	Comments []PromptComment
}

RevisionContext is the template rendering context for the combined prompt.

func BuildRevisionContext

func BuildRevisionContext(specKey string, processed []ProcessedComment, replies []ReviewComment) RevisionContext

BuildRevisionContext converts processed comments into the template rendering context. The replies slice contains all thread reply comments; they are grouped by parent_comment_id and attached to the corresponding PromptComment.

type SpecWithCommentCount

type SpecWithCommentCount struct {
	SpecKey      string
	CommentCount int
}

SpecWithCommentCount is used by the branch picker to list specs with pending review comments.

type ThreadReply added in v1.0.34

type ThreadReply struct {
	ID         string // Reply UUID (for cascade resolution)
	AuthorName string
	Content    string
	CreatedAt  string
}

ThreadReply is a single reply in a comment thread.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL