Expand description
GitHub tokens for an agent’s git and gh.
git-credential <get|store|erase>: git’s credential helper protocol. srv puts it in the environment of an agent whose person connected GitHub through AgentMux Cloud (credential.https://github.com.helper), after an empty helper that clears the list, so no other helper’s login (the person’s, a stored token) is ever asked. Forgetit asks srv for the AgentMux GitHub App’s token for the repository in the request’s path;storeanderasedo nothing, so a token is never written down.github-token -- <gh args>: what theghshell function this wrapper exports calls (shim_functions.rs). It finds the repository the command is about (-R,GH_REPO, the path ofgh api repos/o/r/…, else the working directory’sorigin) and prints a token for it, or prints nothing and says why on stderr. The function then runsghwith that token, or with none: never with another credential.
Both ask POST /api/v1/github/token; who is asking is decided by srv from the agent’s token
(AGENTMUX_AGENT_TOKEN), and the answer is the narrowed installation token or a sentence for
the person. The token is never logged here.
Structs§
- Granted
- What
POST /api/v1/github/tokengranted: the token, who the App’s bot is, and who the agent works for (the account’s own GitHub id and login).
Enums§
- Answer
- The answer of
POST /api/v1/github/token: a token, or what to tell the person.
Constants§
- ASK_
TIMEOUT 🔒 - srv may call AgentMux Cloud twice (a revalidation, then the mint), or wait on the host’s
gh-agentfor a fresh token (up to 50 s,identity::gh_agent_token), and then says why it has none: this waits a little longer than that, so the answer reaches the command. A stuck call still must not hold agit pushforever. - NO_
REPOSITORY 🔒 - What a command that acts on a repository, and found none, is told: where the repository comes from.
- PURPOSE_
GIT 🔒 - What git’s credential helper says the token is for: a push. srv gives a container a token that writes contents only to this ask, and never believes it for more than that.
Functions§
- acts_
on_ 🔒a_ repository - Whether a
ghcommand is one that acts on a repository (a pull request, an issue, a run, a release, an API call…), so a repository it does not name and the working directory does not give leaves it with no token.gh --version,gh auth status,gh searchand the like need none. - ask
- Ask srv for the token a
ghcommand uses forowner/repo. - ask_for
- Ask srv for a token for
owner/repo;purposesays what it is for (gitfrom the credential helper). - credential_
response - What git is told when srv gave a token.
- default_
repo_ source - The repository
ghitself would act on, as a remote’s URL or anOWNER/REPO: the one it was told (gh repo set-default, a cloned fork’s parent), elseorigin’s.cwdis wheregit -Cpoints. - field 🔒
- owner_
repo_ of_ path - The repository named by a git credential request’s
path:owner/repoorowner/repo.git. - owner_
tag - What marks a PR as the work of a person’s agent: the id of the GitHub account it works for.
- parse_
request key=valuelines up to a blank line, as git writes them.- positional_
repo 🔒 - The repository
gh repo <verb> OWNER/REPOis about, when it takes one as an argument. - read_
body_ 🔒file - The text of a PR body file, if it is small enough to go on a command line.
- repo_
of_ 🔒command_ here - The repository a
ghcommand is about, forrun_github_tokenandrun_github_owner_tag. - repo_
of_ default - The repository for what
default_repo_sourcefound: a remote’s URL, or anOWNER/REPOset withgh repo set-default. - repo_
of_ gh_ command - The repository
ghis about to act on, from its arguments and environment, else from the working directory’sorigin.Nonewhen the command names no repository (e.g.gh --version). - repo_
of_ remote owner/repoof a GitHub remote URL (https, scp-style ssh or ssh://), for github.com only.- repo_
of_ spec [HOST/]OWNER/REPO; a host other than github.com is not ours.- resolved_
default - What
ghtakes as the default repository, from the lines ofgit config --get-regexp '^remote\..*\.gh-resolved$'(gh repo set-default, and a fork cloned withgh repo clone):Ok(OWNER/REPO)as set,Err(remote)for “the repository of that remote”. - rewrite_
pr_ body gh pr create/gh pr editarguments withtagadded to the PR’s body:--body/-btext, or a--body-file/-Ffile, whose text (read byread_file) becomes the--body(stdin can’t be read twice, and a file too big to pass stays as it is). Arguments that give no body (--fill, a prompt) are left alone.- run_
git_ credential git-credential <op>: git’s helper protocol. Exit code 0 with the credential on stdout, or 1.- run_
github_ owner_ tag github-owner-tag -- <gh args>: the arguments of agh pr createorgh pr editwith the owner tag in its body, each followed by a NUL byte, for theghfunction to runghwith. The arguments unchanged when there is no owner to name or no body to put it in.- run_
github_ token github-token -- <gh args>: print a token for the repository theghcommand is about; with none, say why on stderr (when there is a repository, or the command needed one) and print nothing.- url_
repo 🔒 - The repository of a
https://github.com/OWNER/REPO/…argument (gh pr view <url>). - with_
tag 🔒