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

Access 1: one Principal for who is asking, an anonymous visitor included #18060

opened this in answer to

Merged 9h 3m ago, live in production

Principal is added as a type. Nothing decides on it yet, so no route answers differently. I ran only the tests that touch this change, plus tsc and the gate.

Notes

opened this

Principal is added as a type. Nothing decides on it yet, so no route answers differently. I ran only the tests that touch this change, plus tsc and the gate. I did not run the full suite, so "full suite unchanged" is not confirmed yet. That is the forge's check on this push.

What changed

  • src/core/principal.ts (new):
    • principalOf(auth) always returns a value. Anonymous is {kind: "anonymous", refused, retryAfter?}, so a credential that matched nothing is still anonymous but remembers that.
    • A signed-in account arriving by session, edge or password is session. A terminal screen acting for a person is also session, with via: "none".
    • Tokens are ro_token, rw_token, admin_token, proposal_token, run_token, contribute_token, read_grant_token and via_token. A token that carries several scopes takes the first match in that order: proposal, run, contribute, read grant, via, plain scope.
    • Each signed-in principal has a subject: person, agent or app. The subject type also has runner, game_box and device, which principalOf never produces yet. A device carries the person it is bound to, as the household-peer review asked. Registering and revoking devices is a later slice.
  • Reachability: roleOf in src/http/usage_tag.ts now reads the account through principalOf(auth) and userOf. I checked by reading that it returns the same role for every Auth. This is what gives the new code a real caller.
  • The words: docs/ROLES.md has a new "The words" table. A visitor has no account and is not a role. Guest, member and admin stay the signed-in roles. The ssh rate-limit message and the comments on it now say "visitor" for a key with no account.
  • test/principal.test.ts: one case for each way of arriving. It pins the kind and subject, checks that every kind is reached by some arrival and that the account behind each principal is the one Auth held.

What I chose not to do

  • I did not touch the other access checks (canRead, canWrite, canAdmin, the CAN table, scopeAllows) or the grant tables. Moving them onto Principal is later slices.
  • I renamed no identifiers. The guest role and the GUEST_* constants in the ssh code keep their names. Only what people read changed.
  • I did not rename "guest" in the other docs and feature pages. A grep found about 20 docs and 40 source files that use the word. I changed only the one sentence that used it for a visitor, and I did not read each of the other uses.
  • No door change: this is a type and words, with no page, action, route or tool.

How to try it: call GET /api/v1/user on the preview with and without a token. The answers are the same as before. bun test test/principal.test.ts prints the table of arrivals.

Closes #18047

5 earlier comments
commented

Principal is added as a type. Nothing decides on it yet, so no route answers differently. I ran only the tests that touch this change, plus tsc and the gate. I did not run the full suite, so "full suite unchanged" is not confirmed yet. That is the forge's check on this push.

What changed

  • src/core/principal.ts (new):
    • principalOf(auth) always returns a value. Anonymous is {kind: "anonymous", refused, retryAfter?}, so a credential that matched nothing is still anonymous but remembers that.
    • A signed-in account arriving by session, edge or password is session. A terminal screen acting for a person is also session, with via: "none".
    • Tokens are ro_token, rw_token, admin_token, proposal_token, run_token, contribute_token, read_grant_token and via_token. A token that carries several scopes takes the first match in that order: proposal, run, contribute, read grant, via, plain scope.
    • Each signed-in principal has a subject: person, agent or app. The subject type also has runner, game_box and device, which principalOf never produces yet. A device carries the person it is bound to, as the household-peer review asked. Registering and revoking devices is a later slice.
  • Reachability: roleOf in src/http/usage_tag.ts now reads the account through principalOf(auth) and userOf. I checked by reading that it returns the same role for every Auth. This is what gives the new code a real caller.
  • The words: docs/ROLES.md has a new "The words" table. A visitor has no account and is not a role. Guest, member and admin stay the signed-in roles. The ssh rate-limit message and the comments on it now say "visitor" for a key with no account.
  • test/principal.test.ts: one case for each way of arriving. It pins the kind and subject, checks that every kind is reached by some arrival and that the account behind each principal is the one Auth held.

What I chose not to do

  • I did not touch the other access checks (canRead, canWrite, canAdmin, the CAN table, scopeAllows) or the grant tables. Moving them onto Principal is later slices.
  • I renamed no identifiers. The guest role and the GUEST_* constants in the ssh code keep their names. Only what people read changed.
  • I did not rename "guest" in the other docs and feature pages. A grep found about 20 docs and 40 source files that use the word. I changed only the one sentence that used it for a visitor, and I did not read each of the other uses.
  • No door change: this is a type and words, with no page, action, route or tool.

How to try it: call GET /api/v1/user on the preview with and without a token. The answers are the same as before. bun test test/principal.test.ts prints the table of arrivals.

commented

This round answers the review's three points: the wording, the dead variants and the missing tests. Principal is still additive, and no route answers differently.

Wording (box 3). Where "guest" meant someone with no account, it now says "visitor". That covers comments in src/tui (ssh.ts, session.ts, ssh-tell.ts, main.ts, about 40 screens, ui/image.ts, forge_parts.ts), one in src/web/pages/milestones_near.ts, and the matching docs under docs/. Identifiers and filenames such as ssh-guest-rate.ts are unchanged.

I kept "guest" where it means a signed-in non-member. That includes people.ts, repo.ts, config.ts, ROLES.md and the make-it-yours text. I also kept the guest-pull meaning, a pull from another forge's fork, in pull-guest.ts, guest-pulls.md and ORIGINS.md.

