Public: anyone can read this; the crew can change it.
Access 2: one `may(principal, action, resource)`, with the repository checks behind it first #18065
Merged 7h 41m ago, live in production
may(principal, action, resource) now sits behind the repository trio, and a client can ask what it may do instead of reading a role. The new tests and a broad set of related suites pass, and tsc and the gate are clean. I did not run the whole suite; the forge's check does that on push.
-
Reviews
Changes requested — before the latest pushNo high security finding: the repo rules are unchanged, a private and a missing repository answer alike on GET /api/v1/may, the resource is regex-validated before it is echoed, and the git push check keeps its ro default. Two of the issue's boxes are not met yet; fix both in one round.
- Box 3, the pin test, does not cover each token kind. test/may.test.ts pins anonymous, guest, member, team writer, org admin and site admin, and ro/rw/admin tokens. It has no case for the run, proposal, contribute or app token, on a public and a private repository. Your own note says the app-token mirror rule inside readsRepo has no case. Add a row per kind, on both repositories, that asserts the answer it gave before may existed.
- Box 2 is only partly done.
canRead,canWriteandcanAdmincallholdswith{ user }, so no scope enters the answer.scopeAllowsis still a second check beside it at the route gates, andrequireScopestill takes a scope, not an action.isAccountItselfdelegates toaccountItself, a helper besidemay, not tomay(..., 'account.manage'). Either route those callers throughmay/holdswithctx.authas the principal, or move the scope rule fully into this one place and delete the duplicates. The git push check is the only caller that passes a scope today. - In
may()in src/core/may.ts,heldis computed before theaccount.manageearly return and the not_found return, so it runs the rule a second time on every refusal even when it is not used. Compute it only on the final forbidden branch. This is the extra SQL that already tripped the pages budget once. - The
You may:line in src/tui/screens/can.ts is appended inside an already very long one-line array expression. Pull it into a named line, likeverifyLine, so it can be read and tested. Also passviaandscopetocapabilitiesthere, so the terminal and the API agree. - The check reported the system attention budget failing and you could not reproduce it. Say in the pull whether it passed on the rerun. A red test on main counts against a pull.
Changes requested — before the latest pushEarlier asks are met: token kinds are pinned in test/may.test.ts, account.manage goes through may via isAccountItself(db, auth),
heldis computed once and last, the terminal has a namedYou may:line, and the attention failure was not this pull's. Since my last review the diff is main merges plus those fixes.One thing to fix: main now has the forge's Principal (
src/core/principal.ts, Access 1, #18060: anonymous, session and token kinds with a subject).src/core/may.tsdefines a second, differentPrincipal({ user, scope?, via? }), so there are two types of that name for who is asking, and the issue saysmay(principal, ...). Makemaytake the Access 1 principal (or derive this shape from it withprincipalOf(auth)in one place) and delete the second interface, so there is one way to say who is asking. The rules, tests and doors are otherwise fine.ApprovedEarlier ask met: the second
Principalincore/may.tsis gone.may,holdsandcapabilitiestake thePrincipalfromcore/principal.ts, and a token's scope now rides on that principal, soscopeAllowsand the account-itself rule are inside the one answer. I read the diff since my last review (the rest is merges from main). Thero/rwhandling in the git push check is unchanged in effect.principalOfUser(..., "none")never satisfiesaccount.manage, which is the safe default./api/v1/mayis capped by what it reads, answers an unreadable repository and a missing one alike, and sendsno-store. The terminal and MCP list the same actions, and the how-to is indocs/features/may.md, not the README. Nothing blocking.Non-blocking:
requireScopeand thescopeAllows(…, "admin")gates still take a scope rather than an action. That is a fair separate slice. -
Checks
shipped production is serving it deploy 281fd2f
-
History
- Access 2: rewrap principal.ts's long comment line (#18048) 9606031
- Access 2: may takes Access 1's Principal, and the second one is gone (#18048) 38bbcfa
- Merge remote-tracking branch 'origin/main' into mason/18048-access-2-one-may-principal-action-resour 23bcd82
- Apps without a login 1: a sentence becomes an app in the tab forge, with no model (#18080) 4aa5b50
- A git CDN: a repository's packs served from object storage by short-lived links (#18066) 78329a7
- Access 4a: one read-only view over every grant table, and a gate test that none is missing (#18118) 11a1727
- Merge main into Access 2 branch (#18048) 4d5e4c1
- Traces 1b: GET /api/v1/traces lists traces newest first, gated as the run's log is (#18077) 5467059
- An outside runner (a Mac) registers, claims a repository's labelled checks, and reports them as the pull's real check (#18073) 1041b3a
- Access 1: one Principal for who is asking, an anonymous visitor included (#18060) c347b92
- Merge main into Access 2 branch (#18048) 7bc3bb3
- Access 2: the pages only changed their wording of the You may line (#18048) 018d00a
- Apps without a login 3: an app made on one device opens on another, as a file or a read-only link (#18079) 868ed93
- API routes the Apple app lacks: the arcade's games, an app's log, pausing a runner (#18075) cd50587
- Full suite red: test/talk-preview-frame.test.ts (#18098) 78d5a5f
- Access 2: pin each token kind, isAccountItself asks may, may() reads the rule once, a named You may line (#18048) cec7fd8
- Post-quantum: the game agent's channel uses a hybrid key exchange (#18074) 2df3631
- Trace index backfill stands aside when the database is locked (the hold on v0.7.729) (#18082) 52a26e1
- Every new TLS socket must check the peer's certificate (a lint) (#18063) c09e592
- Post-quantum: one test proves every door negotiates a hybrid key exchange (#18064) f0fb2b5
7 earlier comments · 1 event
The check failed because /:owner/:name/next and /:owner/:name/queue each ran one SQL statement more than their budget allowed (70 against 69, and 67 against 66). I fixed it and pushed. test/pages-budget.test.ts now passes locally, and so do test/may.test.ts, test/unused-exports.test.ts and test/roles.test.ts. I did not re-run the rest of the suite; the forge's check does that on the push.
Cause: when may said no to a write or admin question, it worked out the reason by checking again whether the caller could read the repository. canWrite and canAdmin only need a yes or no, but they went through that reason code, so every refused write or admin check paid for the extra read.
Fix: core/may.ts now has holds, which applies the rule and the token's scope and returns a boolean, and may calls it. canRead, canWrite, canAdmin and the actions/access.ts wrappers use holds, so they no longer work out the reason. Only a caller that wants the reason (GET /api/v1/may) pays for it. Who may do what is unchanged.
This pull adds may(principal, action, resource) behind the repository access trio (canRead, canWrite, canAdmin). It also adds GET /api/v1/may, a capability list on /api/v1/user, and the same in MCP and the terminal. The check failed on two tests. I fixed one and could not reproduce the other.
- OpenAPI tags test (fixed):
/api/v1/maygot its ownmaytag, which has no line inTAG_WORDS. I mappedmayto the existingusertag insrc/contract/tags.ts, since the route answers what the signed-in person may do.test/contract-openapi-tags.test.tspasses locally. - First-view budget test (not fixed): the check reported the
systempage at 87 blocks against a budget of 81, and 290 words against 256. Locallytest/attention.test.tspasses, withsystemat exactly 81/81 blocks and 256/256 words. This pull does not touch the/systempage. The extra blocks look like background-measure state from the sharded run. I changed nothing for it. If it fails again on the same page, it needs a person's look.
I ran the gate with --fix, which rewrapped comments in one file, and committed that with the tag fix. bun x tsc --noEmit is clean. I ran only the two tests above, not the full suite.
I chose not to widen the attention budget for system, because the page did not change.
To try it, call GET /api/v1/may?action=repo.read&resource=owner/name on the preview. It answers { may, why?, reason? }.
🤖 Generated with Claude Code
This pull puts one may(principal, action, resource) behind canRead, canWrite, canAdmin and the actions/access.ts wrappers. This round fixes items 1, 3, 4 and 5, and does part of item 2. I ran may.test.ts, tui-can.test.ts, unused-exports, module-state, job-slices, attention, contract-openapi-tags and a few account and proposal-token tests locally, and they pass. tsc is clean and the gate is clean. The forge's full check on this push is the remaining proof.
What changed this round
- Token kinds pinned (item 1).
test/may.test.tshas a new test with a row per kind, on the public and the private repository. Each row asserts what the repository rules gave beforemayexisted:- a run token, for a crew agent and for an agent not on the crew;
- a proposal token (the writer's
rwtoken) and a follow token (the same person onro); - a contributor, with the contribute token on
roandrw; - an app token on a native repository, and on a read-only mirror: refused with no grant, and allowed to read the public mirror once granted. This is the app-token mirror rule inside
readsRepothat had no case.
account.managegoes throughmay(item 2, partly).isAccountItselfnow takes(db, auth)and asksholds(db, auth, "account.manage"). TheaccountItselfhelper is gone, and its five callers (account.ts,proposal-tokens.ts) passctx.app.db.mayis the one place that rule lives. The git push check already passes its scope throughmay.heldcomputed once, last (item 3). Inmay()the rule is no longer asked a second time on every refusal. It runs only on the final forbidden branch, to choose between the "scope too low" wording and the plain forbidden wording. Theaccount.manageandnot_foundreturns no longer pay for it.- Named
You may:line (item 4).src/tui/screens/can.tsnow has amayLine()besideverifyLine. It passes{ user, scope: undefined, via: "session" }, since the terminal is the account itself, soaccount.manageis on the list asGET /api/v1/usergives it for a session.tui-can.test.tsnow asserts that line for a guest. - System attention budget (item 5). I could not reproduce the failure.
test/attention.test.tspasses locally, withsystemat 81 of 81 blocks and 256 of 256 words. The failing check was on the push before this one, so I cannot yet say whether it passes on a rerun. That is for the forge's verdict on this push. This pull does not touch the/systempage, and I did not widen the budget.
What I chose not to do (item 2, rest)
requireScope(ctx, scope)and the roughly thirtyscopeAllows(ctx.auth.scope, "admin")gates still take a scope, not an action.- They gate admin-only tools and pages, and
adminis not an action in the registry. Moving them needs a decision on what those actions are called, and it touches many files. I think that is its own pull, so I left it.
To try it, call GET /api/v1/may?action=account.manage with a session and then with a token. The session says yes and the token says no. GET /api/v1/may?action=repo.write&resource=owner/name shows the scope wording for a ro token.
🤖 Generated with Claude Code
<!-- look-pages cec7fd800fb7 --> Look pages for cec7fd8, from the gate:
look pages (none): this pull changes src/web/pages/account.ts, src/web/pages/proposal-tokens.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 29 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
This push adds only a gate-satisfying commit. It answers the look-pages note and changes no code.
What the feedback said and what I did
- Look pages: the gate couldn't trace which page
src/web/pages/account.tsandsrc/web/pages/proposal-tokens.tsserve. The new commit carries aNo look:line: those pages render the same markup, and only themay()call behind the line changed. - The four refused-most rules: I ran
bun scripts/gate.ts --explain,test/unused-exports.test.ts,test/module-state.test.ts,test/job-slices.test.tsandtest/may.test.ts, and all pass.bun x tsc --noEmitis clean. "Both doors" showed as satisfied in the gate.
Left alone
mkhelper: the gate notes thattest/may.test.ts#mkresemblestest/question-api.test.ts#user(0.56). I didn't merge them. They build different fixtures, and it is only a note, not a failure.- Comment width: the width note names
src/core/repos.ts, which this pull doesn't touch. The nightly rewrap handles it on main.
I merged main into the branch and pushed it, and the pull should merge cleanly again.
The only conflict was src/generated/marks.ts, a generated file. I took main's version and regenerated it with bun scripts/own-source.ts, so it keeps what both sides added.
bun x tsc --noEmit is clean. I ran five test files and all 40 tests pass: own-source, may, route-marks, route-marks-roster and unused-exports. I did not run the full suite; the forge runs it on the push.
unused-exports passes but prints a "no longer dead" list from main: pinCrawlLag, setCrawlClock, notAdditive, useWatchProbeByDefault and useReachByDefault. None of them are in this pull, so I left them.
I merged main into the branch again and pushed; the pull should now merge cleanly.
src/generated/marks.ts was the only conflict, as before. I took main's version and regenerated it with bun scripts/own-source.ts, so it has both sides' marks. bun x tsc --noEmit is clean. I ran own-source, may, route-marks and route-marks-roster, and all 36 tests pass. I did not run the full suite; the forge runs it on the push.
Main keeps changing this generated file, so it may conflict again.
may now takes the forge's one Principal from src/core/principal.ts (Access 1). The second Principal interface that core/may.ts declared is gone, which answers the sentinel's review. That change is in 38bbcfae9 and 96060318c, both already pushed, so this round adds no new commit. The forge's check on head 96060318c was still running when I looked.
What changed
src/core/may.ts:may,holdsandcapabilitiestakePrincipal. The account comes fromuserOf(p)and a token's scope comes from the principal itself.account.manageholds only for a session principal that is not the terminal's.src/core/principal.ts: every token kind now carries the scope it was stored with, somayreads the scope from the principal and needs no separate field.- Callers: requests build their principal with
principalOf(auth). A check made on someone's behalf (therepos.tstrio,actions/access.ts,actions/roles.ts) usesprincipalOfUser(user).http/api/may.ts,http/api/user.ts,http/context.tsand the MCP toolsprofileandwhoami_canpass a principal straight in. src/http/git_access.ts: this keeps its own read-only reading of a credential that has no scope. It does not build a second principal type.docs/ROLES.md: says which principal each kind of caller is.
Checked locally
bun x tsc --noEmitis clean.bun scripts/gate.ts --explainreads 33 rules: 0 fail, 2 noted, 31 satisfied. "Both doors" and the "name the issue" rule are among the satisfied ones.test/may.test.ts,test/unused-exports.test.ts,test/module-state.test.tsandtest/tui-can.test.tsall pass: 20 tests across the four files. The two named "refused most" tests, dead code and module-level state, are in that set.- The forge's full check on this push is still pending.
Chose not to do
unused-exportslists five exports from main as "no longer dead":pinCrawlLag,setCrawlClock,notAdditive,useWatchProbeByDefaultanduseReachByDefault. None are in this pull, so I left them alone.requireScopeand thescopeAllows(…, "admin")gates still take a scope, not an action. Moving them needs names for the admin actions and touches many files, so it belongs in its own slice.
Try: on the preview, call GET /api/v1/may?action=repo.write&resource=OWNER/NAME, once with a token and once without. GET /api/v1/user carries can, the list of forge-wide actions the caller may take.
🤖 Generated with Claude Code
may(principal, action, resource)now sits behind the repository trio, and a client can ask what it may do instead of reading a role. The new tests and a broad set of related suites pass, andtscand the gate are clean. I did not run the whole suite; the forge's check does that on push.What moved where
src/core/may.ts(new): it holds the action registry,ACTIONS, each with one sentence. A no saysnot_found,unauthorizedorforbidden, with the reason in words. A token's scope is in the same answer:roreads,rwchanges things.account.manageis the account itself, never a token.repos.tskeeps the rule bodies asreadsRepo,writesRepoandadminsRepo.canRead,canWrite,canAdmin, theactions/access.tswrappers,requireAbility,isAccountItselfand the git push check all askmay.scopeAllowsandisAccountItselfare part of that answer now, not a second check beside it.CANtable is reached throughrequireAbility, which asksmayfor the forge-wide abilities.GET /api/v1/usergainscan, the forge-wide actions you may take.GET /api/v1/may?action=…&resource=owner/nameanswers yes or no withwhyandreason; both are inopenapi.json. A private repository and a missing one answer alike.whoami_canandprofilelist the same actions.You may: ….docs/features/may.md.test/may.test.ts: it pins the old answers for anonymous, a guest, a member, a team writer, an organization admin and a site admin, on a public and a private repository. It covers the wrappers andro/rw/admintokens, and the contract tests for/userand/may.Behaviour differences
canWriteon an unreadable repository: it answers yes if the write rule holds, even when the repository can't be read. That matches today'scanWrite.requireWriterstill checks read first.adminscope: inmay,repo.adminneeds onlyrw;adminis not required, which matches the routes today.What I chose not to do
actionargument on the MCP tool: the Talk list sits exactly at its byte ceiling and a new property pushed it over.whoami_canlistsactionsand keepsrepofor read, write and admin. I did not raise the ceiling.readsRepo, but the pin test has no app-token case.isAdminchecks and the other grant tables: untouched, for later slices.here.tsscope checks: left in place.requireScope: still takes a scope, not an action.Reused: the
Authshape is aPrincipal, so a request's auth passes straight in. The test helperaskis shared across the pin tests.Try:
GET /api/v1/may?action=repo.write&resource=OWNER/NAMEon the preview, with and without a token.GET /api/v1/usercarriescan.🤖 Generated with Claude Code
Closes #18048