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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .changeset/37216-ai-context-package-scoped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@objectstack/spec': minor
'@objectstack/core': minor
'@objectstack/objectql': minor
'@objectstack/service-record-context': minor
'@objectstack/mcp': minor
'@objectstack/runtime': minor
---

feat(objectql,service-record-context)!: a context pack (`ai_context`) is identified by its package and its name; `get_record_context` reaches each package's pack by its face

Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37177

<!-- adr-0087: registered ai-context-package-scoped-name -->

ADR-0150's addendum of 2026-11-25 puts the context pack in bucket 3 beside `skill`. Two packages may each ship a pack of one name, and each reader reaches the one it means.

- **The four lists.** `ai_context` joins `PACKAGE_SCOPED_TYPES` (`@objectstack/core`: the one ADR-0150 D3 rule resolves a bare pack name), `PACKAGE_SCOPED_READ_TYPES` (`@objectstack/objectql`: the `/meta/ai_context/NAME` read and its `?package=` qualifier), `PACKAGE_SLOTTED_METADATA_TYPES` (`@objectstack/spec/api`: the metadata service keeps one copy per `(package, name)`, and uninstalling one package drops its pack and keeps another package's pack of the name) and `NAMESPACE_UNIQUE_TYPES` (`@objectstack/objectql`: D2's refusal of a second holder inside one namespace).
- **`get_record_context` picks a pack by package and name.** The candidates are still the packs rooted on `objectName`. `context` is read the way a skill prompt's name is read. A face (`NS-NAME` for a package's pack, `deriveAiFaceName`) answers its one pack. A bare name resolves as for a caller with no package: the environment's own pack, else the one package that holds the name, else `409 RESOURCE_CONFLICT` naming each candidate by its face. With `context` omitted on an object with several packs, the answer (`400 VALIDATION_ERROR`) lists each pack by its face with its label, in English and in Simplified Chinese; a pack without a label would be listed by its face alone. The tool's description tells the model to name a package's pack as `NAMESPACE-NAME`.
- **New door member.** `RecordContextDoor.packageNamespace(packageId)` (optional) gives a package's manifest namespace. A door without it spells every pack by its bare name, as an environment pack is spelt. Both MCP doors implement it from the `objectql` registry's package record (`@objectstack/runtime`'s `/mcp` route and `@objectstack/mcp`'s stdio bridge), so on either transport two packages' packs of one name are each reached by their face.
- **New exports** (`@objectstack/service-record-context`): `contextPackCandidates`, and the types `ContextPackCandidate`, `ContextPackCandidateName`, `PackageNamespaceOf`. `selectContextPack` now takes the candidates `contextPackCandidates` returns, not the parsed packs. Its `several` outcome carries `packs` (each `{ face, label }`) in place of `names`, and its `duplicate` outcome carries `candidates`. `recordContextReadSet` returns the selected pack's face as `pack`. For an environment pack, and on a door without `packageNamespace`, the face is the pack's name, so these answers are unchanged there.

**BREAKING (narrowing), each counted on `objectstack-ai/objectstack` at `d7f299c0` and `objectstack-ai/hotcrm` at `9b735103`:**

- A second package of one namespace that ships a pack name another package of that namespace already holds is refused at install (`422 NAMESPACE_CONFLICT`, naming every holder) and by `os validate`. First-party packages refused: 0. The one declarer, `examples/app-showcase`, ships two packs with different names in one package. hotcrm declares none.
- `GET /api/v1/meta/ai_context/NAME` with no package, for a name two packages hold, answers `409 RESOURCE_CONFLICT` naming both. Before, it served the first match. Read each pack with `?package=ID`. First-party reads refused: 0.
- A package-less pack row under a name a package ships is that package's customization and is not served. The rule is read by type and name, whatever object the row is rooted on. This was already true and this change does not alter it. What changes is which item such a row is compared against: the one holder's. First-party rows affected: 0.

