project

package
v0.92.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package project opens project directories through the OS file picker. Project metadata (list, active, sessions) lives in internal/store; this service only turns a picked directory into a stable identity the window can group its terminal sessions under.

Index

Constants

This section is empty.

Variables

View Source
var ErrLinesMoved = errors.New("the file changed since this diff was drawn. Refresh and try again")

ErrLinesMoved is what a revert answers when the lines it was asked about are no longer the lines on disk: the diff on screen is older than the file.

View Source
var ErrStagedDiverged = errors.New("these lines have staged changes that differ from the file. Discard the file instead")

ErrStagedDiverged is a revert refused because the index holds a third version of these lines, neither HEAD's nor the working tree's.

Functions

func CheckoutRoots

func CheckoutRoots(dir string) (top, origin string)

CheckoutRoots returns the top of the checkout dir is in and the top of the main checkout of its repository: the same directory for a checkout that is not a linked worktree, and origin "" for a worktree of a bare repository, which has no main checkout. Both are "" when dir is not in a work tree.

func GHTokenEnv added in v0.81.0

func GHTokenEnv(account string) string

GHTokenEnv returns the environment entry carrying the API token gh holds for one account ("<host>/<login>"), or for gh's active account when account is empty, under the variable gh reads for that host. It is what a session is handed so its gh answers as the project's account: inside the sandbox it is the whole reason gh works at all, since gh keeps its tokens in the system keyring, which a private home has no path to.

Every failure answers "" — gh not installed, gh not authenticated, an account gh does not know — because the caller does the same thing with all three: spawn the session without a token and let gh say so itself, rather than fail a whole session over a credential it may never use.

func GitCommonDir

func GitCommonDir(dir string) string

GitCommonDir returns the repository metadata directory shared by a checkout and every worktree linked to it, or "" when dir is not in a repository. It is the same question basestatus.go asks, in the same spelling, and absolute because the caller needs a path rather than something to resolve against dir.

A linked worktree's `.git` is a file naming that directory, so a process that can see the worktree and not the common directory has a checkout git refuses to read at all. It is asked of git rather than parsed out of the `.git` file because git is the one thing that cannot be wrong about its own layout.

Types

type BaseFreshness

type BaseFreshness = api.BaseFreshness

type BaseStatus

type BaseStatus = api.BaseStatus

type Blob

type Blob struct {
	Data        []byte
	ContentType string
}

Blob is one file's bytes at one revision, with the type it is served as.

type BranchRules

type BranchRules = api.BranchRules

type Branches

type Branches = api.Branches

type CheckItem

type CheckItem = api.CheckItem

type ChecksRollup

type ChecksRollup = api.ChecksRollup

type CommitIdentity

type CommitIdentity = api.CommitIdentity

type CommitPattern

type CommitPattern = api.CommitPattern

type DiffStats

type DiffStats = api.DiffStats

type FileListing

type FileListing = api.FileListing

type Issue

type Issue = api.Issue

type PRChanged

type PRChanged = api.PRChanged

type PRComment

type PRComment = api.PRComment

type PRCommit

type PRCommit = api.PRCommit

type PRConversation

type PRConversation = api.PRConversation

type PRDetail

type PRDetail = api.PRDetail

type PRReview

type PRReview = api.PRReview

type PRReviewThread

type PRReviewThread = api.PRReviewThread

type PRReviewer

type PRReviewer = api.PRReviewer

type PRSummary

type PRSummary = api.PRSummary

type PRThreadComment

type PRThreadComment = api.PRThreadComment

type Picker

type Picker interface {
	PickDirectory(title string) (string, error)
	PickFile(title string) (string, error)
	PickSaveFile(title, defaultName string) (string, error)
}

Picker shows native file/directory choosers — zenity in production (picker.go), fakes in tests. Returns "" on user cancel.

type Project

type Project = api.OpenedProject

func Identify

func Identify(path string) (*Project, error)

Identify turns a directory path into the same identity the picker would give it: the id its sessions and its worktree directory hang off, and the name its tab wears. It is the path a caller outside the window hands in — the `lich` command line and its MCP tools — so it normalizes what a person or an agent types, and validates it here rather than letting a typo become a project.

A leading ~ is expanded because an MCP tool call reaches lich through no shell at all: the tilde arrives literally, and a project named "~" is nobody's intent. ~user is not expanded — the home directory of another user is not a path this ever means.

A relative path is refused rather than resolved. There is no shell at this end either: Abs would resolve it against the directory the lich window was launched from, which is not the caller's, and the project that opened would be a different one than the one asked for with nothing on screen saying so.

type PullRequest

type PullRequest = api.PullRequest

type RevertLine

type RevertLine = api.RevertLine

type RevertResult

type RevertResult = api.RevertResult

type ReviewComment

type ReviewComment = api.ReviewComment

type SearchMatch

type SearchMatch = api.SearchMatch

type SearchResult

type SearchResult = api.SearchResult

type Service

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

