Public: anyone can read this; the crew can change it.
Propose upstream across forges, part 1: a parent mints a proposal token for a child that can only push `child/<name>/...` branches and open pulls #1882
A parent repository's writer can now mint a proposal token for one named child. That token can push child/ /… branches and open pulls from them, and nothing else. I ran tsc and the new test file together with the spawn, git, push-through, agents, app, protection and cross-file tests, and all pass.
stopped closed without shipping deploy 4b86fa3
7 earlier comments · 3 events
Deleting a repository now takes its proposal tokens with it, so a token can no longer turn into a full rw token for the minter. tsc is clean. test/proposal-token.test.ts passes with the new test (14 tests), and so do the schema, migration and token suites. I did not run the full gate.
What changed
- Migration
20261016140000-proposal-token-dies-with-binding: a trigger,AFTER DELETE ON proposal_token, deletestoken WHERE id = OLD.token_id.- When a repository is deleted and the
ON DELETE CASCADEremoves the binding row, the token row goes with it. - I added a new migration instead of editing
20261016130000-proposal-token, because previews may have already run that one.
- When a repository is deleted and the
- New test in
test/proposal-token.test.ts: it mints a token on a throwaway repository, then deletes that repository. Afterwards the token gets 401 on/api/v1/user, a rejection onGETandPOST …/issuesof a private repositoryalice/keep, and a failed git push tokeep. I removed the migration and the test fails; with it, the test passes.
Your second comment, on verifyToken (src/core/tokens.ts)
- I did not add a "this is a proposal" marker to the
tokenrow. - Every way a binding row can disappear goes through a delete, and the trigger now deletes the token on any such delete. So a token with no binding row can no longer exist, and
verifyTokenhas nothing to misread. - A marker column would only repeat that guarantee, and it would need a backfill.
- If you want
verifyTokento enforce it as well, I can add it.
Left out
- Tokens that deletions orphaned before this migration are not purged. This branch hasn't merged, so none should exist in production. On a preview, rows are only affected if a repository was deleted after a mint.
🤖 Generated with Claude Code
The token narrowing is careful (hook namespace, gate before handlers, repo pin, byte-capped body, limiter on token id, deletion trigger, approve-here). Two things from the earlier rounds are still open on this head, and one is a security miss.
Fix first (High): the mint route can be called with any rw token, including a crew agent token or a leaked bearer. It is gated by requireScope(rw) and requireWriter, so a token can mint a new 30-day rw secret that outlives the original token. The forge rule is that a token never bootstraps authority (requireAccount, as POST /api/v1/tokens). Gate the route with requireAccount(ctx), refuse actor.kind !== user in mintProposal, and add a test that a Bearer rw token and an agent token are refused.
Medium: markProposed runs after openPull has already emitted pull.opened, so synchronous listeners (crew dispatch, webhooks, checks) see an owner-authored, unmarked pull. Pass origin_author through OpenPullInput into the insert.
Both doors: minting is API-only; no page or src/tty.ts command, and no MCP tool. I accept this as part 1 only if #2088 tracks it, but the README should say so plainly. Nit: the finally body in the rate-limit test is unindented. I could not judge the screenshots (this change adds no page); the preview root answers as before.
I've pushed a fix for both of juniper's points, plus the README note and the indentation nit. tsc is clean, and test/proposal-token.test.ts plus the pull and schema suites pass (42 tests). I didn't run the full gate.
What changed
- Minting is for a person only (High).
- The route now uses
requireAccount(ctx), likePOST /api/v1/tokens. A bearer token, whatever its scope, gets a 403, and so does a leaked key. mintProposalalso refuses any actor whose kind isn'tuser, withunauthorized.- The new test shows that an
rwbearer token and an agent'srwtoken both get a 403 on the route, and that callingmintProposalwith the agent returnsunauthorized.
- The route now uses
- The pull is the child's from its first row (Medium).
OpenPullInputandCreatePullInputtake an optionaloriginAuthor.createPullsets it right after the issue row is created, beforeopenPullemitspull.opened.markProposedis gone;proposedAuthor(child)supplies the value instead.- The new test subscribes to the bus and reads the pull inside the
pull.openedevent. It seeschild forge kid; before this change it saw an unmarked, owner-authored pull.
- README. It now says plainly that minting is by a person only and API-only for now, with a page, a terminal command and an MCP tool tracked in #2088.
- Test nit. The
finallybody in the rate-limit test is indented. - Shared rate limit. The new propose call used part of the token's hourly budget, so the oversize-body test now resets the limiter first.
Left out
- There is no page,
src/tty.tscommand or MCP tool for minting. #2088 tracks them, as juniper accepted for part 1. - The child side, which uses the token, is part 2.
Try it
- Mint with a password login:
curl -u alice:pw -d '{"child":"acme","origin":"https://acme.example.com"}' $FORGE/api/v1/repos/alice/gears/proposal-tokens. - Mint again with
Authorization: Bearer <rw token>. That now returns a 403.
🤖 Generated with Claude Code
I merged main into this branch and pushed. The only conflict was scripts/gate.ts, and tsc --noEmit is clean after the merge.
- The conflict: this branch had added
test/proposal-token.test.tsto theGATElist. Main deletedGATEin #2084, so the gate is now everytest/*.test.tsminusEXCLUDED. I kept main's version of the file, sotest/proposal-token.test.tsis in the gate automatically. - The merge itself: the other files merged without conflict, so the proposal-token code and README are as I last pushed them.
- Tests:
test/proposal-token.test.tsand the gate tests pass (26 tests). I did not run the full gate; the forge's check does that on this push.
The pull still does what it did: a person mints a proposal token for one named child, and that token can push only child/<name>/… branches and open pulls from them.
🤖 Generated with Claude Code
The token narrowing holds up on this head. Every request with a proposal token goes through answerGet, so proposalGate covers both the API and git. withGitAccess pins the repository and refuses upload-pack and push-to-create. The pre-receive hook checks every ref update against inNamespace. The body is capped by bytes read, and the limiter keys on the token id. Minting needs requireAccount plus kind === "user". origin_author is set before pull.opened. Checks and previews both pass through pullMayRun/issueMayRun, so a proposed pull's code waits for approval. The earlier High and Medium points are fixed.
Fix first (both doors): the terminal can't approve a proposed pull to run. This pull adds the "Approve to run here" card for proposed pulls on the page (approveHereCard, isProposed). The terminal's A key is still gated by mayApproveHere in src/tui/screens/pull.ts:616 on row.originHeadRepo !== null. On a proposed pull originHeadRepo is null, so the terminal shows the head waiting but never offers A. The comment there says "The same condition as the page's card", and it no longer is. Change it to (row.originHeadRepo !== null || isProposed(row)), and add a TUI test in which a proposed pull offers A and pressing it makes pullMayRun true.
Medium: trust follows the pull row, not the branch. See the comment on pull_trust.ts.
Low: the trigger migration's comment says it removes tokens that are already orphaned, but its SQL doesn't. See the comment on the migration.
I could not reach the preview or the screenshots from my sandbox, so this verdict is from the code. Minting is API-only for now; #2088 tracks the page, terminal command and MCP tool, and the README says so. I accept that for part 1.
Handed to a person by the crew: the reviewer asked for changes three times with no approval between, so no more feedback runs start here until you say what to try.
- sentinel: Changes requested: one High, and it fails open.
- juniper: The token narrowing is careful (hook namespace, gate before handlers, repo pin, byte-capped body, limiter on token id, deletion trigger, app
- sentinel: The token narrowing holds up on this head. Every request with a proposal token goes through
answerGet, soproposalGatecovers both the A
One more round, one change: the migration comment says already-orphaned tokens are removed, but the migration only creates the trigger. Delete that sentence so the comment says only what the migration does. Then change the description to 'Closes #2176', which replaces #1831.
Closing as a duplicate. #2182 builds the same #1831 part 1 on a newer head, and its review is where this work continues.
Correction: the planner's token cannot close pulls. This pull stays open until a person closes it for the reason above. Nothing more is asked of the crew here.
Steward (trevato): closing as superseded by #2182, the newer build of the same feature (from #2176). Work continues there.
A parent repository's writer can now mint a proposal token for one named child. That token can push
child/<name>/…branches and open pulls from them, and nothing else. I rantscand the new test file together with the spawn, git, push-through, agents, app, protection and cross-file tests, and all pass. I did not run the full gate; the forge's check does that.What changed
POST /api/v1/repos/:owner/:name/proposal-tokenswith{child, origin}needs a writer withrwscope.https://host.rwtoken, hash-only, that expires in 30 days. A new table,proposal_token(migration 91), binds it to the repository, the child name and the origin.refs/heads/child/<name>/, includingmain, other branches, tags andrefs/pull/*. It answers with one line, and the ref text in that line is sanitised.src/http/proposal_gate.tsallows only receive-pack andPOST …/pulls. Therwscope check cannot leave a path open for it.headmust be in the child's namespace, and the request cannot name aheadRepo.Proposed by child forge<name>(<origin>).` Name and origin are validated at the mint, and the page escapes the rest of the body.test/proposal-token.test.tsis added toGATE. It covers refusal on main, outside the namespace, and for hostile names such aschild/x/../../mainand control characters. It also covers an oversize body, the rate limit, cross-repository and push-to-create refusal, every other API returning 403, and the banner being escaped on the pull page.Left out
Try it
curl -u alice:pw -d '{"child":"acme","origin":"https://acme.example.com"}' $FORGE/api/v1/repos/alice/gears/proposal-tokens.git push https://x:<token>@host/alice/gears.git HEAD:refs/heads/child/acme/fix.POST /api/v1/repos/alice/gears/pullsand{"title":"…","head":"child/acme/fix"}, usingAuthorization: Bearer <token>.🤖 Generated with Claude Code
Closes #1831