Fix for an upgrading author: give a pack a name no other package of the same namespace uses, and read a shared name by its package. A model names the pack it means by its face, as the refusals list it.
3 changes: 3 additions & 0 deletions packages/cli/src/utils/namespace-co-owner-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const COLLECTION: Record<NamespaceUniqueType, string> = {
book: 'books',
analytics_cube: 'analyticsCubes',
tool: 'tools',
ai_context: 'aiContexts',
};

/**
Expand Down Expand Up @@ -65,6 +66,8 @@ const item = (type: NamespaceUniqueType, name: string): Record<string, unknown>
return { name, title: name, sql: 'select 1', measures: {}, dimensions: {} };
case 'tool':
return { name, label: name, description: 'A tool', parameters: {} };
case 'ai_context':
return { name, label: name, object: 'crm_account' };
default:
return { name, label: name };
}
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/utils/namespace-co-owner-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

/**
* [ADR-0150 D2, child N] `os validate`'s and `os build`'s half of the package
* door's namespace name refusal: inside one namespace, an item of the twelve
* uncovered bucket 2/3 types (sharing rule, queue, assignment rule, hook, job,
* app, page, dashboard, report, book, analytics cube, tool) has one package
* door's namespace name refusal: inside one namespace, an item of the
* covered bucket 2/3 types (sharing rule, queue, assignment rule, hook, job,
* app, page, dashboard, report, book, analytics cube, tool, and the context
* pack `ai_context` by ADR-0150's 2026-11-25 addendum) has one package
* holder.
*
* ## One judge, not a second rule
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/package-scoped-resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ export const PACKAGE_SCOPED_TYPES = Object.freeze([
'tool',
'skill',
'agent',
// [ADR-0150 addendum 2026-11-25] the context pack joins bucket 3 beside
// `skill`: `get_record_context` resolves a bare pack name by this rule.
'ai_context',
] as const);

/** A type addressed by `(package, name)` ({@link PACKAGE_SCOPED_TYPES}). */
Expand Down
52 changes: 52 additions & 0 deletions packages/mcp/src/mcp-record-context-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,55 @@ describe('[ADR-0160 D4] get_record_context — a package pack the real protocol
}
});
});