Service opens project directories via the native file picker.

func New

func New(picker Picker) *Service

New returns a project service using the given picker.

func (*Service) AwaitThreadFix added in v0.79.0

func (s *Service) AwaitThreadFix(ctx context.Context, opts api.ThreadFixOptions) (api.None, error)

AwaitThreadFix answers a thread just handed to a session and has it wait for the pull request's next push. The head is read here rather than taken from the window, whose read may predate a push that would resolve the thread at once.

func (*Service) BaseFreshness

func (s *Service) BaseFreshness(_ context.Context, opts api.PathBranchOptions) (BaseFreshness, error)

BaseFreshness fetches opts.Branch's upstream and counts the commits each side has that the other lacks. A fetch that fails is part of the answer, never an error: the caller still has a local branch to start from. It is an error only for a branch the repository does not hold.

func (*Service) BaseStatus

func (s *Service) BaseStatus(_ context.Context, opts api.PathOptions) (*BaseStatus, error)

BaseStatus answers baseStatus over RPC.

func (*Service) Blob

func (s *Service) Blob(dir, rel, ref string) (Blob, error)

Blob reads rel at ref for an image preview. ref is "" for the working tree, "HEAD" for the commit a checkout's uncommitted diff stands on, or an object id. An object this clone does not hold, a pull request's head or merge base, is read from GitHub, the way FileLines reads it.

A path absent at ref is fs.ErrNotExist: the side of an added or deleted file that has nothing to show.

func (*Service) Branch

func (s *Service) Branch(path string) string

Branch returns the current git branch of the project directory, or "" when the path is not a git work tree or HEAD is detached (no branch to name). It reads the current state on call, so a checkout made after opening is not reflected until the branch is resolved again.

func (*Service) BranchPullRequest added in v0.79.0

func (s *Service) BranchPullRequest(path string) (*PullRequest, error)

BranchPullRequest returns the pull request of the branch checked out at path whatever its state, nil when the branch has none.

func (*Service) BranchRules

func (s *Service) BranchRules(_ context.Context, opts api.PathBranchOptions) (*BranchRules, error)

BranchRules reads the rules a repository's rulesets apply to one branch, and whether this account may merge past them.

A branch nothing governs answers with an empty list, and so does a token that may not read the rules — both reach the screen as "no rule known", which is the same shape as a repository that has none. That is deliberate: this read exists to *narrow* what the merge menu offers, so failing to answer must leave the menu as wide as it was, never empty. The bypass is the exception and runs the other way; see ViewerCanBypass and viewerAdministers.

func (*Service) BranchesOf

func (s *Service) BranchesOf(_ context.Context, opts api.PathsOptions) (map[string]string, error)

BranchesOf answers branchesOf over RPC.

func (*Service) CarryUncommitted

func (s *Service) CarryUncommitted(_ context.Context, opts api.CarryUncommittedOptions) (api.None, error)

CarryUncommitted copies the work opts.Src has not committed onto opts.Dst, so a new worktree starts from a checkout as it stands rather than from its last commit. opts.Src is a forked session's checkout, or the project's own checkout when the + dialog's working-tree row was picked. Either way opts.Src is only read: the work stays where it was.

Both checkouts must sit on the same commit, which is what the caller picking opts.Src's own branch as the base guarantees: the patch is read against opts.Src's HEAD and applied to opts.Dst's, and git refuses it outright if they differ.

Everything lands unstaged in opts.Dst. Which of opts.Src's changes were staged is not carried: it is a fact about the commit opts.Src is preparing, and opts.Dst is a different piece of work from here on.

What git ignores is not carried here either (--exclude-standard). The ignored files the project names (`.env*` by default) reach opts.Dst through seedWorktree, when CreateWorktree was handed opts.Src as SeedFrom. Nothing builds the rest.

func (*Service) CheckLog added in v0.89.0

func (s *Service) CheckLog(_ context.Context, opts api.CheckLogOptions) (api.CheckLog, error)

CheckLog reads the failed checks of the pull request of opts.ID's checkout, with the tail of each failing step of every failed Actions job.

func (*Service) CommentOnPullRequest

func (s *Service) CommentOnPullRequest(_ context.Context, opts api.PRBodyOptions) (api.None, error)

CommentOnPullRequest leaves a comment on the pull request itself — the conversation with no file and no line behind it.

func (*Service) CommitIdentity

func (s *Service) CommitIdentity(_ context.Context, opts api.PathOptions) (CommitIdentity, error)

CommitIdentity answers commitIdentity over RPC.

func (*Service) CreatePullRequest

func (s *Service) CreatePullRequest(_ context.Context, opts api.PathOptions) (api.None, error)

CreatePullRequest opens GitHub's "new pull request" page in the browser for opts.Path's branch (gh pushes the branch first when it has no upstream). Deliberately the web flow, not an in-app form — GitHub's page already owns the title, body, reviewers and template. Returns once the browser is launched.

func (*Service) CreateWorktree

func (s *Service) CreateWorktree(_ context.Context, opts api.CreateWorktreeOptions) (*Worktree, error)

CreateWorktree creates a git worktree named opts.Name (random when empty) under the app data dir, branching off opts.Base. A remote base is fetched first, and the new branch is left with no upstream. A branch that already exists is checked out as it stands, and opts.Base is ignored. The worktree is verified usable before returning, so a success here means a session can be opened at Path right away.

func (*Service) CreateWorktreeFromPR

func (s *Service) CreateWorktreeFromPR(_ context.Context, opts api.CreateWorktreeFromPROptions) (*Worktree, error)

CreateWorktreeFromPR checks a pull request out into its own worktree under the app data dir, so a session can be opened on the PR's own branch. The checkout is created detached and handed to `gh pr checkout`, which owns resolving the head ref and its tracking — the part raw git cannot do for a pull request.

It refuses a PR from a fork that has "allow edits by maintainers" off: the branch would check out, but the commits an agent makes there have nowhere to push, so the failure belongs before the worktree exists rather than at the first push. With the permission on, the fork's branch takes a push like any other and the pull request opens. A failed checkout takes the worktree with it — a detached husk would sit in the picker offering a resume of nothing, and would hold the path against a second attempt.

func (*Service) DeletePullRequestComment added in v0.78.0

func (s *Service) DeletePullRequestComment(_ context.Context, opts api.PRCommentOptions) (api.None, error)

DeletePullRequestComment removes a comment on the pull request itself, for good.

func (*Service) DeleteReviewComment added in v0.78.0

func (s *Service) DeleteReviewComment(_ context.Context, opts api.PRCommentOptions) (api.None, error)

DeleteReviewComment removes one comment of a review thread; the last one gone takes the thread with it. There is no undo on GitHub's side.

func (*Service) Diff

func (s *Service) Diff(_ context.Context, opts api.PathOptions) (DiffStats, error)

Diff answers diff over RPC.

func (*Service) DiffText

func (s *Service) DiffText(_ context.Context, opts api.PathOptions) (string, error)

DiffText returns the full unified diff of uncommitted changes (staged + unstaged + untracked) against HEAD. A repository without commits diffs against git's empty tree. Untracked files are rendered as new-file hunks so the review panel shows them alongside tracked changes.

func (*Service) DiscardFile

func (s *Service) DiscardFile(_ context.Context, opts api.CheckoutFileOptions) (api.None, error)

DiscardFile reverts one file's uncommitted changes. A file known to HEAD is checked out from it (restoring index and worktree in one step); a new file (staged or untracked) is unstaged and deleted from disk. opts.Rel must be a repo-relative path — the review panel passes paths parsed from git's own diff output.

func (*Service) EditPullRequestBody

func (s *Service) EditPullRequestBody(_ context.Context, opts api.PRBodyOptions) (api.None, error)

EditPullRequestBody rewrites the pull request's description on GitHub, and an empty body clears it. The title is left alone on purpose: sending the one the screen read would undo a rename made on GitHub since.

func (*Service) EditPullRequestComment added in v0.78.0

func (s *Service) EditPullRequestComment(_ context.Context, opts api.PRCommentBodyOptions) (api.None, error)

EditPullRequestComment rewrites a comment on the pull request itself. GitHub files those as issue comments, which is the endpoint they live at.

func (*Service) EditPullRequestTitle added in v0.75.0

func (s *Service) EditPullRequestTitle(_ context.Context, opts api.PRTitleOptions) (api.None, error)

EditPullRequestTitle renames the pull request on GitHub. GitHub refuses a pull request without a title, so an empty one never reaches gh.

func (*Service) EditReviewBody added in v0.78.0

func (s *Service) EditReviewBody(_ context.Context, opts api.PRReviewBodyOptions) (api.None, error)

EditReviewBody rewrites the summary of a submitted review. opts.ReviewID is its database id; the verdict stays what it was, GitHub has no way to change it.

func (*Service) EditReviewComment added in v0.78.0

func (s *Service) EditReviewComment(_ context.Context, opts api.PRCommentBodyOptions) (api.None, error)

EditReviewComment rewrites one comment of a review thread. opts.CommentID is its database id, the same address a reply takes; GitHub refuses the edit unless the account gh runs as may update that comment.

func (*Service) Exists

func (s *Service) Exists(_ context.Context, opts api.PathOptions) (bool, error)

Exists answers exists over RPC.

func (*Service) FileLines

func (s *Service) FileLines(_ context.Context, opts api.FileLinesOptions) ([]string, error)

FileLines returns lines opts.From..opts.To of one repo-relative file — 1-based and inclusive, the numbering a diff's gutter shows — for the review panel's context expander: the unchanged text around a hunk, which git never printed.

