Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/36029-book-audience-system-permission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
'@objectstack/spec': minor
'@objectstack/rest': minor
'@objectstack/runtime': minor
'@objectstack/lint': minor
'@objectstack/setup': minor
'@objectstack/studio': minor
'@object-ui/app-shell': minor
'@object-ui/i18n': minor
---

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

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

A book's `audience` (ADR-0046 §6.7) takes a fourth form, `{ systemPermission: 'TOKEN' }`: the book's pages are read by a signed-in caller who holds that capability through any permission set, the same caller an app with `requiredPermissions: ['TOKEN']` opens for. `{ permissionSet }` names one set, so it could not gate a manual on a capability several sets grant (`setup.access` comes with `organization_admin`, `admin_full_access` and any delegated-admin set an application authors).

- **`@objectstack/spec`.** `BookAudienceSchema` and `BookAudience` gain the arm. It is strict, so `{ systemPermission, label }` is refused at parse; an object that also carries `permissionSet` still parses as the older, non-strict `{ permissionSet }` arm with the other key dropped, as before. `BookAudience` is a wider union now: TypeScript code that reads `.permissionSet` after a bare `typeof audience === 'object'` check narrows by key instead (`'permissionSet' in audience`). `AudienceCaller` gains `systemPermissions`, and `audienceAllows` admits the arm only when that list holds the token; an absent list denies (fail closed). Every other form answers as before.
- **`@objectstack/rest`.** The docs audience reads the caller's own `systemPermissions` (the list every `requiredPermissions` arm of the `/meta` read gate reads) when some book carries the new form, on `GET /meta/doc` (with and without `?include=content`), `GET /meta/doc/:name`, `GET /meta/book`, `GET /meta/book/:name/tree` and the app-nav `doc` entries. New: `anySystemPermissionAudience`, and the optional `resolveAudienceSystemPermissions` port on `MetaReadGateAudienceSources` for a transport whose audience reads someone else's holdings.
- **`@objectstack/runtime`.** The MCP docs tools (`search_package_docs`, `read_package_doc`) gate on the same form; on an OAuth grant they read the delegating person's own capabilities, never the token's ceiling.
- **`@objectstack/setup`, `@objectstack/studio`.** Each package now ships a manual (`setup_manual`, `studio_manual`) claiming its package's doc namespace (`setup_*`, `studio_*`), gated on `setup.access` / `studio.access`. Before, those docs were claimed by no book, so they fell back to `org`: listed to administrators only by the Console's docs index, but readable at their address, and through `?include=content`, by every signed-in member. Now a member who cannot open Setup gets `setup_overview` in neither list and a `403 PERMISSION_DENIED` on its read; an administrator reads it as before. The docs' Console address now names the manual (`/apps/com.objectstack.setup/docs/setup/setup_overview`) in place of the package's implicit one; the flat `/docs/setup_overview` permalink still finds it.
- **`@objectstack/lint`.** `capability-reference-unknown` also resolves a book's `audience.systemPermission`, so a misspelled capability (which hides the manual from everyone) warns.
- **`@object-ui/app-shell`, `@object-ui/i18n`.** Studio's book preview shows a capability-gated book as "Capability: TOKEN" instead of "Org", and the book form round-trips the new form.

Nothing to migrate: the manuals claim by name, so a stored doc bound to no package (which a package-scoped `include: '*'` would also have claimed) keeps the audience it had. Only docs named under those prefixes change audience: on `main` that is `setup_overview` and `studio_overview`.
4 changes: 2 additions & 2 deletions content/docs/permissions/capabilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ plain names. Three consequences worth internalising before you pick one:
capability name; it is simply held by nobody, so the caller is denied. That is
the safe direction, but nothing about the denial says the name exists nowhere.
The authoring lint `validateCapabilityReferences` (ADR-0066 ⑨) closes part of
this gap: it resolves every `requiredPermissions` reference against the
capabilities known at author time and **warns** on the unresolved ones. It
this gap: it resolves every `requiredPermissions` reference, and every book's
`audience: { systemPermission }`, against the capabilities known at author time and **warns** on the unresolved ones. It
reads every package of the artifact being built, so a grant in a sibling
package of the same artifact counts, as it does at run time. It is a warning,
not an error, because the lint cannot see capabilities declared by packages
Expand Down
14 changes: 13 additions & 1 deletion content/docs/references/system/book.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const result = BookSchema.parse(data);
| **slug** | `string` | optional | Portal URL segment; defaults to name sans prefix |
| **icon** | `string` | optional | |
| **order** | `number` | optional | Orders books within the portal |
| **audience** | `'org' \| 'public' \| { permissionSet: string }` | optional | Access audience; defaults to 'org' (inherits package grant) |
| **audience** | `'org' \| 'public' \| { permissionSet: string } \| { systemPermission: string }` | optional | Access audience; defaults to 'org' (inherits package grant) |
| **groups** | `{ key: string; label: string; order?: number; include?: string \| object; … }[]` | ✅ | The spine: ordered sections. Two levels total. |
| **_lock** | `Enum<'none' \| 'no-overlay' \| 'no-delete' \| 'full'>` | optional | Item-level lock — controls overlay & delete (ADR-0010). |
| **_lockReason** | `string` | optional | Human-readable reason shown when a write is refused by _lock. |
Expand Down Expand Up @@ -113,6 +113,18 @@ Type: `'public'`

---

#### Option 4

Readers holding this capability through any permission set, e.g. `{ systemPermission: 'setup.access' }`

### Properties

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **systemPermission** | `string` | ✅ | |

---


---

Expand Down
18 changes: 14 additions & 4 deletions content/docs/ui/doc-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,24 @@ as a preference, not as a limitation. Tags are for membership that cuts across n
| `slug` | `string` | — | Portal URL segment; defaults to the name without its prefix |
| `icon` | `string` | — | Icon name |
| `order` | `number` | — | Orders this book among the portal's books |
| `audience` | `'org' \| 'public' \| { permissionSet }` | — | Who may read it; defaults to `'org'` |
| `audience` | `'org' \| 'public' \| { permissionSet } \| { systemPermission }` | — | Who may read it; defaults to `'org'` |
| `groups` | `BookGroup[]` | ✅ | The spine. Two levels total — groups, then entries |

`audience` is a reference into the permission model rather than a vocabulary of its own:
`'org'` (the default) inherits the package grant and admits any signed-in principal,
`'public'` is anonymously readable and indexable, and `{ permissionSet: 'crm_admin' }`
admits a signed-in principal holding that named set. A caller whose holdings cannot be
resolved is denied — the gate fails closed.
`'public'` is anonymously readable and indexable, `{ permissionSet: 'crm_admin' }`
admits a signed-in principal holding that named set, and
`{ systemPermission: 'crm.read_runbook' }` admits a signed-in principal holding that
capability through any permission set — the same caller an app with
`requiredPermissions: ['crm.read_runbook']` opens for. Use the capability form for the
manual of an app gated on a capability several sets grant: naming one of those sets would
shut out the holders of every other one. A caller whose holdings cannot be resolved is
denied — the gate fails closed.

Claim a gated book's pages by name (a namespace glob such as `include: 'crm_runbook_*'`, or
pinned `pages`), not with `include: '*'`. A package scope leaves out only a doc stamped with
*another* package, so a stored doc bound to no package is in every scope: a catch-all gated
book would claim it as well and take it away from every reader outside the audience.

<Callout type="info">
The gate is a **capability** reference, never a distribution one: packages own permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ hand-patch a number here** — fix the code or the verdict and regenerate.

| Dir | Sites |
|---|---|
| `system/` | 409 |
| `system/` | 410 |
5 changes: 5 additions & 0 deletions packages/apps/setup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { SETUP_APP, SETUP_NAV_CONTRIBUTIONS } from '@objectstack/platform-objects/apps';

import { SETUP_OVERVIEW_DOC } from './setup-overview.doc.js';
import { SETUP_MANUAL_BOOK } from './setup-manual.book.js';

export const SETUP_APP_PACKAGE_ID = 'com.objectstack.setup';
export const SETUP_APP_NAMESPACE = 'setup';
Expand Down Expand Up @@ -60,6 +61,9 @@ export class SetupAppPlugin {
navigationContributions: SETUP_NAV_CONTRIBUTIONS,
// ADR-0046 package docs — grouped under "Setup" at /_console/docs.
docs: [SETUP_OVERVIEW_DOC],
// ADR-0046 §6.7 — the manual claiming those docs, read only by the
// callers who may open the Setup app (its `audience`).
books: [SETUP_MANUAL_BOOK],
});
}
}
Expand All @@ -71,3 +75,4 @@ export function createSetupAppPlugin(): SetupAppPlugin {

export { SETUP_APP, SETUP_NAV_CONTRIBUTIONS };
export { SETUP_OVERVIEW_DOC };
export { SETUP_MANUAL_BOOK };
30 changes: 30 additions & 0 deletions packages/apps/setup/src/setup-manual.book.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import type { Book } from '@objectstack/spec/system';

/**
* The Setup app's manual (ADR-0046 §6), registered beside its docs.
*
* Its job is the `audience`: Setup's pages are administrator help, so they are
* read by exactly the callers who may open the Setup app — whoever holds
* `setup.access` (the app's `requiredPermissions`), through ANY permission set
* (`organization_admin`, `admin_full_access`, a delegated-admin set an
* application authors). A `{ permissionSet }` audience would name one of
* those sets and shut out the holders of every other one.
*
* Membership is derived by this package's doc namespace (`include: 'setup_*'`),
* so a page this package adds later under that prefix is gated the same way
* with no edit here. Not `'*'`: a package scope drops only a doc stamped with
* ANOTHER package, so a stored doc bound to no package (ADR-0070) is in every
* scope, and a catch-all would claim it and gate it on `setup.access` too.
* Without a book claiming them, the docs fall back to `org` (§3.6): listed
* only to admins by the Console's docs index, but readable at their address,
* and through `?include=content`, by every member.
*/
export const SETUP_MANUAL_BOOK: Book = {
name: 'setup_manual',
label: 'Setup',
slug: 'setup',
audience: { systemPermission: 'setup.access' },
groups: [{ key: 'all', label: 'Documentation', include: 'setup_*' }],
};
5 changes: 5 additions & 0 deletions packages/apps/studio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import { STUDIO_APP } from '@objectstack/platform-objects/apps';

import { STUDIO_OVERVIEW_DOC } from './studio-overview.doc.js';
import { STUDIO_MANUAL_BOOK } from './studio-manual.book.js';

export const STUDIO_APP_PACKAGE_ID = 'com.objectstack.studio';
export const STUDIO_APP_NAMESPACE = 'studio';
Expand Down Expand Up @@ -72,6 +73,9 @@ export class StudioAppPlugin {
apps: [STUDIO_APP],
// ADR-0046 package docs — grouped under "Studio" at /_console/docs.
docs: [STUDIO_OVERVIEW_DOC],
// ADR-0046 §6.7 — the manual claiming those docs, read only by the
// callers who may open the Studio app (its `audience`).
books: [STUDIO_MANUAL_BOOK],
});
}
}
Expand All @@ -83,3 +87,4 @@ export function createStudioAppPlugin(): StudioAppPlugin {

export { STUDIO_APP };
export { STUDIO_OVERVIEW_DOC };
export { STUDIO_MANUAL_BOOK };
26 changes: 26 additions & 0 deletions packages/apps/studio/src/studio-manual.book.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import type { Book } from '@objectstack/spec/system';

/**
* The Studio app's manual (ADR-0046 §6), registered beside its docs.
*
* Its job is the `audience`: Studio's pages are builder help, so they are read
* by exactly the callers who may open the Studio app — whoever holds
* `studio.access` (the app's `requiredPermissions`), through ANY permission
* set. A `{ permissionSet }` audience would name one set and shut out the
* holders of every other one.
*
* Membership is derived by this package's doc namespace (`include: 'studio_*'`),
* so a page this package adds later under that prefix is gated the same way
* with no edit here. Not `'*'`: a package scope drops only a doc stamped with
* ANOTHER package, so a stored doc bound to no package (ADR-0070) is in every
* scope, and a catch-all would claim it and gate it on `studio.access` too.
*/
export const STUDIO_MANUAL_BOOK: Book = {
name: 'studio_manual',
label: 'Studio',
slug: 'studio',
audience: { systemPermission: 'studio.access' },
groups: [{ key: 'all', label: 'Documentation', include: 'studio_*' }],
};
3 changes: 2 additions & 1 deletion packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5025,7 +5025,8 @@ const CAPABILITY_REFERENCE_UNKNOWN_EXPLANATION: RuleExplanation = {
'form, or each operation of the per-operation map), each field\'s, each object action\'s and ' +
'each top-level action\'s, each flow\'s, an app\'s and each of its nav entries (through `navigation`, ' +
'`areas`, `tabs`, `children` and `items`), a view\'s (its own, its `config`\'s, its default ' +
'`list`\'s and each `listViews` entry\'s, on views and on objects) and a dashboard\'s.',
'`list`\'s and each `listViews` entry\'s, on views and on objects), a dashboard\'s, and a book\'s ' +
'`audience.systemPermission`, the same gate on a manual\'s pages.',
'A warning, not an error: the lint reads every package of the artifact being built, but it ' +
'cannot see the capabilities other installed packages declare, and the reference fails closed ' +
'anyway, so a dangling one is almost certainly a typo to surface, not a build to break. If ' +
Expand Down
25 changes: 25 additions & 0 deletions packages/lint/src/validate-capability-references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,28 @@ describe('[#22161] one-line verdicts — capability-reference-unknown', () => {
expect(text).toContain('fails CLOSED');
});
});

// [ADR-0046 §6.7] A `{ systemPermission }` book audience is a capability gate
// on a manual: the docs reads serve its pages only to a holder, so a typo hides
// the manual from everyone. It resolves against the same known set.
describe('book audience — a { systemPermission } manual is resolved like every capability gate', () => {
it('warns on a typo at the book audience, at its own path, and passes a built-in and a granted one', () => {
const findings = validateCapabilityReferences({
permissions: [{ name: 'crm_docs', systemPermissions: ['crm.read_runbook'] }],
books: [
{ name: 'setup_manual', audience: { systemPermission: 'setup.access' }, groups: [] },
{ name: 'crm_runbook', audience: { systemPermission: 'crm.read_runbook' }, groups: [] },
{ name: 'crm_typo', audience: { systemPermission: 'crm.read_runbok' }, groups: [] },
// Not capability gates: nothing to resolve.
{ name: 'crm_sets', audience: { permissionSet: 'crm_docs' }, groups: [] },
{ name: 'crm_org', audience: 'org', groups: [] },
{ name: 'crm_public', audience: 'public', groups: [] },
],
});
expect(findings.map((f) => [f.where, f.path])).toEqual([
['book "crm_typo"', 'books[2].audience.systemPermission'],
]);
expect(findings[0]).toMatchObject({ severity: 'warning', rule: CAPABILITY_REFERENCE_UNKNOWN });
expect(findings[0].message).toContain('audience.systemPermission names capability "crm.read_runbok"');
});
});
21 changes: 17 additions & 4 deletions packages/lint/src/validate-capability-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* [ADR-0066 ⑨] Authoring-time validation for capability references.
*
* `requiredPermissions` (on objects, fields, apps, actions, flows, list views
* and dashboards) and `systemPermissions` (on permission sets) are free capability
* strings. A typo
* and dashboards), a book's `audience.systemPermission` (ADR-0046 §6.7) and
* `systemPermissions` (on permission sets) are free capability strings. A typo
* — `mange_users` for `manage_users` — is Zod-valid and fails CLOSED at runtime
* (the caller is denied), which is the safe direction but UNDISCOVERABLE: nothing
* tells the author the referenced capability exists nowhere. This rule closes
Expand Down Expand Up @@ -131,7 +131,7 @@ export function validateCapabilityReferences(stack: AnyRec): CapabilityRefFindin
'Fix the capability name, or declare it with `defineCapability` (`stack.capabilities`) or on a ' +
'permission set’s `systemPermissions`.';

const flag = (cap: string, where: string, path: string) => {
const flag = (cap: string, where: string, path: string, key = 'requiredPermissions') => {
if (known.has(cap)) return;
findings.push({
severity: 'warning',
Expand All @@ -142,7 +142,7 @@ export function validateCapabilityReferences(stack: AnyRec): CapabilityRefFindin
// positions walked and why it only warns is
// `os explain capability-reference-unknown`.
message:
`requiredPermissions names capability "${cap}", which no built-in, \`defineCapability\` ` +
`${key} names capability "${cap}", which no built-in, \`defineCapability\` ` +
`or \`systemPermissions\` grant provides, so this gate fails closed`,
hint,
});
Expand Down Expand Up @@ -283,5 +283,18 @@ export function validateCapabilityReferences(stack: AnyRec): CapabilityRefFindin
}
}

// ── [ADR-0046 §6.7] Books: a `{ systemPermission }` audience is the same
// capability gate on a manual — the docs reads serve its pages only to a
// caller holding the capability, so a misspelled one hides the manual
// from everyone, silently. ──
for (const [i, book] of recordsOf(stack.books).entries()) {
const audience = book.audience;
if (!audience || typeof audience !== 'object' || Array.isArray(audience)) continue;
const cap = (audience as AnyRec).systemPermission;
if (typeof cap !== 'string' || cap.length === 0) continue;
const bName = typeof book.name === 'string' ? book.name : `(book ${i})`;
flag(cap, `book "${bName}"`, `books[${i}].audience.systemPermission`, 'audience.systemPermission');
}

return findings;
}
Loading
Loading