Skip to content

feat(spec): a book audience can name a capability, so Setup and Studio docs open only for callers who can open those apps - #37591

Draft
objectstack-fleet[bot] wants to merge 6 commits into
mainfrom
claude/project-thread-a4oj04
Draft

objectstack-fleet[bot] wants to merge 6 commits into
mainfrom
claude/project-thread-a4oj04

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Sales · project thread

Part of #36029 — the code half. The ADR-0046 §6.7 note the ruling also names lands in its own seat-run PR (Tier H); the seat closes the card when both have merged.

Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: none — no skills/ page teaches the book audience forms; content/docs/ui/doc-pages.mdx documents the new form in this change

维护者速读

  • 没有 Setup 权限的成员,从此在文档列表、搜索内容和直接打开文章三处都看不到 Setup 自带的帮助文档;能进 Setup 的管理员(不管通过哪个权限集拿到的)照常能看。Studio 的帮助文档同理。
  • 这是「控制台 UX 改进」专题里「系统包文档只给管理员看」的收尾:以前只是列表不显示,知道地址的成员仍能打开。按你 11-24 选的方案做:文档可见范围可以写成「持有某项系统权限的人」。
  • 出错时最坏是管理员也看不到这两篇帮助文档(不会多放人进来);改动可直接撤回,不涉及存量数据。
  • 无。

What changes

Ruling of record: the maintainer's answer to the decision card, relayed in comment 7122770897 (「A 按系统权限判定」).

  • @objectstack/spec — BookAudienceSchema / BookAudience gain a fourth, strict arm { systemPermission: string }. AudienceCaller gains systemPermissions?: readonly string[]; audienceAllows admits the arm only for an authenticated caller whose list holds the token, and denies when the list is absent (fail closed, ADR-0049). The other three forms answer exactly as before. Regenerated: content/docs/references/system/book.mdx, the strictness-ledger count (system/ 409 → 410, the new strict arm). Liveness row book.audience re-verified with the new evidence.
  • @objectstack/rest — resolveDocsAudience treats a { systemPermission } book as gated (no fast path), and resolveAudienceCaller fills systemPermissions from the caller's own context — the same list holdsRequiredPermissions reads for an app's requiredPermissions, so the Setup manual opens for exactly the callers the Setup app opens for. Holdings are read only when such a book exists; a capability-only gate never asks the security service for permission sets. New export anySystemPermissionAudience; new optional port MetaReadGateAudienceSources.resolveAudienceSystemPermissions for a transport whose audience reads someone else's holdings.
  • @objectstack/runtime — the MCP docs door (search_package_docs, read_package_doc) supplies that port on a delegated OAuth envelope, so the delegating person's own capabilities decide, never the token's ceiling (the same rule its { permissionSet } reading already follows, ADR-0090 D10).
  • @objectstack/setup, @objectstack/studio — each registers a manual (setup_manual, studio_manual; include: '*' over its own package) with audience: { systemPermission: 'setup.access' } / 'studio.access', the token each app's requiredPermissions names.
  • @objectstack/lint — capability-reference-unknown also resolves books[].audience.systemPermission; its os explain text names the new position.
  • ui/ (@object-ui/app-shell, @object-ui/i18n) — Studio's book preview shows a capability-gated book as "Capability: TOKEN" / 「系统权限:TOKEN」 instead of "Org", and the book form's JSON schema round-trips the new form.
  • Docs — content/docs/ui/doc-pages.mdx documents the form and when to use it.

Decided in the thread (small, listed here per the standing rule):

  • Arm name systemPermission (the ruling left it to the spec lane): it is the same word as the grant side, systemPermissions, which is what an author writes on the permission set.
  • Holdings source: the caller's own systemPermissions (what the app gate reads) rather than a fresh resolvePermissionSetsForContext pass — the ruling's intent is "every admin who can open Setup can read it", and this is that predicate exactly, with no second resolution to drift from it. The MCP door's delegated envelope reads the person's resolved grants, as before.

Item 2 of the card (the other com.objectstack.* docs): exactly two exist on origin/main, setup_overview and studio_overview; both are now gated. No end-user platform help exists today, so nothing stays readable by everyone.

Tests

All run against this branch's head; each pinned behaviour was ablated once (rebuild, change, watch it red, restore).

