Skip to content

Commit 3550665

Browse files
fix(lint)!: a knowledge source is checked for its object, its fields and the search gates that need no caller, also at publish (#37971)
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes #37307 Clause-②: yes (narrowing) Metadata-protocol: narrowed Skills-docs: #37310 (amendment 7221575164: the five rule ids and their fixes) Premise corrected: card #37307 item 3 ("follow the refuse-or-warn verdict the `ai_context` row took") conflicts with ADR-0161 K4; K4 wins, so this rule is `gating` at publish (refuses), not advisory. Seat 1 ruling on this PR: keep gating (seat record: #37307 comment 7221816104). Ruling-ref: `docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md` K4 — "It defines no object, extends none, and is refused when the object or a named field does not exist (the lint and `os validate` checks are row 4)." and "An object whose package is disabled, that the API exposure refuses for search, or that is a system object without `enable.aiReadable`, and a field the author may not query, each refuse the save with a coded refusal that names the object or the field. A packaged item meets the gates that need no principal in `os validate` and at publish (row 4)." ## 维护者速读 - 用户能看到什么变化:写应用包的作者和用 AI 搭建的作者,在 `os validate` 和发布知识源时,就能看到知识源写错的对象名、字段名,或指向不允许检索的对象(API 不开放检索、系统对象未开放 AI 读取),报错写明是哪个对象、哪个字段。 - 为什么做:属于「知识平台」专题第三阶段第 4 行,让知识源的错误在发布前暴露,而不是等到检索时才发现「怎么搜不到」。 - 出错会怎样:带这几类错误的知识源,发布会被拒(以前能发布,但对象不存在时无内容可索引、字段写错时该字段读不到、对象不开放检索时永远搜不到);已存储的知识源不受影响,可以直接撤回本改动。 - 要你做什么:无。 ## What changes ADR-0161 K4, row 4: a knowledge source is checked against the objects it names, by `os validate` / `build` / `lint` and by the runtime publish gate, with one set of rule ids and messages. - **`packages/lint/src/validate-knowledge-source.ts`** (new): `validateKnowledgeSource`, five rule ids, exported from `packages/lint/src/index.ts`. - `knowledge-source-object-unknown` — **error**. `source.object` names no object of the stack, of a package of its artifact (`packages[]`), or at the door of the objects the host serves. Under a stated package closure it is worded for the closure with `closureDependencyRemedy`; at the door with no closure (the whole collection the host serves) it is an error too, and an empty served collection is no universe. On the CLI, while the manifest declares a dependency the artifact does not carry, it is a **warning** with the hedge (the build cannot see that package's objects; the publish judges the source against the closure, which holds them), the `flow-trigger-unknown-object` split. The ladder `validateObjectReferences` uses: a known platform object (`isPlatformProvidedObjectName`) is not judged when the stack does not carry its definition; a platform-prefixed name no known package registers is a **warning**. - `knowledge-source-field-unknown` — **error**. A `source.content` / `source.metadataFields` member names no field of the object: declared (the stack's own extensions folded in, `objectsAsServed`) or addressable without a declaration (`injectedColumnsFor`: `id`, which the driver provisions, and the injected system columns). - `knowledge-source-object-not-searchable` — **error**. `canServeApiOperation(enable, 'search')` is false (the admission module's gate 2): `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 one that grants `list` beside `enable.searchable: false`. With no `apiMethods` list, `searchable: false` does not refuse it. The fix prescribed: keep `apiEnabled` true and, where the object declares `apiMethods`, include `list` with `searchable` not false; or index another object. - `knowledge-source-system-object-not-ai-readable` — **error**. A `sys_` object for which `isAiReadExposed` is false (the admission module's gate 3). - `knowledge-source-field-never-indexed` — **warning**. A member names a credential-class field (`isMaskedOnReadFieldType`, the spec declaration the service's withheld set asks) or an `internal: true` field. The index never carries either (K5). This addition goes past the Execution row, under ADR-0078. - **`authoring-rules.ts`**: one entry, `tier: 'gating'`, all three commands, `surfaces: CLI_AND_RUNTIME`, `runtimeTypes: ['knowledge_source']`, with the package scope passed through, and `wholeCollection` set at the door when no scope is stated. - **`runtime-gate.ts`**: `knowledge_source: 'knowledgeSources'`. - **`rule-explanations.ts`**: one `os explain` entry for each of the five ids. - **`packages/spec/src/migrations/entries/semantic/19.knowledge-source-publish-refuses-missing-references-and-gated-objects.ts`**: the upgrade-guide entry. `check:adr-0087-registration` requires it: `Metadata-protocol: narrowed` refuses `no-migration-prescription` outright. This file is outside the claim's declared file surface. - **Changeset** `.changeset/37307-knowledge-source-references.md`: `@objectstack/lint` minor, `@objectstack/spec` patch, BREAKING, registered disposition. ### The at-publish verdict: refuse, not advise, against the `ai_context` precedent The `ai_context` row (`validateAiContext`) is advisory at publish. Its reason is that a pack still reads what resolves (ADR-0160 D1). This row departs from it, for three reasons. ADR-0161 K4 says an item "is refused when the object or a named field does not exist (the lint and `os validate` checks are row 4)". It also says that "a packaged item meets the gates that need no principal in `os validate` and at publish". And each of the four errors defeats retrieval (a missing object leaves nothing to index, a missing field indexes no text for that member, a gated object is never searched for a caller the service judges), so the card's severity section (all four are errors) has the same reading. The rule is therefore `gating`: its errors refuse the publish (422 with the rule id, path, message and hint), and its warnings ride the 2xx `advisories`. The card's sentence "follow the refuse-or-warn verdict the `ai_context` row took" and its severity section cannot both hold. The ADR text decides between them, and the departure is stated in the rule header, the registry entry and the runtime-gate row. What this narrows at publish, measured on the code paths: - For a non-system author with the knowledge service mounted, the save door already refuses the two gates `403` (`authoredKnowledgeSourceRefusal`), before this gate runs. Where no author judgement is reached, the publish is now refused `422`: a host with no knowledge service, or a system-context write. - A missing object or a missing field is now refused at publish. The save admission accepted a missing object (`canServeApiOperation(undefined)` is true, and with no security service the field gate is masked-only). - `os validate` / `build` / `lint` exit 1 on the same source. Declarations: the claim expected `Clause-②: no` / `Metadata-protocol: none`. The measured reading is `Clause-②: yes (narrowing)`, because five new exports widen `@objectstack/lint`'s public surface and a new refusal narrows the accept set, and `Metadata-protocol: narrowed`, because a requirement is tightened. So the lint bump is `minor` and the title carries `!`. ## Tests `packages/lint/src/validate-knowledge-source.test.ts` (44 cases): - every Acceptance family through `runAuthoringRules('validate')`: a missing object, content field or metadata field; `apiEnabled: false`; an `apiMethods` list that does not grant search; `searchable: false`; a `sys_` object without `aiReadable`. Each prints exactly one finding, with its rule id, severity, path, and the object or field named. A clean source prints none. - the credential-class and `internal` warnings. - the same families at the door (`runRuntimeAuthoringRules` with `type: 'knowledge_source'`). Errors land in `errors` (refused) and warnings in `advisories`, and the face (rule, severity, where, message, hint) equals the `os validate` face. - closure wording and remedy under `packageScope`, with a non-vacuous control: declaring the dependency clears it. - injected columns, stack extensions, artifact `packages[]`, a known platform object skipped, an unknown platform-prefixed name as a warning, `list` granting `search`. - `metadataFields: ['id']` and `content: ['id']` resolve (CLI and door); `enable.searchable: false` with no `apiMethods` list is clean. - the object-unknown split: on the CLI a warning while the manifest declares a dependency `packages[]` does not carry, an error when every declared dependency is carried or none is declared; against the whole collection an error beside the same unseen dependency; an empty served collection at the door judges no object. - `explainRule` answers all five ids. <details><summary>Readings (lint suite at 73441db; the head 3ea6b3c adds only the four docs transcript counts)</summary> - `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2` (with spec and lint rebuilt, then lint `typecheck`): lock VERDICT command-exit 0, **Test Files 243 passed (243), Tests 9836 passed (9836)**; typecheck exit 0 (`check:test-typecheck` included; `tsc -p tsconfig.test.json --listFiles` lists the new test file, 1 hit). - `pnpm --filter @objectstack/spec exec vitest run src/migrations` after the spec build: 5 files, 206 tests passed. - Ablation, one per new pin, each with the anchor proven on disk by `scripts/ablation-replace.mjs`, a trap restore, and `git diff HEAD` empty after restore. Every leg went red: the runtime-gate row removed (12 red); the object-unknown error made a warning (3); the API gate off (6); the system-object gate off (2); the withheld warning off (4); the injected-column merge off (1); the artifact `packages[]` resolution off (1); the closure branch off (1); the platform-object skip off (1); the stack extensions not folded (1). - Public door: `objectstack validate` in `examples/app-showcase` exits 0 with zero `knowledge-source-*` findings, so the shipped corpus is clean. The same command with `content` mutated to `['title', 'notez', 'secret_note']` exits 1 with two `knowledge-source-field-unknown` findings at `knowledgeSources[0].source.content[1]` and `[2]`, and the file is restored. `objectstack explain knowledge-source-object-unknown` and `objectstack explain knowledge-source-system-object-not-ai-readable` both answer. - Full dogfood battery (`pnpm --filter @objectstack/dogfood test`, lock VERDICT command-exit 1, head 73441db): Test Files 14 failed / 476 passed / 3 skipped (493); Tests 20 failed / 4113 passed / 79 skipped (4212). The failures were 17 `Test timed out in 5000ms`, 2 hook timeouts, the cascading `already has a live bootStack kernel` errors, and 1 assertion inside a timed-out file. None names a `knowledge-source-*` rule. The 14 failed files re-run alone on the same head: **14 passed (14), 164 passed (164)**, VERDICT command-exit 0. Read as shared-box contention, not this diff. </details> <details><summary>Rework readings (review 7221784031: M1, S1, S2, N1, N2; head 8301509)</summary> - At 15b32e6, under the lock (VERDICT command-exit 0): `turbo run build --filter='@objectstack/lint...'` 5/5 tasks; the lint suite **Test Files 244 passed (244), Tests 9856 passed (9856)**; spec `src/migrations` 5 files, 206 tests passed; `check:docs-transcript-drift` exit 0 against the built registry (4 declared values, 87). - At 2677e83 (only the test file changed after 15b32e6), a declared narrowing run outside the lock after three lock queue-timeouts behind another seat's dogfood battery: the knowledge-source file 44 passed (44); `pnpm --filter @objectstack/lint typecheck` exit 0 (`check:test-typecheck` included). - Ablations, each anchor proven by `scripts/ablation-replace.mjs` with a trap restore and `git diff HEAD` empty after: the `injectedColumnsFor` existence check off (2 red, `id` among them); the CLI dependency hedge off (2 red); the whole-collection reading off in the rule (1 red); the registry's `wholeCollection` pass set false (1 red); the empty-universe skip off (2 red). - After merging origin/main (bfc0dd0, no lint or transcript file touched): `check:docs-transcript-drift` exit 0 (87; #37986 still open), `check-adr-0087-registration` exit 0, `check:nul-bytes` exit 0, `overlap-check` VERDICT clean. </details> <details><summary>Derived gates (dispatch-gates --commands, then --ran)</summary> - 94 families derived at 73441db, all run locally. 90 exited 0. Of the rest: `check:docs-transcript-drift` was red (four CLI transcripts printed 85 author-time rules, and this rule makes 86); the four counts were fixed in 3ea6b3c, and the gate now exits 0 (4 declared values equal the derived count). `check:exported-any` returned exit 3 while the dogfood build was rebuilding `packages/spec/dist`; re-run after that build, it exits 0. `check:dual-build-cjs-loads` returned exit 3 because the `studio`, `client-react` and `scenarios` dist are not built here: NOT MEASURED, CI. `check:type-check-debt` returned exit 3 on a lock queue-timeout (another seat's hold): NOT MEASURED, CI. - The docs commit derived 23 more families. 22 exit 0. `check:skill-examples` returned exit 3 because the `client-react` dist is not built: NOT MEASURED, CI. - `check:api-surface` and `check:docs` exit 0 after the spec rebuild. `overlap-check` VERDICT clean before every push; #37910 and #37870 merge cleanly. #37870 bumps the same four transcript counts, so whichever lands second needs 87. </details> ## Acceptance notes - The search gate follows the exposure derivation: `apiMethods: ['get', 'list']` **grants** `search` (`list` grants it unless `enable.searchable` is false). The save-door refusal text in `service-knowledge` (`admitAuthoredSource`, `object-api-not-served`) reads "its `enable.apiMethods` list does not include `search`". For `searchable: false` with `list` granted, that wording names the wrong cause. Wording only; the PM files it as a card with the S2 wording. - On the CLI, a platform object the stack does not carry (for example `sys_user`) is not judged, because its declaration is not in hand. The publish door judges it against the live definition. - Fences held: the spec predicates and the admission module are unchanged, there is no adapter work for #37306, and there is no unknown-adapter refusal for #37479. ## Verification Read first, by risk: 1. `packages/lint/src/authoring-rules.ts`, the `validateKnowledgeSource` entry (`tier: 'gating'` on the publish door is the narrowing). 2. `packages/lint/src/validate-knowledge-source.ts`, the object ladder and the two gates. 3. `.changeset/37307-knowledge-source-references.md`. Two-minute check: in `examples/app-showcase/src/ai/task-notes.knowledge-source.ts`, change `content: ['title', 'notes']` to `['title', 'notez']` and run `pnpm exec objectstack validate` in `examples/app-showcase`. Expected: exit 1 and `rule: knowledge-source-field-unknown at knowledgeSources[0].source.content[1]`. Unchanged, the showcase validates with zero `knowledge-source-*` findings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 815e882 commit 3550665

12 files changed

Lines changed: 866 additions & 4 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/spec': patch
4+
---
5+
6+
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
7+
8+
Clause-②: yes (narrowing)
9+
Metadata-protocol: narrowed
10+
Skills-docs: follow-up owed — skills/objectstack-ai/SKILL.md
11+
12+
<!-- adr-0087: registered knowledge-source-publish-refuses-missing-references-and-gated-objects -->
13+
14+
ADR-0161 K4, row 4.
15+
16+
**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.
17+
18+
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:
19+
20+
- `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.
21+
- `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`, …).
22+
- `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.
23+
- `knowledge-source-system-object-not-ai-readable`: a `sys_` object that does not declare `enable.aiReadable: true` (`isAiReadExposed`).
24+
25+
One warning, which refuses nothing:
26+
27+
- `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.
28+
29+
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.
30+
31+
## FROM → TO
32+
33+
- `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.
34+
- `content: ['title', 'bdy']` → `content: ['title', 'body']`.
35+
- 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.
36+
- a source over `sys_audit_note` → index a business object, or declare `enable.aiReadable: true` on the system object's own definition.
37+
38+
`@objectstack/spec` adds only the upgrade-guide entry `knowledge-source-publish-refuses-missing-references-and-gated-objects`.

‎content/docs/deployment/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ os compile --json # JSON output for CI pipelines
937937
→ Normalizing stack definition...
938938
→ Lowering inline handlers...
939939
→ Validating protocol compliance...
940-
→ Running author-time rules (86)...
940+
→ Running author-time rules (87)...
941941
→ Checking that every required capability has a provider installable in this edition...
942942
→ Collecting package docs (ADR-0046)... 0 collected
943943
→ Writing artifact...

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ A clean run walks the registry and reports timing:
870870
Config: /path/to/support-desk/objectstack.config.ts
871871
Load time: 21ms
872872
→ Validating against ObjectStack Protocol...
873-
→ Running author-time rules (86)...
873+
→ Running author-time rules (87)...
874874
→ Checking that every required capability has a provider installable in this edition...
875875
→ Checking package docs (ADR-0046)...
876876

‎content/docs/getting-started/build-with-claude-code.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ visible: 'status != "resolved"'
318318
◆ Validate
319319
────────────────────────────────────────
320320
→ Validating against ObjectStack Protocol...
321-
→ Running author-time rules (86)...
321+
→ Running author-time rules (87)...
322322
323323
✗ Author-time rules failed (1 issue)
324324
• stack · action 'resolve_ticket' visible: bare reference `status` — a

‎content/docs/ui/react-pages.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ objectstack validate
404404
────────────────────────────────────────
405405
→ Loading configuration...
406406
→ Validating against ObjectStack Protocol...
407-
→ Running author-time rules (86)...
407+
→ Running author-time rules (87)...
408408
→ Checking that every required capability has a provider installable in this edition...
409409
→ Checking package docs (ADR-0046)...
410410

‎packages/lint/src/authoring-rules.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ import { validateFormConsumers, validateFormPublicAddresses } from './validate-f
140140
import { validateThankYouRecordFields } from './validate-thank-you-record-fields.js';
141141
import { validateAssignmentRules } from './validate-assignment-rules.js';
142142
import { validateAiContext } from './validate-ai-context.js';
143+
import { validateKnowledgeSource } from './validate-knowledge-source.js';
143144
import { validateSeedStateMachine } from './validate-seed-state-machine.js';
144145
import { validateVisibilityPredicates } from './validate-visibility-predicates.js';
145146
import { validatePredicatePathRefs } from './validate-predicate-path-refs.js';
@@ -2084,6 +2085,46 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
20842085
runtimeTypes: ['ai_context'],
20852086
run: (stack, ctx) => validateAiContext(stack, ctx.packageScope ? { packageScope: ctx.packageScope } : {}),
20862087
},
2088+
// [ADR-0161 K4, row 4] Knowledge sources whose object or a listed field the
2089+
// stack does not have, whose object the API does not serve for `search`, or
2090+
// that index a system object which does not opt into AI reads (the gates of
2091+
// the knowledge service's admission that need no principal), and a listed
2092+
// credential-class or `internal` field, which the index never carries.
2093+
//
2094+
// GATING, and on the runtime publish door for `knowledge_source`: ADR-0161
2095+
// K4 says an item "is refused when the object or a named field does not
2096+
// exist" and that "a packaged item meets the gates that need no principal in
2097+
// `os validate` and at publish". That is the departure from the
2098+
// `validateAiContext` row above, which only advises at publish because a
2099+
// context pack still reads what resolves; a source that fails one of these
2100+
// has nothing to index (a missing object), indexes no text for a member (a
2101+
// missing field), or is never searched for a caller the service judges (a
2102+
// gated object). The rule reads `knowledgeSources`, `objects` (and the
2103+
// stack's own extensions), `manifest.dependencies` and no other collection;
2104+
// `objects` is the context every per-write snapshot carries, and the
2105+
// written source is the sole member of its own collection. Under a stated
2106+
// package scope that `objects` is the write's closure, so the scope is
2107+
// passed through and an object outside it is worded for the closure with
2108+
// `closureDependencyRemedy`. With no scope `objects` is the whole
2109+
// collection the host serves (`wholeCollection`), so an unresolved object
2110+
// is an error there too; only the CLI, where a manifest dependency the
2111+
// artifact does not carry may define it, hedges it as a warning (the
2112+
// `flow-trigger-unknown-object` split). An `error` refuses the publish
2113+
// (422), the `warning`s ride the 2xx `advisories`.
2114+
{
2115+
name: 'validateKnowledgeSource',
2116+
tier: 'gating',
2117+
input: 'parsed',
2118+
commands: ALL,
2119+
source: 'packages/lint/src/validate-knowledge-source.ts',
2120+
surfaces: CLI_AND_RUNTIME,
2121+
runtimeTypes: ['knowledge_source'],
2122+
run: (stack, ctx) =>
2123+
validateKnowledgeSource(stack, {
2124+
...(ctx.packageScope ? { packageScope: ctx.packageScope } : {}),
2125+
wholeCollection: ctx.runtimeWriteType !== undefined && !ctx.packageScope,
2126+
}),
2127+
},
20872128
// [#34613] `validateSeedReplaySafety` (framework#3434, the `insert`-mode
20882129
// replay warning) is retired: `SeedMode` itself refuses `insert` and
20892130
// `replace` at parse (ruling 6942780880), so no stack this rule could flag

