{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package taskgit\n\nPackage taskgit owns the git plumbing an autonomous run needs, deterministically.\n\nThe division of labour is the point: the model decides WHAT should change; this package decides where that happens and how it is recorded. No model output reaches a git command here. Unattended \\`git\\` driven by generated text is where autonomous coding goes wrong, and the failure is silent — a wrong branch, a lost commit, a dirty checkout someone else was using.\n\nMilestone 4 covers isolation and revisions. Branch, commit, push and PR are milestone 5 and deliberately absent.\n\n## Constants\n\n```go\nconst DefaultRemote = \"origin\"\n```\nDefaultRemote is where an autonomous branch is published.\n\n## Functions\n\n```go\nfunc BaseMoved(ctx context.Context, repo, remote, defaultBranch, base string) bool\n```\nBaseMoved reports whether the remote default branch has advanced past the commit this run was based on. Informational: drift alone is normal and fine, and only a CONFLICT is a problem.\n\n```go\nfunc BranchName(pattern, taskName, runID string, now time.Time) string\n```\nBranchName renders a run's branch from the task's pattern. {name} and {date} are substituted; {run} disambiguates two runs of one task on one day, so a retry never collides with the run it is retrying.\n\n```go\nfunc Commit(ctx context.Context, w Worktree, message string) (sha string, created bool, err error)\n```\nCommit records the staged work and returns the new commit.\n\nIdempotent: a worktree already advanced past its base with nothing left staged has been committed by a previous attempt, and that commit is returned rather than a second empty one being made.\n\n```go\nfunc CommitMessage(p Provenance) string\n```\nCommitMessage renders a deterministic commit message. Derived from the task, never from model output: a commit subject generated per-run drifts in style and can carry whatever the model felt like saying, and the one thing this message must do is identify what made the change.\n\n```go\nfunc DefaultBranch(ctx context.Context, repo, remote string) string\n```\nDefaultBranch resolves the remote's default branch, falling back through the conventional names. Used to refuse publishing onto it and as the PR base.\n\n```go\nfunc Fetch(ctx context.Context, repo, remote string) error\n```\nFetch updates remote-tracking refs so drift and conflict checks see the current state of the remote rather than a stale local view.\n\n```go\nfunc FindPR(ctx context.Context, dir, branch string) (number int, url string, found bool)\n```\nFindPR returns an existing open pull request for a branch.\n\nThis is what makes PR creation idempotent. A retry, a restart, or a second attempt inside one run must find the pull request the previous attempt opened instead of opening a duplicate — duplicates are noise a human then has to clean up, and they make the run record ambiguous about which one is real.\n\n```go\nfunc HeadRevision(ctx context.Context, dir string) (string, error)\n```\nHeadRevision resolves the repository's current commit.\n\n```go\nfunc IsRepo(ctx context.Context, dir string) bool\n```\nIsRepo reports whether dir is inside a git working tree.\n\n```go\nfunc MergeConflicts(ctx context.Context, repo, remote, defaultBranch, head string) (conflicts bool, ok bool)\n```\nMergeConflicts reports whether merging head into the remote's default branch would conflict — i.e. whether the base moved under the run in a way that makes the change unmergeable.\n\nIt NEVER rebases or rewrites anything. Rewriting history under an unattended run is how work disappears; the honest response to drift is to say so and let a human decide. ok=false means the check could not be made (an old git), and the caller treats that as \"no conflict detected\" rather than blocking.\n\n```go\nfunc OpenPR(ctx context.Context, dir, branch, base, title, body string) (number int, url string, created bool, err error)\n```\nOpenPR creates a pull request, or returns the one already open for the branch.\n\n```go\nfunc PRBody(p Provenance) string\n```\nPRBody renders the pull request body.\n\nProvenance is carried automatically so an autonomous change is auditable from GitHub alone — what made it, which revision of the task, what it was based on, and what was actually verified. Someone reviewing this should not have to open memcode's local database to find out where it came from.\n\n```go\nfunc PRTitle(p Provenance) string\n```\nPRTitle renders the pull request title.\n\n```go\nfunc Prune(ctx context.Context, repo string) error\n```\nPrune clears worktree registrations whose directories are gone.\n\n```go\nfunc Push(ctx context.Context, w Worktree, remote, commit string, ownedByRun bool) (created bool, err error)\n```\nPush publishes the run's branch. NEW BRANCHES ONLY.\n\nThree refusals, in order of how bad they would be:\n\n  - never the default branch, or the conventional names for it\n  - never a remote branch this run did not create\n  - never a force update of anything\n\nAn existing remote branch whose tip is already our commit is a completed previous attempt, and succeeds without doing anything.\n\n```go\nfunc RemoteBranchExists(ctx context.Context, repo, remote, branch string) (bool, error)\n```\nRemoteBranchExists reports whether the remote already has this branch.\n\n```go\nfunc RemoteExists(ctx context.Context, repo, remote string) bool\n```\nRemoteExists reports whether the repository has a remote by this name. A repo with no remote is a normal local repo, not a broken one: a task there commits its work and stops, rather than failing every run over a setup fact.\n\n```go\nfunc Remove(ctx context.Context, w Worktree) error\n```\nRemove deletes the worktree and its branch.\n\nCalled only for runs whose result nobody needs to look at. A failed or needs-attention run KEEPS its worktree: that checkout is the evidence, and deleting it to stay tidy destroys the thing a human is about to ask for.\n\n```go\nfunc Stage(ctx context.Context, w Worktree) (bool, error)\n```\nStage adds the run's work to the index. Returns whether anything was staged.\n\n```go\nfunc WorktreeRoot(repo string) string\n```\nWorktreeRoot is where run worktrees live: inside the repo's own .memcode, so they are ignored by git, obviously disposable, and easy to find when a failed run needs inspecting.\n\n## Types\n\n```go\ntype ErrBranchNotOurs struct{ Branch, Remote string }\n```\nErrBranchNotOurs means the remote branch exists and this run did not create it. Refusing is the whole point: an autonomous push must never land on a branch a human is using, and a name collision is indistinguishable from one.\n\n```go\nfunc (e ErrBranchNotOurs) Error() string\n```\n\n```go\ntype ErrPRUnsupported struct{ Reason string }\n```\nErrPRUnsupported means a pull request cannot be opened HERE — gh is missing, not signed in, or the remote is not a GitHub host.\n\nThis is deliberately distinct from a PR that failed to open. The work is already pushed and reachable either way, and a repository that simply is not on GitHub should not make every run of every task report a problem. It is reported plainly on the run instead.\n\n```go\nfunc (e ErrPRUnsupported) Error() string\n```\n\n```go\ntype Provenance struct {\n\tTask         string\n\tRunID        string\n\tTaskRevision string\n\tBase         string\n\tOccurrence   string\n\tVerification string\n\tDescription  string\n}\n```\nProvenance is what an autonomous change must say about itself.\n\n```go\ntype Publication struct {\n\tRemote        string\n\tBranch        string\n\tCommit        string\n\tPRNumber      int\n\tPRURL         string\n\tCreatedBranch bool\n\tCreatedCommit bool\n\tCreatedPR     bool\n}\n```\nPublication is what a run left behind, and who created it. The \"created\" flags matter for idempotency: reusing something is not the same as making it, and a retry must be able to tell.\n\n```go\ntype Worktree struct {\n\t// Path is the checkout the run works in. Never the user's own.\n\tPath string\n\t// Branch is the ref created for this run.\n\tBranch string\n\t// Base is the commit the worktree was created from, resolved at EXECUTION\n\t// time. A Monday occurrence recovered on Wednesday builds on Wednesday's\n\t// HEAD, and recording it is what keeps that honest rather than implying the\n\t// repository was frozen at the occurrence.\n\tBase string\n\t// Repo is the repository the worktree belongs to.\n\tRepo string\n}\n```\nWorktree is an isolated checkout a run executes in.\n\n```go\nfunc Create(ctx context.Context, repo, branch string) (Worktree, error)\n```\nCreate makes a fresh worktree on a new branch off current HEAD.\n\nA mutating run NEVER executes in the user's active checkout. Isolation is not politeness: an unattended process editing the tree someone is working in can destroy uncommitted work, and a failed run would leave that tree wrecked with no obvious cause.\n\n```go\nfunc (w Worktree) Changed(ctx context.Context) (bool, error)\n```\nChanged reports whether the run produced anything at all: a new commit, or uncommitted edits. This is a FACT about the repository, not a claim from the agent, and it is what separates a no\\_change outcome from a success.\n\n```go\nfunc (w Worktree) Dirty(ctx context.Context) (bool, error)\n```\nDirty reports whether the worktree has uncommitted changes, which is how a run that edited files but committed nothing is still recognised as having done something.\n\n```go\nfunc (w Worktree) Revision(ctx context.Context) (string, error)\n```\nRevision resolves the worktree's current commit — the same as Base when the run committed nothing.\n\n","path":"github.com/memcode-ai/memcode/internal/taskgit","name":"taskgit","synopsis":"Package taskgit owns the git plumbing an autonomous run needs, deterministically.","isRedistributable":true}