Targeted suites
  • packages/spec src/system/book.test.ts — 50/50 (parse of the arm, strictness, audienceAllows, set ≠ capability both ways, fail closed, resolveDocAudiences union with a { systemPermission } book).
  • packages/lint src/validate-capability-references.test.ts — 22/22 (typo at books[2].audience.systemPermission warns; built-in and granted tokens pass; other forms resolve nothing).
  • packages/rest src/meta-doc-system-permission-audience.test.ts (new) — 12/12: a member without the capability gets the Setup doc in neither GET /meta/doc nor ?include=content (body absent from the whole answer), 403 PERMISSION_DENIED on GET /meta/doc/:name, the book absent from GET /meta/book and 403 on its tree, nothing from the implicit package book either; a holder reads all of it; a non-list systemPermissions denies; anonymous 401; no permission-set resolution for a capability-only gate; fast-path control.
  • packages/runtime src/domains/mcp-package-docs.test.ts — 26/26 (5 new: session holder / non-holder, set-named-like-capability stays closed, no list fails closed, OAuth person decides, OAuth envelope capability opens nothing — no union).
  • packages/qa/dogfood test/setup-docs-audience.dogfood.test.ts (new) — 3/3 on a real boot with the real createSetupAppPlugin(): precondition (member 403 on the Setup app, admin 200), member refused on all three doors, admin reads all three plus the manual's tree.
  • ui packages/app-shell/.../adminPreviews.i18n-10862-s2.test.tsx — 42/42 (new case per language for the capability chip).
Ablations
  • REST: needSystemPermissions: false → the 3 holder pins red (12 → 9 pass).
  • MCP: delegated override removed → the 2 OAuth pins red (26 → 24).
  • Setup: books: [] → both dogfood door pins red (the member reads the doc again — the pre-fix behaviour reproduced on a real boot).

Acceptance notes

  • The Setup/Studio docs' Console address changes from the implicit book (/apps/com.objectstack.setup/docs/com.objectstack.setup/setup_overview) to the manual (.../docs/setup/setup_overview). No link in the repo names the old one; the flat /docs/setup_overview permalink still finds the page.
  • The manual card on the "All docs" page is now labelled by the book (Setup / Studio, English) where the implicit book borrowed the app's translated label. Platform packages ship no books.*.label bundle today; noted, not filed.
  • A { permissionSet, systemPermission } object (both keys) parses as the { permissionSet } arm with the other key dropped, because that older arm is not strict; making it strict is a narrowing and out of scope.
  • Comment drift (carried from the earlier os-dev report on this card): the NOTE (transitional) header in packages/apps/setup/src/index.ts says the package is not yet wired into dev/serve; it is (packages/cli/src/commands/serve.ts, packages/plugins/plugin-dev/src/dev-plugin.ts). Left as is.

Verification

Read first: packages/rest/src/meta-item-read-gate.ts (resolveAudienceCaller, resolveDocsAudience) — the one place the new holdings are read; then packages/spec/src/system/book.zod.ts (audienceAllows); then packages/runtime/src/domains/mcp-package-docs.ts (packageDocsReadGate).

Two-minute check: pnpm --filter @objectstack/dogfood exec vitest run test/setup-docs-audience.dogfood.test.ts — expect 3 passed: a plain member is refused the Setup doc on every door, the admin reads it.

L2 owed at CONTRACT_REVIEW_TIER (Clause-② widening on packages/spec/src), by the seat — not self-reviewed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc


Generated by Claude Code

…o docs open only for callers who can open those apps

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc
…and the REST docs doors

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc
…e Studio book preview; document it

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc
…dger; record the capability arm on the audience liveness row; changeset; Setup docs dogfood pin

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation protocol:system tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 6 package(s): @objectstack/setup, @objectstack/studio, @objectstack/lint, @objectstack/rest, @objectstack/runtime, @objectstack/spec, touching 26 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/spec/liveness/book.json), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

25 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 58570d8002dd213f7f65525d881ac935583f4050.

⛔ 12 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/spec/liveness/book.json) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: requiredPermissions (literal, 42 pages)
  • 6 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 184 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 58570d8002dd213f7f65525d881ac935583f4050 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 6ab8b90ca97ba0a89ffc5215e229a538857a9ee7 — the merge of head 99447c4346f0c6dfb7779ca26d2e2c784a858afb into base 58570d8002dd213f7f65525d881ac935583f4050, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 6ab8b90ca97ba0a89ffc5215e229a538857a9ee7 && git checkout 6ab8b90ca97ba0a89ffc5215e229a538857a9ee7
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 58570d8002dd213f7f65525d881ac935583f4050 99447c4346f0c6dfb7779ca26d2e2c784a858afb && git checkout -B drift-repro 58570d8002dd213f7f65525d881ac935583f4050 && git merge --no-ff 99447c4346f0c6dfb7779ca26d2e2c784a858afb

