skills/settle/SKILL.md

Settle merged tasks

A code task's PR can be merged while the task is not done, for example when a person merges it after the task was reopened. Until the task is done, the tasks that depend on it can't start. Settling finds those tasks and marks them done: a merge by a person accepts the PR, so the task needs no other review, as long as no work would be lost.

The settle script does all of it: it checks and writes the task records itself. Never settle a task by editing its record by hand, and never edit a record while the script runs. It runs unattended: never ask the developer anything and never wait for input. tasks and the start of deliver run it first; the developer can also run it on its own, for example from a scheduled session with a signed-in gh.

1. Run the script

From the product checkout (never the installed factory bundle), run the script that sits next to this file:

node "<this skill's folder>/settle.mjs"

Add --format json when you need its fields.

It takes the candidates from the overview script (--prs): every code task whose recorded delivery.pr was merged while the task is not done. For each one it takes the task lock as storage describes (never taking one over), re-reads the record and checks:

  • Merged: gh pr view says merged; its head is the merged head, and the PR's head on the settings' remote is that commit.
  • Into the integration branch: the PR's base is the settings' integration_branch, or the merged head is in that branch's freshly fetched tip. A stacked PR merged into a parent's branch that hasn't reached the integration branch is not settled.
  • Nothing left behind: the local task branch and the remote one, read fresh from the remote, have no commits the PR didn't merge, and no checkout of the branch (git worktree list) has uncommitted changes.
  • Checks passed: no entry in delivery.manual_checks is pending or failed.
  • Definition unchanged: no scope or criteria change (re-approved by dev) was logged after the task's latest → done log line.

It reaches the remote the way delivery does, over HTTPS with gh credentials when plain git can't connect. When every check holds, it sets status: done, sets submitted to the merged head, ticks the acceptance criteria and adds the settled log line from the task record. It changes nothing else: not the PR, the branches, worktrees, sandboxes or evidence.

If the script exits with an error, report it and stop.

2. Report

Show the script's report:

  • Settled: one line per task, with the PR and the short merged head, and a link to the task file as show every update describes.
  • Needs attention: one line per task it couldn't settle, with every reason and the next step for each.
  • Notes: PRs the overview couldn't check, for example when gh is missing or not signed in. Those tasks are not settled; they need nothing else from this run.

When tasks or deliver ran it and it reports nothing needs settling, say nothing.

3. With the developer

Only deliver uses this section: when the developer names a task that is under Needs attention and whose PR is merged, or when its Finish finds the task's recorded PR merged. The task is never resumed, reopened or given another PR.

  1. Release the task lock if you hold it: the script takes it itself. Run the script with --task <ID> --format json. If it settles the task, report that and stop. If it lists the task under skipped, show the reason and the notes, and stop. Otherwise tell the developer every reason, and keep its state token.

  2. For a lock held by another session, or a PR or remote that couldn't be read, give the script's next step and stop. Otherwise ask how to resolve each reason:

    • Confirm it's in: for "not in the integration branch yet". The developer confirms that the task's changes did reach the integration branch, for example through a squash-merged parent. Pass --confirmed.
    • Record the checks: for each pending check, ask the developer to run it, giving its steps, and take the result. Pass --result <n>=passed or --result <n>=failed for check <n> (1-based, in delivery.manual_checks order) and --by <name>. A failed check doesn't send the task back to building: it is resolved only by Follow up, or stays.
    • Follow up: define a new task with define for what the merge left out: every commit it didn't merge, the uncommitted changes, the criteria of pending or failed checks and the definition change, carried into its acceptance criteria. Pass --follow-up <new ID> --state <token>, with the token from step 1. The script refuses when anything changed since that run, because the follow-up wouldn't cover it.
    • Leave it: change nothing; it stays under Needs attention.

    Confirm it's in combines with the other answers.

  3. Once every reason has an answer other than Leave it, run the script once with --task <ID> and all the answers, and show its report.

Then stop. Delivery goes on only with another task the developer names.

Original Markdown, including metadata
---
name: settle
description: Mark code tasks done when their pull request was merged while the task was not done, for example after a reopen, and report every task that couldn't be settled. Runs unattended; `tasks` and the start of `deliver` run it too.
disable-model-invocation: true
---

# Settle merged tasks

A code task's PR can be merged while the task is not `done`, for example when a person merges it after the task was [reopened](../deliver/SKILL.md#reopen-a-done-task). Until the task is `done`, the tasks that depend on it can't start. Settling finds those tasks and marks them `done`: a merge by a person accepts the PR, so the task needs no other review, as long as no work would be lost.

