import { GitHubActor, PullRequestCheck, PullRequestChecks, PullRequestSnapshot } from "../../github/common/githubPullRequestService.js"; import type { URI as ProtocolURI } from "./state/sessionState.js"; export declare const AgentMergeConfigKey: { readonly Enabled: "agentMerge.enabled"; readonly AddressReviews: "agentMerge.addressReviews"; readonly FixCI: "agentMerge.fixCI"; readonly ResolveConflicts: "agentMerge.resolveConflicts"; readonly MergePullRequest: "agentMerge.mergePullRequest"; readonly MergeMethod: "agentMerge.mergeMethod"; readonly ReplyAttribution: "agentMerge.replyAttribution"; }; export declare const AgentMergeSettingId: { readonly Enabled: "chat.agentMerge.enabled"; readonly AddressReviews: "chat.agentMerge.addressReviews"; readonly FixCI: "chat.agentMerge.fixCI"; readonly ResolveConflicts: "chat.agentMerge.resolveConflicts"; readonly MergePullRequest: "chat.agentMerge.mergePullRequest"; readonly MergeMethod: "chat.agentMerge.mergeMethod"; readonly ReplyAttribution: "chat.agentMerge.replyAttribution"; }; /** * Settings-editor tag carried by every Agent Merge setting, so the UI can open * settings filtered to exactly this group with `@tag:agentMerge`. */ export declare const AGENT_MERGE_SETTING_TAG = "agentMerge"; /** * Work the agent itself can be asked to perform. Merging is deliberately absent: * it is executed by the host, never delegated to a model. */ export type AgentMergeRepairAction = "addressReviews" | "fixCI" | "resolveConflicts"; /** A user-authorizable Agent Merge action, including the host-executed merge. */ export type AgentMergeAction = AgentMergeRepairAction | "mergePullRequest"; export type AgentMergeMethod = "auto" | "squash" | "merge" | "rebase"; /** * When Agent Merge may merge the pull request once it is ready. * * `ifUnchanged` is self-demoting rather than evaluated at merge time: the * moment a repair turn lands a commit the session's value is rewritten to * `never`, so the chosen value always reflects what will actually happen. * Re-selecting `ifUnchanged` starts a fresh baseline from that point. */ export type AgentMergeMergePullRequest = "always" | "ifUnchanged" | "never"; export declare const agentMergeMergePullRequestValues: readonly AgentMergeMergePullRequest[]; export interface AgentMergeActions { readonly addressReviews: boolean; readonly fixCI: boolean; readonly resolveConflicts: boolean; readonly mergePullRequest: AgentMergeMergePullRequest; } export interface AgentMergeConfiguration extends AgentMergeActions { readonly mergeMethod: AgentMergeMethod; readonly replyAttribution: boolean; } export interface AgentMergeSessionOverrides { readonly addressReviews?: boolean; readonly fixCI?: boolean; readonly resolveConflicts?: boolean; readonly mergePullRequest?: AgentMergeMergePullRequest; } export interface AgentMergeTarget { readonly branchName: string; readonly pullRequestUrl?: string; readonly enabledAt: string; readonly commentWatermark: string; } export interface AgentMergeReviewThreadContext { readonly id: string; readonly path?: string; readonly line?: number; /** Authorized comments in the thread, oldest first, so later follow-ups are visible. */ readonly comments: readonly AgentMergeFeedbackComment[]; } export interface AgentMergeFeedbackComment { readonly author?: string; readonly body: string; } export interface AgentMergeInjectedConfiguration { readonly previous: Readonly>; readonly applied: Readonly>; } export interface AgentMergeSessionState { readonly enabled: boolean; readonly overrides?: AgentMergeSessionOverrides; readonly chat?: ProtocolURI; /** See {@link AgentMergeFolderSessionState.readyIgnoredChecks}. */ readonly readyIgnoredChecks?: readonly string[]; readonly target?: AgentMergeTarget; readonly injectedConfiguration?: AgentMergeInjectedConfiguration; readonly lastPromptFingerprint?: string; readonly lastPromptAt?: string; readonly repeatedPromptCount?: number; readonly totalPromptCount?: number; /** Pull request head when the most recent repair turn started; a different head afterwards counts as progress. */ readonly lastPromptHeadSha?: string; /** Blockers the most recent repair turn was asked to fix; resolving any of them counts as progress. */ readonly lastPromptBlockers?: readonly string[]; /** Repair turns since Agent Merge was enabled. Unlike the other counters, progress never resets it. */ readonly lifetimePromptCount?: number; /** * Local worktree commit observed when the most recent repair turn started. * A different local commit afterwards means that turn produced work, which * is what demotes an `ifUnchanged` session to `never`. * * Deliberately the local commit rather than the pull request's published * head: GitHub reports a push only after some replication delay, and a turn * ends by evaluating immediately, so a published comparison would routinely * read a stale head and merge changes it should have held back. */ readonly repairBaseCommit?: string; } export interface AgentMergeControllerState { readonly target?: AgentMergeTarget; readonly injectedConfiguration?: AgentMergeInjectedConfiguration; readonly lastPromptFingerprint?: string; readonly lastPromptAt?: string; readonly repeatedPromptCount?: number; readonly totalPromptCount?: number; readonly lastPromptHeadSha?: string; readonly lastPromptBlockers?: readonly string[]; readonly lifetimePromptCount?: number; readonly repairBaseCommit?: string; } /** The user-owned Agent Merge settings of one folder: whether it runs, its overrides, and the chat that turned it on. */ export interface AgentMergeFolderSessionState { readonly enabled: boolean; readonly overrides?: AgentMergeSessionOverrides; readonly chat?: ProtocolURI; /** * The folder's workspace value of * `chat.artifactIntegrations.githubPullRequests.autoMarkReadyIgnoredChecks`: * check name patterns that need not pass before the pull request counts as * ready for review. When absent, the user's value mirrored to the host applies. */ readonly readyIgnoredChecks?: readonly string[]; } /** The host-owned Agent Merge lifecycle state of one folder. */ export type AgentMergeFolderControllerState = Omit; /** A folder's complete Agent Merge state, with the session-wide elevated configuration. */ export interface AgentMergeFolderState extends AgentMergeFolderSessionState, AgentMergeFolderControllerState { readonly injectedConfiguration?: AgentMergeInjectedConfiguration; } export type AgentMergeRequiredChecks = { readonly kind: "ready"; readonly failed: readonly PullRequestCheck[]; readonly pending: boolean; } | { readonly kind: "indeterminate"; readonly reason: string; }; export declare const agentMergeRootConfigSchema: import("./agentHostSchema.js").ISchema<{ "agentMerge.enabled": import("./agentHostSchema.js").ISchemaProperty; "agentMerge.addressReviews": import("./agentHostSchema.js").ISchemaProperty; "agentMerge.fixCI": import("./agentHostSchema.js").ISchemaProperty; "agentMerge.resolveConflicts": import("./agentHostSchema.js").ISchemaProperty; "agentMerge.mergePullRequest": import("./agentHostSchema.js").ISchemaProperty; "agentMerge.mergeMethod": import("./agentHostSchema.js").ISchemaProperty; "agentMerge.replyAttribution": import("./agentHostSchema.js").ISchemaProperty; }>; export declare const defaultAgentMergeConfiguration: AgentMergeConfiguration; export type AgentMergeGateResult = { readonly kind: "indeterminate"; readonly reason: string; readonly cause: string; } | { readonly kind: "terminal"; } | { readonly kind: "noWork"; readonly waitingOnChecks: boolean; readonly fingerprint: string; } | { readonly kind: "prompt"; readonly actions: readonly AgentMergeRepairAction[]; readonly fingerprint: string; readonly context: AgentMergePromptContext; } | { readonly kind: "merge"; readonly fingerprint: string; }; export interface AgentMergePromptContext { readonly pullRequestUrl: string; readonly title: string; readonly headSha: string; readonly baseRef: string; readonly headRef: string; readonly reviewThreads: readonly AgentMergeReviewThreadContext[]; readonly reviewSummaries: readonly AgentMergeFeedbackComment[]; readonly newComments: readonly AgentMergeFeedbackComment[]; readonly failedChecks: readonly string[]; readonly behind: boolean; readonly conflicting: boolean; readonly commentWatermark: string; } export declare function resolveAgentMergeConfiguration(defaults: AgentMergeConfiguration, overrides: AgentMergeSessionOverrides | undefined): AgentMergeConfiguration; /** * Maps the configured merge method onto a method the repository actually * allows. `auto` prefers squash, then a merge commit, then rebase; an * explicitly configured method is only used when the repository permits it. */ export declare function resolveMergeMethod(configured: AgentMergeMethod, allowed: readonly ("MERGE" | "SQUASH" | "REBASE")[]): "MERGE" | "SQUASH" | "REBASE" | undefined; /** * Why Agent Merge stopped monitoring a session. Keeping both strings together * lets the controller log a stable English detail while the transcript shows a * localized sentence, without either drifting from the other. */ export interface AgentMergeDisableReason { /** Stable English detail appended to the host log line. */ readonly log: string; /** Localized sentence shown to the user in the session transcript. */ readonly notice: string; } /** Every reason the Agent Merge controller can stop monitoring a session on its own. */ export declare const agentMergeDisableReasons: { readonly sessionArchived: () => AgentMergeDisableReason; readonly branchChanged: (from: string, to: string) => AgentMergeDisableReason; readonly branchUnavailable: (expected: string) => AgentMergeDisableReason; readonly differentPullRequest: () => AgentMergeDisableReason; readonly invalidPullRequestUrl: () => AgentMergeDisableReason; readonly differentGitHubHost: () => AgentMergeDisableReason; readonly indeterminate: (minutes: number, reason: string) => AgentMergeDisableReason; readonly pullRequestClosed: () => AgentMergeDisableReason; readonly pullRequestAlreadyMerged: (pullRequestNumber: number, pullRequestUrl: string) => AgentMergeDisableReason; readonly folderWithoutChat: () => AgentMergeDisableReason; readonly repairBudgetExhausted: () => AgentMergeDisableReason; readonly repairWithoutProgress: (attempts: number) => AgentMergeDisableReason; readonly repairLimitReached: (attempts: number) => AgentMergeDisableReason; readonly pendingReviewReply: () => AgentMergeDisableReason; readonly pullRequestMerged: (pullRequestNumber: number, pullRequestUrl: string) => AgentMergeDisableReason; }; /** The transcript notice shown once Agent Merge starts watching a branch. */ export declare function agentMergeEnabledNotice(target: Pick, configuration: AgentMergeConfiguration): string; /** * Whether a configuration change was made for one session alone, or to the * defaults every session follows. */ export type AgentMergeConfigurationChangeScope = "session" | "global"; /** * The transcript notice shown when effective Agent Merge behavior changes. The * scope is named up front because the same change reads very differently * depending on whether it was made for this session or for all of them. */ export declare function agentMergeConfigurationChangedNotice(previous: AgentMergeConfiguration, current: AgentMergeConfiguration, scope: AgentMergeConfigurationChangeScope): string | undefined; /** Keeps the effective merge policy visible in collapsed notices and tool results. */ export declare function agentMergeMergeBehaviorSummary(mergePullRequest: AgentMergeMergePullRequest): string; /** The transcript notice shown when the user, rather than the controller, disables Agent Merge. */ export declare function agentMergeDisabledNotice(): string; /** * The transcript notice shown when Agent Merge stops merging automatically * because its own repair work changed the pull request. */ export declare function agentMergeMergePullRequestDemotedNotice(): string; /** * The transcript notice shown when a chat that runs Agent Merge moves into a * session where another chat already runs it for the same pull request. */ export declare function agentMergeMoveConflictNotice(): string; /** * The transcript notice shown when GitHub refuses Agent Merge's credential for * an organization that enforces SAML single sign-on. * * @param authorizationUrl The GitHub page that authorizes the refused * credential for the organization, which the notice links to. */ export declare function agentMergeSingleSignOnNotice(organization: string, authorizationUrl: string | undefined): string; /** * The transcript notice shown when Agent Merge has waited a while without * finding a pull request for the branch it monitors. */ export declare function agentMergeMissingPullRequestNotice(branchName: string): string; export declare function readAgentMergeSessionState(values: Record | undefined, sessionFolderKey?: string): AgentMergeSessionState | undefined; /** Reads the session-wide elevated configuration, falling back to where earlier versions stored it. */ export declare function readAgentMergeInjectedConfiguration(values: Record | undefined): AgentMergeInjectedConfiguration | undefined; /** * Reads the Agent Merge state of each folder, keyed by working-directory key. * Settings written by earlier versions describe the session folder * (`sessionFolderKey`), and take precedence while they are present. */ export declare function readAgentMergeFolderStates(values: Record | undefined, sessionFolderKey: string | undefined): ReadonlyMap; /** Reads the Agent Merge state of one folder; see {@link readAgentMergeFolderStates}. */ export declare function readAgentMergeFolderState(values: Record | undefined, folderKey: string | undefined, sessionFolderKey: string | undefined): AgentMergeFolderState | undefined; /** Whether Agent Merge is on for any folder of a session. */ export declare function isAnyAgentMergeEnabled(values: Record | undefined, sessionFolderKey: string | undefined): boolean; /** * Returns the session config patch that replaces one folder's Agent Merge * state (or removes it when `state` is `undefined`). Writing the session folder * also clears the settings of earlier versions. */ export declare function withAgentMergeFolderState(values: Record | undefined, folderKey: string, sessionFolderKey: string | undefined, state: AgentMergeFolderState | undefined): Record; /** * Returns the session config patch that replaces only the host-owned lifecycle * state of one folder (or clears it when `controller` is `undefined`). The * folder's user-owned settings are rewritten from `values` as they are, so a * lifecycle update computed from an older read never reverts them. */ export declare function withAgentMergeFolderControllerState(values: Record | undefined, folderKey: string, sessionFolderKey: string | undefined, controller: AgentMergeFolderControllerState | undefined): Record; /** * Applies a client's write of the per-folder settings on top of the current * ones, entry by entry. A client sends only the folders it changes, so the * other folders' settings, including changes the host made meanwhile, stay as * they are. A client sends each folder's working directory, as it cannot * derive the host's keys, so keys are derived here. An entry for a folder * that is not one of the session's is dropped, and so is a `chat` that is not * one of the session's chats. */ export declare function mergeClientAgentMergeFolders(values: Record | undefined, clientFolders: unknown, isSessionFolder: (folderKey: string) => boolean, isSessionChat: (chat: ProtocolURI) => boolean): Record; /** Returns `values` with the per-folder Agent Merge maps keyed by `toKey` of each key. */ export declare function rekeyAgentMergeFolders(values: Record | undefined, toKey: (key: string) => string): Record | undefined; /** Whether a folder has host-owned lifecycle state, such as a captured target or repair counters. */ export declare function hasAgentMergeFolderControllerState(state: AgentMergeFolderState): boolean; /** Returns the session config patch that sets or clears the session-wide elevated configuration. */ /** * The elevation Agent Merge applied to each chat it runs in, keyed by chat: * the chat's own values before elevation (`previous`; a missing key means the * chat had no value of its own) and the values it applied (`applied`). * Host-owned session state, like the folder lifecycle. */ export declare function readAgentMergeChatInjectedConfigurations(values: Readonly> | undefined): ReadonlyMap; /** Whether Agent Merge's elevation is applied in a session: to a chat, or session-wide by an older build. */ export declare function hasAgentMergeElevation(values: Readonly> | undefined): boolean; /** A session config patch that records (or, with `undefined`, removes) one chat's elevation. */ export declare function withAgentMergeChatInjectedConfiguration(values: Readonly> | undefined, chat: ProtocolURI, injectedConfiguration: AgentMergeInjectedConfiguration | undefined): Record; export declare function withAgentMergeInjectedConfiguration(injectedConfiguration: AgentMergeInjectedConfiguration | undefined): Record; /** * Returns session config values with Agent Merge injected overrides removed, * so callers can read the user's own picker selections while merge is active. */ export declare function getNonMergeSessionConfigValues(values: Readonly> | undefined): Readonly>; /** Values with the elevation Agent Merge applied over them undone; a missing previous value means there was none. */ export declare function withoutAgentMergeElevation(values: Readonly>, injected: AgentMergeInjectedConfiguration | undefined): Readonly>; export declare function isAgentMergeFeedbackAuthor(actor: GitHubActor | undefined): boolean; /** * Recorded as the repair baseline when the session worktree cannot be read. * No git object id can equal it, so a session that reached this state always * counts as changed — see {@link shouldStopMergingAfterAgentChanges}. */ export declare const AGENT_MERGE_UNKNOWN_COMMIT = "unknown"; /** * Whether a session that only authorized merging while the pull request is * unchanged must stop merging automatically, because a repair turn produced * work since it started. * * Compares local worktree commits, not the pull request's published head: the * commit exists locally the moment the agent makes it, whereas GitHub reports * it only after a replication delay that a turn-completion check would race. * * Fails closed. Once a repair turn has run, a commit that cannot be resolved * counts as a change: a missed automatic merge is cheap, whereas merging * agent-written changes the user wanted to review first is not. * * Callers rewrite the chosen value to `never` rather than gating on this, so * the value always reflects what will actually happen. Clearing * {@link AgentMergeSessionState.repairBaseCommit} at the same time is what lets * a later re-selection start from a fresh baseline. */ export declare function shouldStopMergingAfterAgentChanges(configuration: AgentMergeConfiguration, agentMerge: AgentMergeSessionState, currentCommit: string | undefined): boolean; export declare function isAgentMergeMergePullRequest(value: unknown): value is AgentMergeMergePullRequest; export declare function evaluateAgentMerge(snapshot: PullRequestSnapshot, configuration: AgentMergeConfiguration, commentWatermark: string, deferredCheckIds?: ReadonlySet): AgentMergeGateResult; /** Fragments the gate must be able to read before it can decide anything. */ export declare const agentMergeGateFragments: readonly [ "core", "topLevelComments", "submittedReviews", "reviewThreads", "checks", "mergeability" ]; /** * Returns whether a draft pull request has no pending or failed required checks * and no actionable review feedback, or `undefined` while that state is incomplete. * * @param ignoredChecks Check name patterns that need not pass, from * `chat.artifactIntegrations.githubPullRequests.autoMarkReadyIgnoredChecks`. */ export declare function isAgentMergePullRequestReadyForReview(snapshot: PullRequestSnapshot, commentWatermark: string, ignoredChecks?: readonly string[]): boolean | undefined; /** * Classifies the checks Agent Merge acts on, as every pull request surface * does (see {@link classifyRequiredPullRequestChecks}): the required checks, * and the checks an unfinished required check waits for. Like Fix CI, it * repairs a failed check suite that reported no check run, such as a workflow * that failed to start. When every check counts but GitHub refused to list the * check suites, the checks stay pending, since a suite that has not reported * may still fail; the known failures are repaired all the same. * * @param ignoredChecks Check name patterns to leave out, as when deciding * whether a draft is ready for review. */ export declare function classifyAgentMergeRequiredChecks(checks: PullRequestChecks, ignoredChecks?: readonly string[]): AgentMergeRequiredChecks; /** * The blockers a repair turn is asked to fix, as stable keys that survive a * new head or a workflow rerun, so a later evaluation can tell whether the * turn made progress; see {@link hasAgentMergeRepairProgress}. */ export declare function getAgentMergeRepairBlockers(actions: readonly AgentMergeRepairAction[], context: AgentMergePromptContext): string[]; /** * Whether the pull request moved forward since the most recent repair turn * started: its head changed, or one of the blockers that turn was asked to * fix is now resolved. A failed check only counts as resolved once a check of * the same name passes, not merely because a new head has not reported it yet. * * Expects a snapshot that {@link evaluateAgentMerge} could evaluate. */ export declare function hasAgentMergeRepairProgress(snapshot: PullRequestSnapshot, commentWatermark: string, previous: { readonly headSha?: string; readonly blockers?: readonly string[]; }): boolean;