node scripts/docs-audit/affected-docs.mjs --json 58570d8002dd213f7f65525d881ac935583f4050

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 58570d8002dd213f7f65525d881ac935583f4050 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…on audience test; docs: lint resolves book audience capabilities

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-sales · session_01L6bhgV6i8jfWwSXjpWJrjA

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 899b3e2f7cd924e3a6de98b481f3a9dc6f4b00b8
Local-runs: none
Scope: packages/spec/src/system/book.zod.ts + packages/rest/src/meta-item-read-gate.ts, packages/runtime/src/domains/mcp-package-docs.ts, packages/lint/src/validate-capability-references.ts, packages/apps/setup/src/setup-manual.book.ts, packages/apps/studio/src/studio-manual.book.ts

Inputs read: card #36029 (body and all six comments, ruling 7122770897 included), PR #37591 (body, 25 files, net diff against main), and the check-runs on the head: every one is success or skipped, none failed. Code outside the diff was read in the tree at the head, never reviewed.

① Derived judgments

  • BookAudienceSchema accepts a fourth arm, { systemPermission: string }, strict. A widening: the shape was refused before. No value that parsed before parses differently now (the three older arms are untouched, and they are tried first). Right.
  • BookAudience (the exported type) gains a union member. A consumer that narrowed with typeof audience === 'object' and then read .permissionSet stops compiling; the one in-repo reader (BookPreview.tsx) is fixed in this diff, and audienceAllows narrows by key. Right at minor under Metadata-protocol: added; the changeset does not tell a TypeScript consumer (see N2).
  • AudienceCaller.systemPermissions is a new optional field, and audienceAllows reads it for the new arm only. The public, org and { permissionSet } answers are the same predicates as on main. Absent or not a list denies. Right.
  • @objectstack/rest: an optional port (resolveAudienceSystemPermissions), an optional option (needSystemPermissions), an optional result field, and anySystemPermissionAudience. All additive. A { systemPermission } book takes every docs door off the fast path, which the arm needs. Right.
  • @objectstack/runtime: on a delegated envelope the MCP docs door reads the delegating person's capabilities in place of the envelope's list, never a union. The same holder its { permissionSet } reading already uses on main. Right (wording: N1).
  • @objectstack/lint: capability-reference-unknown gains one position, books[i].audience.systemPermission, as a warning. Existing messages are unchanged (the new key parameter defaults to the old word). Right.
  • @objectstack/setup, @objectstack/studio: each ships a gated manual, so setup_overview and studio_overview go from org to capability-gated on every docs door. This is the narrowing the ruling asked for. Right for those two docs.
  • The same two manuals also change the effective audience of docs that are not theirs. Not declared, and wrong: S1.

② Semver level

Clause-②: yes (widening) and Metadata-protocol: added stand on the PR body and in the changeset, and they agree with the diff: a new accepted audience value, nothing removed or tightened in the schema. added takes at least minor on each package the diff moves, and the changeset gives minor to all eight (spec, rest, runtime, lint, setup, studio, @object-ui/app-shell, @object-ui/i18n). Check Changeset is green. The level is right.

Two sentences of the changeset body do not hold as written: "Nothing to migrate: no stored or authored value changes meaning" (S1), and "a key beside systemPermission is refused at parse" (N2).

③ Boundary flags

  • os-dev report 7112446659, open question A to D: answered by the maintainer ruling relayed in 7122770897 (A). This diff implements A.
  • The ruling's relay names resolvePermissionSetsForContext as the source of the holdings. On REST the diff reads the caller's own systemPermissions instead, and says so in the PR body. Judged right: that list is the one callerSystemPermissions hands holdsRequiredPermissions for the app arm, so the manual and its app are decided by one list with no second resolution to drift; the maintainer's own words rule the outcome ("every admin who can open Setup can read it"), which this meets. Not escalated.
  • Arm name left to the spec lane: systemPermission. Right: it is the grant side's word (systemPermissions), and the lint and os explain already speak it.
  • ADR-0046 §6.7 note: split out by claim 7194108111 into a seat-run Tier H PR. It is not in this diff and no such PR was open at review time. The jsdoc here already cites §6.7 for the arm, so the card stays open on that note.
  • PR-body acceptance notes: the Console address and label changes are the lane seat's; the two-key parse is N2; the comment drift in packages/apps/setup/src/index.ts is carried from the earlier report and left as noted.
  • SQL push-down: nothing new. REST reads the list off the resolved caller, with no query. The MCP door reuses the one memoised grant resolution its { permissionSet } reading already makes (holdings ??=), so a gate that reads both forms still resolves the person once. No new id materialisation, no in-app join.

④ Design judgment

packages/spec/src/system/book.zod.ts (hits), against ruling 7122770897 and its first consumers.