The [settle script](settle.mjs) does all of it: it checks and writes the task records itself. Never settle a task by editing its record by hand, and never edit a record while the script runs. It runs **unattended**: never ask the developer anything and never wait for input. [`tasks`](../tasks/SKILL.md) and the [start of `deliver`](../deliver/SKILL.md#1-start) run it first; the developer can also run it on its own, for example from a scheduled session with a signed-in `gh`.

## 1. Run the script

From the product checkout (never the installed factory bundle), run the script that sits next to this file:

```sh
node "<this skill's folder>/settle.mjs"
```

Add `--format json` when you need its fields.

It takes the candidates from the [overview script](../tasks/overview.mjs) (`--prs`): every code task whose recorded `delivery.pr` was merged while the task is not `done`. For each one it takes the task lock as [storage](../storage.md#locks) describes (never taking one over), re-reads the record and checks:

- **Merged:** `gh pr view` says merged; its head is the merged head, and the PR's head on the settings' `remote` is that commit.
- **Into the integration branch:** the PR's base is the settings' `integration_branch`, or the merged head is in that branch's freshly fetched tip. A [stacked](../deliver/SKILL.md#stacked-tasks) PR merged into a parent's branch that hasn't reached the integration branch is not settled.
- **Nothing left behind:** the local task branch and the remote one, read fresh from the remote, have no commits the PR didn't merge, and no checkout of the branch (`git worktree list`) has uncommitted changes.
- **Checks passed:** no entry in `delivery.manual_checks` is `pending` or `failed`.
- **Definition unchanged:** no scope or criteria change (`re-approved by dev`) was logged after the task's latest `→ done` log line.

It reaches the remote the way [delivery does](../repository.md#resolve-the-delivery-base), over HTTPS with `gh` credentials when plain `git` can't connect. When every check holds, it sets `status: done`, sets `submitted` to the merged head, ticks the acceptance criteria and adds the `settled` log line from the [task record](../task-record.md#log). It changes nothing else: not the PR, the branches, worktrees, sandboxes or evidence.

If the script exits with an error, report it and stop.

## 2. Report

Show the script's report:

- **Settled:** one line per task, with the PR and the short merged head, and a link to the task file as [show every update](../task-record.md#show-every-update) describes.
- **Needs attention:** one line per task it couldn't settle, with every reason and the next step for each.
- **Notes:** PRs the overview couldn't check, for example when `gh` is missing or not signed in. Those tasks are not settled; they need nothing else from this run.

When `tasks` or `deliver` ran it and it reports nothing needs settling, say nothing.

## 3. With the developer

Only [`deliver`](../deliver/SKILL.md#1-start) uses this section: when the developer names a task that is under **Needs attention** and whose PR is merged, or when its [Finish](../deliver/SKILL.md#6-finish) finds the task's recorded PR merged. The task is never resumed, reopened or given another PR.

1. Release the task lock if you hold it: the script takes it itself. Run the script with `--task <ID> --format json`. If it settles the task, report that and stop. If it lists the task under `skipped`, show the reason and the notes, and stop. Otherwise tell the developer every reason, and keep its `state` token.
2. For a lock held by another session, or a PR or remote that couldn't be read, give the script's next step and stop. Otherwise ask how to resolve each reason:
   - **Confirm it's in:** for "not in the integration branch yet". The developer confirms that the task's changes did reach the integration branch, for example through a squash-merged parent. Pass `--confirmed`.
   - **Record the checks:** for each `pending` check, ask the developer to run it, giving its steps, and take the result. Pass `--result <n>=passed` or `--result <n>=failed` for check `<n>` (1-based, in `delivery.manual_checks` order) and `--by <name>`. A failed check doesn't send the task back to building: it is resolved only by **Follow up**, or stays.
   - **Follow up:** define a new task with `define` for what the merge left out: every commit it didn't merge, the uncommitted changes, the criteria of `pending` or `failed` checks and the definition change, carried into its acceptance criteria. Pass `--follow-up <new ID> --state <token>`, with the token from step 1. The script refuses when anything changed since that run, because the follow-up wouldn't cover it.
   - **Leave it:** change nothing; it stays under **Needs attention**.

   **Confirm it's in** combines with the other answers.
3. Once every reason has an answer other than **Leave it**, run the script once with `--task <ID>` and all the answers, and show its report.

Then stop. Delivery goes on only with another task the developer names.