describe('[ADR-0150 addendum 2026-11-25] get_record_context — the stdio door places each pack\'s package', () => {
const ALPHA = 'com.acme.sales';
const BETA = 'com.acme.people';
const brief = (packageId: string, label: string) => ({
name: 'brief', label, object: 'policy', fields: ['title'], _packageId: packageId, _provenance: 'package',
});
/** The stdio bridge over two packages' same-name packs, its engine's registry placing `namespaces`. */
function placedBridge(namespaces: Record<string, string> | undefined): McpDataBridge {
const placed = engine() as IDataEngine & { registry?: unknown };
if (namespaces) {
placed.registry = { getPackage: (id: string) => (namespaces[id] ? { manifest: { namespace: namespaces[id] } } : undefined) };
}
const tools = createRecordContextTools();
return createStdioDataBridge({
engine: placed,
metadataService: {
getObject: async (name: string) => OBJECTS[name],
listObjects: async () => Object.values(OBJECTS),
list: async (type: string) => (type === 'ai_context' ? [brief(ALPHA, 'Sales brief'), brief(BETA, 'People brief')] : []),
} as unknown as IMetadataService,
resolvePrincipal: async () => ({ userId: 'u_key', isSystem: false }) as never,
recordContextTools: { recordContextTools: () => tools },
});
}
const call = (context: string) => ({ objectName: 'policy', recordId: 'p1', context });

it('two packages\' packs of one name on one root: each is reached by its face, alike on both transports', async () => {
const bridge = placedBridge({ [ALPHA]: 'sales', [BETA]: 'people' });
const sales = await callBoth(bridge, GET_RECORD_CONTEXT_TOOL_NAME, call('sales-brief'));
const people = await callBoth(bridge, GET_RECORD_CONTEXT_TOOL_NAME, call('people-brief'));
expect(sales.http.isError, JSON.stringify(sales.http.payload)).toBe(false);
expect(sales.stdio).toEqual(sales.http);
expect(sales.http.payload.data.pack).toEqual({ name: 'brief', label: 'Sales brief' });
expect(people.stdio).toEqual(people.http);
expect(people.http.payload.data.pack).toEqual({ name: 'brief', label: 'People brief' });
});

it('the bare name both packages hold is refused 409, naming each face', async () => {
const { http, stdio } = await callBoth(placedBridge({ [ALPHA]: 'sales', [BETA]: 'people' }), GET_RECORD_CONTEXT_TOOL_NAME, call('brief'));
expect(stdio).toEqual(http);
expect(http.payload.error).toMatchObject({ code: 'RESOURCE_CONFLICT', status: 409 });
expect(http.payload.error.message).toContain('sales-brief');
expect(http.payload.error.message).toContain('people-brief');
});

it('control: an engine whose registry cannot place the packages spells each pack by its bare name, so no face reaches one', async () => {
const { http } = await callBoth(placedBridge(undefined), GET_RECORD_CONTEXT_TOOL_NAME, call('sales-brief'));
expect(http.isError).toBe(true);
expect(http.payload.error).toMatchObject({ code: 'RESOURCE_NOT_FOUND', status: 404 });
});
});
21 changes: 21 additions & 0 deletions packages/mcp/src/stdio-data-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,23 @@ function droppedFieldsMember(dropped: DroppedFieldsEvent[]): { droppedFields?: D
* bridge produces — the graceful-degradation contract `McpDataBridge` declares,
* honoured rather than re-decided.
*/
/**
* [ADR-0150 D2/D6, addendum 2026-11-25] The manifest namespace of the package
* `packageId` names, from the engine's registry (`getPackage`), or `undefined`:
* an engine with no registry, or an id with no package record. A pack whose
* package cannot be placed is then spelt by its bare name.
*/
function installedPackageNamespaceOf(engine: unknown, packageId: string): string | undefined {
let manifest: { namespace?: unknown } | undefined;
try {
const registry = (engine as { registry?: { getPackage?(id: string): unknown } } | undefined)?.registry;
manifest = (registry?.getPackage?.(packageId) as { manifest?: { namespace?: unknown } } | undefined)?.manifest;
} catch {
return undefined;
}
return typeof manifest?.namespace === 'string' && manifest.namespace !== '' ? manifest.namespace : undefined;
}

export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge {
const { engine, metadataService, protocol, resolvePrincipal, keyedDigest, security, schemaReadDelegates } = deps;
// [#25138] One definition source for the gate, the relation-target gate and
Expand Down Expand Up @@ -1893,6 +1910,10 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge
}
return ((await metadataService.list('ai_context')) ?? []).map(stripReadDecorations);
},
// [ADR-0150 D6, addendum 2026-11-25] A package's pack is spelt by its
// face `NS-NAME`, as a package-held skill's prompt name is: the engine
// here is the `objectql` service, whose registry places the package.
packageNamespace: (packageId: string) => installedPackageNamespaceOf(engine, packageId),
get: (object: string, id: string) => self.get(object, id),
query: (object: string, o: Parameters<McpDataBridge['query']>[1]) => self.query(object, o),
fieldVisibilityOf: (object: string) => self.fieldVisibilityOf!(object),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,37 @@ describe('§4 [ADR-0131 C7] the anonymous form doors\' legacy organization read
});
}
});