‎packages/lint/src/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,16 @@ export {
407407
} from './validate-ai-context.js';
408408
export type { AiContextFinding, AiContextSeverity } from './validate-ai-context.js';
409409

410+
export {
411+
validateKnowledgeSource,
412+
KNOWLEDGE_SOURCE_OBJECT_UNKNOWN,
413+
KNOWLEDGE_SOURCE_FIELD_UNKNOWN,
414+
KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE,
415+
KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE,
416+
KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED,
417+
} from './validate-knowledge-source.js';
418+
export type { KnowledgeSourceFinding, KnowledgeSourceSeverity } from './validate-knowledge-source.js';
419+
410420
export {
411421
validateAssignmentRules,
412422
ASSIGNMENT_RULE_USER_TARGET,

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6188,6 +6188,99 @@ const AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION: RuleExplanation = {
61886188
],
61896189
};
61906190

6191+
// ── Knowledge sources (`validate-knowledge-source.ts`) ──
6192+
6193+
const KNOWLEDGE_SOURCE_DOORS =
6194+
'Judged by `os validate`, `os build` and `os lint`, and at the runtime publish gate for a ' +
6195+
'`knowledge_source` write (Studio, the metadata API, MCP), with the same rule id and message. An error ' +
6196+
'refuses the publish (ADR-0161 K4): a source over a missing object has nothing to index, a missing field ' +
6197+
'indexes no text for that member, and a gated object is never searched for a caller the service judges.';
6198+
6199+
const KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION: RuleExplanation = {
6200+
rule: 'knowledge-source-object-unknown',
6201+
covers: 'why a knowledge source must name an existing object',
6202+
paragraphs: [
6203+
'A knowledge source (`knowledgeSources`, ADR-0161 K4) indexes the records of one object, `source.object`. ' +
6204+
'An object nothing defines has no records, so the source is built empty and every search over it ' +
6205+
'answers nothing, with no error anywhere.',
6206+
'Defined means an object of this stack, of a package in the same artifact (`packages[]`), or, at the ' +
6207+
'publish gate, an object the host serves. A platform object a known package registers (`sys_user`) is ' +
6208+
'not judged when the stack does not carry its definition. A name with a platform prefix that no known ' +
6209+
'package registers is a warning, because a third-party package may still provide it. When the publish ' +
6210+
'gate states the package\'s closure (the package, the packages its manifest declares in ' +
6211+
'`dependencies`, and platform objects), an object outside it is reported with the remedy to declare the ' +
6212+
'dependency.',
6213+
'On the command line a package the manifest declares in `dependencies` but the artifact does not carry ' +
6214+
'is out of sight: its objects cannot be read there. So while the manifest declares such a dependency, ' +
6215+
'an object the stack does not define is a warning, which clears when that dependency defines it (the ' +
6216+
'publish gate judges the source against the package\'s closure, which holds the dependency\'s objects). ' +
6217+
'With no such dependency it is an error, which clears only by naming an object that exists.',
6218+
KNOWLEDGE_SOURCE_DOORS,
6219+
],
6220+
};
6221+
6222+
const KNOWLEDGE_SOURCE_FIELD_UNKNOWN_EXPLANATION: RuleExplanation = {
6223+
rule: 'knowledge-source-field-unknown',
6224+
covers: 'why each listed field must exist on the object',
6225+
paragraphs: [
6226+
'A source lists the fields whose text becomes each document (`source.content`) and the fields projected ' +
6227+
'into a hit\'s metadata (`source.metadataFields`). A name the object does not define reads nothing on ' +
6228+
'every record: the document is built without that text, or the metadata without that value.',
6229+
'Defined means declared in the object\'s `fields` (an object extension of the same stack included) or ' +
6230+
'addressable without a declaration: `id`, which the driver provisions, and the system columns the ' +
6231+
'platform injects (`owner_id`, `created_at` and the rest) are read like any field. An object whose ' +
6232+
'definition carries no readable field map is not judged.',
6233+
KNOWLEDGE_SOURCE_DOORS,
6234+
],
6235+
};
6236+
6237+
const KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE_EXPLANATION: RuleExplanation = {
6238+
rule: 'knowledge-source-object-not-searchable',
6239+
covers: 'why the API must serve the object for search',
6240+
paragraphs: [
6241+
'A knowledge search is a search over the object\'s records, so the knowledge service searches a source ' +
6242+
'only when the API exposure serves its object for `search`: the decision `canServeApiOperation` in ' +
6243+
'`@objectstack/spec/data` answers, the one every door serving object rows asks. `enable.apiEnabled: ' +
6244+
'false` refuses it. So does an `enable.apiMethods` list that does not grant `list`, from which search ' +
6245+
'derives (`search` itself is a retired list value the parse strips), or one that grants `list` beside ' +
6246+
'`enable.searchable: false`. With no `apiMethods` list, `searchable: false` does not refuse it.',
6247+
'To clear it, keep `enable.apiEnabled` true and, where the object declares `enable.apiMethods`, include ' +
6248+
'`list` with `enable.searchable` not false; or index another object.',
6249+
'This gate needs no caller, so it is judged here. The gates that need one (the object\'s package is not ' +
6250+
'disabled, and the author may query every field the source serves) are asked when the source is saved, ' +
6251+
'as its author.',
6252+
KNOWLEDGE_SOURCE_DOORS,
6253+
],
6254+
};
6255+
6256+
const KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE_EXPLANATION: RuleExplanation = {
6257+
rule: 'knowledge-source-system-object-not-ai-readable',
6258+
covers: 'why a system object source must opt into AI reads',
6259+
paragraphs: [
6260+
'A system object (a `sys_` name) is indexed and searched only when its own definition opts into AI reads ' +
6261+
'with `enable.aiReadable: true`, the posture the MCP record tools take (`isAiReadExposed` in ' +
6262+
'`@objectstack/spec/data`). The objects that store serialized metadata bodies are never opened, ' +
6263+
'whatever they declare.',
6264+
'The declaration belongs to the system object\'s author, not to the source: index a business object, or a ' +
6265+
'system object that declares it.',
6266+
KNOWLEDGE_SOURCE_DOORS,
6267+
],
6268+
};
6269+
6270+
const KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED_EXPLANATION: RuleExplanation = {
6271+
rule: 'knowledge-source-field-never-indexed',
6272+
covers: 'why a credential-class or internal field is skipped',
6273+
paragraphs: [
6274+
'Embedding is egress: the text of every listed field is sent to the embedding provider and kept in an ' +
6275+
'index outside the row store. So the index never carries a credential-class field (a `secret`, or a ' +
6276+
'`password` the platform masks on read) or a field declared `internal: true`, even when the source ' +
6277+
'names it (ADR-0161 K5). The member is skipped, and the documents read less than the list says.',
6278+
'A warning, not a refusal: the rest of the source is indexed. Remove the member from `content` or ' +
6279+
'`metadataFields`. Judged by `os validate`, `os build` and `os lint`, and at the runtime publish gate ' +
6280+
'for a `knowledge_source` write, where it rides the advisories.',
6281+
],
6282+
};
6283+
61916284
// ── Assignment rules (`validate-assignment-rules.ts`) ──
61926285

61936286
const ASSIGNMENT_RULE_USER_TARGET_EXPLANATION: RuleExplanation = {
@@ -7271,6 +7364,11 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
72717364
[AI_CONTEXT_RELATED_LINK_UNKNOWN_EXPLANATION.rule]: AI_CONTEXT_RELATED_LINK_UNKNOWN_EXPLANATION,
72727365
[AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION.rule]: AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION,
72737366
[AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION.rule]: AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION,
7367+
[KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION.rule]: KNOWLEDGE_SOURCE_OBJECT_UNKNOWN_EXPLANATION,
7368+
[KNOWLEDGE_SOURCE_FIELD_UNKNOWN_EXPLANATION.rule]: KNOWLEDGE_SOURCE_FIELD_UNKNOWN_EXPLANATION,
7369+
[KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE_EXPLANATION.rule]: KNOWLEDGE_SOURCE_OBJECT_NOT_SEARCHABLE_EXPLANATION,
7370+
[KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE_EXPLANATION.rule]: KNOWLEDGE_SOURCE_SYSTEM_OBJECT_NOT_AI_READABLE_EXPLANATION,
7371+
[KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED_EXPLANATION.rule]: KNOWLEDGE_SOURCE_FIELD_NEVER_INDEXED_EXPLANATION,
72747372
[ASSIGNMENT_RULE_USER_TARGET_EXPLANATION.rule]: ASSIGNMENT_RULE_USER_TARGET_EXPLANATION,
72757373
[ASSIGNMENT_RULE_QUEUE_UNSTAFFED_EXPLANATION.rule]: ASSIGNMENT_RULE_QUEUE_UNSTAFFED_EXPLANATION,
72767374
[SEED_VALUE_OUTSIDE_STATE_MACHINE_EXPLANATION.rule]: SEED_VALUE_OUTSIDE_STATE_MACHINE_EXPLANATION,

‎packages/lint/src/runtime-gate.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@ const TYPE_TO_STACK_KEY: Readonly<Record<string, string>> = {
311311
// pack's names into `objects`, which every snapshot carries, and nothing
312312
// into a sibling pack.
313313
ai_context: 'aiContexts',
314+
// [ADR-0161 K4, row 4] `knowledge_source` — `allowRuntimeCreate: true`, so
315+
// Studio, REST `/meta` and an MCP/AI author mint sources at runtime, and the
316+
// ADR says a packaged item meets the gates that need no principal at
317+
// publish as in `os validate`. ⛔ NOT a mapping ahead of its rule:
318+
// `validateKnowledgeSource` crosses with this row and opens on
319+
// `stack.knowledgeSources`, the key `ObjectStackDefinitionSchema` gives the
320+
// collection. Not a context row either, for the `position` / `app` reason
321+
// above: the rule resolves a source's names into `objects`, which every
322+
// snapshot carries, and nothing into a sibling source. Unlike the
323+
// `ai_context` row, its errors refuse the publish (the rule is gating).
324+
knowledge_source: 'knowledgeSources',
314325
};
315326

316327
/**

0 commit comments

Comments
 (0)