Skip to content
Open
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
2 changes: 1 addition & 1 deletion .changeset/36029-book-audience-system-permission.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
'@objectstack/spec': minor
'@objectstack/rest': minor
Expand All @@ -17,7 +17,7 @@

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/spec`.** `BookAudienceSchema` and `BookAudience` gain the arm. It is strict, so `{ systemPermission, label }` is refused at parse, and an object that also carries `permissionSet` is refused too: an audience names one gate. `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.
Expand Down
22 changes: 22 additions & 0 deletions .changeset/37613-book-audience-one-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@objectstack/spec': minor
'@objectstack/lint': minor
---

fix(spec)!: a book audience names one gate, and a gated book claims its pages by name

Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — no `skills/` page teaches the book audience forms; `content/docs/ui/doc-pages.mdx` documents both refusals in this change

<!-- adr-0087: registered book-audience-two-gates-and-catch-all-claim-refused -->

**BREAKING** for two book shapes (ADR-0046 §6.7) that were accepted and meant less than they said. Stored books are not rewritten or refused at boot; the next save or publish of such a book is refused with the fix named.

- **`@objectstack/spec`.** `BookAudienceSchema` refuses an `audience` naming both `permissionSet` and `systemPermission`. The older `{ permissionSet }` arm is a plain object, so the pair used to parse as the set form with the capability stripped: the author believed the book was gated on a capability, and it was gated on one set. `defineStack`, `os validate` and the `/meta` save now refuse it, and the message says which key to keep. Only the second gate key is refused: every other shape that parsed before still parses the same way.
- **`@objectstack/lint`.** New error `book-gated-catch-all-include` (`validateBookAudienceClaims`): a book whose `audience` is `{ permissionSet }` or `{ systemPermission }` with a group claiming docs by `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, and the catch-all claimed it too and hid it from every reader outside the audience. It runs on `os validate`, `os build` and `os lint`, and at the runtime publish gate on a book write (Studio, REST `/meta`, MCP).

## FROM → TO

- `audience: { permissionSet: 'crm_admin', systemPermission: 'setup.access' }` → `audience: { systemPermission: 'setup.access' }` (everyone holding the capability through any set) or `audience: { permissionSet: 'crm_admin' }` (the holders of that one set).
- `audience: { systemPermission: 'crm.runbook' }` with `groups: [{ key: 'all', label: 'All', include: '*' }]` → `include: 'crm_runbook_*'` (the package's doc namespace), a tag include `{ tag: 'runbook' }`, or pinned `pages`.
2 changes: 1 addition & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
→ Normalizing stack definition...
→ Lowering inline handlers...
→ Validating protocol compliance...
→ Running author-time rules (85)...
→ Running author-time rules (86)...
→ Checking that every required capability has a provider installable in this edition...
→ Collecting package docs (ADR-0046)... 0 collected
→ Writing artifact...
Expand Down
3 changes: 2 additions & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ orthogonal to both, and no cell here can carry it; it is written out in
| Advisory: credential literals in a flow — an `http` node's headers or url query, a node's `connectorConfig.input` (`flow-credential-literal`, #20698) | ✓ | ✓ | ✓ | ✓ᶠ |
| Advisory: credential literals in a connector — its header and environment maps, and a stdio MCP credential route (`connector-credential-literal`, #29424) | ✓ | ✓ | ✓ | ✓ᶜ |
| `views[]` and page-component conditional-visibility predicates — CEL syntax, parse budget, bare identifiers, binding-root layer; schema path refs on `views[]` only (ADR-0089 D3b, #7010; page components at the save door #24491); an app navigation entry's `visible` at the save door (#28663) | ✓ | ✓ | ✓ | ✓ᵛᵖᵃ |
| Gated book claims — a book whose `audience` is `{ permissionSet }` or `{ systemPermission }` claiming docs by `include: '*'`, which also takes every doc bound to no package away from readers outside the audience (`book-gated-catch-all-include`, ADR-0046 §6.7) | ✓ | ✓ | ✓ | ✓ᵇ |
| Advisory: record titles, semantic field pointers (ADR-0085), action placement, seed replay/state safety, capability references | ✓ | ✓ | ✓ | — |
| Advisory: form-section layout | ✓ | ✓ | ✓ | ✓ᵛ |
| Advisory: liveness | ✓ | ✓ | ✓ | ✓ᵉᵐᵈˢ |
Expand Down Expand Up @@ -869,7 +870,7 @@ A clean run walks the registry and reports timing:
Config: /path/to/support-desk/objectstack.config.ts
Load time: 21ms
→ Validating against ObjectStack Protocol...
→ Running author-time rules (85)...
→ Running author-time rules (86)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
2 changes: 1 addition & 1 deletion content/docs/getting-started/build-with-claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ visible: 'status != "resolved"'
◆ Validate
────────────────────────────────────────
→ Validating against ObjectStack Protocol...
→ Running author-time rules (85)...
→ Running author-time rules (86)...

✗ Author-time rules failed (1 issue)
• stack · action 'resolve_ticket' visible: bare reference `status` — a
Expand Down
8 changes: 8 additions & 0 deletions content/docs/references/system/book.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ const result = BookSchema.parse(data);
| **_lockDocsUrl** | `string` | optional | Optional documentation link surfaced next to _lockReason. |
| **overrides** | `{ package: string; basedOn: string }` | optional | Override declaration (ADR-0146 D2): `{ package, basedOn }` — this item of "`<base>`.custom" replaces the base package's same-named item whole. `basedOn` is recorded and never gates; a base's upgrade plan reads it only as advice. |

### Nested Shape: `Book.audience[option 3]`

| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **permissionSet** | `string` | ✅ | |
| **systemPermission** | `never` | optional | Not accepted beside `permissionSet`: an audience names one gate |

### Nested Shape: `Book.groups[number]`

| Property | Type | Required | Description |
Expand Down Expand Up @@ -110,6 +117,7 @@ Type: `'public'`
| Property | Type | Required | Description |
| :--- | :--- | :--- | :--- |
| **permissionSet** | `string` | ✅ | |
| **systemPermission** | `never` | optional | Not accepted beside `permissionSet`: an audience names one gate |

---

Expand Down
6 changes: 5 additions & 1 deletion content/docs/ui/doc-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,16 @@ 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.
denied — the gate fails closed. An audience names one gate: an object carrying both
`permissionSet` and `systemPermission` is refused when the book is parsed, and the message
says which key to keep.

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.
`os validate`, `os build` and `os lint` refuse such a group (`book-gated-catch-all-include`),
and so does saving the book through Studio, REST `/meta` or MCP.

<Callout type="info">
The gate is a **capability** reference, never a distribution one: packages own permission
Expand Down
2 changes: 1 addition & 1 deletion content/docs/ui/react-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ objectstack validate
────────────────────────────────────────
→ Loading configuration...
→ Validating against ObjectStack Protocol...
→ Running author-time rules (85)...
→ Running author-time rules (86)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
1 change: 1 addition & 0 deletions packages/apps/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"scripts": {
"build": "tsup && node ../../../scripts/check-dts-emitted.mjs",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
58 changes: 58 additions & 0 deletions packages/apps/setup/src/manual-claims-docs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* [ADR-0046 §6.7] Every doc this package registers is claimed by its manual,
* and gated as the manual is.
*
* The Setup manual claims its pages by the package's doc namespace
* (`include: 'setup_*'`), and nothing else holds the package's docs to that
* prefix: `docs/namespace-prefix` runs in `os build`, and this package is built
* by tsup. So this pin reads what the plugin really registers, the shipped
* constants and nothing copied, and resolves the audiences the docs doors
* resolve. A doc named outside the prefix is claimed by no book and falls back
* to `org`; the constant put back to `'*'` also claims the control doc bound to
* no package. Either turns this red.
*/

import { describe, expect, it } from 'vitest';
import { resolveDocAudiences, type AudienceBook, type ResolverDoc } from '@objectstack/spec/system';
import { createSetupAppPlugin, SETUP_APP_PACKAGE_ID, SETUP_MANUAL_BOOK } from './index.js';

interface Registered {
id: string;
docs: Array<{ name: string; label?: string }>;
books: AudienceBook[];
}

async function registeredManifest(): Promise<Registered> {
const registered: Registered[] = [];
const manifest = { register: (m: Registered) => registered.push(m) };
await createSetupAppPlugin().start({ getService: (name: string) => (name === 'manifest' ? manifest : undefined) });
expect(registered, 'start() registers one manifest').toHaveLength(1);
return registered[0]!;
}

describe('setup_manual claims every doc @objectstack/setup registers', () => {
it('registers the manual beside its docs', async () => {
const m = await registeredManifest();
expect(m.id).toBe(SETUP_APP_PACKAGE_ID);
expect(m.books).toEqual([SETUP_MANUAL_BOOK]);
expect(m.docs.length, 'a package with no docs pins nothing').toBeGreaterThan(0);
});

it('gives every registered doc the manual\'s audience, and leaves a doc bound to no package alone', async () => {
const m = await registeredManifest();
// The metadata layer stamps each registered item with its package.
const books: AudienceBook[] = m.books.map((b) => ({ ...b, packageId: m.id }));
const docs: ResolverDoc[] = [
...m.docs.map((d) => ({ name: d.name, label: d.label, packageId: m.id })),
// Control: a stored doc bound to no package is in every package scope.
{ name: 'unbound_page', label: 'Unbound' },
];
const audiences = resolveDocAudiences(books, docs);
for (const doc of m.docs) {
expect(audiences.get(doc.name), `${doc.name} is not claimed by setup_manual`).toEqual([SETUP_MANUAL_BOOK.audience]);
}
expect(audiences.get('unbound_page'), 'the manual claims a doc bound to no package').toEqual(['org']);
});
});
2 changes: 1 addition & 1 deletion packages/apps/setup/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"declarationMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
"exclude": ["node_modules", "dist"]
}
32 changes: 32 additions & 0 deletions packages/apps/setup/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { defineConfig } from 'vitest/config';
import path from 'node:path';

export default defineConfig({
test: {
// A late console.* must not redden a green suite: vitest's worker forwards
// console output over RPC and a write landing after teardown is rejected
// into an unhandled error. Mechanism and measured costs:
// examples/app-showcase/vitest.config.ts; enforced repo-wide by
// scripts/check-console-intercept-disarm.mjs.
disableConsoleIntercept: true,
},
resolve: {
// The manual pin (`src/manual-claims-docs.test.ts`) reads this package's
// registered docs and book through the spec's own audience resolver, so
// both specifiers resolve to SOURCE, never to a `dist/` that may be behind
// it (`pnpm check:test-source-alias`). Array form with anchored patterns:
// the object form matches by prefix and would swallow sibling subpaths.
alias: [
{
find: /^@objectstack\/platform-objects\/apps$/,
replacement: path.resolve(__dirname, '../../platform-objects/src/apps/index.ts'),
},
{
find: /^@objectstack\/spec\/system$/,
replacement: path.resolve(__dirname, '../../spec/src/system/index.ts'),
},
],
},
});
1 change: 1 addition & 0 deletions packages/apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"scripts": {
"build": "tsup && node ../../../scripts/check-dts-emitted.mjs",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
58 changes: 58 additions & 0 deletions packages/apps/studio/src/manual-claims-docs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* [ADR-0046 §6.7] Every doc this package registers is claimed by its manual,
* and gated as the manual is.
*
* The Studio manual claims its pages by the package's doc namespace
* (`include: 'studio_*'`), and nothing else holds the package's docs to that
* prefix: `docs/namespace-prefix` runs in `os build`, and this package is built
* by tsup. So this pin reads what the plugin really registers, the shipped
* constants and nothing copied, and resolves the audiences the docs doors
* resolve. A doc named outside the prefix is claimed by no book and falls back
* to `org`; the constant put back to `'*'` also claims the control doc bound to
* no package. Either turns this red.
*/

import { describe, expect, it } from 'vitest';
import { resolveDocAudiences, type AudienceBook, type ResolverDoc } from '@objectstack/spec/system';
import { createStudioAppPlugin, STUDIO_APP_PACKAGE_ID, STUDIO_MANUAL_BOOK } from './index.js';

interface Registered {
id: string;
docs: Array<{ name: string; label?: string }>;
books: AudienceBook[];
}

async function registeredManifest(): Promise<Registered> {
const registered: Registered[] = [];
const manifest = { register: (m: Registered) => registered.push(m) };
await createStudioAppPlugin().start({ getService: (name: string) => (name === 'manifest' ? manifest : undefined) });
expect(registered, 'start() registers one manifest').toHaveLength(1);
return registered[0]!;
}

describe('studio_manual claims every doc @objectstack/studio registers', () => {
it('registers the manual beside its docs', async () => {
const m = await registeredManifest();
expect(m.id).toBe(STUDIO_APP_PACKAGE_ID);
expect(m.books).toEqual([STUDIO_MANUAL_BOOK]);
expect(m.docs.length, 'a package with no docs pins nothing').toBeGreaterThan(0);
});

it('gives every registered doc the manual\'s audience, and leaves a doc bound to no package alone', async () => {
const m = await registeredManifest();
// The metadata layer stamps each registered item with its package.
const books: AudienceBook[] = m.books.map((b) => ({ ...b, packageId: m.id }));
const docs: ResolverDoc[] = [
...m.docs.map((d) => ({ name: d.name, label: d.label, packageId: m.id })),
// Control: a stored doc bound to no package is in every package scope.
{ name: 'unbound_page', label: 'Unbound' },
];
const audiences = resolveDocAudiences(books, docs);
for (const doc of m.docs) {
expect(audiences.get(doc.name), `${doc.name} is not claimed by studio_manual`).toEqual([STUDIO_MANUAL_BOOK.audience]);
}
expect(audiences.get('unbound_page'), 'the manual claims a doc bound to no package').toEqual(['org']);
});
});
2 changes: 1 addition & 1 deletion packages/apps/studio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"declarationMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
"exclude": ["node_modules", "dist"]
}
32 changes: 32 additions & 0 deletions packages/apps/studio/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { defineConfig } from 'vitest/config';
import path from 'node:path';

export default defineConfig({
test: {
// A late console.* must not redden a green suite: vitest's worker forwards
// console output over RPC and a write landing after teardown is rejected
// into an unhandled error. Mechanism and measured costs:
// examples/app-showcase/vitest.config.ts; enforced repo-wide by
// scripts/check-console-intercept-disarm.mjs.
disableConsoleIntercept: true,
},
resolve: {
// The manual pin (`src/manual-claims-docs.test.ts`) reads this package's
// registered docs and book through the spec's own audience resolver, so
// both specifiers resolve to SOURCE, never to a `dist/` that may be behind
// it (`pnpm check:test-source-alias`). Array form with anchored patterns:
// the object form matches by prefix and would swallow sibling subpaths.
alias: [
{
find: /^@objectstack\/platform-objects\/apps$/,
replacement: path.resolve(__dirname, '../../platform-objects/src/apps/index.ts'),
},
{
find: /^@objectstack\/spec\/system$/,
replacement: path.resolve(__dirname, '../../spec/src/system/index.ts'),
},
],
},
});
Loading
Loading