@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
132 lines (131 loc) • 6.45 kB
TypeScript
import type { Json } from "./protocol.js";
import { type ForgeItem } from "../forge/links.js";
/** Where a repository's pull or merge requests live. Phren supports three git
* hosts: GitHub, GitLab and gitboy (self-hosted, any domain). The host is read
* from the remote's URL; a self-hosted GitLab or gitboy is named by an
* override, per remote or per domain, in git config:
*
* git config remote.origin.phrenHost gitlab # this repository's origin
* git config --global phren.git.example.com.host gitboy # every repo on that domain
*
* Each host is a provider with one small interface: list the requests and
* the checked-out branch's own with its checks, and open one. */
export type HostKind = "github" | "gitlab" | "gitboy";
export declare const HOST_KINDS: readonly HostKind[];
export interface HostTerms {
short: string;
long: string;
ref: string;
}
export interface GitHost {
kind: HostKind | null;
/** The product name a link reads ("View on GitLab"), or "the git host". */
name: string;
/** The remote's domain and the repository's web address, when known. */
domain: string | null;
/** Actual token destination (including a configured API port), when resolved. */
apiHost?: string | null;
webUrl: string | null;
remote: string | null;
/** How the kind was found: from the URL, from an override, or not at all. */
source: "url" | "remote-override" | "domain-override" | "none";
terms: HostTerms;
/** False for a provider that is not built yet (GitLab, gitboy). */
supported: boolean;
}
export interface RequestList {
available: boolean;
reason?: string;
message?: string;
pulls: Json[];
current: Json | null;
/** Where the token came from and who it signs in as, when the host says. */
account?: {
source: string;
user?: string;
};
/** The hosted repository the requests were listed from, when the host's tool chose it (see `repository`). */
repository?: string;
}
export interface GitHostProvider {
readonly kind: HostKind;
readonly name: string;
readonly terms: HostTerms;
readonly supported: boolean;
/** Open requests and the checked-out branch's own (any state) with its checks. */
list(root: string, branch: string, host: GitHost): Promise<RequestList>;
/** Open a request from `branch` into the default branch, titled from its commits. */
open(root: string, branch: string, draft: boolean, host: GitHost): Promise<Json>;
/** Merge request `number`, only while its head is still `expectedHeadSha`
* when one is given. The host's own refusal (checks, approvals, conflicts)
* comes back as `{ ok: false, reason: "blocked", message }`. */
merge(root: string, request: MergeRequest, host: GitHost): Promise<Json>;
/** The hosted repository `list` and `merge` act on, as a URL or `domain/owner/repo`, when the host's own
* tool picks it rather than the remote (gh prefers an `upstream` or its `repo set-default`). Without it,
* the remote's `webUrl` is that repository. Null when it cannot be told. */
repository?(root: string, host: GitHost): Promise<string | null>;
/** One pull request or issue by number, now: state, title, and for a pull
* request its checks and mergeability. Throws when the host can't say. */
item?(root: string, kind: "pull" | "issue", number: number, host: GitHost): Promise<ForgeItem>;
/** The newest pull requests (any state) with their head branch and body, for
* finding the ones that name a task. Throws when the host can't say. */
recent?(root: string, host: GitHost): Promise<RecentPull[]>;
/** Who a token signs in as, for Connect; HTTP hosts only. A gitboy agent
* token also reports the agent identity the host attached to it. */
whoami?(root: string, host: GitHost, token: string, api?: string): Promise<{
user: string;
agent?: {
name?: string;
repo_ids?: unknown[];
expires_at?: string;
};
agent_token?: {
name?: string;
repo_ids?: unknown[];
expires_at?: string;
};
}>;
}
export interface RecentPull {
number: number;
url: string;
state: "open" | "merged" | "closed";
head: string;
body: string;
repository?: string;
}
export type MergeMethod = "merge" | "squash" | "rebase";
export interface MergeRequest {
number: number;
method: MergeMethod;
expectedHeadSha?: string;
deleteBranch?: boolean;
/** `domain/owner/repo` checked against the reviewed card: the merge acts there and nowhere else. */
repository?: string;
}
/** `git@host:owner/repo.git`, `ssh://git@host:2222/owner/repo.git`,
* `https://user@host/owner/repo` → the domain and the repository path. */
export declare function parseRemoteUrl(url: string): {
domain: string;
path: string;
} | null;
/** The kind a domain implies on its own: the public hosts by name, a
* self-hosted one when its first label says so (`gitlab.example.com`). */
export declare function kindFromDomain(domain: string): HostKind | null;
/** Which host a repository's remote is on, overrides first. */
export declare function detectHost(root: string, branch: string): Promise<GitHost>;
export declare function hostInfo(kind: HostKind | null, where: Pick<GitHost, "domain" | "webUrl" | "remote" | "source">): GitHost;
export declare function providerFor(host: GitHost): GitHostProvider | null;
/** Why there is no list: an unknown host says how to name it. */
export declare function unknownHost(host: GitHost): RequestList;
/** A check rollup as one word: any failure fails, anything unfinished is
* pending, and only finished successes (or skips) pass. No checks is null. */
export declare function checkRollup(items: unknown): "passing" | "failing" | "pending" | null;
/** Each check as clients list it: a name, the workflow that ran it, one state
* word and its page. Check runs and commit statuses read alike; failing
* first, then pending, then the rest, at most 100. */
export declare function checkRuns(items: unknown): Json[];
/** gh never prompts, never nags about updates, and talks to the remote's own
* domain (a GitHub Enterprise server as much as the public one). */
export declare function ghEnv(host: Pick<GitHost, "domain">): NodeJS.ProcessEnv;
export declare const PROVIDERS: Record<HostKind, GitHostProvider>;