diff --git a/.changeset/32865-object-ai-read-exposure.md b/.changeset/32865-object-ai-read-exposure.md new file mode 100644 index 00000000000..3ebf864070b --- /dev/null +++ b/.changeset/32865-object-ai-read-exposure.md @@ -0,0 +1,16 @@ +--- +'@objectstack/spec': minor +--- + +feat(spec): `enable.aiReadable` — a system object's author can declare its records readable by the AI read tools, never writable + +Clause-②: yes (widening) +Metadata-protocol: added +Skills-docs: follow-up owed — skills/objectstack-data/SKILL.md (the `enable` capability table has no `aiReadable` row; it should say the key is refused on any object whose name does not start with `sys_`, so an app author never writes it) + +- **`ObjectCapabilities.aiReadable`** (`enable.aiReadable`, optional boolean, absent by default) is the per-object, read-only AI exposure of a system object, the read counterpart of an action's `ai.exposed` (ADR-0011). `true` declares that the AI read tools (query, get one, aggregate, describe, list) may reach the object's records, with every gate after admission unchanged: the caller's permissions, row-level security, field masking and the object's API exposure. It never opens a write; a write on a system object stays on its actions, each opened by its own `ai.exposed`. No deployment switch replaces the declaration. +- **Refused at parse** wherever an object is parsed (`ObjectSchema.create`, `defineStack`, `os validate`, the object save door): on any object whose name does not start with `sys_`, where the AI read tools already read records as the caller, so the key would change nothing and a `false` would read as a lock that locks nothing; and on the stored-metadata family (`STORED_METADATA_BODY_OBJECTS`: `sys_metadata`, `sys_metadata_history`), which no declaration opens. Any declared value is judged, `false` included. The key is new, so no stored object carries it. +- **No write arm.** `enable` declares no other AI key. `aiExposed`, `aiWritable`, `aiWrite`, `aiEditable` and `ai` inside `enable` are refused with the read-only prescription; `aiRead`, `aiReadEnabled`, `aiReadExposed` and `mcpReadable` are answered with a rename to `aiReadable`. A value other than a boolean is refused. +- **`isAiReadExposed(schema)`** and **`aiReadExposureRefusal(objectName, enable)`** are exported from `@objectstack/spec/data`. `isAiReadExposed` is the one reading a surface that admits an object to the AI read tools asks: it answers `false` for the stored-metadata family before it reads the key, `false` off a `sys_*` object, and `true` only for the boolean `true`. + +Nothing reads the key at runtime yet: the MCP read tools still refuse every `sys_*` object by name, and the liveness ledger records the key as `planned`. The server half (the MCP bridge attesting the object through `isAiReadExposed`, the MCP object guards honouring the attestation, and `sys_approval_request` declaring the key) lands separately. The Studio object editor does not offer the key, because the objects it edits are the ones the parse refuses it on. diff --git a/content/docs/references/data/object.mdx b/content/docs/references/data/object.mdx index b6824dd2bae..c101ddb1e9c 100644 --- a/content/docs/references/data/object.mdx +++ b/content/docs/references/data/object.mdx @@ -436,6 +436,7 @@ const result = ApiMethod.parse(data); | **searchable** | `boolean` | optional (default: `true`) | Index records for global search | | **apiEnabled** | `boolean` | optional (default: `true`) | Expose object via automatic APIs | | **apiMethods** | `Enum<'get' \| 'list' \| 'create' \| 'update' \| 'delete' \| 'bulk'>[]` | optional | Whitelist of allowed API operations (six primitives; undefined = all, [] = none) | +| **aiReadable** | `boolean` | optional | Read-only AI exposure of a system (sys_) object, opt-in: true lets the AI read tools (query, get one, aggregate, describe, list) reach its records, under the caller's permissions and row-level security as before. Never opens a write: writes stay on actions declared with ai.exposed. Refused on any object whose name does not start with sys_, and on the stored-metadata family (sys_metadata, sys_metadata_history) | | **files** | `boolean` | optional (default: `false`) | Generic record Attachments panel (sys_attachment). Opt-in: true surfaces the panel and permits attachments to target this object; otherwise any write that makes an attachment target it is rejected (403 FILES_DISABLED) — a create and an update that re-points an existing attachment alike. Field.file/Field.image are independent | | **feeds** | `boolean` | optional (default: `true`) | Record comments/collaboration feed. Default on; explicit false hides the feed UI and rejects any write that makes a comment target this object (403 FEEDS_DISABLED) — a new comment and an update that re-threads an existing one alike | | **activities** | `boolean` | optional (default: `true`) | Record activity timeline (sys_activity mirror of CRUD). Default on; explicit false stops mirroring and hides the timeline | @@ -572,6 +573,7 @@ const result = ApiMethod.parse(data); | **searchable** | `boolean` | optional (default: `true`) | Index records for global search | | **apiEnabled** | `boolean` | optional (default: `true`) | Expose object via automatic APIs | | **apiMethods** | `Enum<'get' \| 'list' \| 'create' \| 'update' \| 'delete' \| 'bulk'>[]` | optional | Whitelist of allowed API operations (six primitives; undefined = all, [] = none) | +| **aiReadable** | `boolean` | optional | Read-only AI exposure of a system (sys_) object, opt-in: true lets the AI read tools (query, get one, aggregate, describe, list) reach its records, under the caller's permissions and row-level security as before. Never opens a write: writes stay on actions declared with ai.exposed. Refused on any object whose name does not start with sys_, and on the stored-metadata family (sys_metadata, sys_metadata_history) | | **files** | `boolean` | optional (default: `false`) | Generic record Attachments panel (sys_attachment). Opt-in: true surfaces the panel and permits attachments to target this object; otherwise any write that makes an attachment target it is rejected (403 FILES_DISABLED) — a create and an update that re-points an existing attachment alike. Field.file/Field.image are independent | | **feeds** | `boolean` | optional (default: `true`) | Record comments/collaboration feed. Default on; explicit false hides the feed UI and rejects any write that makes a comment target this object (403 FEEDS_DISABLED) — a new comment and an update that re-threads an existing one alike | | **activities** | `boolean` | optional (default: `true`) | Record activity timeline (sys_activity mirror of CRUD). Default on; explicit false stops mirroring and hides the timeline | diff --git a/packages/spec/api-surface/data.json b/packages/spec/api-surface/data.json index 0460cd72940..35d5652f5ad 100644 --- a/packages/spec/api-surface/data.json +++ b/packages/spec/api-surface/data.json @@ -31,6 +31,7 @@ "AggregationRow (interface)", "AggregationStage (type)", "AggregationStageSchema (const)", + "AiReadExposureRefusal (interface)", "AnalyticsDateRange (type)", "AnalyticsDateRangePreset (type)", "AnalyticsDateRangePresetSchema (const)", @@ -879,6 +880,7 @@ "ValueRoundTripColumn (type)", "ValueShapeFieldDef (interface)", "ZeroLimitConformanceCase (interface)", + "aiReadExposureRefusal (function)", "analyticsDateRangeRefusalMessage (function)", "apiExposureDenialReason (function)", "asciiCaseInsensitiveContains (function)", @@ -958,6 +960,7 @@ "injectedSystemColumnDefs (function)", "isAcceptedFilterComparand (function)", "isAggregateCompatibleWithFieldType (function)", + "isAiReadExposed (function)", "isAnalyticsDateRangeRefusalIssue (function)", "isApiOperationAllowed (function)", "isApiPrimitive (function)", diff --git a/packages/spec/authorable-surface/data.json b/packages/spec/authorable-surface/data.json index 641826654dd..64f4bfbc854 100644 --- a/packages/spec/authorable-surface/data.json +++ b/packages/spec/authorable-surface/data.json @@ -686,6 +686,7 @@ "data/Object:validations", "data/ObjectAccessConfig:default", "data/ObjectCapabilities:activities", + "data/ObjectCapabilities:aiReadable", "data/ObjectCapabilities:apiEnabled", "data/ObjectCapabilities:apiMethods", "data/ObjectCapabilities:approvalsVisibleToReaders", diff --git a/packages/spec/export-origins/data.json b/packages/spec/export-origins/data.json index c7686d73c24..eb319797b65 100644 --- a/packages/spec/export-origins/data.json +++ b/packages/spec/export-origins/data.json @@ -29,6 +29,7 @@ "AggregationRow": "src/data/aggregation-conformance.ts#AggregationRow (interface)", "AggregationStage": "src/data/driver-nosql.zod.ts#AggregationStage (type)", "AggregationStageSchema": "src/data/driver-nosql.zod.ts#AggregationStageSchema (const)", + "AiReadExposureRefusal": "src/data/ai-read-exposure.ts#AiReadExposureRefusal (interface)", "AnalyticsDateRange": "src/data/analytics.zod.ts#AnalyticsDateRange (type)", "AnalyticsDateRangePreset": "src/data/analytics.zod.ts#AnalyticsDateRangePreset (type)", "AnalyticsDateRangePresetSchema": "src/data/analytics.zod.ts#AnalyticsDateRangePresetSchema (const)", @@ -865,6 +866,7 @@ "ValueRoundTripColumn": "src/data/value-roundtrip-conformance.ts#ValueRoundTripColumn (type)", "ValueShapeFieldDef": "src/data/field-value.zod.ts#ValueShapeFieldDef (interface)", "ZeroLimitConformanceCase": "src/data/pagination-conformance.ts#ZeroLimitConformanceCase (interface)", + "aiReadExposureRefusal": "src/data/ai-read-exposure.ts#aiReadExposureRefusal (function)", "analyticsDateRangeRefusalMessage": "src/data/analytics.zod.ts#analyticsDateRangeRefusalMessage (function)", "apiExposureDenialReason": "src/data/api-derivation.ts#apiExposureDenialReason (function)", "asciiCaseInsensitiveContains": "src/data/filter.zod.ts#asciiCaseInsensitiveContains (function)", @@ -944,6 +946,7 @@ "injectedSystemColumnDefs": "src/data/injected-system-column-provenance.ts#injectedSystemColumnDefs (function)", "isAcceptedFilterComparand": "src/data/filter-comparand-type.ts#isAcceptedFilterComparand (function)", "isAggregateCompatibleWithFieldType": "src/data/aggregate-field-type-compatibility.ts#isAggregateCompatibleWithFieldType (function)", + "isAiReadExposed": "src/data/ai-read-exposure.ts#isAiReadExposed (function)", "isAnalyticsDateRangeRefusalIssue": "src/data/analytics.zod.ts#isAnalyticsDateRangeRefusalIssue (function)", "isApiOperationAllowed": "src/data/api-derivation.ts#isApiOperationAllowed (function)", "isApiPrimitive": "src/data/api-derivation.ts#isApiPrimitive (function)", diff --git a/packages/spec/liveness/object.json b/packages/spec/liveness/object.json index 0b9f63efca0..35cbba2c389 100644 --- a/packages/spec/liveness/object.json +++ b/packages/spec/liveness/object.json @@ -393,6 +393,11 @@ "evidence": "packages/spec/src/data/api-derivation.ts, packages/rest/src/rest-server.ts, packages/runtime/src/api-exposure.ts", "note": "three-state whitelist over the six primitives (get/list/create/update/delete/bulk): undefined = unrestricted, [] = deny-all (fully closed), subset = the derived closure; a present-but-non-array value fails CLOSED (#3545). resolveEffectiveApiMethods (the single derivation table) is consumed by the REST gate (405 outside the effective set) and the runtime dispatcher gate. Since #3543 the enum IS the six primitives; the legacy 8 values (upsert/aggregate/history/search/restore/purge/import/export) are DERIVED effective operations (ApiOperation vocabulary) — a stored legacy value is stripped at parse (stripLegacyApiMethods, canonicalize-and-warn, permanent tolerance). Read points for the `sys_api_key` single-record-write exemption pinned in packages/spec/src/data/api-methods-batch-conformance.test.ts (moved out of spec source, #23434), re-read at objectui @b9814b334 (2026-10-14): objectui @b9814b334 packages/plugin-grid/src/ObjectGrid.tsx#selectionMode — with neither `selection` nor `selectable` authored, multi-select is enabled only by objectui @b9814b334 packages/plugin-grid/src/ObjectGrid.tsx#hasBulkActions, and the one implicit bulk action, bulk-delete, is gated on the resolved delete affordance (objectui @b9814b334 packages/plugin-grid/src/ObjectGrid.tsx#rowDeleteVerdict); a list-item action named in `bulkActions` is promoted to `operation: 'custom'` + `actionDef` and dispatched through objectui @b9814b334 packages/plugin-grid/src/ObjectGrid.tsx#dispatchBulkAction; objectui @b9814b334 packages/plugin-grid/src/hooks/useBulkExecutor.ts#useBulkExecutor — a promoted custom def fans out per row through the action runner, and only an `update`/`delete` bulk def reaches the data-plane `bulk` primitive." }, + "aiReadable": { + "status": "planned", + "verifiedAt": "2026-11-13", + "note": "PLANNED RECORD (ruling A on the read half of #32442, spec card #32865): the per-object, read-only AI exposure of a sys_* object. Its REFUSALS are live at parse: ObjectSchema refuses it on any object whose name does not start with sys_ and on the stored-metadata family, judged before the key is read (packages/spec/src/data/ai-read-exposure.ts#aiReadExposureRefusal). Its one reading is packages/spec/src/data/ai-read-exposure.ts#isAiReadExposed, which no runtime reads yet: the MCP read tools still refuse every sys_* object by name. It turns live when the server half (#32442) lands: the bridge attests the object through isAiReadExposed, the three MCP guards honour the attestation, and sys_approval_request declares it." + }, "trackHistory": { "status": "live", "evidence": "objectui app-shell RecordDetailView gates the record's field changes on enable.trackHistory === true (historyEnabled memo): on the synthesized record page they join the one timeline stream (RecordFieldChangesContext, its Changes filter), with no History tab; pairs with per-field trackHistory (plugin-audit renderTrackedChangeSummary, packages/plugins/plugin-audit/src/audit-writers.ts) which selects the field diffs. Audit CAPTURE into sys_audit_log is deliberately unconditional (compliance ledger) — the flag gates the UI surface, not the ledger (#2707)." diff --git a/packages/spec/liveness/state-counts/object.md b/packages/spec/liveness/state-counts/object.md index 4fde1fe4056..92d5ca2a20a 100644 --- a/packages/spec/liveness/state-counts/object.md +++ b/packages/spec/liveness/state-counts/object.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `object` | 78 | 0 | 0 | 1 | 0 | 79 | +| `object` | 78 | 0 | 0 | 1 | 1 | 80 | diff --git a/packages/spec/src/data/ai-read-exposure.test.ts b/packages/spec/src/data/ai-read-exposure.test.ts new file mode 100644 index 00000000000..a50e8ef93fd --- /dev/null +++ b/packages/spec/src/data/ai-read-exposure.test.ts @@ -0,0 +1,129 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { describe, it, expect } from 'vitest'; +import { ObjectSchema, ObjectCapabilities } from './object.zod'; +import { aiReadExposureRefusal, isAiReadExposed } from './ai-read-exposure'; +import { STORED_METADATA_BODY_OBJECTS } from '../kernel/stored-metadata-body-objects'; + +/** + * [ruling A on the read half of #32442] `enable.aiReadable` — the per-object, + * read-only AI exposure of a system object. Four rules, each pinned here: the + * key is accepted on a `sys_*` object; refused on any other object; refused on + * the stored-metadata family, which its one reading judges before the key is + * read; and it has no write arm. + */ + +function objectWith(name: string, enable: Record) { + return { name, label: 'Probe', fields: { title: { type: 'text', label: 'Title' } }, enable }; +} + +function aiReadableIssues(result: ReturnType) { + return result.success + ? [] + : result.error.issues.filter((i) => i.path.join('.') === 'enable.aiReadable'); +} + +describe('enable.aiReadable — accepted on a system object', () => { + it('parses on a sys_* object, and its one reading answers true for true only', () => { + const declared = ObjectSchema.safeParse(objectWith('sys_approval_request', { aiReadable: true })); + expect(declared.success).toBe(true); + expect(declared.success ? declared.data.enable?.aiReadable : undefined).toBe(true); + expect(isAiReadExposed(declared.success ? declared.data : undefined)).toBe(true); + + // `false` on a system object restates the default and is accepted. + const closed = ObjectSchema.safeParse(objectWith('sys_approval_request', { aiReadable: false })); + expect(closed.success).toBe(true); + expect(isAiReadExposed(closed.success ? closed.data : undefined)).toBe(false); + + // Absent: nothing declared, nothing opened, no default written. + const absent = ObjectSchema.safeParse(objectWith('sys_approval_request', {})); + expect(absent.success).toBe(true); + expect(absent.success ? absent.data.enable?.aiReadable : 'parse failed').toBeUndefined(); + expect(isAiReadExposed(absent.success ? absent.data : undefined)).toBe(false); + }); +}); + +describe('enable.aiReadable — refused on a non-system object', () => { + it.each([true, false])('refuses aiReadable: %s on a business object, located at the key', (value) => { + const result = ObjectSchema.safeParse(objectWith('crm_account', { aiReadable: value })); + expect(result.success).toBe(false); + const issues = aiReadableIssues(result); + expect(issues).toHaveLength(1); + expect(issues[0]?.code).toBe('custom'); + }); + + it('its one reading never answers true off a system object, even on input no parse judged', () => { + expect(isAiReadExposed({ name: 'crm_account', enable: { aiReadable: true } })).toBe(false); + }); +}); + +describe('enable.aiReadable — refused on the stored-metadata family, before the key is read', () => { + const family = [...STORED_METADATA_BODY_OBJECTS]; + + it('reads the family from its one list', () => { + expect(family.length).toBeGreaterThan(0); + expect(family).toContain('sys_metadata'); + }); + + it.each(family)('refuses aiReadable on %s, true or false', (name) => { + for (const value of [true, false]) { + const result = ObjectSchema.safeParse(objectWith(name, { aiReadable: value })); + expect(result.success).toBe(false); + const issues = aiReadableIssues(result); + expect(issues).toHaveLength(1); + expect(issues[0]?.code).toBe('custom'); + } + }); + + it.each(family)('its one reading answers false on %s without reading the key', (name) => { + let reads = 0; + const enable = { + get aiReadable() { + reads += 1; + return true; + }, + }; + expect(isAiReadExposed({ name, enable })).toBe(false); + expect(reads).toBe(0); + // Control leg: the same probe on a system object outside the family is read. + expect(isAiReadExposed({ name: 'sys_approval_request', enable })).toBe(true); + expect(reads).toBe(1); + }); + + it('the refusal of a family member is not the business-object refusal', () => { + const family0 = aiReadExposureRefusal(family[0], { aiReadable: true }); + const business = aiReadExposureRefusal('crm_account', { aiReadable: true }); + expect(family0).toBeDefined(); + expect(business).toBeDefined(); + expect(family0?.message).not.toBe(business?.message); + }); +}); + +describe('enable.aiReadable — no write arm', () => { + it('the enable block declares exactly one AI key, and it is the read one', () => { + const aiKeys = Object.keys(ObjectCapabilities.shape).filter((k) => /^(ai|mcp)/i.test(k)); + expect(aiKeys).toEqual(['aiReadable']); + }); + + it.each(['aiWritable', 'aiWrite', 'aiEditable', 'aiExposed'])('refuses enable.%s as an undeclared key', (key) => { + const result = ObjectCapabilities.safeParse({ [key]: true }); + expect(result.success).toBe(false); + expect(result.success ? undefined : result.error.issues[0]?.code).toBe('unrecognized_keys'); + }); + + it('takes a boolean only: no value names a write scope', () => { + for (const value of ['write', 'read_write', 'all', 'true', 1]) { + const result = ObjectCapabilities.safeParse({ aiReadable: value }); + expect(result.success).toBe(false); + expect(result.success ? undefined : result.error.issues[0]?.code).toBe('invalid_type'); + } + }); + + it('its one reading opens on the boolean true only', () => { + for (const value of ['true', 1, {}, 'read']) { + expect(isAiReadExposed({ name: 'sys_approval_request', enable: { aiReadable: value } })).toBe(false); + } + expect(isAiReadExposed(undefined)).toBe(false); + expect(isAiReadExposed({ name: 'sys_approval_request' })).toBe(false); + }); +}); diff --git a/packages/spec/src/data/ai-read-exposure.ts b/packages/spec/src/data/ai-read-exposure.ts new file mode 100644 index 00000000000..5641bd2891e --- /dev/null +++ b/packages/spec/src/data/ai-read-exposure.ts @@ -0,0 +1,121 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { isStoredMetadataBodyObject, STORED_METADATA_BODY_OBJECTS } from '../kernel/stored-metadata-body-objects'; + +/** + * The per-object, READ-ONLY AI exposure declaration, `enable.aiReadable`: its + * one reading and its one refusal. + * + * ## What the key is (ruling A on the read half of #32442) + * + * The MCP record tools refuse every system object (`sys_*`) by name, fail + * closed, and the only switch that lifts the refusal is a host-wide option no + * deployment opens. Actions on a `sys_*` object are opened per action by their + * author's own `ai.exposed` (ADR-0011; ADR-0066 D4, note of 2026-10-30). This + * key is the read counterpart, declared by the system object's own author: + * `enable.aiReadable: true` lets the read tools (query, get one, aggregate, + * describe, list) reach the object, with every gate after admission unchanged + * (the caller's permissions, row-level security, field masking). It never + * opens a write: a write on a system object stays on its declared actions, + * each opened by its own `ai.exposed`. There is no write arm, and no + * deployment switch. + * + * ## Where it means something, and where it is refused + * + * 1. **The stored-metadata family** ({@link STORED_METADATA_BODY_OBJECTS}, + * `stored-metadata-body-objects.ts`, the one list) is judged FIRST, before + * the key is read: its rows carry serialized metadata bodies, which can + * carry credentials, and no declaration opens them. The same order the + * action surface keeps (`systemObjectActionExposureError` in the runtime). + * 2. **A system object** (a `sys_` name: the one predicate the MCP guards + * apply, `/^sys_/i`) is where the key has a reader. + * 3. **Any other object** is refused: the MCP record tools already read a + * business object as the caller, under its permissions and its API + * exposure (`apiEnabled`, `apiMethods`), so the key would change nothing — + * `true` opens nothing new and `false` closes nothing — and an author + * reading `false` as a lock is misled (ADR-0049: a key is enforced or it is + * not declared). + * + * The refusal is judged at parse, in `ObjectSchema`'s refinement + * (`object.zod.ts`), so every door that parses an object inherits it: + * `ObjectSchema.create` at module load, `defineStack`, `os validate` and the + * object save door. The key is new, so no stored object carries it. + * + * ## The one reading + * + * {@link isAiReadExposed} is the ONE reading every surface that admits an + * object to the AI read tools asks, exported beside the declaration so no + * consumer re-derives the order above (the same shape as + * `isPublicSharingEnabled` in `object.zod.ts`). + */ + +/** + * Whether `objectName` names a system object: a `sys_` name. The predicate the + * MCP record tools refuse by (`/^sys_/i`); object names are lowercase + * snake_case, so the flag changes nothing for a parsed name. + */ +function isSystemObjectName(objectName: string): boolean { + return /^sys_/i.test(objectName); +} + +/** Why an object's `enable.aiReadable` is refused — see {@link aiReadExposureRefusal}. */ +export interface AiReadExposureRefusal { + /** Where the refusal is reported: the declaration itself. */ + readonly path: readonly ['enable', 'aiReadable']; + /** The author-facing sentence. */ + readonly message: string; +} + +const AI_READ_EXPOSURE_PATH = ['enable', 'aiReadable'] as const; + +/** + * The refusal of an `enable.aiReadable` declaration on an object where it means + * nothing, or `undefined` when it is accepted (absent, or declared on a system + * object outside the stored-metadata family). Any declared value is judged, + * `false` included: on a business object `false` is a lock that locks nothing. + */ +export function aiReadExposureRefusal(objectName: unknown, enable: unknown): AiReadExposureRefusal | undefined { + if (enable === null || typeof enable !== 'object') return undefined; + if (!Object.prototype.hasOwnProperty.call(enable, 'aiReadable')) return undefined; + if ((enable as { aiReadable?: unknown }).aiReadable === undefined) return undefined; + const name = typeof objectName === 'string' && objectName.length > 0 ? objectName : 'this object'; + if (typeof objectName === 'string' && isStoredMetadataBodyObject(objectName)) { + return { + path: AI_READ_EXPOSURE_PATH, + message: + `Object '${name}' stores serialized metadata bodies (${[...STORED_METADATA_BODY_OBJECTS].join(', ')}), ` + + 'and no declaration opens it to AI reads: a stored body can carry credentials, and every read of one ' + + 'goes through the metadata API, which redacts it. Remove enable.aiReadable.', + }; + } + if (typeof objectName === 'string' && isSystemObjectName(objectName)) return undefined; + return { + path: AI_READ_EXPOSURE_PATH, + message: + `Object '${name}' is not a system object, and enable.aiReadable has a meaning only on one (a name ` + + "starting with 'sys_'): the AI read tools already read a business object as the caller, under the " + + "caller's permissions and the object's API exposure (enable.apiEnabled, enable.apiMethods), so this " + + 'key would change nothing — true opens nothing and false locks nothing. Remove it; to keep this ' + + "object's records off every API, agents included, use enable.apiEnabled: false.", + }; +} + +/** + * Has this object opted its records into the AI READ tools — + * `enable.aiReadable: true` on a system object outside the stored-metadata + * family? + * + * The ONE reading of the declaration: the stored-metadata family is refused + * before the key is read, a non-system object never answers `true` (the key + * has no meaning there), and only the boolean `true` opens — a truthy `'true'` + * or `1` that never went through the schema does not. Fail-closed: an + * unreadable schema answers `false`. It answers reads only; nothing here opens + * a write. + */ +export function isAiReadExposed(schema: unknown): boolean { + if (schema === null || typeof schema !== 'object') return false; + const { name, enable } = schema as { name?: unknown; enable?: unknown }; + if (typeof name !== 'string' || isStoredMetadataBodyObject(name)) return false; + if (!isSystemObjectName(name)) return false; + return (enable as { aiReadable?: unknown } | null | undefined)?.aiReadable === true; +} diff --git a/packages/spec/src/data/index.ts b/packages/spec/src/data/index.ts index cf423b5f07c..99e5885c8d8 100644 --- a/packages/spec/src/data/index.ts +++ b/packages/spec/src/data/index.ts @@ -334,6 +334,11 @@ export * from './datasource-credential-redaction'; // a saved datasource is named by, and judge the pair here rather than copy it. export * from './external-binding-datasource'; +// [ruling A on the read half of #32442] The read-only AI exposure declaration +// `enable.aiReadable`: its one reading (`isAiReadExposed`, for the surfaces +// that admit an object to the AI read tools) and its parse refusal. +export * from './ai-read-exposure'; + // External Datasource Federation — SQL↔field type compatibility (ADR-0015) export * from './type-compat'; export * from './external-catalog.zod'; diff --git a/packages/spec/src/data/object.zod.ts b/packages/spec/src/data/object.zod.ts index c7ef25196d5..90d072fb055 100644 --- a/packages/spec/src/data/object.zod.ts +++ b/packages/spec/src/data/object.zod.ts @@ -45,6 +45,9 @@ import { externalBindingDatasourceRefusal } from './external-binding-datasource' // The one-name-per-action predicate, shared with the v18 stored-row listing. // Internal to the spec. import { duplicateActionNames } from './duplicate-action-names'; +// The read-only AI exposure refusal (`enable.aiReadable`). Public, with its one +// reading `isAiReadExposed`: re-exported from `@objectstack/spec/data`. +import { aiReadExposureRefusal } from './ai-read-exposure'; // The object's default row scope (the RLS policy shape without `object`) and the // roster object's declarative membership keys. No cycle: `security/rls.zod` // imports only zod, `shared/` and the resolver contract's constants. @@ -221,6 +224,30 @@ const CAPABILITIES_RETIRED_KEY_GUIDANCE: Record = { * `PerOperationRequiredPermissionsSchema` in this same file rather than * deleting the assertion, exactly as that test's own note instructs. */ +/** + * [ruling A on the read half of #32442] `enable.aiReadable` is READ-ONLY, and + * has no write arm: an agent writes to a system object only through an action + * the object declares with `ai.exposed` (ADR-0011). These are the names an + * author reaches for when they want the write arm, or when they carry an + * action's `ai.exposed` over to the object; each is refused with that + * prescription rather than renamed, because none of them means what + * `aiReadable` means. Declared above `ObjectCapabilities` for the order reason + * its docblock gives. + */ +const AI_READ_EXPOSURE_WRITE_ARM = + 'AI exposure of an object is read-only: `enable.aiReadable: true`, on a system (`sys_`) object, opens ' + + 'its records to the AI read tools (query, get one, aggregate, describe, list) and never to a write. ' + + 'An agent writes only through an action the object declares with `ai: { exposed: true, description }` ' + + '(ADR-0011), which carries its own permissions and confirmation.'; + +const CAPABILITIES_AI_WRITE_ARM_GUIDANCE: Record = { + aiExposed: AI_READ_EXPOSURE_WRITE_ARM, + aiWritable: AI_READ_EXPOSURE_WRITE_ARM, + aiWrite: AI_READ_EXPOSURE_WRITE_ARM, + aiEditable: AI_READ_EXPOSURE_WRITE_ARM, + ai: AI_READ_EXPOSURE_WRITE_ARM, +}; + const CAPABILITIES_HISTORY = 'Until this shape was closed an unknown flag was dropped without a word — the object ' + 'shipped as if the author had never written it; `enable` is a closed vocabulary ' @@ -268,7 +295,8 @@ const CAPABILITIES_HISTORY = export const ObjectCapabilities = strictObject({ surface: '`enable`', history: CAPABILITIES_HISTORY, - guidance: CAPABILITIES_RETIRED_KEY_GUIDANCE, + aliases: { aiRead: 'aiReadable', aiReadEnabled: 'aiReadable', aiReadExposed: 'aiReadable', mcpReadable: 'aiReadable' }, + guidance: { ...CAPABILITIES_RETIRED_KEY_GUIDANCE, ...CAPABILITIES_AI_WRITE_ARM_GUIDANCE }, }, { /** * History tracking (Audit Trail) master switch — opt-in. @@ -307,6 +335,29 @@ export const ObjectCapabilities = strictObject({ .optional() as unknown as z.ZodOptional>) .describe('Whitelist of allowed API operations (six primitives; undefined = all, [] = none)'), + /** + * Per-object, READ-ONLY AI exposure of a system object — opt-in, absent by + * default (ruling A on the read half of #32442). The read counterpart of an + * action's `ai.exposed` (ADR-0011), declared by the system object's own + * author. + * + * Contract: the AI read tools (query, get one, aggregate, describe, list) + * refuse every `sys_*` object by name, fail closed; `true` lets them reach + * this one, with every gate after admission unchanged — the caller's + * permissions, row-level security, field masking and this block's API + * exposure. It never opens a write: a write stays on the object's actions, + * each opened by its own `ai.exposed`. No deployment switch opens a system + * object instead of this declaration. + * + * Refused at parse ({@link aiReadExposureRefusal}, `ai-read-exposure.ts`, + * judged in `ObjectSchema`'s refinement): on any object that is not a + * `sys_*` object, where the AI read tools already read records as the + * caller and the key would change nothing; and on the stored-metadata family + * (`STORED_METADATA_BODY_OBJECTS`), judged before the key is read, which no + * declaration opens. The one reading is {@link isAiReadExposed}. + */ + aiReadable: z.boolean().optional().describe('Read-only AI exposure of a system (sys_) object, opt-in: true lets the AI read tools (query, get one, aggregate, describe, list) reach its records, under the caller\'s permissions and row-level security as before. Never opens a write: writes stay on actions declared with ai.exposed. Refused on any object whose name does not start with sys_, and on the stored-metadata family (sys_metadata, sys_metadata_history)'), + /** * Generic Attachments panel (Salesforce "Notes & Attachments" parity) — * opt-in. @@ -3264,6 +3315,24 @@ function refuseWriteLockedUserActions( } } +/** + * [ruling A on the read half of #32442] `enable.aiReadable` is declared only + * where it has a reader: a `sys_*` object outside the stored-metadata family. + * One located issue at `['enable', 'aiReadable']`; the family is judged before + * the key is read, and any declared value is judged, `false` included. + * + * Refused at parse on every door, not only at `create()`: the key is new, so + * no stored object carries it. Kept in the existing callback beside + * {@link refuseExternalBindingOnPrimaryDatasource} so it adds no check node the + * JSON Schema projection would have to drop. Predicate and message: + * `ai-read-exposure.ts` ({@link aiReadExposureRefusal}). + */ +function refuseMisplacedAiReadExposure(objectName: unknown, enable: unknown, ctx: z.RefinementCtx): void { + const refusal = aiReadExposureRefusal(objectName, enable); + if (refusal === undefined) return; + ctx.addIssue({ code: 'custom', path: [...refusal.path], message: refusal.message }); +} + /** * [#26725] An object's `actions` array declares each action name once. One * located issue per repeated name, at `['actions', ]` of its SECOND @@ -4516,6 +4585,10 @@ const ObjectSchemaBase = strictObject( // [ADR-0154 D10] Each `lifecycle.seal.valueFields` name is a declared field. // See the helper's docblock. refuseUndeclaredSealValueFields(object.lifecycle, object.fields, ctx); + // [ruling A on the read half of #32442] `enable.aiReadable` only on a `sys_*` + // object, never on the stored-metadata family — the same door: only the + // object knows its name. See the helper's docblock. + refuseMisplacedAiReadExposure(object.name, object.enable, ctx); }).overwrite((object) => { // [#23065] A `tree` that names no `reference` references this object, and the // parse writes that down after the refinements above judged what the author diff --git a/packages/spec/src/shared/alias-integrity.test.ts b/packages/spec/src/shared/alias-integrity.test.ts index b278947094f..b5588aea08d 100644 --- a/packages/spec/src/shared/alias-integrity.test.ts +++ b/packages/spec/src/shared/alias-integrity.test.ts @@ -1053,7 +1053,12 @@ describe('alias integrity — every table is a true claim about its schema', () const capabilities = bySurface.get('`enable`'); expect(capabilities, 'ObjectCapabilities no longer declares through strictObject').toBeDefined(); - expect(Object.keys(capabilities!.options.guidance ?? {}).sort()).toEqual(['mru', 'trash']); + // The retired-flag tombstones `mru` / `trash`, and [ruling A on the read + // half of #32442] the write-arm names `enable.aiReadable` refuses with its + // read-only prescription. + expect(Object.keys(capabilities!.options.guidance ?? {}).sort()).toEqual([ + 'ai', 'aiEditable', 'aiExposed', 'aiWritable', 'aiWrite', 'mru', 'trash', + ]); }); it('NO module outside the shared helpers writes its own `unrecognized_keys` map', () => { diff --git a/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts b/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts index 014e8248972..85becb809fb 100644 --- a/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts +++ b/packages/spec/src/system/metadata-form-zod-reconciliation.test.ts @@ -217,6 +217,13 @@ const LEDGER: ReadonlyArray = [ key: 'apiMethods', why: 'the Capabilities block is a toggle grid; apiMethods is a method whitelist (array of ApiMethod) that needs its own control, and is authored on the object body rather than as a switch', }, + { + kind: 'omit', + type: 'object', + path: 'enable', + key: 'aiReadable', + why: "the read-only AI exposure of a system object (ruling A on the read half of #32442): the parse refuses it on any object whose name does not start with sys_, and the Studio object editor authors business objects, so a toggle there would offer a value every save of that object refuses. Its writers are system objects declared in code (sys_approval_request first, the server half's)", + }, { kind: 'subset', type: 'object',