Skip to content
Draft
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
38 changes: 38 additions & 0 deletions .changeset/37307-knowledge-source-references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@objectstack/lint': minor
'@objectstack/spec': patch
---

fix(lint)!: a knowledge source is checked for its object, its fields and the search gates that need no caller, in `os validate` and at publish

Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up owed — skills/objectstack-ai/SKILL.md

<!-- adr-0087: registered knowledge-source-publish-refuses-missing-references-and-gated-objects -->

ADR-0161 K4, row 4.

**BREAKING** for the publish of a knowledge source that carries one of the four errors below: it was accepted before and is refused now (422, the finding's rule id, path, message and fix), and `os validate` / `lint` / `compile` / `build` refuse the same source. The schema is unchanged, and stored sources are not rewritten or refused at boot.

A new rule, `validateKnowledgeSource`, exported from `@objectstack/lint` with its five rule id constants. It runs on all three CLI commands and on the runtime publish gate for a `knowledge_source` write, with one set of rule ids and messages. Four errors: a source over a missing object has nothing to index, a missing field indexes no text for that member, and a gated object is never searched for a caller the service judges:

- `knowledge-source-object-unknown`: `source.object` names an object that the stack, a package of its artifact, or (at the publish gate) the host does not define. Under the package closure the publish gate states, an object outside it is worded for the closure with the remedy to declare the dependency. On the CLI, while the manifest declares a dependency the artifact does not carry, the build cannot see that package's objects, so the finding is a warning that clears when the dependency defines the object (the publish gate judges it against the closure, which holds them); with no such dependency it is an error. A platform object a known package registers is not judged when the stack does not carry it; a platform-prefixed name no known package registers is a warning.
- `knowledge-source-field-unknown`: a `source.content` or `source.metadataFields` member names no field of the object, declared (the stack's own object extensions included) or addressable without a declaration (`id`, which the driver provisions, and the injected system columns `owner_id`, `created_at`, …).
- `knowledge-source-object-not-searchable`: the object's API exposure does not serve `search` (`canServeApiOperation(enable, 'search')`): `enable.apiEnabled: false`, an `enable.apiMethods` list that does not grant `list` (search derives from it; `search` itself is a retired list value the parse strips), or a list that grants `list` beside `enable.searchable: false`. With no `apiMethods` list, `searchable: false` does not refuse it.
- `knowledge-source-system-object-not-ai-readable`: a `sys_` object that does not declare `enable.aiReadable: true` (`isAiReadExposed`).

One warning, which refuses nothing:

- `knowledge-source-field-never-indexed`: a member names a credential-class field or a field declared `internal: true`; the index never carries either, even when named, so the member is skipped.

The two gates are the knowledge service's own search-time gates that need no caller, asked through the same spec predicates. The disabled-package gate and the field-queryable gate need an environment or a caller and stay at save, judged for the author. `os explain` answers each of the five ids.

## FROM → TO

- `source: { object: 'kb_artcle', … }` → `source: { object: 'kb_article', … }`, an object the stack defines. An object a dependency defines clears at publish once the package's manifest declares that dependency in `dependencies`; on the CLI it stays a warning while the artifact does not carry the dependency.
- `content: ['title', 'bdy']` → `content: ['title', 'body']`.
- a source over an object with `enable: { apiEnabled: false }` → serve the object (`apiEnabled: true` and, where it declares `apiMethods`, a list that includes `list`, with `searchable` not false), or index another object.
- a source over `sys_audit_note` → index a business object, or declare `enable.aiReadable: true` on the system object's own definition.

`@objectstack/spec` adds only the upgrade-guide entry `knowledge-source-publish-refuses-missing-references-and-gated-objects`.
2 changes: 1 addition & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
→ Normalizing stack definition...
→ Lowering inline handlers...
→ Validating protocol compliance...
→ Running author-time rules (86)...
→ Running author-time rules (87)...
→ Checking that every required capability has a provider installable in this edition...
→ Collecting package docs (ADR-0046)... 0 collected
→ Writing artifact...
Expand Down
2 changes: 1 addition & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ A clean run walks the registry and reports timing:
Config: /path/to/support-desk/objectstack.config.ts
Load time: 21ms
→ Validating against ObjectStack Protocol...
→ Running author-time rules (86)...
→ Running author-time rules (87)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
2 changes: 1 addition & 1 deletion content/docs/getting-started/build-with-claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ visible: 'status != "resolved"'
◆ Validate
────────────────────────────────────────
→ Validating against ObjectStack Protocol...
→ Running author-time rules (86)...
→ Running author-time rules (87)...

✗ Author-time rules failed (1 issue)
• stack · action 'resolve_ticket' visible: bare reference `status` — a
Expand Down
2 changes: 1 addition & 1 deletion content/docs/ui/react-pages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ objectstack validate
────────────────────────────────────────
→ Loading configuration...
→ Validating against ObjectStack Protocol...
→ Running author-time rules (86)...
→ Running author-time rules (87)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
41 changes: 41 additions & 0 deletions packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import { validateFormConsumers, validateFormPublicAddresses } from './validate-f
import { validateThankYouRecordFields } from './validate-thank-you-record-fields.js';
import { validateAssignmentRules } from './validate-assignment-rules.js';
import { validateAiContext } from './validate-ai-context.js';
import { validateKnowledgeSource } from './validate-knowledge-source.js';
import { validateSeedStateMachine } from './validate-seed-state-machine.js';
import { validateVisibilityPredicates } from './validate-visibility-predicates.js';
import { validatePredicatePathRefs } from './validate-predicate-path-refs.js';
Expand Down Expand Up @@ -2084,6 +2085,46 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
runtimeTypes: ['ai_context'],
run: (stack, ctx) => validateAiContext(stack, ctx.packageScope ? { packageScope: ctx.packageScope } : {}),
},
// [ADR-0161 K4, row 4] Knowledge sources whose object or a listed field the
// stack does not have, whose object the API does not serve for `search`, or
// that index a system object which does not opt into AI reads (the gates of
// the knowledge service's admission that need no principal), and a listed
// credential-class or `internal` field, which the index never carries.
//
// GATING, and on the runtime publish door for `knowledge_source`: ADR-0161
// K4 says an item "is refused when the object or a named field does not
// exist" and that "a packaged item meets the gates that need no principal in
// `os validate` and at publish". That is the departure from the
// `validateAiContext` row above, which only advises at publish because a
// context pack still reads what resolves; a source that fails one of these
// has nothing to index (a missing object), indexes no text for a member (a
// missing field), or is never searched for a caller the service judges (a
// gated object). The rule reads `knowledgeSources`, `objects` (and the
// stack's own extensions), `manifest.dependencies` and no other collection;
// `objects` is the context every per-write snapshot carries, and the
// written source is the sole member of its own collection. Under a stated
// package scope that `objects` is the write's closure, so the scope is
// passed through and an object outside it is worded for the closure with
// `closureDependencyRemedy`. With no scope `objects` is the whole
// collection the host serves (`wholeCollection`), so an unresolved object
// is an error there too; only the CLI, where a manifest dependency the
// artifact does not carry may define it, hedges it as a warning (the
// `flow-trigger-unknown-object` split). An `error` refuses the publish
// (422), the `warning`s ride the 2xx `advisories`.
{
name: 'validateKnowledgeSource',
tier: 'gating',
input: 'parsed',
commands: ALL,
source: 'packages/lint/src/validate-knowledge-source.ts',
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['knowledge_source'],
run: (stack, ctx) =>
validateKnowledgeSource(stack, {
...(ctx.packageScope ? { packageScope: ctx.packageScope } : {}),
wholeCollection: ctx.runtimeWriteType !== undefined && !ctx.packageScope,
}),
},
// [#34613] `validateSeedReplaySafety` (framework#3434, the `insert`-mode
// replay warning) is retired: `SeedMode` itself refuses `insert` and
// `replace` at parse (ruling 6942780880), so no stack this rule could flag
Expand Down
10 changes: 10 additions & 0 deletions packages/lint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ export {
} from './validate-ai-context.js';
export type { AiContextFinding, AiContextSeverity } from './validate-ai-context.js';

export {
validateKnowledgeSource,
KNOWLEDGE_SOURCE_OBJECT_UNKNOWN,
KNOWLEDGE_SOURCE_FIELD_UNKNOWN,
KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE,
KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE,
KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED,
} from './validate-knowledge-source.js';
export type { KnowledgeSourceFinding, KnowledgeSourceSeverity } from './validate-knowledge-source.js';

export {
validateAssignmentRules,
ASSIGNMENT_RULE_USER_TARGET,
Expand Down
98 changes: 98 additions & 0 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6188,6 +6188,99 @@ const AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION: RuleExplanation = {
],
};

// ── Knowledge sources (`validate-knowledge-source.ts`) ──

const KNOWLEDGE_SOURCE_DOORS =
'Judged by `os validate`, `os build` and `os lint`, and at the runtime publish gate for a ' +
'`knowledge_source` write (Studio, the metadata API, MCP), with the same rule id and message. An error ' +
'refuses the publish (ADR-0161 K4): a source over a missing object has nothing to index, a missing field ' +
'indexes no text for that member, and a gated object is never searched for a caller the service judges.';

const KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION: RuleExplanation = {
rule: 'knowledge-source-object-unknown',
covers: 'why a knowledge source must name an existing object',
paragraphs: [
'A knowledge source (`knowledgeSources`, ADR-0161 K4) indexes the records of one object, `source.object`. ' +
'An object nothing defines has no records, so the source is built empty and every search over it ' +
'answers nothing, with no error anywhere.',
'Defined means an object of this stack, of a package in the same artifact (`packages[]`), or, at the ' +
'publish gate, an object the host serves. A platform object a known package registers (`sys_user`) is ' +
'not judged when the stack does not carry its definition. A name with a platform prefix that no known ' +
'package registers is a warning, because a third-party package may still provide it. When the publish ' +
'gate states the package\'s closure (the package, the packages its manifest declares in ' +
'`dependencies`, and platform objects), an object outside it is reported with the remedy to declare the ' +
'dependency.',
'On the command line a package the manifest declares in `dependencies` but the artifact does not carry ' +
'is out of sight: its objects cannot be read there. So while the manifest declares such a dependency, ' +
'an object the stack does not define is a warning, which clears when that dependency defines it (the ' +
'publish gate judges the source against the package\'s closure, which holds the dependency\'s objects). ' +
'With no such dependency it is an error, which clears only by naming an object that exists.',
KNOWLEDGE_SOURCE_DOORS,
],
};

const KNOWLEDGE_SOURCE_FIELD_UNKNOWN_EXPLANATION: RuleExplanation = {
rule: 'knowledge-source-field-unknown',
covers: 'why each listed field must exist on the object',
paragraphs: [
'A source lists the fields whose text becomes each document (`source.content`) and the fields projected ' +
'into a hit\'s metadata (`source.metadataFields`). A name the object does not define reads nothing on ' +
'every record: the document is built without that text, or the metadata without that value.',
'Defined means declared in the object\'s `fields` (an object extension of the same stack included) or ' +
'addressable without a declaration: `id`, which the driver provisions, and the system columns the ' +
'platform injects (`owner_id`, `created_at` and the rest) are read like any field. An object whose ' +
'definition carries no readable field map is not judged.',
KNOWLEDGE_SOURCE_DOORS,
],
};

const KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE_EXPLANATION: RuleExplanation = {
rule: 'knowledge-source-object-not-searchable',
covers: 'why the API must serve the object for search',
paragraphs: [
'A knowledge search is a search over the object\'s records, so the knowledge service searches a source ' +
'only when the API exposure serves its object for `search`: the decision `canServeApiOperation` in ' +
'`@objectstack/spec/data` answers, the one every door serving object rows asks. `enable.apiEnabled: ' +
'false` refuses it. So does an `enable.apiMethods` list that does not grant `list`, from which search ' +
'derives (`search` itself is a retired list value the parse strips), or one that grants `list` beside ' +
'`enable.searchable: false`. With no `apiMethods` list, `searchable: false` does not refuse it.',
'To clear it, keep `enable.apiEnabled` true and, where the object declares `enable.apiMethods`, include ' +
'`list` with `enable.searchable` not false; or index another object.',
'This gate needs no caller, so it is judged here. The gates that need one (the object\'s package is not ' +
'disabled, and the author may query every field the source serves) are asked when the source is saved, ' +
'as its author.',
KNOWLEDGE_SOURCE_DOORS,
],
};

const KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE_EXPLANATION: RuleExplanation = {
rule: 'knowledge-source-system-object-not-ai-readable',
covers: 'why a system object source must opt into AI reads',
paragraphs: [
'A system object (a `sys_` name) is indexed and searched only when its own definition opts into AI reads ' +
'with `enable.aiReadable: true`, the posture the MCP record tools take (`isAiReadExposed` in ' +
'`@objectstack/spec/data`). The objects that store serialized metadata bodies are never opened, ' +
'whatever they declare.',
'The declaration belongs to the system object\'s author, not to the source: index a business object, or a ' +
'system object that declares it.',
KNOWLEDGE_SOURCE_DOORS,
],
};

const KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED_EXPLANATION: RuleExplanation = {
rule: 'knowledge-source-field-never-indexed',
covers: 'why a credential-class or internal field is skipped',
paragraphs: [
'Embedding is egress: the text of every listed field is sent to the embedding provider and kept in an ' +
'index outside the row store. So the index never carries a credential-class field (a `secret`, or a ' +
'`password` the platform masks on read) or a field declared `internal: true`, even when the source ' +
'names it (ADR-0161 K5). The member is skipped, and the documents read less than the list says.',
'A warning, not a refusal: the rest of the source is indexed. Remove the member from `content` or ' +
'`metadataFields`. Judged by `os validate`, `os build` and `os lint`, and at the runtime publish gate ' +
'for a `knowledge_source` write, where it rides the advisories.',
],
};

// ── Assignment rules (`validate-assignment-rules.ts`) ──

const ASSIGNMENT_RULE_USER_TARGET_EXPLANATION: RuleExplanation = {
Expand Down Expand Up @@ -7271,6 +7364,11 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
[AI_CONTEXT_RELATED_LINK_UNKNOWN_EXPLANATION.rule]: AI_CONTEXT_RELATED_LINK_UNKNOWN_EXPLANATION,
[AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION.rule]: AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION,
[AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION.rule]: AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION,
[KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION.rule]: KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION,
[KNOWLEDGE_SOURCE_FIELD_UNKNOWN_EXPLANATION.rule]: KNOWLEDGE_SOURCE_FIELD_UNKNOWN_EXPLANATION,
[KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE_EXPLANATION.rule]: KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE_EXPLANATION,
[KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE_EXPLANATION.rule]: KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE_EXPLANATION,
[KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED_EXPLANATION.rule]: KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED_EXPLANATION,
[ASSIGNMENT_RULE_USER_TARGET_EXPLANATION.rule]: ASSIGNMENT_RULE_USER_TARGET_EXPLANATION,
[ASSIGNMENT_RULE_QUEUE_UNSTAFFED_EXPLANATION.rule]: ASSIGNMENT_RULE_QUEUE_UNSTAFFED_EXPLANATION,
[SEED_VALUE_OUTSIDE_STATE_MACHINE_EXPLANATION.rule]: SEED_VALUE_OUTSIDE_STATE_MACHINE_EXPLANATION,
Expand Down
11 changes: 11 additions & 0 deletions packages/lint/src/runtime-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ const TYPE_TO_STACK_KEY: Readonly<Record<string, string>> = {
// pack's names into `objects`, which every snapshot carries, and nothing
// into a sibling pack.
ai_context: 'aiContexts',
// [ADR-0161 K4, row 4] `knowledge_source` — `allowRuntimeCreate: true`, so
// Studio, REST `/meta` and an MCP/AI author mint sources at runtime, and the
// ADR says a packaged item meets the gates that need no principal at
// publish as in `os validate`. ⛔ NOT a mapping ahead of its rule:
// `validateKnowledgeSource` crosses with this row and opens on
// `stack.knowledgeSources`, the key `ObjectStackDefinitionSchema` gives the
// collection. Not a context row either, for the `position` / `app` reason
// above: the rule resolves a source's names into `objects`, which every
// snapshot carries, and nothing into a sibling source. Unlike the
// `ai_context` row, its errors refuse the publish (the rule is gating).
knowledge_source: 'knowledgeSources',
};

/**
Expand Down
Loading
Loading