From ad4a41846e6d7b16de3aaa7f8921b3d42bfbc5b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 23:22:45 +0000 Subject: [PATCH 1/5] test(objectql): pin what the presentation and AI by-name readers answer under package addressing Adds the nine-type list the ADR-0150 E8 readers consult (package, name) for, and the 409 RESOURCE_CONFLICT refusal they raise, with the expected answers of every reader: the two-holder refusal, D3 (a), the outside-closure step, and the one-holder controls. The reader wiring waits for the resolver core to become reachable from the lean ./core entry; until then the narrowing cases are red by design and the controls green. Claude-Session: https://claude.ai/code/session_01ADHkmTH1oAwgDMigQ9pj37 Co-authored-by: Claude --- .../src/package-scoped-e8-readers.test.ts | 242 ++++++++++++++++++ packages/objectql/src/package-scoped-read.ts | 93 +++++++ 2 files changed, 335 insertions(+) create mode 100644 packages/objectql/src/package-scoped-e8-readers.test.ts create mode 100644 packages/objectql/src/package-scoped-read.ts diff --git a/packages/objectql/src/package-scoped-e8-readers.test.ts b/packages/objectql/src/package-scoped-e8-readers.test.ts new file mode 100644 index 00000000000..3dbe0f0b5a0 --- /dev/null +++ b/packages/objectql/src/package-scoped-e8-readers.test.ts @@ -0,0 +1,242 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +// Pays the lint root's first load at collection, never inside a clocked case. +import './__fixtures__/lint-root-preload.testkit.js'; + +/** + * ADR-0150 child E8 (#31680): the by-name readers of the presentation and AI + * types — app, page, dashboard, report, book, analytics cube, tool, skill and + * agent — consult `(package, name)` through the one resolver + * (`resolvePackageScopedName`, child R). + * + * The readers, each over the real `SchemaRegistry`: + * + * - the protocol's by-name read (`getMetaItem` / `getMetaItemForExecution`, + * what `GET /api/v1/meta/TYPE/NAME` and MCP `agent_prompt` read) when it + * names no package — a caller with no package; + * - `SchemaRegistry.getApp(name, currentPackageId?)`; + * - `MetadataFacade.get` / `getEntry` / `exists`. + * + * Narrowings, each declared on the card and the PR: (1) a bare name of an + * uncovered type two packages hold refuses naming both, where the first + * registered was served; (2) a package caller's bare name whose only holder is + * the environment's own item (ADR-0150 D3 (a)); (3) a package caller's bare + * name whose one package holder is outside its declared closure (D3 step 3, + * the epic seat's ruling on #31527). Everything else is the CONTROL: one + * holder answers as before, zero holders stays not-found, and the protocol + * read that names a package (`?package=`, child G1's exact qualifier) is not + * touched here. + */ + +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol'; +import { SchemaRegistry } from './registry.js'; +import { MetadataFacade } from './metadata-facade.js'; +import { resolveThrownHttpError } from '@objectstack/types'; +import { + PACKAGE_SCOPED_READ_TYPES, + PackageScopedNameRefusedError, +} from './package-scoped-read.js'; +import { isPackageScopedType, resolvePackageScopedName } from './package-scoped-resolver.js'; +import { BARE_NAME_REGISTRY_TYPES } from './bare-name-one-holder.js'; + +const A = 'com.acme.alpha'; +const B = 'com.acme.beta'; +const P = 'com.acme.caller'; + +/** The nine types this card wires, as the registry spells them. */ +const E8_TYPES = ['app', 'page', 'dashboard', 'report', 'book', 'analytics_cube', 'tool', 'skill', 'agent'] as const; +/** Of them, the ones phase 1's one-holder refusal does not cover: two package holders can exist today. */ +const UNCOVERED = E8_TYPES.filter((t) => !(BARE_NAME_REGISTRY_TYPES as readonly string[]).includes(t)); + +const manifest = (id: string, deps: string[] = []) => ({ + id, + name: id, + version: '1.0.0', + type: 'app', + namespace: id.split('.').pop()!, + ...(deps.length > 0 ? { dependencies: Object.fromEntries(deps.map((d) => [d, '^1.0.0'])) } : {}), +}) as never; + +let registry: SchemaRegistry; +let protocol: ObjectStackProtocolImplementation; +let facade: MetadataFacade; + +const install = (id: string, deps: string[] = []) => registry.installPackage(manifest(id, deps), 'code'); +const body = (type: string, name: string, tag: string): Record => + type === 'skill' + ? { name, label: `${tag} skill`, description: `${tag} skill`, instructions: tag, tools: [] } + : type === 'agent' + ? { name, label: `${tag} agent`, role: tag, instructions: tag } + : { name, label: `${tag} ${type}` }; +/** A package's item, in its composite slot. */ +const ship = (type: string, name: string, packageId: string) => + registry.registerItem(type, body(type, name, packageId.split('.').pop()!), 'name' as never, packageId); +/** The environment's own item: a package-less row in the bare slot. */ +const envItem = (type: string, name: string) => + registry.registerItem(type, { ...body(type, name, 'env'), _provenance: 'org' }, 'name' as never); +const labelOf = (item: unknown) => (item as { label?: string } | undefined)?.label; + +/** The coded refusal every rewired reader raises, with every candidate named. */ +async function expectRefusal(read: () => unknown, reason: string, named: readonly string[]) { + let thrown: unknown; + try { + await read(); + } catch (err) { + thrown = err; + } + expect(thrown, 'the read refuses').toBeInstanceOf(PackageScopedNameRefusedError); + const err = thrown as PackageScopedNameRefusedError; + expect(err.code).toBe('RESOURCE_CONFLICT'); + expect(err.status).toBe(409); + expect(err.refusal.reason).toBe(reason); + for (const holder of named) expect(err.message).toContain(holder); +} + +beforeEach(() => { + registry = new SchemaRegistry({ multiTenant: false }); + const engine = { + registry, + find: vi.fn().mockResolvedValue([]), + findOne: vi.fn().mockResolvedValue(null), + insert: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + count: vi.fn().mockResolvedValue(0), + aggregate: vi.fn().mockResolvedValue([]), + }; + protocol = new ObjectStackProtocolImplementation(engine as never); + facade = new MetadataFacade(registry); + install(A); + install(B); +}); + +describe('E8 wires exactly the nine types, every one of them package-scoped', () => { + it('PACKAGE_SCOPED_READ_TYPES is the card\'s nine, each one R addresses by package', () => { + expect([...PACKAGE_SCOPED_READ_TYPES].sort()).toEqual([...E8_TYPES].sort()); + for (const type of PACKAGE_SCOPED_READ_TYPES) expect(isPackageScopedType(type), type).toBe(true); + }); +}); + +describe('the refusal crosses a wire door as 409 RESOURCE_CONFLICT (ADR-0150 D5), never 500 or 404', () => { + it('the dispatcher\'s thrown-error reading answers 409 with the resolver\'s sentence', () => { + install(P); + ship('page', 'home', A); + ship('page', 'home', B); + const refusal = resolvePackageScopedName(registry, { type: 'page', name: 'home' }); + expect(refusal.status).toBe('refused'); + const err = new PackageScopedNameRefusedError(refusal as never); + const answer = resolveThrownHttpError(err, 500); + expect(answer.status).toBe(409); + expect(answer.code).toBe('RESOURCE_CONFLICT'); + expect(answer.message).toBe((refusal as { message: string }).message); + expect(answer.message).toContain(A); + expect(answer.message).toContain(B); + }); +}); + +describe('narrowing (1) — an uncovered type two packages hold: the bare read refuses naming both', () => { + for (const type of UNCOVERED) { + it(`${type}: a caller with no package is refused at the protocol read (both faces), the registry and the facade`, async () => { + ship(type, 'home', A); + ship(type, 'home', B); + await expectRefusal(() => protocol.getMetaItem({ type, name: 'home' }), 'ambiguous-in-environment', [A, B]); + await expectRefusal(() => protocol.getMetaItemForExecution({ type, name: 'home' }), 'ambiguous-in-environment', [A, B]); + await expectRefusal(() => facade.get(type, 'home'), 'ambiguous-in-environment', [A, B]); + await expectRefusal(() => facade.getEntry(type, 'home'), 'ambiguous-in-environment', [A, B]); + if (type === 'app') await expectRefusal(() => registry.getApp('home'), 'ambiguous-in-environment', [A, B]); + }); + + it(`${type}: each package's own item for its own callers`, async () => { + ship(type, 'home', A); + ship(type, 'home', B); + expect(labelOf(await facade.get(type, 'home', A))).toBe(`alpha ${type}`); + expect(labelOf(await facade.get(type, 'home', B))).toBe(`beta ${type}`); + if (type === 'app') { + expect(labelOf(registry.getApp('home', A))).toBe('alpha app'); + expect(labelOf(registry.getApp('home', B))).toBe('beta app'); + } + }); + } + + it('`exists` answers true: two holders are a fact, not an absence', async () => { + ship('page', 'home', A); + ship('page', 'home', B); + expect(await facade.exists('page', 'home')).toBe(true); + }); +}); + +describe('CONTROL — one holder answers exactly as before, at every rewired reader', () => { + for (const type of E8_TYPES) { + it(`${type}: one package holder is served to a caller with no package, to the holder and to a dependent`, async () => { + install(P, [A]); + ship(type, 'solo', A); + const before = registry.getItem(type, 'solo'); + expect(labelOf(before)).toBe(`alpha ${type}`); + expect(labelOf((await protocol.getMetaItem({ type, name: 'solo' }))?.item)).toBe(`alpha ${type}`); + expect(labelOf((await protocol.getMetaItemForExecution({ type, name: 'solo' }))?.item)).toBe(`alpha ${type}`); + expect(labelOf(await facade.get(type, 'solo'))).toBe(`alpha ${type}`); + expect(labelOf(await facade.get(type, 'solo', A))).toBe(`alpha ${type}`); + expect(labelOf(await facade.get(type, 'solo', P))).toBe(`alpha ${type}`); + expect(labelOf(facade.getEntry(type, 'solo'))).toBe(`alpha ${type}`); + expect(await facade.exists(type, 'solo')).toBe(true); + }); + + it(`${type}: the environment's own item is served to a caller with no package`, async () => { + envItem(type, 'local'); + expect(labelOf((await protocol.getMetaItem({ type, name: 'local' }))?.item)).toBe(`env ${type}`); + expect(labelOf(await facade.get(type, 'local'))).toBe(`env ${type}`); + }); + + it(`${type}: zero holders stays not-found, never a refusal`, async () => { + expect((await protocol.getMetaItem({ type, name: 'nothing' }))?.item).toBeUndefined(); + expect(await facade.get(type, 'nothing')).toBeUndefined(); + expect(await facade.get(type, 'nothing', A)).toBeUndefined(); + expect(await facade.exists(type, 'nothing')).toBe(false); + }); + + it(`${type}: the protocol read that names a package is untouched (child G1's exact qualifier)`, async () => { + ship(type, 'solo', A); + expect(labelOf((await protocol.getMetaItem({ type, name: 'solo', packageId: A }))?.item)).toBe(`alpha ${type}`); + }); + } + + it('an app served through getApp still carries its navigation contributions', () => { + ship('app', 'crm', A); + registry.registerAppNavContribution({ app: 'crm', items: [{ id: 'nav_x', type: 'url', url: '/x', label: 'X' }] }, B); + for (const app of [registry.getApp('crm'), registry.getApp('crm', A)] as Array<{ navigation?: Array<{ id?: string }> }>) { + expect(app?.navigation?.map((n) => n.id)).toContain('nav_x'); + } + }); +}); + +describe('narrowing (2) — D3 (a): a package caller never resolves to the environment\'s own item', () => { + for (const type of E8_TYPES) { + it(`${type}: refused, naming the environment`, async () => { + install(P); + envItem(type, 'local'); + await expectRefusal(() => facade.get(type, 'local', P), 'outside-closure', ['the environment']); + if (type === 'app') await expectRefusal(() => registry.getApp('local', P), 'outside-closure', ['the environment']); + }); + } +}); + +describe('narrowing (3) — D3 step 3: one holder outside the package caller\'s declared closure', () => { + for (const type of E8_TYPES) { + it(`${type}: refused, naming the holder; inside the closure it is served`, async () => { + install(P); + ship(type, 'solo', A); + await expectRefusal(() => facade.get(type, 'solo', P), 'outside-closure', [A]); + if (type === 'app') await expectRefusal(() => registry.getApp('solo', P), 'outside-closure', [A]); + install('com.acme.dependent', [A]); + expect(labelOf(await facade.get(type, 'solo', 'com.acme.dependent'))).toBe(`alpha ${type}`); + }); + } +}); + +describe('the types E8 does not wire keep the legacy read', () => { + it('a view (bucket 1) and a flow (child E1) are read by getItem, untouched', async () => { + ship('flow', 'onboard', A); + expect(labelOf(await facade.get('flow', 'onboard', P))).toBe('alpha flow'); + }); +}); diff --git a/packages/objectql/src/package-scoped-read.ts b/packages/objectql/src/package-scoped-read.ts new file mode 100644 index 00000000000..99329714992 --- /dev/null +++ b/packages/objectql/src/package-scoped-read.ts @@ -0,0 +1,93 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * # The by-name readers that consult `(package, name)` (ADR-0150 D3/D4) + * + * Child R (#31575) built ONE resolver for a bare name and wired no reader to + * it. Each child E of epic #31527 wires the readers of its types; this module + * holds what those readers share beside the resolver itself: which types are + * wired, and the refusal a reader raises. + * + * ## The types wired so far + * + * {@link PACKAGE_SCOPED_READ_TYPES}: the presentation and AI types of child E8 + * (#31680) — app, page, dashboard, report, book, analytics cube, tool, skill + * and agent. A later child adds its own types to the list in its own change. + * + * ## What a reader answers + * + * - **resolved** → the item, from the step that reached it; + * - **not-found** → `undefined`, as before: zero holders is never a refusal; + * - **refused** → {@link PackageScopedNameRefusedError}, thrown: the + * resolver's refusal, its sentence unchanged, naming every candidate. + * ⛔ Never `undefined`: a refusal read as a miss would tell the caller the + * name means nothing, when it means more than one thing (red line 2). + * + * Lean on purpose: it imports nothing, so the registry, the engine and + * `MetadataFacade` — all inside the `./core` entry's closure (ADR-0076 D2) — + * may read it. + */ + +/** + * The types whose by-name readers consult `(package, name)` today — child E8's + * nine (#31680), as the registry spells them. Each later child of epic #31527 + * appends its own. + */ +export const PACKAGE_SCOPED_READ_TYPES = Object.freeze([ + 'app', + 'page', + 'dashboard', + 'report', + 'book', + 'analytics_cube', + 'tool', + 'skill', + 'agent', +] as const); + +/** A type whose by-name readers consult `(package, name)` ({@link PACKAGE_SCOPED_READ_TYPES}). */ +export type PackageScopedReadType = (typeof PACKAGE_SCOPED_READ_TYPES)[number]; + +/** Do `type`'s by-name readers consult `(package, name)`? */ +export function isPackageScopedReadType(type: unknown): type is PackageScopedReadType { + return typeof type === 'string' && (PACKAGE_SCOPED_READ_TYPES as readonly string[]).includes(type); +} + +/** + * The resolver's refusal as a reader carries it: the reason, the item, the + * caller's package, every candidate, and the resolver's one sentence + * (`PackageScopedRefusal`, described here by shape so this module stays lean). + */ +export interface PackageScopedReadRefusal { + readonly status: 'refused'; + readonly reason: string; + readonly type: string; + readonly name: string; + readonly callerPackageId: string | null; + readonly candidates: readonly unknown[]; + readonly message: string; +} + +/** + * A by-name read the package-scoped resolver refused (ADR-0150 D3): the name + * means more than one item here, or only items the caller may not reach. The + * message is the resolver's own sentence, which names every candidate. + * + * The ADR-0112 envelope a wire door answers: `409 RESOURCE_CONFLICT`, the + * standard catalog's member for a name in conflict, which ADR-0150 D5 gives a + * by-name door's ambiguity. ⛔ Never the `500` fallback, and never `404`. + */ +export class PackageScopedNameRefusedError extends Error { + readonly code = 'RESOURCE_CONFLICT'; + readonly status = 409; + /** The same number under ADR-0112 D5's spelling — what a consumer holding the THROWN error reads. */ + readonly httpStatus = 409; + /** The resolver's refusal: the reason, the caller's package and every candidate. */ + readonly refusal: PackageScopedReadRefusal; + + constructor(refusal: PackageScopedReadRefusal) { + super(refusal.message); + this.name = 'PackageScopedNameRefusedError'; + this.refusal = refusal; + } +} From 5915671caa340ace1460f405b31aee8a2d1fe18a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 04:48:39 +0000 Subject: [PATCH 2/5] feat(objectql)!: by-name readers of presentation and AI types resolve (package, name) getApp, MetadataFacade get/getEntry/exists and the protocol's package-less by-name read now answer through the one package-scoped resolver for app, page, dashboard, report, book, analytics_cube, tool, skill and agent. A name the resolver refuses throws a coded 409 RESOURCE_CONFLICT naming every candidate; one holder and zero holders answer as before. Claude-Session: https://claude.ai/code/session_01ADHkmTH1oAwgDMigQ9pj37 Co-authored-by: Claude --- .../31680-presentation-ai-reads-by-package.md | 21 +++++ .../src/protocol-meta-item-reads.ts | 31 ++++++- packages/objectql/src/index.ts | 11 +++ packages/objectql/src/metadata-facade.ts | 38 +++++++-- packages/objectql/src/package-scoped-read.ts | 80 +++++++++++++------ packages/objectql/src/registry.ts | 51 +++++++++++- 6 files changed, 190 insertions(+), 42 deletions(-) create mode 100644 .changeset/31680-presentation-ai-reads-by-package.md diff --git a/.changeset/31680-presentation-ai-reads-by-package.md b/.changeset/31680-presentation-ai-reads-by-package.md new file mode 100644 index 00000000000..052e9ed81f9 --- /dev/null +++ b/.changeset/31680-presentation-ai-reads-by-package.md @@ -0,0 +1,21 @@ +--- +'@objectstack/objectql': patch +'@objectstack/metadata-protocol': patch +--- + +feat(objectql)!: the by-name reads of apps, pages, dashboards, reports, books, analytics cubes, tools, skills and agents consult `(package, name)` (ADR-0150 D3) + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +`SchemaRegistry.getApp`, `MetadataFacade.get` / `getEntry` / `exists` and the protocol's by-name read that names no package (`GET /api/v1/meta/TYPE/NAME`, and MCP `agent_prompt`, which reads it) now answer these nine types through the one package-scoped resolver. A package caller gets its own item, else the one holder in its declared dependencies (plus `sys`). A caller with no package gets the environment's own item, else the one package holder. A name with one holder, and a name with none, answer exactly as before. + +**BREAKING** for three bare-name reads that were served a guess and are now refused with `409 RESOURCE_CONFLICT`, the message naming every holder: + +1. A caller with no package reads a name that two packages both ship (for app, page, dashboard, report, book, analytics cube or tool; skills and agents already allow one holder only). It was served whichever package registered first. +2. A package caller reads a name that only the environment's own item holds. +3. A package caller reads a name whose one holder is a package it does not declare as a dependency. + +The fix is one line. For 1 and 3, declare the holding package in the reading package's `dependencies`, or name the package the read means with `?package=`. For 2, ship the item in the reading package or in a package it depends on. None of the four example apps in this repository hits any of the three. diff --git a/packages/metadata-protocol/src/protocol-meta-item-reads.ts b/packages/metadata-protocol/src/protocol-meta-item-reads.ts index fb96a7ddd7f..d1c8e27d276 100644 --- a/packages/metadata-protocol/src/protocol-meta-item-reads.ts +++ b/packages/metadata-protocol/src/protocol-meta-item-reads.ts @@ -92,6 +92,22 @@ export async function readMetaItem(host: Pick wantedMember === undefined || itemDiscriminator(request.type, candidate) === wantedMember; + // [ADR-0150 D3, #31680 child E8] A read that names no package is a caller + // with no package. For a type whose by-name readers consult + // `(package, name)` (the registry's `readsByPackage`), the registry's + // answer is the ONE package-scoped resolver's (`resolveItem`): the + // environment's own item, else the unique package holder. A name two + // packages hold is refused HERE, before any layer below is read, naming + // both (a thrown `409 RESOURCE_CONFLICT`); it served the first registered. + // Step 3 serves this answer in place of `getItem`'s, and nothing else + // below changes. A read that names a package (`?package=`) keeps + // `getItem`'s prefer-local read: that address is the exact qualifier of + // child G1 (ADR-0150 D5), not a caller. + const registry = host.engine?.registry; + const packagelessScopedRead: { item: unknown } | undefined = + !request.packageId && typeof registry?.readsByPackage === 'function' && registry.readsByPackage(request.type) + ? { item: registry.resolveItem(request.type, request.name, null, member) } + : undefined; let item: unknown; // [ADR-0131 D6] Environment → code: the environment's stored row, // else the code packages' definition. No organization's row is read — @@ -566,10 +582,17 @@ export async function readMetaItem(host: Pick { // [#7378 row 2] Read the store `register` wrote: the canonical type. - return this.registry.getItem(canonicalMetadataServiceType(type), name, currentPackageId); + return this.registry.resolveItem(canonicalMetadataServiceType(type), name, currentPackageId); } /** @@ -241,9 +247,15 @@ export class MetadataFacade { * resolution. ([#7519] Historically documented as "with metadata wrapper" — * there is no wrapper; {@link get} returns the same stored document. This * member survives as the sync, scope-free variant.) + * + * [ADR-0150 D3, #31680 child E8] Scope-free is a caller with no package: a + * type of `PACKAGE_SCOPED_READ_TYPES` resolves environment-wide through the + * one package-scoped resolver, and a name two packages hold is refused. + * + * @throws {PackageScopedNameRefusedError} when the resolver refuses. */ getEntry(type: string, name: string): any { - return this.registry.getItem(canonicalMetadataServiceType(type), name); + return this.registry.resolveItem(canonicalMetadataServiceType(type), name); } /** @@ -285,9 +297,19 @@ export class MetadataFacade { /** * Check if a metadata item exists + * + * [ADR-0150 D3, #31680 child E8] Read as {@link getEntry} reads it. A name + * the package-scoped resolver refuses exists: its holders are a fact, and + * no item is served for it here. */ async exists(type: string, name: string): Promise { - const item = this.registry.getItem(canonicalMetadataServiceType(type), name); + let item: unknown; + try { + item = this.registry.resolveItem(canonicalMetadataServiceType(type), name); + } catch (err) { + if (err instanceof PackageScopedNameRefusedError) return true; + throw err; + } return item !== undefined && item !== null; } diff --git a/packages/objectql/src/package-scoped-read.ts b/packages/objectql/src/package-scoped-read.ts index 99329714992..3b302bbcdad 100644 --- a/packages/objectql/src/package-scoped-read.ts +++ b/packages/objectql/src/package-scoped-read.ts @@ -3,31 +3,60 @@ /** * # The by-name readers that consult `(package, name)` (ADR-0150 D3/D4) * - * Child R (#31575) built ONE resolver for a bare name and wired no reader to - * it. Each child E of epic #31527 wires the readers of its types; this module - * holds what those readers share beside the resolver itself: which types are - * wired, and the refusal a reader raises. + * Child R (#31575, made a lean core by R2 #31716) built ONE resolver for a + * bare name, {@link resolvePackageScopedName}, and wired no reader to it. + * Each child E of epic #31527 wires the readers of its types, and every one of + * them goes through {@link readPackageScopedItem} here — the resolver's answer + * turned into what a by-name reader returns — so no reader re-states the rule. * * ## The types wired so far * * {@link PACKAGE_SCOPED_READ_TYPES}: the presentation and AI types of child E8 * (#31680) — app, page, dashboard, report, book, analytics cube, tool, skill - * and agent. A later child adds its own types to the list in its own change. + * and agent. A later child adds its own types to the list in its own change; + * until then a type's by-name read stays `SchemaRegistry.getItem`'s, exactly + * as before (`SchemaRegistry.resolveItem`). * * ## What a reader answers * - * - **resolved** → the item, from the step that reached it; + * - **resolved** → the item, from the step that reached it (the caller + * package's own, the unique holder in its declared closure, or for a + * caller with no package the environment's own item, else the unique + * package holder); * - **not-found** → `undefined`, as before: zero holders is never a refusal; * - **refused** → {@link PackageScopedNameRefusedError}, thrown: the * resolver's refusal, its sentence unchanged, naming every candidate. * ⛔ Never `undefined`: a refusal read as a miss would tell the caller the * name means nothing, when it means more than one thing (red line 2). * - * Lean on purpose: it imports nothing, so the registry, the engine and - * `MetadataFacade` — all inside the `./core` entry's closure (ADR-0076 D2) — - * may read it. + * ## What this changes against `getItem` (declared on #31680) + * + * `getItem` answers the bare slot, then the caller's composite slot, then the + * FIRST composite slot of any package. Through the resolver: + * + * 1. a bare name two packages hold, read by a caller with no package, is + * refused naming both (it served the first registered); + * 2. a package caller's bare name whose only holder is the environment's own + * item is refused, naming the environment (ADR-0150 D3 (a)); + * 3. a package caller's bare name whose one package holder is outside its + * declared dependency closure (plus `sys`) is refused, naming the holder + * (D3 step 3). + * + * Every other answer is unchanged: one holder is served to every caller that + * may reach it, and an overlay of the one holder is still served first. + * + * Inside the lean `./core` entry's closure (ADR-0076 D2): it reads the + * resolver, which since R2 reads only `@objectstack/core` and + * `@objectstack/metadata-core`. */ +import type { PackageScopedRefusal } from '@objectstack/core'; +import { + resolvePackageScopedName, + type PackageScopedQuery, + type PackageScopedRegistry, +} from './package-scoped-resolver.js'; + /** * The types whose by-name readers consult `(package, name)` today — child E8's * nine (#31680), as the registry spells them. Each later child of epic #31527 @@ -53,21 +82,6 @@ export function isPackageScopedReadType(type: unknown): type is PackageScopedRea return typeof type === 'string' && (PACKAGE_SCOPED_READ_TYPES as readonly string[]).includes(type); } -/** - * The resolver's refusal as a reader carries it: the reason, the item, the - * caller's package, every candidate, and the resolver's one sentence - * (`PackageScopedRefusal`, described here by shape so this module stays lean). - */ -export interface PackageScopedReadRefusal { - readonly status: 'refused'; - readonly reason: string; - readonly type: string; - readonly name: string; - readonly callerPackageId: string | null; - readonly candidates: readonly unknown[]; - readonly message: string; -} - /** * A by-name read the package-scoped resolver refused (ADR-0150 D3): the name * means more than one item here, or only items the caller may not reach. The @@ -83,11 +97,25 @@ export class PackageScopedNameRefusedError extends Error { /** The same number under ADR-0112 D5's spelling — what a consumer holding the THROWN error reads. */ readonly httpStatus = 409; /** The resolver's refusal: the reason, the caller's package and every candidate. */ - readonly refusal: PackageScopedReadRefusal; + readonly refusal: PackageScopedRefusal; - constructor(refusal: PackageScopedReadRefusal) { + constructor(refusal: PackageScopedRefusal) { super(refusal.message); this.name = 'PackageScopedNameRefusedError'; this.refusal = refusal; } } + +/** + * Read `(type, name)` for a caller through {@link resolvePackageScopedName}: + * the item, `undefined` when nothing holds the name, or a thrown + * {@link PackageScopedNameRefusedError} naming every candidate. + * + * @throws {PackageScopedNameRefusedError} when the resolver refuses. + */ +export function readPackageScopedItem(registry: PackageScopedRegistry, query: PackageScopedQuery): T | undefined { + const resolution = resolvePackageScopedName(registry, query); + if (resolution.status === 'resolved') return resolution.item; + if (resolution.status === 'refused') throw new PackageScopedNameRefusedError(resolution); + return undefined; +} diff --git a/packages/objectql/src/registry.ts b/packages/objectql/src/registry.ts index 8d88a0518cc..5c0a32d8aa4 100644 --- a/packages/objectql/src/registry.ts +++ b/packages/objectql/src/registry.ts @@ -99,6 +99,9 @@ import { type BareNameHolder, type BareNameOneHolderType, } from './bare-name-one-holder.js'; +// [ADR-0150 D3, #31680 child E8] The by-name readers that consult (package, name): +// `resolveItem` hands the types they cover to the one package-scoped resolver. +import { isPackageScopedReadType, readPackageScopedItem } from './package-scoped-read.js'; // [ADR-0150 D2, child N] Inside one namespace, a `(type, name)` of the twelve // uncovered bucket 2/3 types has one package holder — the one predicate the // package door and `os validate` both ask (module doc). @@ -8482,6 +8485,37 @@ export class SchemaRegistry { return unbound[0]?.item as T | undefined; } + /** + * [ADR-0150 D3, #31680 child E8] Does a by-name read of `type` consult + * `(package, name)` — is it one of `PACKAGE_SCOPED_READ_TYPES` + * (`package-scoped-read.ts`)? Asked by a reader that picks its path before + * it reads, such as the protocol's by-name read. + */ + readsByPackage(type: string): boolean { + return isPackageScopedReadType(type); + } + + /** + * [ADR-0150 D3, #31680 child E8] The by-name read for a caller. A type of + * `PACKAGE_SCOPED_READ_TYPES` resolves through the ONE package-scoped + * resolver (`readPackageScopedItem` over `resolvePackageScopedName`): the + * caller's own item, else the unique holder in its declared closure; for a + * caller with no package the environment's own item, else the unique package + * holder. Every other type is {@link getItem}'s, unchanged, until its own + * child of epic #31527 wires it. + * + * @param callerPackageId - The package the caller belongs to; omitted or + * `null` is a caller with no package (the whole environment). + * @returns the item, or `undefined` when nothing holds the name. + * @throws {PackageScopedNameRefusedError} when the resolver refuses — never + * `undefined` for a name that means more than one item, or only items the + * caller may not reach. + */ + resolveItem(type: string, name: string, callerPackageId?: string | null, member?: string): T | undefined { + if (!isPackageScopedReadType(type)) return this.getItem(type, name, callerPackageId ?? undefined, member); + return readPackageScopedItem(this, { type, name, callerPackageId, member }); + } + /** The bare-slot entries of `(type, name)`: one, or a bundle's members, canonical first. */ private bareSlotEntriesOf(type: string, collection: Map, name: string): BundleEntry[] { const disc = ITEM_KEY_DISCRIMINATORS[type]; @@ -9442,11 +9476,20 @@ export class SchemaRegistry { this.registerItem('app', app, 'name', packageId); } + /** + * One app by name, with its navigation contributions merged in. + * + * [ADR-0150 D3, #31680 child E8] Resolved through the one package-scoped + * resolver ({@link resolveItem}): `currentPackageId` is the caller's + * package (its own app, else the unique holder in its declared closure); + * omitted, the caller has no package (the environment's own app, else the + * unique package holder). A name two holders make ambiguous, or one the + * caller may not reach, is refused naming every candidate. + * + * @throws {PackageScopedNameRefusedError} when the resolver refuses. + */ getApp(name: string, currentPackageId?: string): any { - // ADR-0048 §3.1 — apps are addressed by package id (one app per package). - // When the caller knows it (route segment / `_packageId`), resolve - // prefer-local; otherwise this is a best-effort by-name lookup. - const app = this.getItem('app', name, currentPackageId); + const app = this.resolveItem('app', name, currentPackageId); if (!app) return app; return this.applyNavContributions(app); } From 9ba0c56e9d03a543c32543d881495cd85b6364ae Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 04:48:39 +0000 Subject: [PATCH 3/5] test(mcp): a refused by-name agent read travels naming every holder Claude-Session: https://claude.ai/code/session_01ADHkmTH1oAwgDMigQ9pj37 Co-authored-by: Claude --- .../31680-presentation-ai-reads-by-package.md | 6 ++++- ...er-runtime.agent-prompt-advertised.test.ts | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.changeset/31680-presentation-ai-reads-by-package.md b/.changeset/31680-presentation-ai-reads-by-package.md index 052e9ed81f9..2d73b4423df 100644 --- a/.changeset/31680-presentation-ai-reads-by-package.md +++ b/.changeset/31680-presentation-ai-reads-by-package.md @@ -18,4 +18,8 @@ Metadata-protocol: none 2. A package caller reads a name that only the environment's own item holds. 3. A package caller reads a name whose one holder is a package it does not declare as a dependency. -The fix is one line. For 1 and 3, declare the holding package in the reading package's `dependencies`, or name the package the read means with `?package=`. For 2, ship the item in the reading package or in a package it depends on. None of the four example apps in this repository hits any of the three. +The fix is one line, and none of the four example apps in this repository needs it: + +- FROM a bare read of a name two packages ship TO the read that names the package it means (`?package=`). +- FROM a package caller reading the environment's own item TO the item shipped in the reading package, or in a package it depends on. +- FROM a package caller reading a package it does not depend on TO that package declared in the reader's `dependencies`. diff --git a/packages/mcp/src/mcp-server-runtime.agent-prompt-advertised.test.ts b/packages/mcp/src/mcp-server-runtime.agent-prompt-advertised.test.ts index f8f2b5da9b9..406fac1726b 100644 --- a/packages/mcp/src/mcp-server-runtime.agent-prompt-advertised.test.ts +++ b/packages/mcp/src/mcp-server-runtime.agent-prompt-advertised.test.ts @@ -409,6 +409,30 @@ describe('agent_prompt — one reader with GET /meta/agent/NAME (the protocol)', } }); + it('[#31680, ADR-0150 D3] a by-name read the package-scoped resolver refuses (409 RESOURCE_CONFLICT) travels naming every holder: never "not found", never the outage text', async () => { + // The protocol's package-less by-name read refuses a name more than one + // package holds, naming each (child E8). Read here as a miss it would tell + // the client the agent does not exist; read as the #6055 outage it would + // say nothing is known. It is neither: it travels as the refusal it is. + const refusal = Object.assign( + new Error('agent "pkg_helper" is held by com.acme.alpha and com.acme.beta: qualify the name with its package'), + { code: 'RESOURCE_CONFLICT', status: 409, httpStatus: 409 }, + ); + const session = await connectWith( + metadataService({ agents: [] }), + protocol({ byName: async () => { throw refusal; } }), + ); + try { + const got = session.client.getPrompt({ name: 'agent_prompt', arguments: { agentName: 'pkg_helper' } }); + await expect(got).rejects.toThrow(/com\.acme\.alpha and com\.acme\.beta/); + await expect(got).rejects.not.toThrow(/not found|SERVICE_UNAVAILABLE/); + await expect(got).rejects.not.toThrow(PACKAGE_AGENT.instructions); + expect(session.log.warn).not.toHaveBeenCalledWith(expect.stringContaining('agent prompt refused'), expect.anything()); + } finally { + await session.close(); + } + }); + it('a degraded roster verdict with the protocol present and no agent named keeps the prompt listed, naming no agent', async () => { const session = await connectWith( metadataService({ From 76054c08085d0a1b6d52e4817a062b057521466f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 05:52:11 +0000 Subject: [PATCH 4/5] test(dogfood): a booted clash's package-less by-name read refuses naming both holders The AI-family boot pin asserted the first-registered package's agent and tool were served at GET /meta/TYPE/NAME. That read now answers 409 RESOURCE_CONFLICT naming both holders; the ?package= read serves each package's own, and the skill prompt list is unchanged. Claude-Session: https://claude.ai/code/session_01ADHkmTH1oAwgDMigQ9pj37 Co-authored-by: Claude --- ...-name-one-holder-ai-family.dogfood.test.ts | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts b/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts index aa4d093152c..850499e1c0e 100644 --- a/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts +++ b/packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts @@ -16,9 +16,12 @@ // `AppPlugin` packages, `alpha` and `beta`, shipping one agent, one skill // and one tool under the same names — boots, and logs ONE bare-name // warning line naming all three, both packages and the rename for each; -// the readers keep serving the first-registered package's item, as -// before: `/meta/agent/NAME`, the skill an MCP client's `prompts/get` -// resolves and `/meta/tool/NAME`; +// the skill an MCP client's `prompts/get` resolves stays the +// first-registered package's (the merged list), and [#31680, ADR-0150 D3] +// the by-name read that names no package — `/meta/agent/NAME`, +// `/meta/skill/NAME`, `/meta/tool/NAME` — refuses `409 RESOURCE_CONFLICT` +// naming both holders, where it served the first registered; the read +// that names the package (`?package=`) serves each package's own; // - `POST /marketplace/install-local` of a third package declaring the held // agent name, of a fourth declaring the held skill name, and of a fifth // declaring the held tool name, is 422 PLUGIN_REGISTER_FAILED naming both @@ -125,6 +128,29 @@ describe('one package holder per agent, skill and tool name, on a booted showcas return d?._packageId ?? d?.item?._packageId; }; + /** + * [#31680, ADR-0150 D3] The by-name read that names no package, of a name two + * packages hold: refused `409 RESOURCE_CONFLICT`, naming both holders. + */ + const expectMetaRefused = async (type: string, name: string) => { + const r = await stack.apiAs(admin, 'GET', `/meta/${type}/${name}`); + const body = (await r.json()) as any; + expect([r.status, codeOf(body)], JSON.stringify(body)).toEqual([409, 'RESOURCE_CONFLICT']); + // The meta door's error envelope: `{ error: , code }`. + const message = String(typeof body?.error === 'string' ? body.error : body?.error?.message ?? body?.message ?? ''); + expect(message).toContain('com.qa.bare.alpha'); + expect(message).toContain('com.qa.bare.beta'); + }; + + /** The package whose item `GET /meta/TYPE/NAME?package=PKG` serves. */ + const metaPackageAt = async (type: string, name: string, pkg: string): Promise => { + const r = await stack.apiAs(admin, 'GET', `/meta/${type}/${name}?package=${pkg}`); + expect(r.status).toBe(200); + const body = (await r.json()) as any; + const d = body?.data ?? body; + return d?._packageId ?? d?.item?._packageId; + }; + /** The skill an MCP client's `prompts/get` of `name` resolves: the MCP prompt projection over the merged `skill` list. */ const skillPromptTitle = async (name: string): Promise => { const r = await stack.apiAs(admin, 'GET', '/meta/skill'); @@ -166,11 +192,16 @@ describe('one package holder per agent, skill and tool name, on a booted showcas expect(line).toContain('package "com.qa.bare.alpha"'); expect(line).toContain('package "com.qa.bare.beta"'); expect(await packageIds(), 'both packages booted').toEqual(expect.arrayContaining(['com.qa.bare.alpha', 'com.qa.bare.beta'])); - // Unchanged by the rule: the readers keep serving the first-registered package's item. - expect(await metaPackage('agent', AGENT)).toBe('com.qa.bare.alpha'); - expect(await metaPackage('skill', SKILL)).toBe('com.qa.bare.alpha'); + // Unchanged by the rule: the skill prompt is the first-registered package's. expect(await skillPromptTitle(SKILL)).toBe('alpha skill'); - expect(await metaPackage('tool', TOOL)).toBe('com.qa.bare.alpha'); + // [#31680, ADR-0150 D3] The by-name read that names no package refuses the + // held name naming both holders (it served the first registered); the read + // that names the package serves that package's own. + for (const [type, name] of [['agent', AGENT], ['skill', SKILL], ['tool', TOOL]] as const) { + await expectMetaRefused(type, name); + expect(await metaPackageAt(type, name, 'com.qa.bare.alpha')).toBe('com.qa.bare.alpha'); + expect(await metaPackageAt(type, name, 'com.qa.bare.beta')).toBe('com.qa.bare.beta'); + } }); it('install-local of a third package declaring a held agent name is 422 PLUGIN_REGISTER_FAILED naming both holders and the rename; nothing is installed', async () => { @@ -183,7 +214,7 @@ describe('one package holder per agent, skill and tool name, on a booted showcas expect(message).toContain('com.qa.bare.beta'); expect(message).toContain(`"gamma_${AGENT}"`); expect(await packageIds(), 'the package list is unchanged').toEqual(before); - expect(await metaPackage('agent', AGENT)).toBe('com.qa.bare.alpha'); + await expectMetaRefused('agent', AGENT); }); it('install-local of a package declaring a held skill name is refused the same way; the skill prompt is untouched', async () => { @@ -209,7 +240,7 @@ describe('one package holder per agent, skill and tool name, on a booted showcas expect(message).toContain('com.qa.bare.beta'); expect(message).toContain(`"zeta_${TOOL}"`); expect(await packageIds(), 'the package list is unchanged').toEqual(before); - expect(await metaPackage('tool', TOOL)).toBe('com.qa.bare.alpha'); + await expectMetaRefused('tool', TOOL); }); it('CONTROL — install-local of a package declaring fresh agent, skill and tool names installs', async () => { From e9cf4d6c75f7f315c0955fff5085b317dca45f97 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 05:53:15 +0000 Subject: [PATCH 5/5] chore(changeset): name which presentation and AI types a package-less clash reaches Claude-Session: https://claude.ai/code/session_01ADHkmTH1oAwgDMigQ9pj37 Co-authored-by: Claude --- .changeset/31680-presentation-ai-reads-by-package.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/31680-presentation-ai-reads-by-package.md b/.changeset/31680-presentation-ai-reads-by-package.md index 2d73b4423df..5938d5f722c 100644 --- a/.changeset/31680-presentation-ai-reads-by-package.md +++ b/.changeset/31680-presentation-ai-reads-by-package.md @@ -14,7 +14,7 @@ Metadata-protocol: none **BREAKING** for three bare-name reads that were served a guess and are now refused with `409 RESOURCE_CONFLICT`, the message naming every holder: -1. A caller with no package reads a name that two packages both ship (for app, page, dashboard, report, book, analytics cube or tool; skills and agents already allow one holder only). It was served whichever package registered first. +1. A caller with no package reads a name that two packages both ship. For an app, page, dashboard, report, book or analytics cube that can happen today; for an agent, skill or tool only on a deployment that booted already holding the clash (a new install of a held name is refused). It was served whichever package registered first. 2. A package caller reads a name that only the environment's own item holds. 3. A package caller reads a name whose one holder is a package it does not declare as a dependency.