Skip to content
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contributing

CodeCrew is developed with CodeCrew: the protocol in [SPEC.md](SPEC.md) is
the contribution process.

- **Ideas and bugs** — open an issue. Leave it unlabelled: that is a backlog
capture, not protocol traffic, until it is adopted into a milestone.
- **Work** — every change is a task under the open milestone
([ROADMAP.md](ROADMAP.md) names it): a task issue with a plan written
before the first commit, atomic conventional commits referencing the task
(`(#123)`), a PR that closes it, and a review from the reviewer seat — an
App identity here, whose review arrives by dispatch, not by request. The
operator merges through `task finish`; nothing merges around it.
- **Code ships with tests** in the same PR (the #46 convention); documented
commands are executed by the reviewer, verbatim.
- **Decisions and deviations** are recorded as comments when they happen
(SPEC §4), so the milestone document can be synthesized from the record.

If you are an agent, start at [AGENTS.md](AGENTS.md).
17 changes: 17 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Security

- **Nothing secret lives in a CodeCrew repo.** App private keys and
credential stubs live in `~/.config/codecrew/` on the operator's machine
or in an orchestrator's secret store; the pointer file, contracts and
scaffolds carry no credentials.
- **Tokens are short-lived.** Crew identities act with GitHub App
installation tokens minted per invocation (one hour); nothing long-lived
is written.
- **Least privilege by role.** Each App carries its contract's minimal
permission set ([docs/identities.md](docs/identities.md)); a reviewer
App's write access, when granted, is an explicit operator choice that is
recorded.
- **Reporting.** Open a private vulnerability report on this repository
(Security → Report a vulnerability; enabled), or email
opensource@radiusred.uk. Please do not open a public issue for a
credential or permission flaw.
8 changes: 6 additions & 2 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ 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). A hub's routing table fetched from a spoke is advisory and is not checked. |
| `codecrew task finish <ref>` | The gatekeeper: verifies 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), and deviations referenced in the PR body have recorded comments — 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>` | The gatekeeper: verifies 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 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. |

Expand Down Expand Up @@ -520,7 +520,9 @@ protocol major, and the CLI that implements it refuses the old pointer.
- **Go**, single static binary (`CGO_ENABLED=0`), cross-compiled for
linux/mac/windows. Also installable as a `gh` extension (`gh codecrew …`),
since a gh extension is just a binary named `gh-codecrew`.
- **Wraps `gh`** in v1 — auth, base URLs, and enterprise quirks come for free.
- **Wraps `gh`** in v1 — authentication comes for free. github.com only in
1.0: the URLs the verbs build and recognise are github.com's; GitHub
Enterprise Server is a non-goal (§12) until it is proven.
- **Backend interface** is shaped by the workflow verbs (§6), not by GitHub's
feature set. The GitHub adapter is the only v1 implementation; the interface
keeps two ports conceptually separate even though GitHub fuses them — the
Expand Down Expand Up @@ -553,6 +555,8 @@ CodeCrew deliberately does not have:
boundaries, from records captured at decision time
- a Jira adapter — GitHub only, with the backend interface as the seam if
that ever changes
- GitHub Enterprise Server, in 1.0 — github.com only; the verbs hardcode its
URLs, and no GHES run has been made
- configuration for behavior the model can decide well — the framework
manages trust (specification, verification, audit), not capability

Expand Down
3 changes: 3 additions & 0 deletions docs/first-milestone.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ the agent does the typing and the record proves what happened.

A GitHub account, [`gh`](https://cli.github.com/) installed and signed in
(`gh auth login`), `git`, and (recommended) your coding agent of choice.
One thing to know before your first PR: `task finish` refuses a PR that
reports no CI check at all, with no override — `init` does not write a
workflow, so step 5 shows the ten-line one you add yourself.
You and your agent are the whole crew today (SPEC §5 calls this solo
routing; the [What next](#what-next) ladder covers expanding it).

Expand Down
39 changes: 31 additions & 8 deletions docs/identities.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Roles are contracts, not accounts. A seat is held by exactly one of four
kinds of principal: **you**, the operator (`~` in the routing table — the
whole protocol runs on `gh auth login` alone); **a named human** (a
username); **a GitHub team** (`identity: org/team-slug` — any member holds
the seat); or **a GitHub App identity** minted for a crew member. Nothing requires an
App to exist before a role can be staffed — App identities are
the seat); or **a GitHub App identity** minted for a crew member. Nothing
requires an App to exist before a role can be staffed — App identities are
infrastructure you add when you want them (attribution) or need them
(enforced independent review). This document covers the ends of that
range: the zero-setup solo path, and minting a proper App identity for a
role — with the advice on which to choose in between.
(enforced independent review). This document covers the ends of that range:
the zero-setup solo path, and minting a proper App identity for a role —
with the advice on which to choose in between.

The conceptual model — identity tiers, credential resolution order — is in
[SPEC §5](../SPEC.md); this is the operational companion.
Expand Down Expand Up @@ -152,8 +152,10 @@ quirk), the manual ritual it automates — one App per role:
Mint a short-lived installation token per invocation — either via the
env-var path from SPEC §5 (`GITHUB_CLIENT_ID` / `GITHUB_PRIVATE_KEY` /
`GITHUB_INSTALLATION_ID`, for orchestrators), or with the bootstrap script
in this repo: `scripts/codecrew-token <app-slug>` — the **full** App slug
(`myorg-coder`, not `coder`). Then:
this repo ships — in your own project, install it once with
`mkdir -p ~/.local/bin && curl -fsSL https://raw.githubusercontent.com/radiusred/gh-codecrew/main/scripts/codecrew-token -o ~/.local/bin/codecrew-token && chmod +x ~/.local/bin/codecrew-token`
— then `codecrew-token <app-slug>`, the **full** App slug (`myorg-coder`,
not `coder`). Then:

- `GH_TOKEN=$tok gh codecrew …` / `GH_TOKEN=$tok gh …` for API actions.
- Push over HTTPS as `https://x-access-token:$TOKEN@github.com/owner/repo.git`.
Expand Down Expand Up @@ -203,7 +205,7 @@ however it is triggered:
deterministic, so it runs as code, not hope. The qa contract refuses past
an unreachable record from its side too.
- **Credentials.** The env-var path from SPEC §5, or
`scripts/codecrew-token <slug>`. Beside the private key, `identity new`
`codecrew-token <slug>` (the script above). Beside the private key, `identity new`
writes a credential stub (`~/.config/codecrew/<slug>.json` — the App ID
and client ID, nothing secret): with it, the helper mints the App's JWT
and discovers the installation itself, touching no user credential. For
Expand Down Expand Up @@ -267,3 +269,24 @@ dispatched reviewer seat does that, whatever else also comments on the PR.
recommendation, granting the reviewer App write access, or
`task finish --bypass` where the ruleset lists the operator as a bypass
actor (the bypass is recorded on the PR).

## Teardown

What CodeCrew created, and what to do with it when a project ends or you
stop using the framework:

- **Record — keep.** Milestone and task issues, their comments, the PRs and
the merged milestone documents under `docs/milestones/` are the audit
trail; nothing needs deleting for the framework to be gone.
- **The pointer and contracts** — `.codecrew.yml`, `roles/`, `AGENTS.md`,
`ROADMAP.md` in each repo. Delete or keep; they are plain files with no
hooks.
- **Labels** — `cc:milestone`, `cc:task`, `cc:needs-decision` on each repo,
created on first use. Remove in the repo's label settings if you like.
- **Task branches** — `task finish` deletes a merged head and `milestone
close` sweeps; anything left is listed by `git branch -r`.
- **App identities** — each crew App under the owning account's Developer
settings: uninstall it from the org or account, then delete the App. Its
private key and credential stub live only in `~/.config/codecrew/`;
delete the files. Tokens minted from them expire within the hour.
- **The extension** — `gh extension remove codecrew`.
8 changes: 5 additions & 3 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ yet in a release: `roles show <role>` composing a contract with its
`roles/<role>.local.md` extensions (#122), and protocol 1.0 — `version`
printing `v1.0.0 (protocol 1.0)` and the pointer's major checked (#114) —
both ship with the next release.
Not yet here: any backend other than GitHub.
Not yet here: any backend other than GitHub, and GitHub Enterprise Server —
github.com only.

**Who holds a seat.** Every role is always staffed, by exactly one of four
kinds of principal: the operator themselves (`~` in the routing table), a
Expand All @@ -74,8 +75,9 @@ possible ([identities.md](identities.md)).
on choosing yours). The hub's config also routes the four roles, and `init`
writes that table for you. Agents dispatched into a CodeCrew repo start at
[AGENTS.md](../AGENTS.md). Agent identities are GitHub Apps; short-lived
tokens come from `scripts/codecrew-token` (SPEC §5 and
[identities.md](identities.md) for the tiers).
tokens come from the `codecrew-token` script this repo ships — your project
installs it from upstream, see [identities.md](identities.md) (SPEC §5 for
the tiers).

