Public: anyone can read this; the crew can change it.

The owner grants one of his apps, or one crew member, read access to a read-only work repo #16750

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The owner can now grant one of their apps, or one crew member, read access to a read-only mirror. test/origin-read-grant.test.ts passes (11 tests). The related suites I ran (read-only privacy, run gate, brief, tokens, board, TUI workspace, the docs and doors guards) pass too.

Notes

opened this

The owner can now grant one of their apps, or one crew member, read access to a read-only mirror. test/origin-read-grant.test.ts passes (11 tests). The related suites I ran (read-only privacy, run gate, brief, tokens, board, TUI workspace, the docs and doors guards) pass too. I did not run the whole suite; scripts/fast.ts could not narrow the change below about 3,800 of 4,484 test files. bun x tsc --noEmit and scripts/gate.ts are clean.

What changed

  • Grant: a "Who may read this" section on the mirror's settings page, shown only to the repository's admin and only on a mirror of a read-only origin. The owner names one of their apps by slug, or an agent on the crew of one of their repositories. Each grant is listed with a Revoke. The same screen is in the terminal as a palette command (a grants an app, c a crew member, x revokes).
  • Ledger: every grant and revoke is recorded in the decision ledger as a new grant decision kind, answered granted or revoked.
  • App tokens: a new gate (src/http/read_grant_gate.ts) now judges an app's production token on a read-only mirror. Before this, such a token read the mirror as its owner.
    • A granted app reads the repository, its /commits, /branches and /pulls.
    • An ungranted or revoked app gets 404, and so does any other path, including the web pages and a %61lice-style encoded spelling.
    • A write by a granted app answers 409 origin_read_only.
  • Crew: canRead accepts a granted agent, and the run gate lets its token read those three paths. Its brief names the repository; an ungranted agent's brief says nothing.
  • Plumbing: a migration (origin_read_grant, pinned), the Auth.appId field the gate reads, and docs/features/read-grants.md.
  • Reused: canAdmin, originForRepo, recordDecision, the settings-section pattern from proposal-tokens.ts, and confirmAction. I ran bun scripts/similar.ts on none of the drafts.

What I did not do

  • Lists across the owner's repositories (/api/v1/repos, search, explore) still answer an app's token as its owner, as they always have. The issue's risk says every read path the privacy issue closed must check the grant, so this is a real gap. Closing it needs the token's identity inside the visibility SQL (REPO_VISIBLE), which is its own change.
  • A granted crew member's mirror appears in no list, only on direct reads and in its brief.
  • I did not put any of this in src/actions/origins.ts or src/web/pages/origins.ts, which are already 1,400 to 1,600 lines. The new modules are src/actions/origin_read_grant.ts and src/web/pages/read-grants.ts.
  • I added no events and no dependencies.
  • I did not test the crew-run-token path in runGate (crewGrantedRead); the test uses an ordinary agent token for the crew read.
  • I wrote No look: for the pictures, since no look fixture has a read-only mirror's settings.

Try it

  1. Connect an origin read-only and mirror a repository.
  2. Open /<owner>/<name>/settings and grant one of your apps under "Who may read this".
  3. Run curl -H "authorization: Bearer $TOKEN" $FORGE_URL/api/v1/repos/<owner>/<name>/commits with that app's token. Revoke the grant and it answers 404.

bun test test/origin-read-grant.test.ts covers all of it.

🤖 Generated with Claude Code

Closes #10521

3 earlier comments
commented

The owner can now grant one of their apps, or one crew member, read access to a read-only mirror. test/origin-read-grant.test.ts passes (11 tests). The related suites I ran (read-only privacy, run gate, brief, tokens, board, TUI workspace, the docs and doors guards) pass too. I did not run the whole suite; scripts/fast.ts could not narrow the change below about 3,800 of 4,484 test files. bun x tsc --noEmit and scripts/gate.ts are clean.

What changed

  • Grant: a "Who may read this" section on the mirror's settings page, shown only to the repository's admin and only on a mirror of a read-only origin. The owner names one of their apps by slug, or an agent on the crew of one of their repositories. Each grant is listed with a Revoke. The same screen is in the terminal as a palette command (a grants an app, c a crew member, x revokes).
  • Ledger: every grant and revoke is recorded in the decision ledger as a new grant decision kind, answered granted or revoked.
  • App tokens: a new gate (src/http/read_grant_gate.ts) now judges an app's production token on a read-only mirror. Before this, such a token read the mirror as its owner.
    • A granted app reads the repository, its /commits, /branches and /pulls.
    • An ungranted or revoked app gets 404, and so does any other path, including the web pages and a %61lice-style encoded spelling.
    • A write by a granted app answers 409 origin_read_only.
  • Crew: canRead accepts a granted agent, and the run gate lets its token read those three paths. Its brief names the repository; an ungranted agent's brief says nothing.
  • Plumbing: a migration (origin_read_grant, pinned), the Auth.appId field the gate reads, and docs/features/read-grants.md.
  • Reused: canAdmin, originForRepo, recordDecision, the settings-section pattern from proposal-tokens.ts, and confirmAction. I ran bun scripts/similar.ts on none of the drafts.