opts.Ref names the revision the diff's new side stands at, and the panels differ in which one they have: "" is the working tree, an oid is a git object this checkout holds (a turn's snapshot tree), and a pull request's head is an oid this clone need not hold at all — measured, the head oids `gh pr list` reports are absent from a clone that never checked those branches out, so a local read alone would leave the Pulls screen's expander dead. The object is tried first because it costs nothing; GitHub answers for the rest.

opts.Rel is validated against traversal like every other file-by-path surface, and binaries and oversize files are refused the way ReadFile refuses them: this is a source viewer, and a blob has no lines to show.

func (*Service) GitAuthors added in v0.91.0

func (s *Service) GitAuthors(ctx context.Context, opts api.GitAuthorsOptions) ([]string, error)

GitAuthors lists who wrote the history, the one with most commits first, by the names GitLog prints and its Author filter matches.

func (*Service) GitBranchOnly added in v0.89.0

func (s *Service) GitBranchOnly(_ context.Context, opts api.GitBranchOptions) (int, error)

GitBranchOnly counts the commits no other branch, remote branch or tag reaches: what deleting the branch would leave without a name.

func (*Service) GitCheckout added in v0.89.0

func (s *Service) GitCheckout(_ context.Context, opts api.GitCheckoutOptions) (api.None, error)

GitCheckout switches the checkout to a branch. git refuses a switch that would overwrite uncommitted edits and a branch checked out in another worktree; its message is the answer.

func (*Service) GitCommit added in v0.89.0

func (s *Service) GitCommit(ctx context.Context, opts api.GitCommitOptions) (api.GitCommitDetail, error)

GitCommit reads one commit's message and the files it changed.

func (*Service) GitCommitDiff added in v0.89.0

func (s *Service) GitCommitDiff(ctx context.Context, opts api.GitCommitDiffOptions) (string, error)

GitCommitDiff is one file's patch in a commit, one file so a commit that rewrites a generated tree does not cross the RPC whole to show one path.

func (*Service) GitConflict added in v0.92.0

func (s *Service) GitConflict(_ context.Context, opts api.CheckoutFileOptions) (api.GitConflict, error)

GitConflict reads a conflicted file's base, ours and theirs from the index (stages 1, 2 and 3) and lays out where each side changed the base. A file added on both sides has no base; one deleted on a side, a binary or a non-UTF-8 one is refused, since the resolver writes the text it shows.

func (*Service) GitCreateBranch added in v0.89.0

func (s *Service) GitCreateBranch(_ context.Context, opts api.GitCreateBranchOptions) (api.None, error)

GitCreateBranch makes a branch at From and leaves the checkout where it is.

func (*Service) GitDeleteBranch added in v0.89.0

func (s *Service) GitDeleteBranch(_ context.Context, opts api.GitBranchOptions) (api.GitDeletedBranch, error)

GitDeleteBranch deletes a local branch whatever it holds, the caller having asked first, and returns the commit and upstream it had so it can be made again.

func (*Service) GitHubAccountOf added in v0.89.0

func (s *Service) GitHubAccountOf(ctx context.Context, o api.PathOptions) (api.GitHubAccountState, error)

GitHubAccountOf answers the Pulls screen's question before it lists: which account the checkout's project runs gh as, which it could run as instead, and whether GitHub hides the repository from the one selected. The visibility costs a gh call, so it is asked only for a selected account with another one to switch to.

func (*Service) GitHubAccounts

func (s *Service) GitHubAccounts(_ context.Context, _ api.None) ([]string, error)

GitHubAccounts lists the accounts gh is authenticated as, "<host>/<login>", in gh's own order (each host's active account first). It backs the account picker in the project's Version Control settings; an unauthenticated gh yields an error, which the picker shows instead of an empty list.

func (*Service) GitLog added in v0.89.0

func (s *Service) GitLog(ctx context.Context, opts api.GitLogOptions) (api.GitLogPage, error)

GitLog returns a page of the history, in an order where every commit comes before its parents, which is what the graph is drawn from.

func (*Service) GitMarkResolved added in v0.92.0

func (s *Service) GitMarkResolved(_ context.Context, opts api.CheckoutFileOptions) (api.None, error)

GitMarkResolved stages a conflicted file as it stands, which is how git records it resolved.

func (*Service) GitMerge added in v0.92.0

GitMerge merges opts.Ref into the checkout. It refuses a checkout with uncommitted changes, so Abort always goes back to where the merge started, and a merge already running. A merge that stops on conflicts is an outcome, not an error: it answers with the files.

func (*Service) GitMergeAbort added in v0.92.0

func (s *Service) GitMergeAbort(_ context.Context, opts api.PathOptions) (api.None, error)

GitMergeAbort puts the checkout back where it stood before the merge, dropping whatever was resolved since.

func (*Service) GitMergeCommit added in v0.92.0

func (s *Service) GitMergeCommit(_ context.Context, opts api.PathOptions) (api.None, error)

GitMergeCommit concludes the merge with the message git prepared. Refused outside a merge, where the same commit would take whatever happens to be staged.

func (*Service) GitMergePreview added in v0.92.0

func (s *Service) GitMergePreview(_ context.Context, opts api.GitMergeOptions) (api.GitMergePreview, error)

GitMergePreview reads, without touching the checkout, what merging opts.Ref would bring. The conflicts come from merge-tree, so a git older than 2.38 answers with an error rather than a guess.

func (*Service) GitMergeUndo added in v0.92.0

func (s *Service) GitMergeUndo(_ context.Context, opts api.GitMergeUndoOptions) (api.None, error)

GitMergeUndo takes a merge back for as long as nothing has moved HEAD past it: reset --keep refuses to touch an edit made since.

func (*Service) GitRefs added in v0.89.0

func (s *Service) GitRefs(ctx context.Context, opts api.PathOptions) (api.GitRefs, error)

GitRefs lists the repository's branches and tags. Run on every poll of an open panel, so it stays one for-each-ref and one rev-parse.

func (*Service) GitRenameBranch added in v0.89.0

func (s *Service) GitRenameBranch(_ context.Context, opts api.GitRenameBranchOptions) (api.None, error)

func (*Service) GitResolveFile added in v0.92.0

func (s *Service) GitResolveFile(_ context.Context, opts api.GitResolveFileOptions) (api.None, error)

GitResolveFile writes content over a conflicted file and stages it, which is how git records the conflict resolved.

func (*Service) Home

func (s *Service) Home(_ context.Context, _ api.None) (*Project, error)

Home returns a project rooted at the user's home directory, without a picker. The update flow opens an install terminal there when no project is in view, so clicking Install never dead-ends on the Home screen.

func (*Service) Issue

func (s *Service) Issue(_ context.Context, opts api.NumberOptions) (Issue, error)

Issue resolves one GitHub issue through gh, as the account the project selected. The title names the branch the dialog is about to create, and the body is what that worktree's session finds at its prompt.

A pull request is refused rather than answered. GitHub numbers issues and pull requests in one sequence and its API calls them all issues, so `gh issue view <n>` answers for either — and taking the pull request would branch off the base under its title instead of checking its head branch out, which is a different flow entirely (CreateWorktreeFromPR). The URL is the only field in the answer that tells the two apart.

func (*Service) ListBranches

func (s *Service) ListBranches(_ context.Context, opts api.PathOptions) (Branches, error)

ListBranches returns the repository's local and remote branches and its existing worktrees. A path that is not a git repository yields an error.

func (*Service) ListCheckouts

func (s *Service) ListCheckouts(_ context.Context, opts api.PathOptions) ([]Worktree, error)

ListCheckouts returns every checkout of the repository holding a branch — the project's own directory included, which ListBranches deliberately leaves out because a main checkout is not something the worktree picker can resume. It answers a different question: which branches are spoken for. git refuses to check one branch out twice, so a caller about to check a branch out has to know about the main checkout as much as about the linked ones.

func (*Service) ListPullRequests

func (s *Service) ListPullRequests(_ context.Context, opts api.ListPullRequestsOptions) ([]PRSummary, error)

ListPullRequests returns the repository's pull requests in the given state (open|closed|merged|all, defaulting to open), newest update first — gh's own order, which the window re-sorts. It returns nil for a repository with none; a real failure (gh missing, unauthenticated, not a GitHub repo) yields an error so the column can say why it is empty.

func (*Service) MergePullRequest

func (s *Service) MergePullRequest(_ context.Context, opts api.MergePullRequestOptions) (api.None, error)

