From 91dd6b6881d4a5cab4e0080190ec94e292130e9f Mon Sep 17 00:00:00 2001 From: "radiusred-cody[bot]" <270330637+radiusred-cody[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 10:39:19 +0100 Subject: [PATCH 1/3] feat: count verdicts from the qa role holder, routed or operator-held (#42) --- SPEC.md | 31 +++++++++++++++++------- docs/identities.md | 25 ++++++++++++------- internal/cli/context.go | 44 ++++++++++++++++++++++------------ internal/cli/milestone.go | 8 +++++-- internal/config/config.go | 17 +++++++++++++ internal/config/config_test.go | 40 +++++++++++++++++++++++++++++++ roles/qa.md | 4 +++- 7 files changed, 135 insertions(+), 34 deletions(-) diff --git a/SPEC.md b/SPEC.md index 68f356b..717c2a8 100644 --- a/SPEC.md +++ b/SPEC.md @@ -296,14 +296,29 @@ roles: Role routing is **advisory**: CodeCrew does not dispatch agents, so the config is a contract for the orchestrator (or human) that does. -`identity` names the **GitHub App** the role acts as. Each role gets its own -app identity so agent-authored work is attributable and distinct from the -operator — without this, every PR is authored by the operator's account and -GitHub's prohibition on self-approval makes the non-doer review gate -unsatisfiable. App private keys live outside the repo (by convention +**Every role is always staffed — solo is a routing configuration, not a +reduced protocol.** The routing table says *who* holds each role: a GitHub +App (an agent acting as itself), a specific human (their GitHub username), +or — with no identity (`~`) — the human operator. An orchestrator dispatches +sub-agents or delegates to other harnesses per this table; a solo operator +embodies whatever routes to `~`. The hub's config should declare all four +roles at project onboarding, each routed explicitly; an orchestrator finding +no routing table should prompt for one rather than assume. The CLI tolerates +an absent table (every role is then operator-held) but says so in its output. + +`identity` names the **GitHub App** — or the GitHub username of a specific +human — the role acts as. Each agent-staffed role gets its own app identity +so agent-authored work is attributable and distinct from the operator — +without this, every PR is authored by the operator's account and GitHub's +prohibition on self-approval makes the non-doer review gate unsatisfiable. +App private keys live outside the repo (by convention `~/.config/codecrew/.*.private-key.pem`); short-lived installation -tokens are minted per invocation. A role with no identity (`~`) acts as the -human operator. +tokens are minted per invocation. + +Where a verb gates on a role — `milestone close` counts only the qa role +holder's verdicts — "holder" means the routed identity, or, for an unrouted +role, any human identity not routed to a different role. Crew identities can +never stand in for a role they are not routed to. ### Identity tiers @@ -365,7 +380,7 @@ hub). | `codecrew task start ` | Assigns the caller's identity, verifies a plan is present (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 --question "…"` | Raises a human gate: posts the question as a comment, applies `cc:needs-decision`. | | `codecrew task finish ` | The gatekeeper: verifies a PR exists, CI checks are green, an approving review exists from a non-doer, and deviations referenced in the PR body have recorded comments — then merges (rebase) and closes. 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]`. | -| `codecrew milestone close ` | Verifies all tasks closed and every requirement's latest QA verdict is `satisfied` (`refused[VERDICT_MISSING]` / `refused[VERDICT_UNSATISFIED]` otherwise; only verdicts from the QA role's identity count, and a later verdict supersedes an earlier one); 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 ` | Verifies all tasks closed 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); 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. diff --git a/docs/identities.md b/docs/identities.md index 7a13b22..e0f155c 100644 --- a/docs/identities.md +++ b/docs/identities.md @@ -16,14 +16,23 @@ Prerequisites: a GitHub account, `gh` authenticated (`gh auth login`), the extension installed (`gh extension install radiusred/gh-codecrew`), and a `.codecrew.yml` in your repo (`hub: self` for a single-repo project). -Everything works. You (or agents running under your auth) create milestones -and tasks, write plans, commit, open PRs, raise and resolve gates. Exactly -one thing degrades: the non-doer review gate. GitHub forbids approving your -own PR, and in pure solo there is no second principal to approve — so -`task finish` accepts `--operator-confirm` instead, and records an explicit -confirmation comment on the PR. When the confirming operator is also the PR -author, the recorded comment says so in as many words: *no independent -principal exists in this project*. +Everything works, because solo is a routing configuration, not a reduced +protocol: every role is always staffed, and in pure solo *you* hold each +unrouted one. You (or agents running under your auth) create milestones and +tasks, write plans, commit, open PRs, raise and resolve gates. You also +perform the qa contract yourself: post per-requirement verdicts on the +milestone issue in the standard `**M1-R1 — satisfied.**` form — the close +gate counts the qa role holder's verdicts, and unrouted, that is you. +Declare the routing table in your hub's `.codecrew.yml` at onboarding (all +four roles, `~` for the ones you embody); an absent table works but the CLI +will nag. + +Exactly one thing degrades: the non-doer review gate. GitHub forbids +approving your own PR, and in pure solo there is no second principal to +approve — so `task finish` accepts `--operator-confirm` instead, and records +an explicit confirmation comment on the PR. When the confirming operator is +also the PR author, the recorded comment says so in as many words: *no +independent principal exists in this project*. Two honesty notes: diff --git a/internal/cli/context.go b/internal/cli/context.go index c43d967..ab4c417 100644 --- a/internal/cli/context.go +++ b/internal/cli/context.go @@ -15,6 +15,8 @@ type ctx struct { current string // owner/repo the command runs in hub string // owner/repo of the hub t tracker.Tracker + + roles *config.Config // memoized routing table (local or hub) } func load() (*ctx, error) { @@ -34,23 +36,35 @@ func load() (*ctx, error) { }, nil } -// roleFor resolves a viewer login to its role name via the routing table. -// Spokes carry only the pointer config (SPEC §5), so when the local file has -// no roles the hub's .codecrew.yml is fetched; an unreadable hub config -// degrades to no role rather than failing the verb — routing is advisory. -func (c *ctx) roleFor(login string) string { - if len(c.cfg.Roles) > 0 { - return c.cfg.RoleFor(login) +// rolesConfig returns the config whose routing table governs role +// resolution. Spokes carry only the pointer config (SPEC §5), so when the +// local file has no roles the hub's .codecrew.yml is fetched (memoized); an +// unreadable hub config degrades to the local one rather than failing the +// verb — routing is advisory. +func (c *ctx) rolesConfig() *config.Config { + if c.roles != nil { + return c.roles } - data, err := c.t.FileContent(c.hub, ".codecrew.yml") - if err != nil { - return "" - } - hubCfg, err := config.Parse(data) - if err != nil { - return "" + c.roles = c.cfg + if len(c.cfg.Roles) == 0 { + if data, err := c.t.FileContent(c.hub, ".codecrew.yml"); err == nil { + if hubCfg, err := config.Parse(data); err == nil { + c.roles = hubCfg + } + } } - return hubCfg.RoleFor(login) + return c.roles +} + +// roleFor resolves a viewer login to its role name via the routing table. +func (c *ctx) roleFor(login string) string { + return c.rolesConfig().RoleFor(login) +} + +// holdsRole reports whether login holds the named role (config.HoldsRole +// over the governing routing table). +func (c *ctx) holdsRole(login, role string) bool { + return c.rolesConfig().HoldsRole(login, role) } // refusal is a blocked gate: a machine-readable code plus a human detail. diff --git a/internal/cli/milestone.go b/internal/cli/milestone.go index ac1b386..c75a4d3 100644 --- a/internal/cli/milestone.go +++ b/internal/cli/milestone.go @@ -126,7 +126,8 @@ func milestoneClose(w io.Writer, args []string) error { } // Gate 2: every requirement carries a satisfied QA verdict (a later - // verdict supersedes an earlier one; only the QA role's count). + // verdict supersedes an earlier one; only the qa role's holder counts — + // its routed identity, or the human operator when the role is unrouted). body, err := c.t.IssueBody(milestone.Ref) if err != nil { return err @@ -137,7 +138,7 @@ func milestoneClose(w io.Writer, args []string) error { } latest := map[string]string{} for _, v := range tracker.ParseVerdicts(comments) { - if c.roleFor(v.Author) == "qa" { + if c.holdsRole(v.Author, "qa") { latest[v.ID] = v.State } } @@ -157,6 +158,9 @@ func milestoneClose(w io.Writer, args []string) error { if len(unsatisfied) > 0 { return refuse("VERDICT_UNSATISFIED", "latest QA verdict not satisfied for: %s — remedy and re-dispatch QA", strings.Join(unsatisfied, ", ")) } + if len(latest) > 0 && c.rolesConfig().Roles["qa"].Identity == "" { + fmt.Fprintln(w, "note: qa is unrouted — verdicts counted from the human operator holding the role; declare role routing in the hub's .codecrew.yml at onboarding (SPEC §5)") + } // Gather Decision/Deviation raw material for the doc-synthesizer. records, err := gatherRecords(c, milestone) diff --git a/internal/config/config.go b/internal/config/config.go index 5570238..39d6639 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -82,6 +82,23 @@ func (c *Config) RoleFor(login string) string { return "" } +// HoldsRole reports whether login holds the named role. A routed role is +// held exactly by its identity — a GitHub App slug or a human's username. +// An unrouted role (no identity) is held by the human operator: any human +// login not routed to a different role. Solo is a routing configuration, +// not a degraded tier — every role is always staffed (SPEC §5, decided at +// the gate on gh-codecrew#42). +func (c *Config) HoldsRole(login, role string) bool { + bare := strings.TrimSuffix(login, "[bot]") + if bare == "" { + return false + } + if id := c.Roles[role].Identity; id != "" { + return bare == id + } + return bare == login && c.RoleFor(login) == "" +} + // HubRepo resolves the hub to an owner/repo string. current is the // owner/repo of the repository the command runs in, used when hub is "self". func (c *Config) HubRepo(current string) string { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index b9c25e8..4380d88 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -60,6 +60,46 @@ func TestRoleFor(t *testing.T) { } } +func TestHoldsRole(t *testing.T) { + routed := &Config{Roles: map[string]Role{ + "implementer": {Identity: "radiusred-cody"}, + "qa": {Identity: "radiusred-testy"}, + }} + human := &Config{Roles: map[string]Role{ + "implementer": {Identity: "radiusred-cody"}, + "qa": {Identity: "alice"}, + }} + unrouted := &Config{Roles: map[string]Role{ + "implementer": {Identity: "radiusred-cody"}, + "qa": {}, // identity: ~ — held by the human operator + }} + empty := &Config{} + cases := []struct { + name string + cfg *Config + login string + want bool + }{ + {"routed: its bot holds", routed, "radiusred-testy[bot]", true}, + {"routed: bare slug holds", routed, "radiusred-testy", true}, + {"routed: a human does not", routed, "davison", false}, + {"routed: another crew bot does not", routed, "radiusred-cody[bot]", false}, + {"routed to a human: that human holds", human, "alice", true}, + {"routed to a human: another human does not", human, "bob", false}, + {"unrouted: the operator holds", unrouted, "davison", true}, + {"unrouted: a crew bot does not", unrouted, "radiusred-cody[bot]", false}, + {"unrouted: an unrelated bot does not", unrouted, "somebot[bot]", false}, + {"unrouted: an identity routed elsewhere does not", unrouted, "radiusred-cody", false}, + {"no roles at all: the operator holds", empty, "davison", true}, + {"empty login never holds", unrouted, "", false}, + } + for _, c := range cases { + if got := c.cfg.HoldsRole(c.login, "qa"); got != c.want { + t.Errorf("%s: HoldsRole(%q) = %v, want %v", c.name, c.login, got, c.want) + } + } +} + func TestHubRepo(t *testing.T) { self := &Config{Hub: "self"} if got := self.HubRepo("radiusred/spoke"); got != "radiusred/spoke" { diff --git a/roles/qa.md b/roles/qa.md index a44f22c..cd00346 100644 --- a/roles/qa.md +++ b/roles/qa.md @@ -33,7 +33,9 @@ Resolve credentials as in `roles/implementer.md`, using `roles.qa.identity`. A later verdict supersedes your earlier one for the same requirement; say so when re-verifying. Every requirement's latest verdict must be - `satisfied` before the milestone can close. + `satisfied` before the milestone can close. When the qa role is unrouted, + the human operator holds it and performs this contract themselves — same + format, same gate (SPEC §5). - Raise `cc:needs-decision` when behaviour is defensible but the requirement is ambiguous — that ambiguity is a human's to resolve, not yours. From 75928845286008d844dd6b589332b1cfb1406ef1 Mon Sep 17 00:00:00 2001 From: "radiusred-cody[bot]" <270330637+radiusred-cody[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 10:39:19 +0100 Subject: [PATCH 2/3] docs: add the M4 roadmap row (#42) --- ROADMAP.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ROADMAP.md b/ROADMAP.md index 8298e52..7891a77 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -5,6 +5,7 @@ | M1 | Role contracts and CLI skeleton — prove the protocol by using it | [#1](https://github.com/radiusred/codecrew/issues/1) | [Done](docs/milestones/1-role-contracts-and-cli-skeleton.md) | | M2 | Protocol hardening | [#15](https://github.com/radiusred/codecrew/issues/15) | [Done](docs/milestones/2-protocol-hardening.md) | | M3 | First spoke | [#25](https://github.com/radiusred/gh-codecrew/issues/25) | [Done](docs/milestones/3-first-spoke.md) | +| M4 | Solo flight | [#41](https://github.com/radiusred/gh-codecrew/issues/41) | Open | Candidate future milestones (not yet committed): milestone-close synthesis automation, read-only Projects mirror, multi-spoke proving project. From c0180e1a77c0d1a9959d18406fe59a60ab7072e3 Mon Sep 17 00:00:00 2001 From: "radiusred-cody[bot]" <270330637+radiusred-cody[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 11:57:49 +0100 Subject: [PATCH 3/3] docs: reserve slash identities for team routing (#42) --- SPEC.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SPEC.md b/SPEC.md index 717c2a8..2bd7c03 100644 --- a/SPEC.md +++ b/SPEC.md @@ -307,7 +307,9 @@ no routing table should prompt for one rather than assume. The CLI tolerates an absent table (every role is then operator-held) but says so in its output. `identity` names the **GitHub App** — or the GitHub username of a specific -human — the role acts as. Each agent-staffed role gets its own app identity +human — the role acts as. A value containing a slash is reserved: it will +name a GitHub team (`org/team-slug`), routing the role to any member +([#44](https://github.com/radiusred/gh-codecrew/issues/44)). Each agent-staffed role gets its own app identity so agent-authored work is attributable and distinct from the operator — without this, every PR is authored by the operator's account and GitHub's prohibition on self-approval makes the non-doer review gate unsatisfiable.