**What it has done** — the receipts are on the [landing
page](../README.md#the-receipts); the per-milestone records are in
Expand Down
22 changes: 21 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package cli

import (
"errors"
"flag"
"fmt"
"os"
)
Expand Down Expand Up @@ -31,8 +33,26 @@ verbs:
Blocked gates exit nonzero with "refused[CODE]: detail".
`

// Run executes one verb.
// Run executes one verb. --help on any verb prints its usage and is not
// a failure: flag.ErrHelp maps to a clean exit.
func Run(args []string) error {
// Asking for help never runs the verb: a --help anywhere in the
// arguments prints usage and exits 0 — before any gate, refusal or
// side effect could be mistaken for it.
for _, a := range args {
if a == "--help" || a == "-h" {
fmt.Fprint(os.Stderr, usage)
return nil
}
}
err := run(args)
if errors.Is(err, flag.ErrHelp) {
return nil
}
return err
}

func run(args []string) error {
if len(args) == 0 {
fmt.Fprint(os.Stderr, usage)
return fmt.Errorf("no verb given")
Expand Down
12 changes: 9 additions & 3 deletions internal/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
codecrew "github.com/radiusred/gh-codecrew"
)

// U is the upstream repository every scaffolded reference resolves to —
// an adopter's hub holds no copy of the protocol or its docs.
const U = "https://github.com/radiusred/gh-codecrew/blob/main"

const hubConfigScaffold = `codecrew: "%s" # protocol version (SPEC.md §5): a different major is refused; not the CLI release — see codecrew version
hub: self

Expand All @@ -37,7 +41,7 @@ const agentsScaffold = `# Agents

This repository is part of a CodeCrew project — coordination state lives in
GitHub issues and PRs, per the protocol at
https://github.com/radiusred/gh-codecrew (SPEC.md).
` + U + `/SPEC.md.

- ` + "`.codecrew.yml`" + ` names the hub; the hub's ` + "`roles/`" + ` holds the role
contracts. Read the contract for the role you were dispatched as before
Expand All @@ -60,7 +64,8 @@ https://github.com/radiusred/gh-codecrew (SPEC.md).
not dispatched as any specific role — then when a role is routed to a
GitHub App and that role's action is needed (a review, a verdict),
dispatching a clean-context sub-agent session as that App is authorized
and expected; use the dispatch prompt in the hub's docs/identities.md. A
and expected; use the dispatch prompt in
` + U + `/docs/identities.md. A
session dispatched *as* a role never dispatches another role — that
belongs to its coordination layer (platform, orchestrating session, or
operator) — and never chooses or briefs its own judge.
Expand Down Expand Up @@ -148,7 +153,8 @@ func initCmd(w io.Writer, args []string) error {
fmt.Fprintln(w, " gh repo create <owner>/<name> --private --source=. --push")
}
if *hub == "self" {
fmt.Fprintln(w, "\nnext: declare who holds each role in .codecrew.yml (~ = you),")
fmt.Fprintln(w, "\nnext: every seat is routed to you (~ in .codecrew.yml); to hand one to a")
fmt.Fprintln(w, "colleague, a team or an App later, see "+U+"/docs/identities.md")
fmt.Fprintln(w, "commit, then `codecrew milestone new --title \"...\" --goal \"...\"`")
} else {
fmt.Fprintf(w, "\nnext: commit the pointer; tasks for this spoke attach to milestones in %s\n", *hub)
Expand Down
50 changes: 50 additions & 0 deletions internal/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"slices"
"strings"
"testing"

codecrew "github.com/radiusred/gh-codecrew"
"testing/fstest"
)

Expand Down Expand Up @@ -142,3 +144,51 @@ func TestScaffoldsCarryProtocolVersion(t *testing.T) {
}
}
}

// Nothing init writes may point at a file the adopter's repo does not
// have: the protocol and its docs live upstream (Codex pre-launch scan,
// #131).
func TestScaffoldReferencesResolveUpstream(t *testing.T) {
dir := t.TempDir()
if _, _, err := scaffold(dir, "self", codecrew.Roles); err != nil {
t.Fatal(err)
}
var files []string
if err := filepath.WalkDir(dir, func(p string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() {
files = append(files, p)
}
return nil
}); err != nil {
t.Fatal(err)
}
for _, f := range files {
data, _ := os.ReadFile(f)
for _, bad := range []string{"the hub's docs/", "hub's `SPEC.md`", "hub's SPEC.md", "`scripts/codecrew-token"} {
if strings.Contains(string(data), bad) {
t.Errorf("%s contains hub-relative reference %q", strings.TrimPrefix(f, dir), bad)
}
}
}
}

func TestHelpIsNotAnError(t *testing.T) {
for _, args := range [][]string{
{"task", "finish", "--help"}, {"task", "new", "--help"}, {"init", "--help"},
{"roles", "show", "x", "--help"}, {"milestone", "close", "--help"}, {"checkpoint", "-h"},
{"task", "new", "--milestone", "999", "--title", "--help"}, // help wins before the verb runs
} {
if err := Run(args); err != nil {
t.Errorf("%v: %v", args, err)
}
}
// A genuine bad argument is still a failure — help must not swallow it.
for _, args := range [][]string{{"milestone", "close", "notanumber"}, {"bogusverb"}, {"roles", "show"}} {
if err := Run(args); err == nil {
t.Errorf("%v: accepted", args)
}
}
}
Loading
Loading