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
1 change: 1 addition & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
33 changes: 25 additions & 8 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,31 @@ 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. 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.
App private keys live outside the repo (by convention
`~/.config/codecrew/<slug>.*.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

Expand Down Expand Up @@ -365,7 +382,7 @@ hub).
| `codecrew task start <ref>` | 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 <ref> --question "…"` | Raises a human gate: posts the question as a comment, applies `cc:needs-decision`. |
| `codecrew task finish <ref>` | 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 <id>` | 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 <id>` | 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.
Expand Down
25 changes: 17 additions & 8 deletions docs/identities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
44 changes: 29 additions & 15 deletions internal/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions internal/cli/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 40 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 3 additions & 1 deletion roles/qa.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading