Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ semantic versioning, and the protocol carries its own version (SPEC §5).

## [Unreleased]

### Dry runs
- `milestone new --dry-run` prints the number the milestone would get, its
title, the requirement IDs it would number and the ROADMAP row, and
creates nothing — requirement prose can be written knowing the number
(a closed duplicate still counts toward it; #119 finding 45).
`task finish --dry-run` and `milestone close --dry-run` evaluate exactly
the gates the live verb would, in order, print each as ok, refused with
its code, not reached or not applicable, then the actions a clean pass
takes — the comments it would post, the merge and the head it would
delete; every branch the sweep would delete or keep and why, and the
closing comment — writing nothing and exiting with the first refusal's
code. One code path builds the plan for both modes, so the preview
cannot disagree with the run. (M7-R5, #133, #178)

### A seat finishes only its own task
- `task finish` refuses `NOT_OWNER` — the twenty-eighth code — when the
caller is not the seat that started the task, read from the
Expand Down
6 changes: 3 additions & 3 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ hub).
|------|--------------|
| `codecrew status` | Where the project is: open milestones, task states, raised gates; notes contract drift and a repo that does not delete branches on merge. |
| `codecrew init [--hub owner/repo]` | Scaffolds a new repo: hub mode writes `.codecrew.yml` with the full `~`-routed roles table, the ROADMAP.md seed, the role contracts (embedded at the installed release) each with a blank `roles/<role>.local.md` extension beside it (a comment saying what the file is for, pointing at §7 and the upstream examples page; comments-only composes to nothing), and an AGENTS.md entry point; spoke mode writes the two-line pointer. Idempotent — existing files are kept and reported. Scaffolded contracts carry a provenance stamp naming the release that wrote them. |
| `codecrew milestone new` | Creates a milestone tracking issue in the hub from the template; each `--requirement` (repeatable) becomes a bold-ID line under `## Requirements`, numbered M<n>-R1, R2, … in the order given — the section the close gate reads — and the IDs counted are printed; text that brings its own ID is refused. The CLI derives n: a title carrying an `M<k>` prefix that disagrees is refused, one that agrees is stripped. Updates ROADMAP.md. |
| `codecrew milestone new` | Creates a milestone tracking issue in the hub from the template (`--dry-run` prints the number it would assign, the title, the requirement IDs and the ROADMAP row, and creates nothing — so requirement prose can be written knowing the number); each `--requirement` (repeatable) becomes a bold-ID line under `## Requirements`, numbered M<n>-R1, R2, … in the order given — the section the close gate reads — and the IDs counted are printed; text that brings its own ID is refused. The CLI derives n: a title carrying an `M<k>` prefix that disagrees is refused, one that agrees is stripped. Updates ROADMAP.md. |
| `codecrew task new --milestone <id> --repo <spoke>` | Creates a task issue in the spoke from the template; attaches it to the milestone as a sub-issue. |
| `codecrew task start <ref>` | Verifies a plan is present, posts the `**Started by** @<login>.` record (and assigns the caller where GitHub allows — humans; App identities are not assignable) (refuses to start a planless nontrivial task), creates the working branch — unless the caller's role routing resolves to a role whose contract forbids commits (`qa`, `reviewer`), which get no branch. |
| `codecrew checkpoint <ref> --question "…"` | Raises a human gate: posts the question as a comment, applies `cc:needs-decision`. |
Expand All @@ -435,9 +435,9 @@ hub).
| `codecrew roles diff <role>` / `codecrew roles show <role> [--latest]` | Contract tooling: `show` prints the contract a dispatched session loads — the hub's `roles/<role>.md` with its local extensions appended in §7 order (hub, then spoke); `show --latest` prints the contract embedded in the installed CLI whole. Drift: `status` reports when a local `roles/` contract differs from the embedded copy (scaffolded contracts carry a provenance stamp naming their release) and `diff` shows the divergence; `roles/<role>.local.md` files are never drift. Contracts are the project's own fork — reconciliation is a judgment routed through a task and PR, never an overwrite. |
| `codecrew role <name>` | Prints the identity holding a role — an App slug or username, or `~` for the operator (§5). Script-consumable; resolves from the hub's routing table when run in a spoke. The implementer uses it to request review from the reviewer role's holder at PR creation when the holder is review-requestable — a username or team; App-held seats are dispatched instead, Apps not being requestable (CODEOWNERS-driven requests coexist — requested reviewers union). |
| *(every verb that reads the working repo's `.codecrew.yml`)* | Refuses `PROTOCOL_MISMATCH` when the pointer's protocol major differs from the one the binary implements (§5), and `GH_TOO_OLD` when the installed `gh` is below the floor the verbs need (2.50.0, for `gh pr checks --json`) — checked once, up front, so the gate never fails inside `gh`. A hub's routing table fetched from a spoke is advisory and is not checked. |
| `codecrew task finish <ref>` | The gatekeeper: verifies the caller is the seat that started the task (the `**Started by**` record `task start` posts on every start — accepted only from the login it names — else, for tasks started before the record, the assignee: the same login with the `[bot]` suffix ignored, or the same routed seat — a team-held role is any member; `refused[NOT_OWNER]` otherwise — the operator's own auth is not exempt; handover is `task start` again by the new seat, latest record wins, and `--bypass` is the recorded override for a human operator; a task with no start record is not gated), that a PR exists, CI checks exist and are green (`refused[NO_CHECKS]` when a PR reports zero checks — the deterministic gate cannot be satisfied by absence, and there is no override), an approving review exists from the reviewer role's holder when the role routes to a distinct principal (`refused[NO_HOLDER_REVIEW]` otherwise — other approvals coexist but do not satisfy the gate; any non-doer approval suffices only when the role is operator-held) — then merges (rebase) and closes. When GitHub's own required-review rule is still unmet at that point (`reviewDecision: REVIEW_REQUIRED` — approvals count only from principals with write access: a write-access App's approval counts, a read-only App's and an operator confirmation do not), it refuses with `refused[REVIEW_NOT_COUNTED]` naming the supported paths; `--bypass` performs the ruleset's administrator merge instead, recorded as a PR comment, and only for a human operator the ruleset lists as a bypass actor. Refuses otherwise, with the specific unmet condition. In a solo-tier project (§5) where author and operator are the same principal, the non-doer approval degrades to an explicit operator confirmation, recorded as a PR comment; the confirming identity must be human — crew identities (`[bot]` suffix or routed role) are refused with `refused[SELF_CONFIRM]`. After the merge it deletes the head branch — the counterpart of `task start` creating it; a deletion failure is a note, the merge stands. |
| `codecrew task finish <ref> [--dry-run]` | The gatekeeper (`--dry-run` evaluates every gate below in order and prints each — ok, refused with its code, not reached, not applicable — then the comments, merge and head deletion it would perform, writing nothing and exiting with the first refusal's code): verifies the caller is the seat that started the task (the `**Started by**` record `task start` posts on every start — accepted only from the login it names — else, for tasks started before the record, the assignee: the same login with the `[bot]` suffix ignored, or the same routed seat — a team-held role is any member; `refused[NOT_OWNER]` otherwise — the operator's own auth is not exempt; handover is `task start` again by the new seat, latest record wins, and `--bypass` is the recorded override for a human operator; a task with no start record is not gated), that a PR exists, CI checks exist and are green (`refused[NO_CHECKS]` when a PR reports zero checks — the deterministic gate cannot be satisfied by absence, and there is no override), an approving review exists from the reviewer role's holder when the role routes to a distinct principal (`refused[NO_HOLDER_REVIEW]` otherwise — other approvals coexist but do not satisfy the gate; any non-doer approval suffices only when the role is operator-held) — then merges (rebase) and closes. When GitHub's own required-review rule is still unmet at that point (`reviewDecision: REVIEW_REQUIRED` — approvals count only from principals with write access: a write-access App's approval counts, a read-only App's and an operator confirmation do not), it refuses with `refused[REVIEW_NOT_COUNTED]` naming the supported paths; `--bypass` performs the ruleset's administrator merge instead, recorded as a PR comment, and only for a human operator the ruleset lists as a bypass actor. Refuses otherwise, with the specific unmet condition. In a solo-tier project (§5) where author and operator are the same principal, the non-doer approval degrades to an explicit operator confirmation, recorded as a PR comment; the confirming identity must be human — crew identities (`[bot]` suffix or routed role) are refused with `refused[SELF_CONFIRM]`. After the merge it deletes the head branch — the counterpart of `task start` creating it; a deletion failure is a note, the merge stands. |
| `codecrew milestone evidence <n>` | Walks the milestone's record — tracking issue and every sub-issue, bodies and comments — and verifies every cited link resolves (github.com references via the API under the caller's auth, everything else by HTTP). `refused[EVIDENCE_UNREACHABLE]` otherwise. Run by the coordination layer before dispatching QA, and by QA as its first act: uncommitted evidence cost M4-R4 its verdict, and the check is deterministic, so it runs as code. |
| `codecrew milestone close <id>` | Verifies all tasks closed, that the tracking issue's `## Requirements` section declares at least one bold requirement ID (`refused[NO_REQUIREMENTS]` otherwise — IDs written elsewhere in the body are not requirements, so a close can never verify nothing), and every requirement's latest QA verdict is `satisfied` (`refused[VERDICT_MISSING]` / `refused[VERDICT_UNSATISFIED]` otherwise; only verdicts from the qa role's holder count — its routed identity, or the human operator when the role is unrouted (§5) — and a later verdict supersedes an earlier one); once every gate has passed, sweeps the tasks' branches (the heads of their PRs, the `task/<n>-…` names `task start` cut) — deleting one only when its PR merged and the branch still sits at the merged commit, or when no PR is open and it carries nothing beyond the default branch; never a fork's branch or the default branch itself; reporting every other one — so the successful close and its closing comment record what was removed and why; gathers every Decision/Deviation comment across the milestone's tasks into raw material for the doc-synthesizer; refuses to close until the milestone document PR is merged. |
| `codecrew milestone close <id> [--dry-run]` | (`--dry-run`: the same gates in order, then every branch the sweep would delete or keep and why, and the closing comment; nothing written, the first refusal's code.) Verifies all tasks closed, that the tracking issue's `## Requirements` section declares at least one bold requirement ID (`refused[NO_REQUIREMENTS]` otherwise — IDs written elsewhere in the body are not requirements, so a close can never verify nothing), and every requirement's latest QA verdict is `satisfied` (`refused[VERDICT_MISSING]` / `refused[VERDICT_UNSATISFIED]` otherwise; only verdicts from the qa role's holder count — its routed identity, or the human operator when the role is unrouted (§5) — and a later verdict supersedes an earlier one); once every gate has passed, sweeps the tasks' branches (the heads of their PRs, the `task/<n>-…` names `task start` cut) — deleting one only when its PR merged and the branch still sits at the merged commit, or when no PR is open and it carries nothing beyond the default branch; never a fork's branch or the default branch itself; reporting every other one — so the successful close and its closing comment record what was removed and why; gathers every Decision/Deviation comment across the milestone's tasks into raw material for the doc-synthesizer; refuses to close until the milestone document PR is merged. |

Verbs exit nonzero with a machine-readable reason when a gate blocks them, so
agents can act on the refusal rather than parse prose.
Expand Down
4 changes: 3 additions & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ when a gate blocks. `task start` is role-aware: roles whose contracts forbid
commits (qa, reviewer) get no linked development branch; `roles show <role>`
prints a contract with its `roles/<role>.local.md` extensions appended;
`task finish` deletes the branch it merged and `milestone close` sweeps what
its tasks left. What changed and when: [CHANGELOG.md](../CHANGELOG.md). Not
its tasks left; `milestone new`, `task finish` and `milestone close` take
`--dry-run` — every gate in order with its outcome, then what the verb would
do, nothing written, the same refusal code. What changed and when: [CHANGELOG.md](../CHANGELOG.md). Not
yet here: any backend other than GitHub, and GitHub Enterprise Server —
github.com only.

Expand Down
56 changes: 43 additions & 13 deletions internal/cli/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,29 @@ func prByHead(prs []tracker.PR) map[string]tracker.PR {
// skipped silently. Failures are reported and never abort: the caller has
// passed every gate by the time it sweeps.
func sweepBranches(w io.Writer, t tracker.Tracker, m *tracker.Milestone) (deleted []string) {
return executeSweep(w, t, planSweep(t, m))
}

// sweepItem is one branch the close would consider — delete it, or keep
// it and say why — or a note about a lookup it had to skip, in the order
// the sweep meets them.
type sweepItem struct {
Repo, Name string
Delete bool
Reason string
Note string
}

// planSweep decides, without touching anything, what the sweep would do
// to every branch a milestone's tasks left. The dry run prints the plan;
// the live close executes it.
func planSweep(t tracker.Tracker, m *tracker.Milestone) (items []sweepItem) {
defaults := map[string]string{}
for _, task := range m.Tasks {
if _, ok := defaults[task.Repo]; !ok {
info, err := t.RepoInfo(task.Repo)
if err != nil {
fmt.Fprintf(w, "note: branch sweep skipped for %s (%v)\n", task.Repo, err)
items = append(items, sweepItem{Note: fmt.Sprintf("note: branch sweep skipped for %s (%v)", task.Repo, err)})
defaults[task.Repo] = ""
continue
}
Expand All @@ -97,14 +114,14 @@ func sweepBranches(w io.Writer, t tracker.Tracker, m *tracker.Milestone) (delete
}
nums, err := t.ClosingPRs(task, true)
if err != nil {
fmt.Fprintf(w, "note: branch sweep skipped for %s (%v)\n", task, err)
items = append(items, sweepItem{Note: fmt.Sprintf("note: branch sweep skipped for %s (%v)", task, err)})
continue
}
var prs []tracker.PR
for _, num := range nums {
pr, err := t.PRInfo(task.Repo, num)
if err != nil {
fmt.Fprintf(w, "note: branch sweep skipped for %s (%v)\n", task, err)
items = append(items, sweepItem{Note: fmt.Sprintf("note: branch sweep skipped for %s (%v)", task, err)})
prs = nil
break
}
Expand Down Expand Up @@ -140,17 +157,30 @@ func sweepBranches(w io.Writer, t tracker.Tracker, m *tracker.Milestone) (delete
}
pr, hasPR := byHead[name]
del, reason := branchAction(pr, hasPR, ahead, tip)
if !del {
fmt.Fprintf(w, "branch %s: kept (%s)\n", name, reason)
continue
}
if err := t.DeleteBranch(task.Repo, name); err != nil {
fmt.Fprintf(w, "branch %s: kept (%s; delete failed: %v)\n", name, reason, err)
continue
}
fmt.Fprintf(w, "branch %s: deleted (%s)\n", name, reason)
deleted = append(deleted, name)
items = append(items, sweepItem{Repo: task.Repo, Name: name, Delete: del, Reason: reason})
}
}
return items
}

// executeSweep performs a sweep plan, reporting each branch's fate and
// each skipped lookup where the sweep met it.
func executeSweep(w io.Writer, t tracker.Tracker, items []sweepItem) (deleted []string) {
for _, it := range items {
if it.Note != "" {
fmt.Fprintln(w, it.Note)
continue
}
if !it.Delete {
fmt.Fprintf(w, "branch %s: kept (%s)\n", it.Name, it.Reason)
continue
}
if err := t.DeleteBranch(it.Repo, it.Name); err != nil {
fmt.Fprintf(w, "branch %s: kept (%s; delete failed: %v)\n", it.Name, it.Reason, err)
continue
}
fmt.Fprintf(w, "branch %s: deleted (%s)\n", it.Name, it.Reason)
deleted = append(deleted, it.Name)
}
return deleted
}
3 changes: 3 additions & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ verbs:
status where the project is
milestone new --title T [--goal G] create a milestone tracking issue
[--requirement R]... (repeatable: numbered M<n>-R1, R2, … in order, under ## Requirements)
[--dry-run] (print the number and row it would get; create nothing)
milestone close <milestone number> close a milestone (gates: tasks closed, doc merged)
[--dry-run] (print every gate and the sweep; write nothing)
milestone evidence <milestone number> verify every cited link in the milestone's record resolves (M2 → 2)
task new --milestone N --title T create a task issue, linked into the milestone
[--repo owner/repo] [--goal G] [--requirements IDs]
task start <ref> assign, verify plan, create linked branch
task finish <ref> [--operator-confirm] enforce gates, then rebase-merge
[--bypass] (recorded admin merge when GitHub won't count the approval)
[--dry-run] (print every gate and what it would do; write nothing)
checkpoint <ref> --question "..." raise a human gate (cc:needs-decision)
role <name> who holds a role (identity, or ~ for the operator)
roles diff <role> local contract vs the one embedded in the CLI
Expand Down
Loading
Loading