@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
95 lines (94 loc) • 4.54 kB
TypeScript
import type { Json } from "./protocol.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;
};
}
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>;
/** Who a token signs in as, for Connect; HTTP hosts only. */
whoami?(root: string, host: GitHost, token: string, api?: string): Promise<{
user: string;
}>;
}
export type MergeMethod = "merge" | "squash" | "rebase";
export interface MergeRequest {
number: number;
method: MergeMethod;
expectedHeadSha?: string;
deleteBranch?: boolean;
}
/** `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[];
export declare const PROVIDERS: Record<HostKind, GitHostProvider>;