Skip to content

Commit cfe3563

Browse files
feat(objectql)!: by-name readers of apps, pages, dashboards, reports, books, cubes, tools, skills and agents consult (package, name) (#31847)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9YGpy1NJdhGQFV6brdHkrTP)_ Fixes #31680 Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — no skill or doc teaches a bare read of a name two packages ship, an environment item read by a package caller, or a read of an undeclared package's item; ADR-0150 D3 already states the rule, and the `?package=` qualifier the refusals point to is already documented on the meta read. Narrowing: (1) a bare name two packages ship, read with no package, is refused naming both (first-party count 0; for agent, skill and tool only on a deployment that booted already holding the clash); (2) a package caller's name only the environment holds is refused, D3 (a) (count 0); (3) a package caller's name whose one holder is outside its declared closure is refused (count 0, same-artifact siblings 0). ## 维护者速读 - 改了什么:应用、页面、仪表盘、报表、手册、分析立方体、工具、技能和智能体这九类元数据,按名字读取时统一走 R 的那一个包内解析器(ADR-0150 D3),不再由注册表"谁先注册就给谁"。 - 为什么改:两个包发布同名页面时,不带包名的读取一直悄悄返回先注册的那个;包内调用方还能读到它没声明依赖的包或环境自有的条目。 - 收窄的三种情况一律返回 409 RESOURCE_CONFLICT 并列出全部持有者;只有一个持有者或没有持有者时,行为与之前完全一样。仓库内四个示例应用触发次数均为 0。 - 风险与回滚:只改读取路径(getApp、MetadataFacade、协议的不带包名读取),不改任何存储形状、schema 或 MCP 输入输出;回滚即 revert 本 PR。 - 先看:`packages/objectql/src/package-scoped-read.ts`,然后 `registry.ts` 的 `resolveItem`,再看 `protocol-meta-item-reads.ts` 中的 `packagelessScopedRead`。 - 需要你做的:无,席位做合同审查,史诗席位做红线审查后落地。 ## What changes Child E8 of epic #31527 wires the by-name readers of nine types (`app`, `page`, `dashboard`, `report`, `book`, `analytics_cube`, `tool`, `skill`, `agent`) to R's one resolver, `resolvePackageScopedName` (the lean core R2 #31733 landed). This follows the epic seat's ruling (option A): both arms of `getApp` and `MetadataFacade`, and no bindable reader. - **`package-scoped-read.ts` (new).** `PACKAGE_SCOPED_READ_TYPES` lists the nine types. `readPackageScopedItem` turns the resolver's answer into a reader's: resolved returns the item, not-found returns `undefined`, and a refusal throws `PackageScopedNameRefusedError`. That error carries `code: 'RESOURCE_CONFLICT'`, `status`/`httpStatus: 409`, the resolver's own sentence naming every candidate, and the `refusal`. It restates no part of the rule and holds no closure walk of its own. - **`SchemaRegistry.resolveItem(type, name, callerPackageId?, member?)` and `readsByPackage(type)`.** A wired type is read through `readPackageScopedItem`; every other type keeps `getItem`. The readers, and the caller package each one passes: | Reader | Caller package passed | |---|---| | `SchemaRegistry.getApp(name, currentPackageId?)` | `currentPackageId` | | `MetadataFacade.get(type, name, currentPackageId?)` | `currentPackageId` | | `MetadataFacade.getEntry(type, name)` | none | | `MetadataFacade.exists(type, name)` | none; a refusal answers `true` (the holders exist) | | protocol `readMetaItem` with no `packageId` (`GET /api/v1/meta/TYPE/NAME`, both faces, so MCP `agent_prompt` too) | `null` (a caller with no package) | - **Protocol read.** The package-less arm calls `registry.resolveItem(type, name, null, member)` once, before any layer is read, and step 3 serves that answer in place of `getItem` and its plural retry. A read with `?package=` keeps `getItem`; that address is G1's exact qualifier, not a caller. metadata-protocol still cannot import objectql, so it reaches the resolver only through the registry's `resolveItem`. No new import edge. - **MCP.** No code change and no input or output shape change (that is G2's). `agent_prompt` already reads through the protocol read (#31514). One new pin: a 409 refusal travels as a protocol error naming both holders. It is never answered as "not found" or as the outage text. - Barrel exports: the four names and the type from `@objectstack/objectql`. ## Tests - `packages/objectql/src/package-scoped-e8-readers.test.ts` (new, 71 tests). It runs the real `SchemaRegistry`, the real `ObjectStackProtocolImplementation` and the real `MetadataFacade`, and covers: - the type list; - the 409 mapping through `resolveThrownHttpError`; - narrowing (1) for each of the six types phase 1 does not cover (app, page, dashboard, report, book, analytics cube), at both protocol faces, `facade.get`/`getEntry` and `getApp`; - narrowings (2) and (3) for all nine types; - the CONTROL for all nine types: one holder, the environment's item, zero holders not-found, the `?package=` read untouched, and getApp's nav contributions; - a non-wired type keeps `getItem`. - `packages/mcp/src/mcp-server-runtime.agent-prompt-advertised.test.ts`: one new test, the refusal travels. - **Forced test edit, one:** `packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts` (#30803 / #31414, phase 1). Its cold boot holds an agent, skill and tool clash between two packages (a boot warns, it does not refuse), and it pinned that `GET /meta/agent|tool/NAME` with no package "keeps serving the first-registered package's item". That is narrowing (1) on the wire, and the full dogfood battery went red on exactly those 3 tests (3 failed / 3659 passed) on head 9e37aef. The pin now asserts `409 RESOURCE_CONFLICT` naming both packages for agent, skill and tool, and that `?package=` serves each package's own. The boot warning, the install refusals and the skill-prompt reading are unchanged. **Red on main** (b126c13, the probe in the card notes): for every uncovered type, with two holders, `/meta`, `facade.get` and `getApp` with no package served `alpha`, the first registered. A package caller was served an outside-closure single holder and an environment-only item. Before the wiring, the new file ran 25 failed and 48 passed; the 25 failures were exactly the three narrowing arms. **Ablations.** Each mutation was put in through `scripts/ablation-replace.mjs` and its run went red. Each was then restored, with the blob back to HEAD. | # | Mutation | Result | |---|---|---| | A1 | `readsByPackage` → false (the protocol arm off) | 6 failed | | A2 | `facade.get` → `getItem` | 24 failed | | A3 | `getApp` → `getItem` | 3 failed | | A4 | `resolveItem` → `getItem` | 24 failed | | A5 | `exists` refusal → false | 1 failed | | A6 | MCP `readAgentByName` reads `RESOURCE_CONFLICT` as a miss | 1 failed | | A7 | protocol source arm disabled, metadata-protocol rebuilt | 6 failed; `ablation-dist-preflight` marker present in dist | For A7, the restore leg rebuilt metadata-protocol, the preflight found the marker absent from dist with the tree clean, and the run went back to 71/71. ## Acceptance notes The four readings: - **(a) The phase-1 one-holder tests stay green.** These ran green on the final head with no edit: `registry-bare-name-one-holder.test.ts`, `package-scoped-resolver.test.ts`, `core-boundary.ratchet.test.ts`, `registry-cross-package-collision.test.ts`, `engine-cross-package-collision.test.ts`, and the full objectql suite. The one exception is the dogfood boot-clash pin named above: its "first registered is served" line is the behaviour E8 removes, so it is flipped. Its boot warning and install refusals are untouched. - **(b) One-holder bare-name behaviour is unchanged except for the declared narrowings.** The CONTROL block pins it for all nine types at every rewired reader. Agent, skill and tool are phase-1 covered: a new install of a held name is refused, so narrowing (1) reaches them only on a deployment that booted already holding the clash. - **(c) Migration.** None. This changes only what a read answers; no stored row, schema or shape changes (the `adr-0087: not-required (no-migration-prescription)` marker). - **(d)** `Clause-②: no (narrowing)`, per seat 2's ruling. The changeset carries the BREAKING banner, with FROM→TO and the one-line fix. Red lines: - ONE resolver: every wired reader goes through `readPackageScopedItem` → `resolvePackageScopedName`. No reader walks a closure or falls back to the first composite. - Ambiguity refuses, naming every candidate; zero holders stays not-found. - `package-scoped-resolver.ts` was not edited. - No `packages/spec/**`, `ui/**`, `docs/adr/**` or E6 readers were touched, and `registry.ts installPackage` was not touched. By-name reads not rewired here. Each keeps `getItem`: - the layered read (`getMetaItemLayered`); - `readCodeLayerForCarryForward`; - `protocol-artifact-lookup.ts`; - the write side (`protocol-save.ts`, `protocol-authoring-gate.ts`); - MCP's `diagnosedGet` for a host without a protocol; - `getAppNavContributions`; - the `getAllApps` list. The seat can file any of these as later cards. ADR-0146 overrides: a pair's stored override row is hydrated into the registry's bare slot (`protocol-registry-hydration.ts`), so a package-less read still finds the environment's item first, and the full ADR-0146 suites are green. New public names, which are the seat's call: `PACKAGE_SCOPED_READ_TYPES`, `PackageScopedReadType`, `isPackageScopedReadType`, `readPackageScopedItem`, `PackageScopedNameRefusedError`, `SchemaRegistry.resolveItem` and `SchemaRegistry.readsByPackage`. ## Verification Head `d981cf7c1ce46776fafe4b725f2a3ef9c77dec9e`, which merges origin/main fdfcc7a. Every run below is on that head, under `os-verify-lock`, and each VERDICT was command-exit 0. - Full `pnpm build`: green. - Tests: objectql 22610 passed (29 skipped), metadata-protocol 980 passed, mcp 11887 passed. - typecheck: clean for all three packages. - Lint: eslint is clean on the three packages' `src` and on the edited dogfood file. - Gates: `dispatch-gates.mjs --commands` listed 75 commands. All 75 exited 0, and `--ran` reconciles 75 derived, 75 run, 0 NOT-MEASURED. - Dogfood battery (`pnpm --filter @objectstack/dogfood test`): Test Files 441 passed, 3 skipped (444). Tests 3662 passed, 42 skipped (3704). 0 failed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmTH1oAwgDMigQ9pj37 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 31ae944 commit cfe3563

9 files changed

Lines changed: 567 additions & 25 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@objectstack/objectql': patch
3+
'@objectstack/metadata-protocol': patch
4+
---
5+
6+
feat(objectql)!: the by-name reads of apps, pages, dashboards, reports, books, analytics cubes, tools, skills and agents consult `(package, name)` (ADR-0150 D3)
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) no metadata shape, schema, stored row or registered node type changes: the change is which item a bare name resolves to at read time, the stored metadata is read exactly as before, so there is nothing for `objectstack migrate meta` to rewrite -->
12+
13+
`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.
14+
15+
**BREAKING** for three bare-name reads that were served a guess and are now refused with `409 RESOURCE_CONFLICT`, the message naming every holder:
16+
17+
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.
18+
2. A package caller reads a name that only the environment's own item holds.
19+
3. A package caller reads a name whose one holder is a package it does not declare as a dependency.
20+
21+
The fix is one line, and none of the four example apps in this repository needs it:
22+
23+
- FROM a bare read of a name two packages ship TO the read that names the package it means (`?package=<id>`).
24+
- 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.
25+
- FROM a package caller reading a package it does not depend on TO that package declared in the reader's `dependencies`.

‎packages/mcp/src/mcp-server-runtime.agent-prompt-advertised.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,30 @@ describe('agent_prompt — one reader with GET /meta/agent/NAME (the protocol)',
409409
}
410410
});
411411

412+
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 () => {
413+
// The protocol's package-less by-name read refuses a name more than one
414+
// package holds, naming each (child E8). Read here as a miss it would tell
415+
// the client the agent does not exist; read as the #6055 outage it would
416+
// say nothing is known. It is neither: it travels as the refusal it is.
417+
const refusal = Object.assign(
418+
new Error('agent "pkg_helper" is held by com.acme.alpha and com.acme.beta: qualify the name with its package'),
419+
{ code: 'RESOURCE_CONFLICT', status: 409, httpStatus: 409 },
420+
);
421+
const session = await connectWith(
422+
metadataService({ agents: [] }),
423+
protocol({ byName: async () => { throw refusal; } }),
424+
);
425+
try {
426+
const got = session.client.getPrompt({ name: 'agent_prompt', arguments: { agentName: 'pkg_helper' } });
427+
await expect(got).rejects.toThrow(/com\.acme\.alpha and com\.acme\.beta/);
428+
await expect(got).rejects.not.toThrow(/not found|SERVICE_UNAVAILABLE/);
429+
await expect(got).rejects.not.toThrow(PACKAGE_AGENT.instructions);
430+
expect(session.log.warn).not.toHaveBeenCalledWith(expect.stringContaining('agent prompt refused'), expect.anything());
431+
} finally {
432+
await session.close();
433+
}
434+
});
435+
412436
it('a degraded roster verdict with the protocol present and no agent named keeps the prompt listed, naming no agent', async () => {
413437
const session = await connectWith(
414438
metadataService({

‎packages/metadata-protocol/src/protocol-meta-item-reads.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
9292
const wantedMember = bundleMemberDiscriminator(request.type, member);
9393
const isWantedMember = (candidate: unknown): boolean =>
9494
wantedMember === undefined || itemDiscriminator(request.type, candidate) === wantedMember;
95+
// [ADR-0150 D3, #31680 child E8] A read that names no package is a caller
96+
// with no package. For a type whose by-name readers consult
97+
// `(package, name)` (the registry's `readsByPackage`), the registry's
98+
// answer is the ONE package-scoped resolver's (`resolveItem`): the
99+
// environment's own item, else the unique package holder. A name two
100+
// packages hold is refused HERE, before any layer below is read, naming
101+
// both (a thrown `409 RESOURCE_CONFLICT`); it served the first registered.
102+
// Step 3 serves this answer in place of `getItem`'s, and nothing else
103+
// below changes. A read that names a package (`?package=`) keeps
104+
// `getItem`'s prefer-local read: that address is the exact qualifier of
105+
// child G1 (ADR-0150 D5), not a caller.
106+
const registry = host.engine?.registry;
107+
const packagelessScopedRead: { item: unknown } | undefined =
108+
!request.packageId && typeof registry?.readsByPackage === 'function' && registry.readsByPackage(request.type)
109+
? { item: registry.resolveItem(request.type, request.name, null, member) }
110+
: undefined;
95111
let item: unknown;
96112
// [ADR-0131 D6] Environment → code: the environment's stored row,
97113
// else the code packages' definition. No organization's row is read —
@@ -566,10 +582,17 @@ export async function readMetaItem(host: Pick<ProtocolHost, 'artifactLockLayerAt
566582
if (artifact !== undefined && isWantedMember(artifact)) item = artifact;
567583
}
568584
if (item === undefined) {
569-
item = host.engine.registry.getItem(request.type, request.name, request.packageId, member);
570-
if (item === undefined) {
571-
const alt = PLURAL_TO_SINGULAR[request.type] ?? SINGULAR_TO_PLURAL[request.type];
572-
if (alt) item = host.engine.registry.getItem(alt, request.name, request.packageId, member);
585+
// [ADR-0150 D3, #31680] The package-scoped resolver's answer, read
586+
// once above, for a caller with no package of a type it covers; no
587+
// first-composite read and no plural-spelling retry beside it.
588+
if (packagelessScopedRead) {
589+
item = packagelessScopedRead.item;
590+
} else {
591+
item = host.engine.registry.getItem(request.type, request.name, request.packageId, member);
592+
if (item === undefined) {
593+
const alt = PLURAL_TO_SINGULAR[request.type] ?? SINGULAR_TO_PLURAL[request.type];
594+
if (alt) item = host.engine.registry.getItem(alt, request.name, request.packageId, member);
595+
}
573596
}
574597
// [#22877] A registry that does not narrow by member (a host
575598
// double, an older registry) can answer another member of the

‎packages/objectql/src/index.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ export type {
140140
PackageScopedRefusalReason,
141141
} from './package-scoped-resolver.js';
142142

143+
// [#31680, ADR-0150 D3] Child E8: the by-name readers of the presentation and
144+
// AI types consult `(package, name)` through the resolver above — the types
145+
// wired, the read every reader shares, and the coded refusal it throws.
146+
export {
147+
PACKAGE_SCOPED_READ_TYPES,
148+
isPackageScopedReadType,
149+
readPackageScopedItem,
150+
PackageScopedNameRefusedError,
151+
} from './package-scoped-read.js';
152+
export type { PackageScopedReadType } from './package-scoped-read.js';
153+
143154
// [#31673, ADR-0150 D4] The action engine's `(package, objectName, name)` key:
144155
// the declaration half — which package's action a bare name on an object means
145156
// to a caller, resolved by the resolver above over the items that own that

‎packages/objectql/src/metadata-facade.ts‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
canonicalMetadataServiceType,
66
} from '@objectstack/core';
77
import { SchemaRegistry } from './registry.js';
8+
import { PackageScopedNameRefusedError } from './package-scoped-read.js';
89

910
/**
1011
* Is this (already canonical) type the object metadata type?
@@ -225,25 +226,36 @@ export class MetadataFacade {
225226
* path can only corrupt — so there is none, and no replacement envelope key
226227
* either (any key chosen would just collide with the next authorable field).
227228
*
228-
* `currentPackageId` (ADR-0048) opts into package-scoped resolution: when two
229-
* installed packages ship an item of the same `type`/`name`, the registry
230-
* prefers the one owned by `currentPackageId` (composite key
231-
* `${packageId}:${name}`) before falling back to first-match. Omit it for the
232-
* legacy context-free lookup.
229+
* `currentPackageId` (ADR-0048) is the caller's package. [ADR-0150 D3,
230+
* #31680 child E8] For a type whose by-name readers consult
231+
* `(package, name)` (`PACKAGE_SCOPED_READ_TYPES`) the read is the one
232+
* package-scoped resolver's (`SchemaRegistry.resolveItem`): the caller's own
233+
* item, else the unique holder in its declared closure; with no package, the
234+
* environment's own item, else the unique package holder; a name that is
235+
* ambiguous, or held only where the caller may not reach, is refused naming
236+
* every candidate. Every other type keeps `getItem`'s prefer-local read.
237+
*
238+
* @throws {PackageScopedNameRefusedError} when the resolver refuses.
233239
*/
234240
async get(type: string, name: string, currentPackageId?: string): Promise<any> {
235241
// [#7378 row 2] Read the store `register` wrote: the canonical type.
236-
return this.registry.getItem(canonicalMetadataServiceType(type), name, currentPackageId);
242+
return this.registry.resolveItem(canonicalMetadataServiceType(type), name, currentPackageId);
237243
}
238244

239245
/**
240246
* Get the raw stored entry, synchronously and without package-scoped
241247
* resolution. ([#7519] Historically documented as "with metadata wrapper" —
242248
* there is no wrapper; {@link get} returns the same stored document. This
243249
* member survives as the sync, scope-free variant.)
250+
*
251+
* [ADR-0150 D3, #31680 child E8] Scope-free is a caller with no package: a
252+
* type of `PACKAGE_SCOPED_READ_TYPES` resolves environment-wide through the
253+
* one package-scoped resolver, and a name two packages hold is refused.
254+
*
255+
* @throws {PackageScopedNameRefusedError} when the resolver refuses.
244256
*/
245257
getEntry(type: string, name: string): any {
246-
return this.registry.getItem(canonicalMetadataServiceType(type), name);
258+
return this.registry.resolveItem(canonicalMetadataServiceType(type), name);
247259
}
248260

249261
/**
@@ -285,9 +297,19 @@ export class MetadataFacade {
285297

286298
/**
287299
* Check if a metadata item exists
300+
*
301+
* [ADR-0150 D3, #31680 child E8] Read as {@link getEntry} reads it. A name
302+
* the package-scoped resolver refuses exists: its holders are a fact, and
303+
* no item is served for it here.
288304
*/
289305
async exists(type: string, name: string): Promise<boolean> {
290-
const item = this.registry.getItem(canonicalMetadataServiceType(type), name);
306+
let item: unknown;
307+
try {
308+
item = this.registry.resolveItem(canonicalMetadataServiceType(type), name);
309+
} catch (err) {
310+
if (err instanceof PackageScopedNameRefusedError) return true;
311+
throw err;
312+
}
291313
return item !== undefined && item !== null;
292314
}
293315

0 commit comments

Comments
 (0)