# Proposal operations

AI agent getting started? Read [Agents: start here](https://docs.openeng.io/agents/start-here.md) first.

Submit, approve, merge and dispose through the API.

Source: https://docs.openeng.io/developers/proposal-operations/

Use the Branches API when an integration needs a reviewed change workflow. Start with [CLI and SDK setup](https://docs.openeng.io/developers/overview.md), and read the source branch head before approving or merging.

## Choose a proposal target

When you call `submitProposal`, use `target` to name `main`, a writable organisation branch or a project
branch. If you omit `target`, the proposal targets `main`. A read-only organisation branch is refused
with `invalid-proposal-target`.

An agent's apply run can submit its plan's branch only. Submitting any other branch is refused with
`write-refused`. The agent proposes the work; a person approves it.

## Approve a proposal

1. Read the proposal and inspect the changes at its branch head.
2. Call `approveProposal` as a user, with the proposal identifier and the `headHash` you read.
3. If the hash is no longer the branch's head, the call returns `proposal-head-moved`. Read and review the current head before trying again.

The person who submitted the proposal, including through their agent run, cannot approve it:
the refusal is `author-cannot-approve`. A repeat approval is refused with `already-approved`.
From a CLI session in agent mode, each approval needs confirmation on the web.

## Read approvals and counts

`readProposal` and `listProposals` show the branch head and mark each approval as `current` or `stale`.
An approval is current when its recorded hash matches the branch's head. The results also show the
counted and required approval numbers per project for each rule you may read.

A proposal remains readable when its source branch is gone. It then has no head, its approvals are
stale, and it has no counts.

## Merge or resolve conflicts

People, services and client apps may merge within their project write permissions. Agent runs and
hosted apps are refused `token-kind-not-admitted`. With no rule matching the target, writers of all
affected projects may merge, including Contributors.

A matching rule can require a pending proposal from the source to that target. Without the rule's
bypass, a missing proposal answers `proposal-required`. Unmet approvals for the subject project
answer `approvals-required`, carrying `approvals.counted` and `approvals.required`. Ask eligible
reviewers to approve the source branch's current head. Approvals at an older head do not count.
A bypass member may merge without the proposal or approvals that rule requires, within their write
permissions. A person's bypass counts only from a web session or a CLI session in human mode; an
agent-mode CLI session, or a session with no recorded channel, takes no bypass for a merge. A
conflicting change still needs resolution before it can land.

Send the source branch's current head as `sourceHash`. Success closes only that source branch's pending
proposal for the merge target, including targets other than `main`.

1. If the shared design has changed, inspect the current values shown for the target and proposal.
2. If the merge is refused, have someone with merge authority on the project refuse the pending proposal. A refused merge leaves it pending, which blocks a second submission.
3. Update the branch through the workspace to express the result you intend to keep.
4. Submit the branch again for review.

A merge that includes named resolutions is refused; no operation applies those choices for you. See [refusal names](https://docs.openeng.io/reference/refusals.md) and [Read merge conflicts](https://docs.openeng.io/reference/cli.md), which compares the source branch with main.

## Dispose of a branch

When a branch is no longer wanted, use `openeng branches-sdk disposeRef` to dispose of it. There is
no web control for disposing of a branch. See the [CLI reference](https://docs.openeng.io/reference/cli.md) for the command shape.

Call `disposeRef` with the branch name and the head you reviewed as `atHash`. A writer may dispose
when no proposal is pending and no matching rule restricts deletions. When no rule matches the
branch, a writer may also dispose with a pending proposal.

A deletion restriction answers `deletion-restricted` unless the caller bypasses every matching rule.
A pending proposal with matching rules answers `bypass-required` without that bypass. A bypass
member may dispose with or without a proposal, including under restricted deletions, but a person's
bypass counts only from a web session or a CLI session in human mode; an agent-mode CLI session, or
a session with no recorded channel, takes no bypass for a disposal. A branch that changed a row of
any project other than its own is refused `write-refused`, whatever the caller's rights there. Only after engine disposal succeeds does the pending proposal
become `discarded`.

Disposal admits people, services and client apps. Agent runs and hosted apps are refused
`token-kind-not-admitted`.

1. If drafts block disposal, check the rejection details for the object and the person holding each blocking draft.
2. If you want to dispose of the branch and its drafts, repeat the command with `deleteDrafts: true`.

This removes the drafts you may write and keeps them in draft trash for their authors. Draft trash is not currently listed in the interface.

A client with the `branches.proposalSubmit` grant may submit a proposal under the person's
project permissions. That grant alone permits no other branch write.