Two things for you to check:

  • Terminal title: the terminal dashboard's visible title still says "Guest" for a signed-out session (dashboard.ts:1265). That is output rather than a comment, so I left it. If you want it to say "Visitor", it's a one-word change plus any test that pins it.
  • Ambiguous docs lines: a few docs lines are ambiguous. For example, "a reader, a guest and an agent are refused" in demo.md and flow-valves.md could mean either sense. I kept those as "guest". Say if any should flip.

Dead variants.

  • Removed: runner, device and game_box are gone from Subject. So is the device branch of userOf, and userOf is now principal.subject.user.
  • ROLES.md: the paragraph that mentioned them is gone too.
  • Next slice: each variant comes back in the slice that produces it, with a test.

Tests, in test/principal.test.ts.

  • Real auth path: one case runs the server's real resolveAuth, which is now exported, over a real session cookie, an ro bearer token, no credential and an unknown token. It checks the principal kind and the user behind it.
  • Scope precedence: one Auth carrying proposal, run, contribute, app, via and admin scopes is stripped one scope at a time. The kind falls through proposal_token, run_token, contribute_token, read_grant_token, via_token and admin_token, which is the order the doc comment claims.

Checks.

  • Passed: tsc is clean. These pass: principal, unused-exports, roles, docs-index, features and features-tui.
  • Gate: I ran scripts/gate.ts --fix and committed the rewrap.
  • Not run: fast.ts named 4092 test files, which is too many to run here. I did not run the rest of the suite. The forge's check does that on this push.

Doors. This change adds no feature. The terminal and docs/features/ edits are wording only.

Not done. I did not touch identifiers, route behaviour, or the role table.

commented

<!-- look-pages 60ca81800b21 --> Look pages for 60ca818, from the gate:

  • look pages (none): this pull changes src/web/pages/milestones_near.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
commented

This pull adds one Principal value for who is asking, and a visitor with no account is a case of it. roleOf now reads it. No route's answer changes.

Look pages: the gate couldn't trace a page for src/web/pages/milestones_near.ts. The only change there is one word in a doc comment ("guest" became "visitor"), so no page renders differently. I added an empty commit with No look: the only change under src/web is a word in a doc comment …, which is the line the gate asks for, and pushed it. I didn't re-run the gate or any tests, because nothing in the code changed.

The other refusals you listed (both doors, dead exports, process-wide state, untimed jobs): I made no code changes for them. The earlier commits already carry No door:. I haven't re-checked the dead-export, process-wide state and untimed-job tests against the current branch; I'm leaving those to the forge's check on this push.

commented

Adds src/core/principal.ts: one Principal value says who is asking. It covers a session, each kind of token, and a visitor with no account; roleOf reads it. No route's answer changes. The real run and contribute scopes are built in the tests, and which scope wins is pinned. GET /api/v1/user answers as before with and without a token.

The words now say "visitor" wherever no account is meant: docs/ROLES.md, the ssh rate-limit message, and the terminal dashboard's title for a signed-out session (src/tui/screens/dashboard.ts:1265, which said "Guest"). Two tests pinned the old title, test/ssh-app.test.ts and test/tui-screens.test.ts, and now expect "Visitor". The tests weren't wrong: the words changed on purpose.

"Guest" stays where it means the guest role or a guest pull. It also stays in two docs lines, demo.md and flow-valves.md, where the meaning is unclear; a later slice can settle those.

Before the last push the gate showed 0 failures, 1 rule noted and 31 satisfied. bun x tsc --noEmit is clean. ssh-app, tui-screens, tui-dashboard-alarms and tui-home-row pass, with 7 tests skipped because they need a unix socket. scripts/fast.ts named 4092 test files for this pull, too many to run here, so the forge's check covers the rest.

To try it: ssh in with the command in FORGE_APP_SSH using a key no account owns. The breadcrumb should read "Visitor" and list only public repositories.

[{"go":"ssh with FORGE_APP_SSH using a key no account owns","look":"the dashboard breadcrumb","expect":"it reads Visitor, and only public repositories are listed"},
 {"go":"GET /api/v1/user without a token, then with one","look":"status and body","expect":"same answers as on main"}]

🤖 Generated with Claude Code

commented

Adds src/core/principal.ts: one Principal value says who is asking, whether that is a session, a token of any kind, or a visitor with no account. roleOf now reads it. No route's answer changes. The tests build the real run and contribute scopes, and they pin which scope wins. GET /api/v1/user answers as before with and without a token.

Wherever no account is meant, the words now say "visitor": docs/ROLES.md, the ssh rate-limit message, and the terminal title for a signed-out session (src/tui/screens/dashboard.ts:1265, which used to say "Guest"). Four tests read that title and now expect "Visitor". The tests were not wrong; the wording changed on purpose:

  • test/ssh-app.test.ts
  • test/tui-screens.test.ts
  • test/tui-changelog-waves.test.ts
  • test/turnstile.test.ts, which waited for "Guest ›" before typing. That is why its sign-up assertion failed in the last check.

"Guest" stays wherever it means the guest role or a guest pull. It also stays in two docs lines whose meaning is unclear, demo.md and flow-valves.md, which are left for a later slice.

Checks:

  • The four tests above pass, along with tui-dashboard-alarms and tui-home-row. Seven tests in those files were skipped here because they need a unix socket.
  • bun x tsc --noEmit is clean.
  • The gate reports 0 failures, 1 rule noted and 31 satisfied.
  • scripts/fast.ts named 4092 test files for this pull, too many to run here, so the forge's check covers the rest.
[{"go":"ssh with FORGE_APP_SSH using a key no account owns","look":"the breadcrumb on the dashboard and on Sign in","expect":"it starts with Visitor, and only public repositories are listed"},
 {"go":"GET /api/v1/user without a token, then with one","look":"status and body","expect":"same answers as on main"}]

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs