---
name: claim-step
description: >
  Claim a plan step in the status table of a GitLab work item, and link its
  MR once it exists. Refuses only a step another user is assigned to, then sets the Assignee
  cell to the operator's handle and the Status cell to
  `~"workflow::in dev"`; later sets the MR cell. Use for "claim step 2",
  "put me on step 4 of <work item url>", or "link the MR to the table".
  `/run-step` calls it, so run it alone only to claim without implementing.
argument-hint: "<work item url> <step> | link-mr <work item url> <step> <mr iid>"
disable-model-invocation: true
---

# Claim a step

Run `scripts/claim-step.py` (stdlib Python, shells out to `glab api`). The
work item URL looks like
`https://gitlab.com/<project>/-/work_items/<iid>`; ask for it when
`$ARGUMENTS` has none.

| Need | Command |
| --- | --- |
| Show the rows | `claim-step.py show <url> [<step>]` |
| Check without writing | `claim-step.py claim <url> <step> --dry-run` |
| Claim | `claim-step.py claim <url> <step>` |
| Set the MR cell | `claim-step.py link-mr <url> <step> <mr iid>` |

Each prints one JSON object; read `status`:

- `ok`, `already_yours` (a no-op), `dry_run`: done.
- `not_unclaimed`: another user is the step's assignee. Report `row` and
  stop. An empty Assignee is claimed whatever the Status says. Don't claim a different step unasked.
- `not_yours`, `mr_already_set`: `link-mr` refuses a row that isn't the
  operator's or already names another MR. Report it.
- `no_table`, `no_step`, `bad_url`, `error`: report `message`.
- `verify_failed`: the row read back differently from what was written.
  Report both rows and stop; someone edited the table at the same moment.

The write replaces the whole description, read just before it, so edits to
other rows survive unless they land in that moment.

## Rules

- `claim` and `link-mr` write to GitLab. Run them only when the operator
  asked for that write in the current turn, or answered a question that named
  it. `show` and `--dry-run` write nothing.
- The columns are found by header name: `#`, `MR`, `Status`, `Assignee`.
  Other columns and their order don't matter, and only the target cell
  changes.
- Claiming is not reversible from here. Clear a claim by hand in the table.
