/** * The git workflows behind /commit, /push, /merge and /pr. Each is a short conversation: gather * what git knows, draft with the model where that helps, show it, and only then change anything. * * Rules every flow keeps: * - git is run with argument arrays (run.ts), never through a shell. * - nothing is forced: no force-push, no --no-verify, no hard reset. Hooks run as usual. * - anything that publishes or merges asks first; a message you typed yourself is not asked twice. * - a failure shows git's own output and leaves the repository as git left it. * * Every command also reports what it did, with a fresh repository status, through `Env.report`, so * the model can be told on its next turn (index.ts sends it). A report is made exactly once whenever * a command ran, whether it finished, failed, was cancelled, found nothing to do or threw. Reports * hold text written here, plus at most one short quoted line of tool output, labelled untrusted: * hook, remote and forge output is never passed on in full. * * The UI and the model arrive through `Env`, so the flows are tested against real temporary * repositories with scripted answers. */ import { type RepoStatus } from "./repo.ts"; import { type RunResult } from "./run.ts"; export type Level = "info" | "warning" | "error"; export interface Ui { notify(message: string, level?: Level): void; confirm(title: string, message: string): Promise; select(title: string, options: string[]): Promise; editor(title: string, prefill?: string): Promise; } export type GitCommand = "commit" | "push" | "merge" | "pr"; /** How a command ended: it did its job, had nothing to do, was cancelled, was refused, or failed. */ export type OutcomeKind = "done" | "nothing" | "cancelled" | "blocked" | "failed"; export interface Outcome { kind: OutcomeKind; /** What happened, in one line written by this code, starting lower case ("committed a7420ed ..."). */ text: string; /** The one line of a failed tool's output worth showing (see `keyLine`); untrusted. */ output?: string; sha?: string; url?: string; } /** What the model is told after a command: plain text, plus the same facts as data. */ export interface Report { command: GitCommand; content: string; details: { command: GitCommand; outcome: OutcomeKind; summary: string; /** One line of tool output, at most 200 characters; untrusted. */ output?: string; sha?: string; url?: string; /** The repository right after the command; undefined when it could not be read. */ repo?: RepoStatus & { clean: boolean; }; }; } export interface Env { cwd: string; ui: Ui; /** Pass a command's result on to the model (it is not shown to the user). */ report(report: Report): void; /** Ask the model for text; undefined when there is no model or the call failed. */ draft(prompt: { system: string; user: string; }): Promise; } /** Typed or commit-derived text for a report: one line, at most 120 characters. */ export declare function clip(text: string, max?: number): string; /** * The one line of a failed tool's output worth passing on. Hooks, linters and git put the line that * says what is wrong last, so this takes the last line that looks like an error, else the last * line. A rejection line from git push ("! [rejected] ..." or "[remote rejected] ...") wins over * other lines, and git's generic "error: failed to push some refs" trailer only counts when * nothing else matches. Credentials are masked. Single line, and at most 200 characters once * quotes are escaped. */ export declare function keyLine(r: RunResult): string; /** The repository in one line, for a report. */ export declare function describeState(st: RepoStatus): string; /** One line per fact, for /git status. */ export declare function describeStatus(st: RepoStatus): string; export declare function showStatus(env: Env): Promise; export declare function commit(env: Env, args: string): Promise; /** Push the current branch. Returns false when it did not happen (the reason is already shown). */ export declare function push(env: Env, opts?: { confirmed?: boolean; }): Promise; export declare function merge(env: Env, args: string): Promise; export declare function pullRequest(env: Env, args: string): Promise;