The arm is what the ruling asked for: one key, a string, strict, described. audienceAllows tries the forms in the order the union parses them, and an unrecognised shape still denies. Tried and held:

  • Anonymous: authenticated is false before either gated form is read, so a list on an unauthenticated caller opens nothing (pinned in book.test.ts, and as 401 on REST).
  • Missing or non-array list: undefined, null and a bare string all deny, in the spec helper and again in resolveAudienceCaller (pinned on both).
  • Name collision with a permission set: the two forms read two separate lists, so a set named like the token opens nothing, and a capability named like a set opens no { permissionSet } book (pinned both ways, and on the MCP door).
  • Delegated OAuth: the person's own capabilities decide, with no union with the envelope (pinned, including an envelope that carries the capability the person lacks).

S1 (should-fix) — the two manuals claim docs that are not their package's. SETUP_MANUAL_BOOK and STUDIO_MANUAL_BOOK use groups: [{ include: '*' }], scoped by the book's own package. matchesInclude drops a doc from a scoped rule only when the doc carries a packageId that differs; a doc with no stamped package is in every scope (pinned on main: book.test.ts, "a doc with no stamped packageId is in every scope"). A stored doc row bound to no package is served with no _packageId (withRowBinding, packages/metadata-protocol/src/protocol-package-bindings.ts), and docCorpusOf reads that stamp alone. So wherever either package is installed, every package-less doc is claimed by setup_manual and studio_manual, and its effective audience (the §6.7 union) stops being the org fallback. A member who read such a doc before this change gets 403 on its read and loses it from the list, the content answer and the MCP search; the doc also shows up inside the Setup and Studio manual trees. The card does not ask for this, the PR does not declare it, and three sentences in the diff say otherwise: the book files' "over this package's own docs", the new spec test's "include: '*' reaches only the book's own package" (its corpus is all stamped), and the changeset's "no stored or authored value changes meaning". Graded should-fix, not must-fix, because the package-less state is ADR-0070's legacy and migration-source state, and because this was read in the tree, not measured on a boot. The fix is inside the diff: have each manual claim by its own namespace (setup_*, studio_*) or by pinned pages, correct the three sentences, and pin the control: with both manuals registered, a doc carrying no _packageId that no other book claims stays readable by a member on the list, the single read and the MCP answer.

Nits (no effect on correctness or the contract; left as accepted deviations or a follow-up card):

  • N1 — the jsdoc on BookAudienceSchema ("the same answer an app's requiredPermissions: [token] gets") and on AudienceCaller.systemPermissions ("exactly for whoever can open an app gated on that token") is true of a session. On the MCP door's delegated envelope the person's capabilities decide whatever list the envelope carries, by design and as the runtime docblock says. The spec sentences could name that exception.
  • N2 — an audience carrying both keys parses as the { permissionSet } arm with systemPermission dropped, because the older arm is not strict (the PR body says so). The changeset's "a key beside systemPermission is refused at parse" is therefore not true of permissionSet, and the type accepts the two-key literal. Worth a follow-up card: a lint finding on the two-key shape, or a strict older arm under its own narrowing declaration. The changeset could also tell a TypeScript consumer to narrow BookAudience by key.
  • N3 — with a gated manual shipped by two platform packages, allReadable is false in every deployment that installs either one, so the docs doors' fast path no longer applies there: each doc read, doc list and app-nav doc gate now reads the doc corpus and runs the audience pass. Correct, and the price of the ruling; worth a line in the PR body, and a follow-up if the docs doors show up in a profile.

Implementing files, sentence by sentence.

  • packages/rest/src/meta-item-read-gate.ts — agrees. Holdings are read only when a { systemPermission } book is among the books judged; a rejecting or non-list answer leaves the field off and the audience denies; permission sets are not resolved for a capability-only gate (pinned); the port, when present, replaces the caller's list.
  • packages/runtime/src/domains/mcp-package-docs.ts — agrees. The port exists only on a delegated envelope; an unknown person, a person with no membership in the request's organization, or unreadable grants throw and read as closed; one resolution per gate.
  • packages/lint/src/validate-capability-references.ts — agrees with its header and with os explain.
  • packages/apps/setup/src/setup-manual.book.ts, packages/apps/studio/src/studio-manual.book.ts — the audience is the token each app's requiredPermissions names, and the dogfood pin shows the member and the administrator on a real boot. The membership sentence does not hold: S1.

Implemented-by: claude/project-thread-a4oj04
Reviewed-by: session_01L6bhgV6i8jfWwSXjpWJrjA

VERDICT: PASS

…ge-less doc

A package scope leaves out only a doc stamped with another package, so a
stored doc bound to no package is in every scope: include '*' made both
manuals claim it and gate it on setup.access / studio.access. Claim by
setup_* / studio_* instead, pin an unstamped control doc on spec, REST and
MCP, and correct the docs, jsdoc and changeset sentences that said otherwise.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgV8bjXeBN9N25FTesc

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:system size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants