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`.
21 changes: 21 additions & 0 deletions .changeset/38019-knowledge-source-review-follow-ups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/lint': minor
'@objectstack/service-knowledge': patch
'@objectstack/spec': patch
---

fix(lint)!: a knowledge source naming an absent platform object is refused at publish; `ai_context` accepts `id`; the save door's search refusal names `list`

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37310

<!-- 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 whose `source.object` is a platform name the host does not serve: when the publish gate judges the source against the whole collection the host serves (a write that names no package), a platform-prefixed name no package registers there, and a known platform object (`sys_user`) the host does not serve, are now `knowledge-source-object-unknown` errors (422), as an unprefixed name already was. Before, the first was a warning and the second was not judged. FROM a source over such an object TO a source over an object the host serves: name the object by its full name, or install the package that registers it. On the command line nothing changes: a platform-prefixed name no known package registers stays a warning, and a known platform object the stack does not carry is not judged.

- `ai_context`: a field named `id` (in `fields`, a related list's `fields`, `where` or `orderBy`) is no longer reported as `ai-context-field-unknown`. The driver provisions it, so it exists on every object; existence is now asked through the same column set the other existence rules use. A `body.field` of `id` is reported as not long text, never as unknown.
- `@objectstack/service-knowledge`: the save refusal for an object the API does not serve for search names the cause and fix in the words of `knowledge-source-object-not-searchable`: `enable.apiEnabled` false, an `enable.apiMethods` list that does not grant `list` (from which search derives), or `list` beside `enable.searchable: false`; the fix is to include `list` with `enable.searchable` not false. It no longer tells the author to grant `search`, a retired list value the parse strips.
- `@objectstack/spec`: the upgrade entry `knowledge-source-publish-refuses-missing-references-and-gated-objects` is listed by `os migrate meta` only for a stack that declares `knowledgeSources` (`--all` still lists it), and its surface states that the platform-name warning is the CLI's.
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
Loading
Loading