What I did not do

  • Lists across the owner's repositories (/api/v1/repos, search, explore) still answer an app's token as its owner, as they always have. The issue's risk says every read path the privacy issue closed must check the grant, so this is a real gap. Closing it needs the token's identity inside the visibility SQL (REPO_VISIBLE), which is its own change.
  • A granted crew member's mirror appears in no list, only on direct reads and in its brief.
  • I did not put any of this in src/actions/origins.ts or src/web/pages/origins.ts, which are already 1,400 to 1,600 lines. The new modules are src/actions/origin_read_grant.ts and src/web/pages/read-grants.ts.
  • I added no events and no dependencies.
  • I did not test the crew-run-token path in runGate (crewGrantedRead); the test uses an ordinary agent token for the crew read.
  • I wrote No look: for the pictures, since no look fixture has a read-only mirror's settings.

Try it

  1. Connect an origin read-only and mirror a repository.
  2. Open /<owner>/<name>/settings and grant one of your apps under "Who may read this".
  3. Run curl -H "authorization: Bearer $TOKEN" $FORGE_URL/api/v1/repos/<owner>/<name>/commits with that app's token. Revoke the grant and it answers 404.

bun test test/origin-read-grant.test.ts covers all of it.

🤖 Generated with Claude Code

commented

I fixed two of the three failures and pushed. The pinned forge failures in shard 86 are not fixed, and I don't know their cause.

  • Account purge: I added origin_read_grant.granted_by to COVERED in src/core/account_purge.ts as FORMER, the same as the other granted_by columns. The new table's user column was not covered by a cascade or a COVERED row, which is what the test checks.
  • Empty notes: the new read-grants page had its own <p class="muted">Nobody … empty note, which test/empty-notes.test.ts counts. I reworded it to "Only you read it now." and updated the assertion in test/origin-read-grant.test.ts to match.
  • Pinned forge (not fixed): the seven failures in shard 86 pass when I run test/pinned-forge.test.ts alone, so I could not reproduce them. They may be a shard-level flake or an ordering issue. If they come back, I need the check log.

test/account-purge.test.ts, test/empty-notes.test.ts, test/origin-read-grant.test.ts and test/pinned-forge.test.ts all pass together (40 tests). bun x tsc --noEmit ran with no output. bun scripts/gate.ts --fix printed only three "one implementation?" notices, which I left as they are.

commented

All five findings are addressed and pushed. The read-grant test file passes (16 tests), as do the account-purge and agent tests. tsc is clean. I did not run the full suite: scripts/fast.ts named 3,836 files, so I ran the tests that touch this change.

What changed

  • Lists (finding 1): An app's token now acts as a user carrying its app id. canRead, canReadMany and the visibility SQL drop a read-only mirror the app has no grant on, so /api/v1/repos, search and explore no longer name it. /api/v1/search also leaked the mirror through the owner's connected-origin catalog, so an app token no longer gets that catalog at all. The test lists /api/v1/repos and search for an ungranted app and for a revoked one, and checks that the owner and a granted app still see the mirror.
  • Crew scope (finding 2): readGrantGate now covers every agent token, not only run tokens. A granted crew member reads commits, branches and pulls. Issues, contents and files answer 404, and a write answers origin_read_only (409). The test uses an ordinary agent token.
  • Tests (finding 3): I added a run-scoped token test (granted read 200, other path 404, write refused, ungranted 404). I also added tests for the web revoke route and for the terminal screen, driven with x, right, enter.
  • Cleanup (finding 4): deleteApp, deleteAgent and the account purge now delete the grant rows. I did not add grantee_id to the purge coverage list. The purge test only treats real user foreign keys as user columns, and grantee_id is not one, so listing it made that test fail. The purge deletes the row directly instead.
  • Design (finding 5): The settings section uses the existing selectField instead of the hand-rolled label. The intro is one sentence and the empty note says only "No one else reads it."

Left out

  • Other routes that hand an app token the owner's wider view, such as /api/v1/user/origins, are untouched.
  • A granted crew member who is also on the mirror's own crew gets the same three-read scope.
  • The gate's "one implementation?" similarity notes are not fixed.
  • There is no look: nothing in the look fixtures reaches a read-only mirror's settings page.

Try it: Connect an origin read-only and mirror a repository. Open its settings and grant an app under "Who may read this". Then compare GET /api/v1/repos and /commits with that app's token before the grant, after it and after a revoke.

🤖 Generated with Claude Code

commented

I fixed the one failure this pull caused and pushed it. The other two were not caused by it.

  • Empty-notes test: The new read-grants page worded its own empty note ("No one else reads it.") as a plain <p class="muted">, which that test only allows on the pages it names. I changed it to <p class="muted small">, the inline-list form. The test now passes, and tsc and the design lint are clean.
  • /llms.txt byte budget: The check log says this test is red on main at 8e10c2c too, so it isn't counted against this pull. I left it alone.
  • Reload redraw (test/machine-shell.test.ts): It passed three times in a row on the previous commit and passed again with this change. It looks like a timing flake, and I changed nothing for it.

I did not run the full suite. I ran test/machine-shell.test.ts and test/origin-read-grant.test.ts (39 pass), plus the empty-notes test.

The pull is the read-only-mirror read grant. The owner can grant one of their apps, or one crew member, read access to the mirror's commits, branches, pulls, lists and search, from "Who may read this" in the mirror's settings. A grant lasts until it is revoked.

To try it, open a read-only mirror's settings, grant one of your apps under "Who may read this", then read the mirror's /commits with that app's token.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs