diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..edbccaf --- /dev/null +++ b/CONTRIBUTING.md @@ -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). diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..fdc3fc6 --- /dev/null +++ b/SECURITY.md @@ -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. diff --git a/SPEC.md b/SPEC.md index f1d2f36..4e8cd93 100644 --- a/SPEC.md +++ b/SPEC.md @@ -419,7 +419,7 @@ hub). | `codecrew roles diff ` / `codecrew roles show [--latest]` | Contract tooling: `show` prints the contract a dispatched session loads — the hub's `roles/.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/.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 ` | 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 ` | 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 ` | 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 ` | 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 ` | 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/-…` 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. | @@ -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 @@ -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 diff --git a/docs/first-milestone.md b/docs/first-milestone.md index 21907e2..722c05e 100644 --- a/docs/first-milestone.md +++ b/docs/first-milestone.md @@ -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). diff --git a/docs/identities.md b/docs/identities.md index def79e2..f21b4c9 100644 --- a/docs/identities.md +++ b/docs/identities.md @@ -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. @@ -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 ` — 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 `, 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`. @@ -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 `. Beside the private key, `identity new` + `codecrew-token ` (the script above). Beside the private key, `identity new` writes a credential stub (`~/.config/codecrew/.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 @@ -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`. diff --git a/docs/introduction.md b/docs/introduction.md index 3c4cedc..105e3fb 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -52,7 +52,8 @@ yet in a release: `roles show ` composing a contract with its `roles/.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 @@ -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 diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 4f2f5b3..79446e3 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -2,6 +2,8 @@ package cli import ( + "errors" + "flag" "fmt" "os" ) @@ -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") diff --git a/internal/cli/init.go b/internal/cli/init.go index 1f6b4be..3e76b9e 100644 --- a/internal/cli/init.go +++ b/internal/cli/init.go @@ -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 @@ -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 @@ -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. @@ -148,7 +153,8 @@ func initCmd(w io.Writer, args []string) error { fmt.Fprintln(w, " gh repo create / --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) diff --git a/internal/cli/init_test.go b/internal/cli/init_test.go index 7e650d1..9998d14 100644 --- a/internal/cli/init_test.go +++ b/internal/cli/init_test.go @@ -6,6 +6,8 @@ import ( "slices" "strings" "testing" + + codecrew "github.com/radiusred/gh-codecrew" "testing/fstest" ) @@ -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) + } + } +} diff --git a/roles/implementer.md b/roles/implementer.md index aaee63f..af33c03 100644 --- a/roles/implementer.md +++ b/roles/implementer.md @@ -11,8 +11,11 @@ Resolve your GitHub credentials in this order: vars (set by your orchestrator) — mint an installation token and export it as `GH_TOKEN`. 2. The app named by `roles.implementer.identity` in the hub's `.codecrew.yml`, - with its private key from `~/.config/codecrew/` (use - `scripts/codecrew-token `). + with its private key from `~/.config/codecrew/`, minted with the + `codecrew-token` script from upstream — until an `identity token` verb + exists, 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 `. 3. The operator's existing `gh` auth (identity `~` — solo tier only). ## On dispatch, read @@ -20,7 +23,7 @@ Resolve your GitHub credentials in this order: 1. `.codecrew.yml` in your working repo — follow `hub:` to the hub. 2. The task issue you were dispatched for, and the milestone issue it links to (goal, requirement IDs, gates). -3. The hub's `SPEC.md` if any convention is unclear. +3. The protocol — https://github.com/radiusred/gh-codecrew/blob/main/SPEC.md — if any convention is unclear. ## Obligations @@ -50,12 +53,13 @@ Resolve your GitHub credentials in this order: operator holds the role; there is no username to request), and stand down when the holder is an App identity: GitHub cannot receive a review request for an App, so its review arrives by dispatch instead (see "Dispatching a - role session" in the hub's docs/identities.md) — do not raise a gate over + role session" in https://github.com/radiusred/gh-codecrew/blob/main/docs/identities.md) — do not raise a gate over the unrequestable name, and do not dispatch the reviewer yourself either: dispatch belongs to the coordination layer above the roles — the operator, an orchestrating session, or a platform watching the App's webhook — never to the doer, who must not choose or brief their own judge. Opening the PR - is your whole part; the review reaches it without you. CODEOWNERS-driven requests coexist: requested + is your whole part; the review reaches it without you. CODEOWNERS-driven + requests coexist: requested reviewers union, and neither mechanism should be disabled for the other. ## Never