/**
* [ADR-0150 addendum 2026-11-25, "Overlays"] The overlay consequence of a
* context pack, measured. `ai_context` opens no overlay channel (ADR-0160 D1)
* and is not among the sealed types whose declared override is served from
* its row, so a package-less row under a name a package ships is that
* holder's customization, never a second pack — today and with `ai_context`
* package-scoped. The rule is read at `(type, name)`, whatever the row's
* root: an environment pack rooted on one object stops being served when a
* package holding its name installs, though the package's pack roots on
* another object.
*/
describe('§5 [ADR-0150 addendum 2026-11-25] a package-less context pack under a name a package ships is not served, whatever its root', () => {
const shipped: Artifact = {
type: 'ai_context',
name: 'brief',
body: { name: 'brief', label: 'packaged', object: 'policy', fields: ['title'], _packageId: PKG },
};
const envPack = (name: string) => metaRow('ai_context', name, { label: 'environment', object: 'claim', fields: ['number'] });

it('the environment pack on another root is declined: the item and list reads serve the package\'s pack alone', async () => {
const { protocol } = harness({ sys_metadata: [envPack('brief')] }, [shipped]);
expect(protocol.declinesStoredRow('ai_context', 'brief')).toBe(true);
expect((await protocol.getMetaItem({ type: 'ai_context', name: 'brief' })).item?.label).toBe('packaged');
const listed = ((await protocol.getMetaItems({ type: 'ai_context' })).items as Row[]).filter((i) => i.name === 'brief');
expect(listed.map((i) => `${String(i.label)}@${String(i.object)}`)).toEqual(['packaged@policy']);
});

it('control: an environment pack under a name no package ships is served from its row', async () => {
const { protocol } = harness({ sys_metadata: [envPack('our_brief')] }, [shipped]);
expect(protocol.declinesStoredRow('ai_context', 'our_brief')).toBe(false);
expect((await protocol.getMetaItem({ type: 'ai_context', name: 'our_brief' })).item?.label).toBe('environment');
});
});
14 changes: 12 additions & 2 deletions packages/metadata/src/loaders/database-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,16 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => {
const registryKeys = (m: MetadataManager, type: string) => [...((m as any).registry.get(type)?.keys() ?? [])].sort();
const HOST = 'com.host.app';
/** The real pass on a host declaring `hostPackage`, over its own file-system loader under `rootDir` and then a database loader. */
/**
* The host's file of `helper`, spelt as the registry's YAML pattern for `type`
* declares (`helper.tool.yml`; `helper.ai-context.yml` for `ai_context`,
* whose suffix is hyphenated): the pass reads files by those patterns alone.
*/
const hostFile = (rootDir: string, type: string) => {
const pattern = DEFAULT_METADATA_TYPE_REGISTRY.find((entry) => entry.type === type)?.filePatterns.find((p) => p.endsWith('.yml'));
if (!pattern?.startsWith('**/*.')) throw new Error(`no YAML file pattern for ${type}`);
return join(rootDir, type, pattern.replace('**/*', 'helper'));
};
const bootOverFiles = async (rootDir: string, hostPackage: string) => {
const plugin = new MetadataPlugin({ rootDir, packageId: hostPackage, watch: false, config: { bootstrap: 'eager' } });
const m = (plugin as any).manager as MetadataManager;
Expand Down Expand Up @@ -3176,7 +3186,7 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => {
const rootDir = mkdtempSync(join(tmpdir(), 'i32521-d1-'));
try {
mkdirSync(join(rootDir, type));
const file = join(rootDir, type, `helper.${type}.yml`);
const file = hostFile(rootDir, type);
writeFileSync(file, 'name: helper\nlabel: file v1\n');
await bootOverFiles(rootDir, HOST);
expect(await stored(type)).toEqual([[HOST, 'file v1', 1]]);
Expand All @@ -3196,7 +3206,7 @@ describe('[#32521] the boot priming pass primes every holder of a name', () => {
const rootDir = mkdtempSync(join(tmpdir(), 'i32521-d1-'));
try {
mkdirSync(join(rootDir, type));
writeFileSync(join(rootDir, type, `helper.${type}.yml`), 'name: helper\nlabel: file\n');
writeFileSync(hostFile(rootDir, type), 'name: helper\nlabel: file\n');
await seed(type, ALPHA, 1);
await seed(type, BETA, 2);
const m = await bootOverFiles(rootDir, HOST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,9 @@ describe('[#32517] the unscoped plural reads answer every package\'s item of an
const A = 'com.acme.alpha';
const B = 'com.acme.beta';
// [#31699 PR 2] `webhook` joins the slotted set, and so these plural reads;
// [#31985] `tool` joins with its narrowing; [#31699 PR 3] `connector` with its.
const UNBUNDLED = ['api', 'agent', 'skill', 'action', 'flow', 'permission', 'picklist', 'mapping', 'dataset', 'webhook', 'tool', 'connector'];
// [#31985] `tool` joins with its narrowing; [#31699 PR 3] `connector` with its;
// `ai_context` with the ADR-0150 addendum (packs are identified by package + name).
const UNBUNDLED = ['api', 'agent', 'skill', 'action', 'flow', 'permission', 'picklist', 'mapping', 'dataset', 'webhook', 'tool', 'connector', 'ai_context'];
const NAME = 'shared_item';
const item = (packageId: string | undefined, extra: Record<string, unknown> = {}) => ({
name: NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const item = (type: NamespaceUniqueType, name: string, tag: string): Record<stri
return { name, title: label, sql: 'select 1', measures: {}, dimensions: {} };
case 'tool':
return { name, label, description: 'A tool', parameters: {} };
case 'ai_context':
return { name, label, object: 'crm_account' };
default:
return { name, label };
}
Expand Down
15 changes: 11 additions & 4 deletions packages/objectql/src/namespace-co-owner-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
* {@link NAMESPACE_UNIQUE_TYPES}: the twelve bucket 2/3 types phase 1's
* `BARE_NAME_ONE_HOLDER_TYPES` does not list in ADR-0150's execution plan —
* sharing rule, queue, assignment rule, hook, job, app, page, dashboard,
* report, book, analytics cube and tool. ⛔ No other type: a narrowing beyond
* these twelve is the maintainer's to rule. (`tool` is in both lists once
* report, book, analytics cube and tool — and the context pack,
* `ai_context`, which the maintainer admitted by merging ADR-0150's addendum
* of 2026-11-25 (point 3: this predicate carries D2's refusal for a type that
* never had a phase-1 one-holder rule). ⛔ No other type: a narrowing beyond
* these thirteen is the maintainer's to rule. (`tool` is in both lists once
* phase 1 takes it: that rule refuses a second holder anywhere in the
* deployment after the cold boot; this one refuses a second holder inside one
* namespace at every install. The two never disagree about a refusal, only
Expand Down Expand Up @@ -87,11 +90,13 @@ export type NamespaceUniqueType =
| 'sharing_rule' | 'queue' | 'assignment_rule'
| 'hook' | 'job'
| 'app' | 'page' | 'dashboard' | 'report' | 'book' | 'analytics_cube'
| 'tool';
| 'tool'
| 'ai_context';

/**
* The covered types, in the order a refusal lists them — ADR-0150's
* execution-plan order (child N's row).
* execution-plan order (child N's row), then `ai_context` (the 2026-11-25
* addendum).
*/
export const NAMESPACE_UNIQUE_TYPES: readonly NamespaceUniqueType[] = Object.freeze([
'sharing_rule',
Expand All @@ -106,6 +111,8 @@ export const NAMESPACE_UNIQUE_TYPES: readonly NamespaceUniqueType[] = Object.fre
'book',
'analytics_cube',
'tool',
// [ADR-0150 addendum 2026-11-25, point 3] admitted by the maintainer's merge.
'ai_context',
]);

/** Is `type` one of the covered types? */
Expand Down
2 changes: 1 addition & 1 deletion packages/objectql/src/package-scoped-e8-readers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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;
/** The types wired since, each by its own card: `api` (#32069), the email template (#31699), the picklist's bare read (#32070), `mapping` (#32071), `dataset` (#32072), `permission` (#32162), `flow` (#31696) and `webhook` (#31699 PR 2). */
const WIRED_SINCE = ['api', 'email_template', 'picklist', 'mapping', 'dataset', 'permission', 'flow', 'webhook', 'connector'] as const;
const WIRED_SINCE = ['api', 'email_template', 'picklist', 'mapping', 'dataset', 'permission', 'flow', 'webhook', 'connector', 'ai_context'] 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));

Expand Down
Loading
Loading