Skip to content
Merged
11 changes: 11 additions & 0 deletions .changeset/37310-skill-knowledge-source-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@objectstack/skills': patch
---

docs(skills): `objectstack-ai` teaches `knowledge_source` as a metadata item

Clause-②: no
Metadata-protocol: none

`skills/objectstack-ai` § Knowledge Sources (RAG) now teaches the shape the 19 spec accepts. A source is a `knowledge_source` item shipped in a package (`knowledgeSources`, `*.knowledge-source.ts` / `.yml`) or authored in Studio or over MCP, with registration in code as a second door for the same schema. The key table lists `name`, `label`, `description`, the optional `adapter` (omitted, the source binds to the deployment's store), `source.object`, `source.content` (an explicit, non-empty list: `'*'` is refused because embedding is egress), `source.metadataFields`, `source.where`, `source.split`, `refresh.onRecordChange` and `aiExposed`. A source the app ships in `knowledgeSources` mounts the knowledge service and its store; an app that ships none and authors its sources at run time needs `requires: ['knowledge']`, or its items are never indexed. A source is identified by its package and `name`: `search_knowledge` lists a package's source as `NAMESPACE-NAME`, and a code registration and an environment item of one name are one slot. The closing note says that `topK` is a `search_knowledge` argument and that no shipped store has a rerank or hybrid-weight setting. The section says that a source's first build sends every listed field of every matching record to the embedding provider, and that a run-time save needs `manage_knowledge_sources` and passes save-time admission. It names each key retired in 19 with its fix: `id` → `name`, `contentFields` → `content`, `embedding`, `vectorStore`, `adapterConfig`, `refresh.cron`, and the `file` and `http` arms. `split.strategy` is required once `split` is written. The eval cases for knowledge sources move to the same shape, a new case asks for a wildcard source, and another for a source an app authors at run time.

52 changes: 52 additions & 0 deletions packages/runtime/src/domains/mcp-authoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,58 @@ describe('done when: an OAuth author saves an app-crm flow draft with no routabl
expect(missing.body.contract).toBeUndefined();
});

it('[ADR-0161 K4, K5] the knowledge_source contract serves the content rule and no create seed; a source with one object and one content field saves, a wildcard or a retired key is refused', async () => {
const metadata = new MetadataManager({} as never);
metadata.setTypeRegistry(DEFAULT_METADATA_TYPE_REGISTRY);
const protocol = await realProtocol(new Map([['metadata', metadata]]));
const { authoring } = await authorThroughDomain({ protocol, systemPermissions: ['manage_metadata', 'manage_knowledge_sources'] });
const entry = (await protocol.getMetaTypes!()).entries!.find((e) => e.type === 'knowledge_source') as any;

const { contract } = (await call(authoring, 'list_metadata_items', { type: 'knowledge_source', contract: true })).body;
expect(contract.form).toBe('lean');
// No seed is served: the type stays unseeded until the Studio form builds `source` (metadata-create-seeds.test.ts).
expect(getMetadataCreateSeed('knowledge_source')).toBeUndefined();
expect(contract).not.toHaveProperty('createSeed');
expect(Object.keys(contract.schema.properties)).toEqual(Object.keys(entry.schema.properties));

// The content rule, as the served schema states it: a non-empty list, no empty name, no `'*'` member.
const contentPath = '/properties/source/properties/content';
const content = (await call(authoring, 'list_metadata_items', { type: 'knowledge_source', contract: true, contractPath: contentPath })).body.contract;
expect(content).toMatchObject({ form: 'full', path: contentPath });
expect(content.schema).toEqual(entry.schema.properties.source.properties.content);
expect(content.schema.minItems).toBe(1);
expect(content.schema.items).toMatchObject({ minLength: 1 });
expect(new RegExp(content.schema.items.pattern).test('*')).toBe(false);
expect(new RegExp(content.schema.items.pattern).test('body')).toBe(true);

// A tombstone is not served: the served schema publishes what an author MAY write (`{ not: {} }` is
// dropped). Its prescription reaches the author through the save, below.
expect(entry.schema.properties.id).toBeUndefined();
expect(entry.schema.properties.source.properties.contentFields).toBeUndefined();

// A source with one object and one content field saves as a draft; with a wildcard it is refused and nothing is written.
const item = { name: 'crm_opportunity_notes', label: 'Opportunity notes', source: { kind: 'object', object: 'crm_opportunity', content: ['name'] } };
const saved = await call(authoring, 'save_metadata_draft', { type: 'knowledge_source', name: item.name, item, package: STUDIO_BASE });
expect(saved.isError, JSON.stringify(saved.body)).toBe(false);
expect(saved.body.saved).toMatchObject({ type: 'knowledge_source', name: 'crm_opportunity_notes', package: STUDIO_BASE, state: 'draft' });

const wildcard = { ...item, name: 'crm_opportunity_all', source: { ...item.source, content: ['*'] } };
const refused = await call(authoring, 'save_metadata_draft', { type: 'knowledge_source', name: wildcard.name, item: wildcard, package: STUDIO_BASE });
expect(refused.body.error).toMatchObject({ code: 'INVALID_METADATA', status: 422 });
expect(JSON.stringify(refused.body.error.issues)).toContain('content');

// A retired key is refused with its tombstone's prescription, as the describe reads.
for (const [retired, replacement] of [
[{ ...item, name: 'crm_opportunity_id', id: 'crm_opportunity_id' }, '`name`'],
[{ ...item, name: 'crm_opportunity_cf', source: { ...item.source, contentFields: ['name'] } }, '`content`'],
] as const) {
const tomb = await call(authoring, 'save_metadata_draft', { type: 'knowledge_source', name: retired.name, item: retired, package: STUDIO_BASE });
expect(tomb.body.error, replacement).toMatchObject({ code: 'INVALID_METADATA', status: 422 });
expect(JSON.stringify(tomb.body.error.issues), replacement).toContain(`use ${replacement}`);
}
expect((await call(authoring, 'list_drafts', { package: STUDIO_BASE })).body.drafts.map((d: any) => d.name)).toEqual(['crm_opportunity_notes']);
});

it('an inherited member\'s name as `type`, which the fold keeps as sent, is refused and writes nothing', async () => {
const protocol = await realProtocol();
const { authoring } = await authorThroughDomain({ protocol });
Expand Down
8 changes: 7 additions & 1 deletion packages/spec/scripts/lib/platform-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,13 @@ export function renderPlatformCatalog(): string {
);
for (const token of PLATFORM_CAPABILITY_TOKENS) {
const provider = PLATFORM_CAPABILITY_PROVIDERS[token];
const boot = PLATFORM_ALWAYS_ON_CAPABILITIES.includes(token) ? 'every boot' : 'on `requires`';
// A provider an item also mounts (`mountedBy`, read by `stackItemCapabilities`)
// says so: only a SHIPPED item of that collection does, never one saved at run time.
const boot = PLATFORM_ALWAYS_ON_CAPABILITIES.includes(token)
? 'every boot'
: provider?.mountedBy
? `on \`requires\`, or a shipped \`${provider.mountedBy.collection}\` item`
: 'on `requires`';
lines.push(`| \`${token}\` | ${CAPABILITY_ROWS[token]} | ${provider?.edition ?? 'unknown'} | ${boot} |`);
}
lines.push('');
Expand Down
6 changes: 6 additions & 0 deletions packages/spec/scripts/platform-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ describe('the live catalog — every name is one the contract package declares',
}
});

it('a token a shipped item also mounts says so in its Boot cell; the others read on `requires`', () => {
const page = renderPlatformCatalog();
expect(page).toMatch(/^\| `knowledge` \|.*\| on `requires`, or a shipped `knowledgeSources` item \|$/m);
expect(page).toMatch(/^\| `record-context` \|.*\| on `requires` \|$/m);
});

it('covers every value domain exactly', () => {
expect(Object.keys(VALUE_DOMAIN_ROWS).sort()).toEqual([...ValueDomainSchema.options].sort());
});
Expand Down
14 changes: 9 additions & 5 deletions packages/spec/src/kernel/metadata-create-seeds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ describe('metadata create seeds validate against their spec schemas', () => {
// from `view` until card ③ (#37087), which brings the designer and its
// seed. Deferred work, named here so it is not a silent gap.
'form',
// [ADR-0161 K4] `knowledge_source` is runtime-creatable, and its create
// seed is deferred work with a name: it lands with the Studio form and
// the MCP create seed (rows 5 and 5b of #37000), which are what would
// serve one. Until then a source is created by a `/meta` save or shipped
// in a package, never from a blank form.
// [ADR-0161 K4, K5] `knowledge_source` is runtime-creatable, and its
// create seed is deferred work with a name: it lands with the Studio
// form (row 5 of #37000). The type's object binding and its content list
// sit inside `source`, and K5 makes `content` non-empty, so a seed that
// passes the schema carries a placeholder object AND a placeholder field
// there. The Studio create flow takes placeholder identity out only at
// the top level (objectui#12810), so it would save both into a new
// source. Until the form builds `source` from the author's input, a
// source is created by a `/meta` or MCP save, or shipped in a package.
'knowledge_source',
]);
const seeded = new Set(listMetadataCreateSeedTypes());
Expand Down
35 changes: 34 additions & 1 deletion scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,40 @@ export const CEILINGS = new Map([
// 6791 -> 6609: the section that taught an authored AI button on a record
// page is replaced by one sentence (ADR-0160 D6, "Entry point": the shell's
// entry is the only one); the row follows the measurement down.
['skills/objectstack-ai/SKILL.md', 6609], // -18 (was 6824), then -5 A2′ (was 6806)
// 6609 -> 6639 (2026-11-27, the ADR-0161 K6 item 6 skills follow-up): § Knowledge
// Sources teaches the `knowledge_source` item (`name`, an explicit `content`
// list with `'*'` refused, the optional `adapter`), egress and cost with the
// save-time permission and admission, the retired keys with their fixes, and
// `split.strategy` as required. Raise path the standing ruling
// 「A:先削重复,余额按实测提高」 (ruling record 6513306068,
// letter B). PAID DOWN FIRST: the wiring paragraph's package list, the old key
// table's `source.kind` Hygiene column (folded into the `content` and `where`
// rows), the example's four comments restating those rows and its
// `refresh: { onRecordChange: true }` line restating the default, and the
// split passage's adapter-list aside. Arithmetic in priced bytes (stamp line
// excluded), against `main`'s 26435 (headroom 0): the file is 26462 -> 26581
// bytes, so the LANDED priced text is 26554 -> ceil(26554 / 4) = 6639; the row
// moves +30, the measured remainder only. Pinned AT the measurement.
// ceil(($(wc -c < skills/objectstack-ai/SKILL.md) - 27) / 4) == ceil(26554 / 4)
// 6639 -> 6695 (2026-11-27, the same follow-up's review round): the section
// says which items mount the service (a SHIPPED `knowledgeSources` item does;
// an app that ships none and authors sources at run time needs
// `requires: ['knowledge']`), that a source is identified by its package and
// `name` (`search_knowledge` lists a package's source as `NAMESPACE-NAME`; a
// code registration and an environment item of one name are one slot), that
// the display field is kept as each title, and that no shipped store has a
// rerank or hybrid-weight setting. Raise path the standing ruling
// 「A:先削重复,余额按实测提高」 (ruling record 6513306068, letter B). PAID DOWN
// FIRST: the intro's "which records of one object are indexed, and which of
// their fields" (the `source.object` and `source.content` rows say it), its
// separate `search_knowledge` sentence (folded into the identity sentence),
// the "one name is one source" clause it replaces, and a shorter closing
// note. Arithmetic in priced bytes (stamp line excluded), against the row's
// 26554: the file is 26581 -> 26806 bytes, so the LANDED priced text is
// 26779 -> ceil(26779 / 4) = 6695; the row moves +56, the measured remainder
// only. Pinned AT the measurement.
// ceil(($(wc -c < skills/objectstack-ai/SKILL.md) - 27) / 4) == ceil(26779 / 4)
['skills/objectstack-ai/SKILL.md', 6695], // -18 (was 6824), then -5 A2′ (was 6806)
// -12 (was 6331): the `http.server` decision-table row dropped a trailing
// clause that taught `contributes.routes` as a key that "parses but serves
// nothing". The key is retired — an authored entry is now REFUSED, carrying
Expand Down
Loading
Loading