MergePullRequest merges a pull request on GitHub with the given method (squash|merge|rebase) — the given number, or the PR of the branch checked out at opts.Path when opts.Number is zero. A non-empty opts.Subject overrides the commit message (the dock's "edit message" flow); an empty opts.Subject leaves gh's default, the quick merge. opts.Admin merges with administrator privileges, GitHub's own bypass of the rules on the base branch. It does not pass --delete-branch: lich's worktree removal owns that cleanup, and deleting a checked-out worktree's branch is trouble. gh's stderr is surfaced on failure (not mergeable, branch protection, gh missing).

func (*Service) Missing

func (s *Service) Missing(_ context.Context, opts api.PathsOptions) ([]string, error)

Missing answers missing over RPC.

func (*Service) Open

func (s *Service) Open(_ context.Context, _ api.None) (*Project, error)

Open shows the native directory picker and returns the chosen project, or nil if the user cancels the dialog.

func (*Service) OpenPullRequest added in v0.89.0

func (s *Service) OpenPullRequest(_ context.Context, opts api.PathOptions) (*api.PullRequest, error)

OpenPullRequest is the open pull request of opts.Path's branch, nil when it has none open, as the badge shows it: the watch's last read when there is one, else one gh read, which is not recorded, since only the window's ask starts following a checkout. A repository with no remote has none, with no gh read.

func (*Service) PickDirectory added in v0.89.0

func (s *Service) PickDirectory(_ context.Context, opts api.PickFileOptions) (string, error)

PickDirectory shows the native directory picker and returns the chosen directory, or "" if the user cancels the dialog.

func (*Service) PickFile

func (s *Service) PickFile(_ context.Context, opts api.PickFileOptions) (string, error)

PickFile shows the native file picker and returns the chosen file path, or "" if the user cancels the dialog.

func (*Service) PickSaveFile

func (s *Service) PickSaveFile(_ context.Context, opts api.PickSaveFileOptions) (string, error)

PickSaveFile shows the native save dialog seeded with opts.DefaultName and returns the chosen destination, or "" if the user cancels.

func (*Service) PullRequestAvatar added in v0.84.0

func (s *Service) PullRequestAvatar(_ context.Context, opts api.AvatarOptions) ([]byte, error)

PullRequestAvatar reads the picture at opts.URL, an author's Avatar in a conversation. It goes through gh so an enterprise instance that serves avatars only to signed-in users gets the project's account like every other read; github.com's avatar host is not one gh holds a token for, so nothing is sent there.

func (*Service) PullRequestConflicts

func (s *Service) PullRequestConflicts(_ context.Context, opts api.PRConflictsOptions) ([]string, error)

PullRequestConflicts lists the files a merge of pull request opts.Number into opts.Base would collide on. GitHub publishes that a pull request conflicts and never where: its answer is one word (mergeable: CONFLICTING), which left the reader opening github.com or a session to find out which files it meant. This computes it instead — both commits are fetched into refs lich owns and merged in the object database alone (mergeConflicts), never in a worktree, an index or HEAD. The refs live no longer than the answer (dropPRRefs).

nil means the merge is clean, so this is asked only once GitHub has said it is not: the fetch is a network round trip, not something to poll.

opts.PRURL is the pull request's own URL, which names the repository it lives on — see prRemote. refs/pull/<n>/head is GitHub's own ref, a fork's pull request included, since GitHub keeps that ref on the base repository.

func (*Service) PullRequestConversation

func (s *Service) PullRequestConversation(_ context.Context, opts api.NumberOptions) (*PRConversation, error)

PullRequestConversation reads one pull request's reviews, comments and review threads. opts.Number is required: the query addresses a pull request by number, and the screen always knows it by the time there is a conversation to show — resolving "the branch's PR" here would cost a second gh round-trip on every read.

func (*Service) PullRequestDetail

func (s *Service) PullRequestDetail(_ context.Context, opts api.NumberOptions) (*PRDetail, error)

PullRequestDetail returns one open pull request in full: the given number, or the PR of the branch checked out at opts.Path when opts.Number is zero. It yields nil when there is no open PR — gh reports none, or the PR is merged/closed, which the OPEN-only gate treats the same as the badge does. A real failure (gh missing, not a GitHub repo) yields an error so the panel can tell "no PR" apart from "could not look up".

func (*Service) PullRequestDiff

func (s *Service) PullRequestDiff(_ context.Context, opts api.NumberOptions) (string, error)

PullRequestDiff returns the unified diff of opts.Path's branch pull request — every change the PR would merge into its base, as GitHub computes it — for the Pulls screen's "Files changed" tab. --color never keeps the output plain so the window's parsePatchFiles reads it. An empty string with no error means the branch has no open PR (nothing to show).

Ceiling: the whole diff is buffered here and shipped as one JSON string, so a monster PR costs its own size in memory on both sides. Reviewing a diff that large in a panel is not the workflow; stream it (or cap and mark it truncated) if that ever stops being true.

func (*Service) PullRequestMergeBase added in v0.77.0

func (s *Service) PullRequestMergeBase(_ context.Context, opts api.NumberOptions) (string, error)

PullRequestMergeBase is the commit pull request opts.Number's diff is taken from, the old side of every file GitHub shows. The base branch's tip is not it once the base moved past where the branch left it. The tips come from GitHub; their merge base is computed here when the clone holds both, and asked of GitHub otherwise.

func (*Service) ReadFile

func (s *Service) ReadFile(_ context.Context, opts api.CheckoutFileOptions) (string, error)

ReadFile returns the text content of one repo-relative file for the read-only preview. opts.Rel goes through relpath.Resolve rather than the lexical Validate its neighbours use, because this is the surface that reads bytes: a checkout can ship a symlink out of the tree, and a preview that followed one would print a file the diff beside it describes as the link's target text. Binaries, irregular files, and files above maxReadFileSize are refused — the preview is for source, not blobs.

func (*Service) ReadFileAt added in v0.77.0

func (s *Service) ReadFileAt(_ context.Context, opts api.ReadFileAtOptions) (string, error)

ReadFileAt is ReadFile at opts.Ref, for a preview of a file's new version that the working tree does not hold: a pull request's head. See FileLines for what a ref can be and where it is read from.

func (*Service) RecheckPullRequest added in v0.79.0

func (s *Service) RecheckPullRequest(_ context.Context, opts api.PathOptions) (api.None, error)

RecheckPullRequest reads the pull request of opts.Path's branch again, behind the call: the answer arrives as api.BranchPullRequestEvent. A window asks when it has seen the branch or the head move, a turn end, or anything else gh would answer differently after.

func (*Service) Relocate

func (s *Service) Relocate(_ context.Context, opts api.ProjectIDOptions) (*Project, error)

Relocate points a stored project at a directory chosen from the picker, keeping opts.ID rather than deriving a new one from the path. The id is the project's identity in the store — what its sessions hang off and what names its worktree directory — so a checkout that was moved or renamed keeps both. The name follows the new directory. nil when the user cancels.

A directory another project already sits on is refused: the two rows would hold the same path under different ids, and every path-addressed lookup the app makes — which project a checkout belongs to, which account its gh calls run as — answers with whichever row the query reached first.

func (*Service) RemoveWorktree

func (s *Service) RemoveWorktree(ctx context.Context, opts api.RemoveWorktreeOptions) (api.None, error)

RemoveWorktree removes a worktree checkout. Without opts.Force git refuses to delete a dirty worktree, which is the safety net the close-session flow relies on; opts.Force discards uncommitted changes after the user has confirmed. The branch is never deleted either way.

An adopted checkout is the user's own directory, made outside lich and only listed by it, so deleting one needs opts.AdoptedAck on top of the usual answers: the caller has put the absolute path in front of the user and been told to go ahead. Without it the removal is refused, opts.Force or not — which is the answer for a caller that has nobody to ask (the MCP close_session tool) and the one that holds when a caller forgets.

func (*Service) ReplyToReviewThread

func (s *Service) ReplyToReviewThread(_ context.Context, opts api.PRCommentBodyOptions) (api.None, error)

ReplyToReviewThread answers an existing thread. opts.CommentID is the database id of any comment in it — GitHub files the reply against the thread that comment belongs to. A reply posts immediately and is never part of the pending review: it is an answer to something already said, which is the same split GitHub draws between "add single comment" and "start a review".

func (*Service) ResolveReviewThread

func (s *Service) ResolveReviewThread(_ context.Context, opts api.ResolveThreadOptions) (api.None, error)

ResolveReviewThread marks a thread resolved, or reopens it. opts.ThreadID is the GraphQL node id the conversation read carries — the database id a reply uses does not address a thread here.

func (*Service) RestoreLines

func (s *Service) RestoreLines(_ context.Context, opts api.RestoreLinesOptions) (api.None, error)

RestoreLines undoes RevertLines: the same patches applied forwards, to the same targets. They come back from the caller, so each is held to the one file it was built for before git sees it.

func (*Service) RevertLines

func (s *Service) RevertLines(_ context.Context, opts api.RevertLinesOptions) (RevertResult, error)

RevertLines puts the chosen changed lines of opts.Rel back to HEAD, leaving every other change in the file alone. The patch is rebuilt here from git's own diff rather than taken from the caller, so a stale screen fails instead of reverting whatever those line numbers point at now.

The index is reverted with the working tree whenever it holds the change: the panel draws staged and unstaged as one diff, so reverting only the file would leave the line in the next commit with nothing on screen showing it.

func (*Service) RunBranchPRWatch added in v0.79.0

func (s *Service) RunBranchPRWatch()

RunBranchPRWatch reads the followed checkouts every branchPRTick, for as long as lich runs.

func (*Service) RunThreadFixWatch added in v0.79.0

func (s *Service) RunThreadFixWatch()

RunThreadFixWatch settles the waiting threads every threadFixPoll, for as long as lich runs.

func (*Service) Search

func (s *Service) Search(ctx context.Context, opts api.SearchOptions) (SearchResult, error)

Search finds the lines that contain opts.Query, case-insensitively and as a literal, across the files Tree lists for opts.Path. It reads Tree's listing rather than running git grep so that every hit is a file the tree beside it shows, in a repository and in a plain folder alike. A file the preview would refuse (binary, irregular, above maxReadFileSize) is skipped, so every hit opens. Matches come in Tree's order, file by file, line by line.

func (*Service) ServeBlob

func (s *Service) ServeBlob(w http.ResponseWriter, r *http.Request)

ServeBlob is Blob over HTTP, so the bytes travel raw rather than as base64 inside an RPC answer. The query carries path, rel and ref.

The window tells the sides apart by status: 404 is a side with no file, 413 a file over the limit, 415 a type with no preview. The body says which, in the words the window shows.

func (*Service) SetAccounts

func (s *Service) SetAccounts(lookup accountLookup)

SetAccounts wires the per-project account resolution. Left unset, every gh call runs as gh's active account — lich's behaviour before this existed.

func (*Service) SetAgentCheckouts added in v0.79.0

func (s *Service) SetAgentCheckouts(checkouts func() []string)

SetAgentCheckouts wires the checkouts an agent runs in, which the watch reads every tick: a pull request opens there whether or not a window is looking.

func (*Service) SetAnnounceMerge added in v0.79.0

func (s *Service) SetAnnounceMerge(announce func(context.Context, api.AnnounceMergeOptions) (api.None, error))

SetAnnounceMerge wires who tells a checkout's agents that its pull request merged (internal/relay AnnounceMerge).

func (*Service) SetEmit

func (s *Service) SetEmit(emit func(name string, data any))

SetEmit wires where pull request writes report (api.PullRequestChangedEvent).

func (*Service) SetProjects

func (s *Service) SetProjects(lookup projectLookup)

SetProjects wires the workspace lookup Relocate validates against. Left unset, any picked directory is taken as free.

func (*Service) SetPullRequestWatch added in v0.87.0

func (s *Service) SetPullRequestWatch(watched func(path string) bool, read func(api.PRRead))

SetPullRequestWatch wires who wants more than the badge from a checkout's pull request (internal/relay, watch.go): watched says a checkout holds a watch, and read receives what those checkouts' reads found.

func (*Service) SetSessionCheckout added in v0.88.0

func (s *Service) SetSessionCheckout(checkout func(id string) string)

SetSessionCheckout wires the directory a live session runs in, "" for one that is gone. Set once at startup.

func (*Service) SetThreadFixes added in v0.79.0

func (s *Service) SetThreadFixes(store threadFixStore)

SetThreadFixes wires where the waiting threads are kept.

func (*Service) ShowCode added in v0.88.0

func (s *Service) ShowCode(ctx context.Context, opts api.ShowCodeOptions) (api.ShowCode, error)

ShowCode refuses what the preview could not show, so the agent hears it and corrects itself instead of the person finding an error in the panel.

func (*Service) SubmitReview

func (s *Service) SubmitReview(_ context.Context, opts api.SubmitReviewOptions) (api.None, error)

SubmitReview files one review on GitHub: the verdict, the summary body, and every line comment the window has been holding, in a single call. opts.Head is the commit the comments were written against — empty lets GitHub assume its own latest, which is wrong the moment a push landed while the review was open.

This is also the plain Approve: no comments, no body, opts.Event "approve". GitHub refuses an approval of one's own pull request, which the message table turns into a sentence (gherror.go).

func (*Service) ThreadFixes added in v0.79.0

func (s *Service) ThreadFixes(_ context.Context, _ api.None) ([]api.ThreadFix, error)

ThreadFixes is every thread waiting for its fix.

func (*Service) Tree

func (s *Service) Tree(_ context.Context, opts api.PathOptions) (FileListing, error)

Tree lists a directory's files as root-relative, slash-separated paths, sorted. Inside a repository it merges tracked files with untracked-but-not-ignored ones (`ls-files --cached --others --exclude-standard`) and drops any tracked file deleted from disk (`--deleted`), so a file created or removed since the session began shows without a commit; .gitignore is honored for free, so no node_modules and no build output leak in. Anywhere else — a plain folder, a machine without git — it falls back to walking the directory: browsing a project's files is not a git feature, and only the diff panel beside it is.

func (*Service) UpstreamCounts added in v0.89.0

func (s *Service) UpstreamCounts(_ context.Context, opts api.PathOptions) (BaseFreshness, error)

UpstreamCounts counts HEAD against its upstream from the refs on disk, with no fetch: the numbers `git status` prints. A detached HEAD or a branch with no upstream answers zero.

func (*Service) WorktreeAdopted

func (s *Service) WorktreeAdopted(_ context.Context, opts api.PathOptions) (bool, error)

WorktreeAdopted answers worktreeAdopted over RPC.

func (*Service) WorktreeDirty

func (s *Service) WorktreeDirty(_ context.Context, opts api.PathOptions) (bool, error)

WorktreeDirty reports whether the worktree at opts.Path has uncommitted changes (modified or untracked files) — the state that makes a plain remove fail.

type ThreadTally added in v0.78.0

type ThreadTally = api.ThreadTally

type Worktree

type Worktree = api.Worktree

type ZenityPicker

type ZenityPicker struct{}

ZenityPicker opens the OS file chooser through github.com/ncruces/zenity. Only Linux shells out to zenity/qarma; Windows and macOS run the dialog in-process, so there it is a window of lich's own and wears the executable's icon. Cancel maps to ("", nil).

func (ZenityPicker) PickDirectory

func (ZenityPicker) PickDirectory(title string) (string, error)

func (ZenityPicker) PickFile

func (ZenityPicker) PickFile(title string) (string, error)

func (ZenityPicker) PickFiles added in v0.84.0

func (ZenityPicker) PickFiles(title string) ([]string, error)

func (ZenityPicker) PickSaveFile

func (ZenityPicker) PickSaveFile(title, defaultName string) (string, error)

PickSaveFile opens the save dialog. ConfirmOverwrite is the dialog's own guard: the caller writes whatever path comes back, so replacing an existing file is agreed to here or nowhere.

Jump to

Keyboard shortcuts

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