Skip to content

Re-plan a pull request from a comment

llms.txtlists every page for an agent
Optional: hand this page to your coding agentThe steps work by hand too.
Show the whole prompt
Read https://intentius.io/terragucci/guides/re-plan-from-a-comment/.
Check that the default branch's pipeline has the comment trigger (on GitLab, the `comments` job and a pipeline schedule with TERRAGUCCI_SCHEDULE set to comments); if it does not, run `npx terragucci init` and open a pull request with the result.
You may comment `/terragucci plan` on a pull request and report what the note says.
Never comment `/terragucci apply`, `/terragucci lock` or `/terragucci unlock`.
Never apply, approve (a pull request review or `terragucci approve`), override a policy denial (`terragucci override`), use `--mode apply`, or merge; never touch `.chant/allowed_signers` or `chant/lifecycle`.

/terragucci plan on a pull request plans it again and updates its plan note and terragucci/plan status. /terragucci plan envs/dev/orders plans that root alone.

You need Why
The pipeline with the comment trigger comment workflows run from the default branch; to add it, run npx terragucci init again and merge the result
Write access to the repo, for whoever comments (on GitLab, the Developer role or above) anyone else gets no answer and no plan

Each new pull request comment starts the replan job.

  1. Comment on the pull request with this line alone:

    /terragucci plan

    The optional word after plan is a root path from the repository root.

  2. Read the note. The replan job plans the head with the read-only role and no forge token, and the replan-note job updates the same note and status.

    The re-plan edits the note in place.

    A named root the change does not reach gets a “not affected” reply and no update; a name that is not a root is refused with the list of roots.

A chat front end or a script can re-plan without a comment. On GitHub and Forgejo the workflow takes a workflow_dispatch:

Input Value
pr the pull request’s number. Drift runs by hand from its own workflow, terragucci-drift.yml (Turn on drift checks)
root optional: one root path, read by the comment grammar

The re-plan runs the same checks as /terragucci plan [root] and updates the same note and status.

Terminal window
gh workflow run terragucci.yml -f pr=42 -f root=envs/dev/orders

The decision step asks the API for the dispatcher’s permission and plans nothing without write access.

The text is untrusted and never reaches a script. terragucci comment reads it from the event file, or on GitLab from the API. Only one line in one of these forms is accepted; anything else is refused with the reason.

Comment Runs Where GitLab, with comments: set
/terragucci plan a re-plan every GitHub and Forgejo pipeline a new merge request pipeline
/terragucci plan <root> a re-plan of that root, which must be exactly a root the pipeline knows every GitHub and Forgejo pipeline the root is checked, and the whole merge request is planned
/terragucci apply the approved waves merged pull requests; open ones with apply.when: pull-request merged merge requests: a retry of the merge commit’s first apply job that did not succeed; with apply.when: pull-request, open ones: chant’s decision, then the waves’ pipeline on the default branch
/terragucci apply wave-<n> the approved waves up to wave n as above an open merge request with apply.when: pull-request; otherwise refused, since GitLab runs the waves after a retried job by itself
/terragucci lock locks on the roots (in a Terragrunt repo, the units) this pull request reaches, with no apply locks: plan under apply.when: merge; with apply.when: pull-request, /terragucci apply takes the locks answered as unsupported
/terragucci unlock a release of this pull request’s locks as lock as lock
atlantis plan [-d <dir>], atlantis apply the same as /terragucci plan [<root>] and /terragucci apply, with the same checks atlantis_comments: true the same, with atlantis_comments: true
/terragucci agent <ask> a coding agent’s change agent.comment set; see Have an agent change a pull request with agent.comment set, starts the agent’s pipeline on the default branch; otherwise answered that it is off

No comment approves, and a re-plan cannot change what an approval binds. When a comment runs nothing lists every check each command must pass. A refusal is a reply that starts with terragucci:.

Case Job
a comment that asks for nothing ends cleanly
a forge 403 or failure, or an unreadable event file fails, with the cause in the log

A comment command needs write access to the repository. comment_allow in terragucci.yml narrows a command to a list of logins and teams, so that moving from a setup that maps teams to commands keeps the same people:

comment_allow:
unlock: ["team:acme/platform", alice]
skip-soak: ["team:acme/release"]

A key is a command (plan, apply, lock, unlock, agent, action or skip-soak) or default for every command the map does not name. An entry is a login, or team: and the team’s path: team:<org>/<team> on GitHub and Forgejo, team:<group path> on GitLab, where it means the group’s members, inherited ones included. A command with no list keeps write access alone. An empty list is refused, since it would let nobody run the command.

The list is read from terragucci.yml in the job’s checkout, which is the default branch, so a pull request cannot add its author. Someone with write access who is on no list for the command gets a reply that names the list, and nothing runs.

Where it is read depends on who answers the comment.

Forge Limited by comment_allow Write access alone
GitLab plan, apply, lock, unlock, agent and skip-soak, in the comments job
GitHub and Forgejo action, skip-soak, and lock and unlock under locks: plan with apply.when: merge
GitHub and Forgejo, chant’s jobs plan, apply and agent, and lock and unlock under apply.when: pull-request, with a terragucci built on chant 0.124.98 or newer the same commands, with a terragucci built on an older chant

chant’s jobs read the list in the workflow the generator wrote, which is the default branch’s copy: the re-plan checks plan before it plans, the apply-comment job checks apply (and lock and unlock before merge), and the agent checks agent. A default covers them too. The re-plan and the apply-comment job reply to someone the list leaves out; the agent’s push job does. With a terragucci built on an older chant, those commands check write access alone, so config check refuses a list for them and a default, naming the chant release, and a list that would limit nothing is never written. A dispatch of the re-plan asks no list, as it asks no permission.

Team membership is read from the forge’s API with a token, and the job’s own token cannot read it on GitHub. Set a token that can and name it TG_TEAM_TOKEN; a job falls back to TG_TOKEN when it is unset.

Forge What the token needs
GitHub a secret TG_TEAM_TOKEN holding a token that can read the organization’s members: a fine-grained token or app with the organization permission Members: read, or a classic token with read:org; the generated workflows pass it to the jobs that check a team, chant’s among them
Forgejo a secret TG_TEAM_TOKEN holding a token with read:organization
GitLab a CI/CD variable TG_TEAM_TOKEN, or the comments job’s TG_TOKEN, belonging to a user who can see the group’s members (read_api)

When the forge cannot answer (the token lacks the permission, or the team does not exist or is not visible to it) nothing runs, the job fails, and the reply says that membership could not be read. A pending invitation to a GitHub team is not membership.

On a merged pull request, /terragucci apply re-runs the waves’ jobs of the merge commit’s run that did not succeed, for the waves approved as Approve a waiting wave shows.

Part What happens
Workflow apply-comment, chant’s comment job, runs the default branch’s workflow; it holds no cloud credential and runs none of the change’s code
Checks apply-comment checks the comment before it re-runs anything, against the merged-PR column
Credentials the re-run wave jobs assume oidc.apply_role, as on a push
Another run’s resources with choudoufu, a wave that changes a resource another run is applying is refused; the reply names that run, and you comment again once it is done
Waves from wave 1 until one does not apply; wave-<n> stops after wave n
A waiting wave waits as on a push
A refused wave prints its diff (respond.wave-refused)
A failed wave prints its triage (respond.apply-failed)
Terragrunt the same job and refusals; each wave job runs terragucci run wave on its units from the merge commit
On GitLab
/terragucci apply retries the waiting wave’s job in the merge commit’s pipeline
The gate the wave job decides it again, so a wave with no approval waits again; the waves after it follow, each behind its own gate
A merge commit a later apply superseded refused, as on GitHub

With apply.when: pull-request, /terragucci apply on an open pull request applies its head before merge. Apply a pull request before it merges has the steps.

/terragucci apply takes the locks of the roots the change reaches when it decides the head, and /terragucci lock and /terragucci unlock do not run. Locks lists everything that takes and releases one.

Comment Does Refused when
/terragucci apply locks the roots the pull request reaches, then applies its head another open pull request holds one of those roots; the reply names it
/terragucci plan, under locks: plan takes the locks again once a holder is gone

terragucciHelp setting it up: Intentius

These docs count page views and clicks with PostHog. They set no cookies, store nothing in your browser, and send nothing when your browser asks not to be tracked.