Repository navigation
docs(adr): ADR-0161 dated note — item 17, the typed scope a search hands its adapter: record ids, or a parent object through a listed lookup - #37329
Conversation
…nds its adapter (#37324) A second dated note under the table of K8, and a second Amended bullet in the header list. The note records the maintainer's ruling on Q3 (ruling record 7168192820) and gives item 17 its final shape: the member is AdapterSearchOptions.scope, a list of terms the service builds from scope: [{ object, ids }] and the adapter applies before it ranks. No code, no schema, no changeset. The status line is left as it is. Claude-Session: https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm Co-authored-by: Claude <noreply@anthropic.com>
|
repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U 维护者速读
席位意见:建议按现稿合并。作者交给适配器的是平台换算好的过滤条件(记录 id 或某个筛选字段的 id),不是卡面写的「对象 + id」原样,这与记录第 17 项原文「由服务构建」和裁决记录「过滤条件变成该字段在 ids 内」一致,是卡面措辞不准,不是改了您裁的东西。第 ③ 处是唯一有产品语义分歧的细节,席位推荐现稿的「不参与并记日志」:两个字段取并集会把「只是引用了这份制度」的别处条款算进来,答错比答空更糟;今天零用例,等第一个真实知识源出现再用一条补充说明放开。 席位核对ACCEPT
Contract reviewServed-tier: Face: governed rules text ( ① Derived judgments
② Semver levelNone. ③ Boundary flags
④ Design judgmentThe change holds against the cited code and against the acceptance scenes of #37308 (20 records, two ids,
The bound on entries and ids is adapter-facing ("so that an adapter can rely on them") and lands on the member's TSDoc in #37308; that PR touches the published contract and owes its own review at this tier. If #37308 finds any shape here cannot be built as written, K8 rule 3 applies: it stops and the change is another dated note. Implemented-by: VERDICT: PASS |
|
repo:cloud#1 · os-warren · session_01JQwxbW5anP6GDaVi5LKi2U Hand-off for approval (Tier H,
|
…ped bucket beside skill and ai_context (objectstack-ai#37330) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8ThLXnc2MYoAdJHGZxSsdaA)_ repo:cloud#1 · os-warren · session_01JQwxbZjKjZ947xtTvgJuHX Fixes objectstack-ai#37325 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感(只改决定记录,不改代码);把你今天定的「按应用+名字区分,都保留」写进记录:两个应用各带的同名知识源都保留、各建各的索引,AI 用「应用前缀-名字」指明是哪一个。 - 为什么做:属于「知识检索平台化」专题;哪些类型按应用区分要先写进记录,后面的实现卡 objectstack-ai#37304(让知识源成为应用包里的一份配置)才能照着做。 - 出错会怎样:记录写偏的话,后面的实现会照着偏的做;这次只有文档,撤回这次合并即可。 - 要你做什么:合并这个 PR,合并就是这条裁定的记录;其中一处超出你的原话、只能由你定:同一个应用前缀下不允许两个应用包带同名知识源(前缀不同的同名知识源照样都保留),不同意就先划掉这一条再合并。 ## What changes Two files under `docs/adr/`: 58 lines added, 1 line changed. No schema, no code, no changeset. **ADR-0150** (Accepted) gains a dated addendum. No ruled sentence is rewritten. - The status line gains one **Amended** clause, dated 2026-11-25, after the `ai_context` one. This is the one changed line: the clause is appended, and nothing before it is edited. - The D1 table gains one row, marked with the date, after the `ai_context` row and before bucket 4. - A new section after the `ai_context` addendum and before D2, "Addendum (2026-11-25): `knowledge_source` joins bucket 3". It writes the maintainer's ruling of that day into the record: the knowledge source type of ADR-0161 K4 is identified by `(package, name)`, in bucket 3 beside `skill` and `ai_context`. The ruling is quoted with its record id in the status clause, at the head of the addendum and in the ADR-0161 note: seat record `7168239918` on the code card, decision card tapped **B 「按应用+名字区分,都保留」** at 2026-11-25T16:34:09Z, against the card's recommendation. The addendum says, in this order: 1. **The type**, and what D2, D3, D4, D5, D6 and D8 mean for it. A package's source is spelled `NS-NAME` where its name crosses the AI face, which is inside `search_knowledge`: the `sources` list of an answer and the `sourceIds` argument. 2. **The principle, read for this type.** The recommendation read a source's name under D1's storage half. The ruling did not, so the keys of a source's index are derived from its identity, as its face is. Three things that reading does not hide are listed. 3. **The tree today**, measured on `main` at `fbb62e1c`. The type is not registered and is in none of the four lists. A source reaches the service through code only. The keys of an index are the bare `id`. 4. **What changes with the bucket**: the service's copy, overlays, owner stamps, uninstall and the keys of an index. 5. **The readers that move.** It names five and moves none. 6. **The follow-up**, the code card objectstack-ai#37304, after this merge. 7. **Past the ruling's words**: seven points, none decided here. One is the maintainer's, two follow from text already ruled, and four are left open for the code card. **ADR-0161** gains one cross-reference note after point 3 of K4 and before K5. No sentence of it is changed. **Not in this PR**, by the card's contract: none of the four lists is edited, no reader is moved and no store is re-keyed. That is the code card's work, after this merge. ## Tests No package is touched, so no package build or test is owed. The checks that read these two files are the docs gates under Verification. ## Acceptance notes - **The chain.** This PR is the ruling's record and step 1 of its execution. The code card objectstack-ai#37304 comes after it and stays open: it takes the four lists, the readers and the store keying in memory, pgvector and turso. - **One decision is the maintainer's alone** (point 1 of "Past the ruling's words"). The ruling record counts "the `domain:server` four lists and readers (precedent PR objectstack-ai#37291)" and names none of them. In that PR the fourth list is `NAMESPACE_UNIQUE_TYPES`: one package holder of a name inside one namespace, refused at install and in `os validate`. So "Two packages shipping one source name both work" holds for two namespaces, and inside one namespace the second is refused. The list's header reserves a further type to the maintainer. The merge accepts this point. Struck, two co-owners of a namespace may ship one name, and the one face they derive is refused at the call. - **Two points follow from text already ruled** and are no new decision. A source name takes the name grammar of buckets 2 and 3, which refuses a `_`-led name that today's `id` pattern admits. And a `409` names only the sources the tool may search (ADR-0161 K9). - **Four points are left open for the code card.** Each is stated in the addendum and decided nowhere in it: what each shape carries (a hit's `sourceId` and `documentId`, a stored document's `sourceId`, the by-name members of the service contract); which coordinate a key carries, the package id or the namespace, and what removes an index left under the old key; which holder a source registered in code is; and an environment source under a name a package later ships. - **The acceptance line of the card**, "The addendum quotes the ruling comment id and the maintainer's words; earlier text of the record unchanged". The id and the words are in all three places named above. ADR-0150's diff has one changed line, the status line, and its old text is a strict prefix of the new text. Every other old line of both files survives, in order. - **The tree moved once during the work.** `main` gained the knowledge splitter (PR objectstack-ai#37287) under six of the files the addendum anchors. `main` is merged into the branch (a merge commit, no rebase and no force-push). Every "today" sentence and every anchor was read again at `fbb62e1c`, and all hold. The two dated readings name that commit. - **Overlap.** PR objectstack-ai#37329 adds a dated note under K8 of the same ADR-0161 file. `node scripts/pm/overlap-check.mjs --branch=claude/project-thread-4uapwf` answered `VERDICT clean exit 0` at this head, against `origin/main` and that PR's head. Whichever of the two lands second merges `main`. - **Line budget.** 58 added and 1 changed; the precedent PR objectstack-ai#37209 was 44 and 1. The difference is the "principle" paragraph, which the precedent did not need because its ruling followed the recommendation, and the seven-point list. - **Citation form.** `check:adr-symbol-anchors` refuses a line anchor under `docs/adr/`, so the record cites `path#Symbol`, and the line numbers are in the table under Verification. - **No changeset.** `docs/adr/` ships in no package, so this PR carries `skip-changeset`. - **Tier H.** This PR stays draft. The merge is the maintainer's, and it is the ruling's record. - **Shallow checkout.** No claim here is read from history dates. - **Attribution lines.** The dispatch asked for a commit trailer that names a model and for the harness's two-line block at the end of this body. The repository's rules ask for the model-free trailer pair and for one footer line under a rule, and those are what the commits and this body carry. - **Noted, not filed.** ADR-0161's status keyword still reads Proposed on `main`, and its own status line says the record is in force from the merge of the PR that carried it. This PR adds one note to that record and does not touch its status line. ## Verification **Read first**, by risk: 1. `docs/adr/0150-…-literal-prefix.md`, "Past the ruling's words" at the end of the addendum (lines 191 to 199). Point 1 is the one decision that is the maintainer's. 2. The same file, "The principle, read for this type" (line 160): how D1's storage half reads for a type the ruling placed against the recommendation. 3. The same file, the D1 table hunk (line 95) and the status line (line 3): one row inserted into a ruled table and one appended clause. Check that both read as additions and change no ruled text. **Two-minute check**: run `node scripts/check-adr-symbol-anchors.mjs`. Expect `4220 anchors across 163 records resolve` and exit 0. Twenty-one of them are this diff's `path#Symbol` anchors. <details> <summary>Measured anchors on main at fbb62e1 (file:line)</summary> | What the addendum says | Where it is read | |---|---| | The type is in no row of the registry; `skill` and `ai_context` open no environment overlay | `packages/spec/src/kernel/metadata-plugin.zod.ts:798` (`DEFAULT_METADATA_TYPE_REGISTRY`), `:1384`, `:1388` | | The service keeps one slot per (package, name) for listed types | `packages/spec/src/api/protocol.zod.ts:2753` (`PACKAGE_SLOTTED_METADATA_TYPES`; `skill` at `:2754`) | | Any other type is keyed by name alone | `packages/metadata/src/package-slotted-store.ts:797` (`storeWriteKey`), `:820` | | The one rule resolves only its listed types, and throws for a type outside the list | `packages/core/src/package-scoped-resolution.ts:245` (`PACKAGE_SCOPED_TYPES`; `skill` at `:270`), `:740`; `packages/objectql/src/package-scoped-resolver.ts:149` | | A by-name read consults (package, name) for listed types | `packages/objectql/src/package-scoped-read.ts:88` (`PACKAGE_SCOPED_READ_TYPES`; `skill` at `:96`) | | One package holder of a name inside a namespace; the list is reserved to the maintainer | `packages/objectql/src/namespace-co-owner-names.ts:96` (`NAMESPACE_UNIQUE_TYPES`), `:27` | | A source reaches the service through code only | `packages/services/service-knowledge/src/knowledge-service-plugin.ts:91` (`KnowledgeServicePlugin`), `:44`, `:220` | | One map by `id`; a second registration replaces the first with a warning | `packages/services/service-knowledge/src/knowledge-service.ts:121` (`KnowledgeService`), `:123`, `:166`, `:168` | | A document id is the source's `id`, a `:` and the record id | `packages/services/service-knowledge/src/knowledge-service.ts:1570` (`documentIdFor`), `:1571` | | An adapter is handed the whole source | `packages/spec/src/contracts/knowledge-adapter.ts:33` (`AdapterContext`), `:35` | | The one in-tree store keyed by the bare `id` | `packages/plugins/knowledge-memory/src/index.ts:44` (`KnowledgeMemoryAdapter`), `:48`, `:55` | | The push door that takes a document id from a caller | `packages/spec/src/contracts/knowledge-service.ts:107` (`IKnowledgeService`), `:127` | | The tool lists each source by its `id`; a hit shows `sourceId` and `documentId` | `packages/services/service-knowledge/src/knowledge-tools.ts:61` (`SearchKnowledgeSourceSummary`), `:70`, `:72`, `:222` | | An unknown `sourceIds` entry is refused `NOT_FOUND` | `packages/services/service-knowledge/src/knowledge-tools.ts:246` (`createKnowledgeTools`), `:257`, `:260` | | Today's `id` pattern admits a `_`-led name; the bucket's pattern does not | `packages/spec/src/ai/knowledge-source.zod.ts:174` (`KnowledgeSourceSchema`), `:176`; `packages/spec/src/kernel/address-grammar.ts:68` (`ROUTER_ADDRESSABLE_NAME_PATTERN`) | | The one face derivation | `packages/spec/src/ai/face-name.ts:86` (`deriveAiFaceName`) | | A skill prompt's name: a face, else a bare name by the one rule | `packages/mcp/src/skill-prompts.ts:373` (`lookupSkillPrompt`) | | The owner stamp's judge, and the collections it judges | `packages/spec/src/kernel/collection-item-owner-stamp.ts:129` (`judgeCollectionItemOwnerStamp`), `:100` | | The type's row is not among the served overrides | `packages/metadata-protocol/src/protocol-package-bindings.ts:388` (`SEALED_ROW_SERVED_OVERRIDE_TYPES`) | | Uninstall, the registry's half | `packages/objectql/src/registry.ts:5328` (`uninstallPackage`) | | Uninstall, the service's half | `packages/metadata/src/metadata-manager.ts:2880` (`unregisterPackage`) | Absence readings at the same commit, each with a positive control: - `knowledge_source` in the four list files, in `packages/metadata/src/package-slotted-store.ts` and in the registry's rows: 0 lines each. Control: `skill` is in the first three lists and in the registry, at the lines the table gives. - A stack collection: `knowledgeSources` in `packages/spec/src/stack.zod.ts`, 0 lines. Control: `aiContexts`, 3 lines. - `knowledge_source` under `packages/`, `examples/`, `ui/`, `skills/` and `content/`: 0 files. Control: `ai_context`, 60 files. - `KnowledgeServicePlugin` or `registerSource` under `examples/`: 0 files. Control: 25 files under `packages/`. - Tracked paths under `knowledge-pgvector` or `knowledge-turso`: 0. Control: `packages/plugins/knowledge-memory`, 10 files. - Before this diff, ADR-0161 named ADR-0150 on 0 lines (control: ADR-0088, 7 lines), and ADR-0150 held the word "knowledge" on 0 lines (control: `ai_context`, 6 lines). </details> <details> <summary>Local gates at head 05f35b6: 21 derived, 21 run, all exit 0</summary> Derived with `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --commands`, and reconciled with `--ran`: ``` Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN. ✓ dispatch-gates --ran: 21 derived famil(ies) accounted for — 21 run, 0 NOT-MEASURED (a DERIVED zero — all 21 recorded an exit code and none of them is 3). ``` Each exit code was captured before any pipe: ``` 0 node scripts/check-adr-links.mjs 1225 relative link destination(s) under docs/adr/ resolve 0 node scripts/check-adr-links.mjs --self-test 0 node scripts/check-closing-keyword-parity.mjs 3 parsers agree on all 9 keywords 0 node scripts/check-closing-keyword-parity.mjs --self-test 0 node scripts/check-comment-mask-corpus.mjs 23929 files, 0 disagree, 0 unparseable 0 node scripts/ci/plan-test-core-shards.mjs --self-test 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions 0 pnpm check:adr-anchors 132 anchored file(s), every governing ADR still referenced 0 pnpm check:adr-index docs/adr/README.md is current, every record parsed 0 pnpm check:adr-symbol-anchors 4220 anchors across 163 records resolve 0 pnpm check:ci-filter-parity 0 pnpm check:closed-ceremony-text 0 pnpm check:cross-package-test-inputs 0 pnpm check:doc-authoring 0 pnpm check:driver-memory-census 0 pnpm check:gitlink-declared 0 pnpm check:nul-bytes no raw ASCII control bytes 0 pnpm check:pm-governed-merges 0 pnpm check:pm-prior-rulings 0 pnpm check:refd-timer-probe 0 pnpm check:watch-hint-literal ``` `check:doc-formula-expressions` reads the compiled output of `@objectstack/formula` and `@objectstack/lint`. Those two and their dependencies were built first on the merged tree, under the shared verify lock (`VERDICT command-exit 0`). `docs/adr/README.md` is generated from each record's status keyword. ADR-0150's keyword stays Accepted and ADR-0161's stays Proposed, so the index does not change and is not in this diff. Also at this head: `node scripts/check-commit-card-trailers.mjs --range origin/main..HEAD` exits 0 over the 3 commits of the branch. Not measured locally, and CI's to run: the type-check lanes, the `Plan Test Core shards` job and the governed-merges audit, which take values only a CI run has. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZjKjZ947xtTvgJuHX)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
…ope, by the records a source indexes or by a parent through a listed lookup (objectstack-ai#37342) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8GWXHtfAHuZXmmZpkARr4Wi)_ Fixes objectstack-ai#37308 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:知识检索可以限定范围了:只在指定的几条记录里找,或者只在一份上级记录(比如一份制度)下面的条款里找,返回的前几条结果都来自范围内。 - 为什么做:属于「知识检索平台化」专题第三阶段,按您定的「也能指定上级对象(制度)」实现;之后给 AI 用的检索工具也会接上这个参数。 - 出错会怎样:范围只会缩小结果,不会放宽权限,每条结果仍按提问人的权限重新读取;最坏是限定范围后漏掉结果。没有数据迁移,撤回即可。 - 要你做什么:无需你操作。您已在卡片上同意的安全登记行已在(`d1ca7f01`)。开源向量库那个改动先合并了,本分支已合入主干,并让向量库也按范围过滤(在数据库里先筛再排序);由座位做差量复核后重新排队合并。「按记录返回」已合并并合入本分支;与开源向量库那个改动仍有文字冲突,后合并的一方处理。 ## What changes ADR-0161 K8 item 17, in the shape its dated note of 2026-11-25 (objectstack-ai#37324, merged as `13ffe1c0`) gives it, built in one PR as the note says: the member, its first reader in `knowledge-memory`, and the suite cases. **`@objectstack/spec`** (types only, no metadata key): - `KnowledgeSearchOptions.scope?: Array<{ object: string; ids: string[] }>` (`packages/spec/src/contracts/knowledge-service.ts`): an option of the service, not a contract member. Its TSDoc states the own-object and parent readings, union, absent/empty, and the bounds with the coded refusal. - `AdapterSearchOptions.scope?: AdapterScopeTerm[]` and the exported type `AdapterScopeTerm` (`packages/spec/src/contracts/knowledge-adapter.ts`): `{ kind: 'record', ids }` or `{ kind: 'metadata', field, ids }`. Its TSDoc states absent/present/empty, the AND with `organizationIds` and `filter`, the bounds an adapter can rely on (at most 10 terms, at most 500 ids each, every id a non-empty string), and that the service checks every hit after the answer, so an adapter returns the document's `metadata` on its hits. - Regenerated: `api-surface/contracts.json`, `export-origins/contracts.json` (the new export). **`@objectstack/service-knowledge`**: - New `src/knowledge-search-scope.ts`: - `readSearchScope`: the bounds, `SEARCH_SCOPE_MAX_ENTRIES = 10`, `SEARCH_SCOPE_MAX_IDS = 500`. Past them it throws `code: 'VALIDATION_ERROR'`, `status: 400` (ADR-0112), naming the bound, before anything else in `search` runs. - `scopeTermsFor`: an entry naming the source's object gives a `record` term. An entry naming another object gives a `metadata` term on the one `metadataFields` member that is a `lookup` or `master_detail` field whose `referenceTargetOf` is that object, read from the registered definition. A `user` field, a withheld (credential-class or `internal`) field, a field whose target cannot be read, two or more such fields, no definition, and a `file` / `http` source all give nothing. - `scopeCheck`: the hit check. It judges `sourceRecordId` or `metadata[field]`, compares strings and numbers by `String(v)`, and matches a list when any element matches. Anything else, or no value, fails closed. - `KnowledgeService.search`: - Validates first. - `sourcesInScope` pairs each admitted source with its terms. A source no entry reaches is not searched (debug). The two-lookup ambiguity is logged once per source and object at `warn`, naming the fields. - `searchRound` hands each adapter a copy of its terms and checks every hit after the answer. The first drop for an adapter is logged once at `warn`. - `answered` stays the adapter's own count. - `src/testing.ts` (the contract suite): - New required `implements.scope`. - Adapter-alone cases, run when `implements.scope` is true: a record term filters before ranking (topK 1); a metadata term with a list value returns the document's metadata; the number 7 matches `'7'`; terms are a union; an empty list or a term with no ids ranks nothing; without the member everything is ranked; with `organizationIds`, both apply. - Cases through a real `KnowledgeService` for every adapter: an own-object scope fills topK from in-scope passages; a parent scope works through the listed lookup; an adapter with the member stripped answers no out-of-scope hit, and the service logs once. - `serviceOver` gains `schemas`, `stripScope` and `logger`. **`@objectstack/knowledge-memory`**: applies `scope` after the organization filter and before scoring. It declares `implements.scope: true`. **`@objectstack/knowledge-pgvector`** (landed first, objectstack-ai#37337): applies `scope` in the same inner `WHERE` as the organization filter, before `ORDER BY` / `LIMIT`. A `record` term is `source_record_id = ANY($n::text[])`; a `metadata` term holds when the stored jsonb value of its field is a string or number equal to an id as text, or a list with such an element. Ids and field names are bound parameters only. A scope with no term that has ids answers `[]` before any query. Its live contract run declares `implements.scope: true`. **Docs**: - `content/docs/protocol/knowledge.mdx`: a new "Record scope" section in §5, a pointer in §3.4, the suite sample, and §4.1 / the adapter table naming pgvector's record scope. - `content/docs/ai/knowledge-rag.mdx`: a new "Searching inside chosen records" section. **Changeset**: patch for the four packages, with `Clause-②: yes` and `Metadata-protocol: none`. The change adds no metadata key, and a non-protocol widening ships patch. ## Tests - New `src/__tests__/knowledge-search-scope.test.ts`: bounds (each refusal, and the exact-bound acceptance), term building (each reading of the note), and the hit check. - `src/__tests__/knowledge-service.test.ts`, new describe "search scope (ADR-0161 K8, item 17)": - the card's acceptance: 20 records, two in scope, topK 5, a full page; - an ignoring adapter: no out-of-scope hit, one log; - an unreached object: no adapter asked, empty answer; - an unreadable scoped record yields no hit; - the bounds refuse before any adapter or engine call; - empty scope and empty ids answer nothing; - the two-lookup case logs once; - a numeric lookup value matches its string id; - a parent scope makes no engine call naming the parent object, and an adapter that widens the terms it was handed (more ids, an extra term) still has every out-of-scope hit dropped; every round is handed the service's own terms (review round 1); - a scope with `groupBy`, and one with `granularity: 'record'`, over an adapter that ignores the scope: every round is handed the record term and no out-of-scope record answers (review round 2). - The contract suite runs on `knowledge-memory` and both stubs. - Mutation checks, run locally and reverted: - `knowledge-memory` with its scope filter removed: 7 suite cases fail. - `KnowledgeService` without the after-answer check: 7 cases fail across the stubs and the service tests. - Handing the adapter the live terms, or reading the parent object's definition: the round-1 case fails. - Skipping the scope under `groupBy`, skipping it under record granularity, or the `groupBy` source filter rebuilding its entries without the terms: the round-2 case fails. **Local runs at `760716bc`** (after merging `main` at `98bda0ac`, which brought objectstack-ai#37337): - `pnpm --filter @objectstack/spec build` and `check:generated`: exit 0, after the merge's deferred regeneration of `api-surface/contracts.json` and `export-origins/contracts.json` (`4552e7c4`). - `pnpm --filter @objectstack/service-knowledge typecheck` and `check:test-typecheck`: exit 0. `test`: 13 files, 365 tests passed. - `pnpm --filter @objectstack/knowledge-memory typecheck` and `check:test-typecheck`: exit 0. `test`: 2 files, 56 tests passed. - `pnpm --filter @objectstack/knowledge-pgvector typecheck`: exit 0. `test` against a local PostgreSQL 16 with pgvector, `OS_TEST_POSTGRES_URL` set and `OS_EXPECT_LIVE_DIALECT_MATRIX=1`: 4 files, 67 tests passed, every scope case of the suite among them (record term, metadata term with a list, the number 7, union, empty, absent, with `organizationIds`; through the service: own object, the parent through the listed lookup, the member stripped). With the SQL scope filter removed: 7 of them fail. - `pnpm --filter @objectstack/core test:repo` (the census pin, at `d1ca7f01`): 8 files, 110 tests passed. - **Derived gates at `760716bc`.** `dispatch-gates --commands` derives 119 commands from the 19 changed paths (the 118 before, plus `pnpm check:kernel-hook-pairs`). Each was run at this head with its output in its own file and its exit code read before any pipe. `check:dual-build-cjs-loads` first answered 3 (prerequisite not met: the new `knowledge-pgvector` had no `dist/`); after `pnpm --filter @objectstack/knowledge-pgvector build` it was run again, and the record holds that run. ```text Run reconciliation — 119 derived, 119 run, 0 NOT-MEASURED, 0 UNRUN. ✓ dispatch-gates --ran: 119 derived famil(ies) accounted for — 119 run, 0 NOT-MEASURED (a DERIVED zero — all 119 recorded an exit code and none of them is 3). ``` <details><summary>The 119 commands at <code>760716bc</code></summary> | Command | Exit | |:--|:--| | `node scripts/check-adr-0087-registration.mjs --base origin/main` | 0 | | `node scripts/check-adr-0087-registration.mjs --self-test` | 0 | | `node scripts/check-adr-links.mjs` | 0 | | `node scripts/check-adr-links.mjs --self-test` | 0 | | `node scripts/check-changeset-no-major.mjs --base origin/main` | 0 | | `node scripts/check-closing-keyword-parity.mjs` | 0 | | `node scripts/check-closing-keyword-parity.mjs --self-test` | 0 | | `node scripts/check-comment-mask-adoption.mjs` | 0 | | `node scripts/check-comment-mask-adoption.mjs --self-test` | 0 | | `node scripts/check-comment-mask-corpus.mjs` | 0 | | `node scripts/check-dev-prereqs.mjs --self-test` | 0 | | `node scripts/check-doc-route-spelling.mjs --advisory` | 0 | | `node scripts/check-doc-route-spelling.mjs --self-test` | 0 | | `node scripts/check-docs-section-name.mjs` | 0 | | `node scripts/check-docs-section-name.mjs --self-test` | 0 | | `node scripts/check-dts-emitted.mjs --self-test` | 0 | | `node scripts/check-empty-changeset.mjs --base origin/main` | 0 | | `node scripts/check-empty-changeset.mjs --self-test` | 0 | | `node scripts/check-issue-citations.mjs` | 0 | | `node scripts/check-plugin-teardown-shape.mjs` | 0 | | `node scripts/check-plugin-teardown-shape.mjs --self-test` | 0 | | `node scripts/check-section-landing-index.mjs` | 0 | | `node scripts/check-section-landing-index.mjs --self-test` | 0 | | `node scripts/check-tenant-audit-census.mjs` | 0 | | `node scripts/check-tenant-audit-census.mjs --self-test` | 0 | | `node scripts/ci/assert-turbo-remote-cache.mjs --self-test` | 0 | | `node scripts/ci/plan-test-core-shards.mjs --self-test` | 0 | | `node scripts/ci/prune-turbo-cache.mjs --self-test` | 0 | | `node scripts/ci/snapshot-next.mjs --self-test` | 0 | | `node scripts/docs-audit/check-affected-docs.mjs` | 0 | | `node scripts/docs-audit/check-drift-comment.mjs` | 0 | | `node scripts/pm/check-governed-queue-guard.mjs --self-test` | 0 | | `node scripts/pm/release-rehearsal-clone.mjs --self-test` | 0 | | `node scripts/release-pending-publish.mjs --self-test` | 0 | | `pnpm --filter @objectstack/lint run check:doc-formula-expressions` | 0 | | `pnpm --filter @objectstack/lint run check:doc-security-posture` | 0 | | `pnpm --filter @objectstack/spec run check:api-surface` | 0 | | `pnpm --filter @objectstack/spec run check:authorable-surface` | 0 | | `pnpm --filter @objectstack/spec run check:browser-reachable-entries` | 0 | | `pnpm --filter @objectstack/spec run check:docs` | 0 | | `pnpm --filter @objectstack/spec run check:dual-source-exports` | 0 | | `pnpm --filter @objectstack/spec run check:duration-unit-keys` | 0 | | `pnpm --filter @objectstack/spec run check:empty-state` | 0 | | `pnpm --filter @objectstack/spec run check:entry-nameability` | 0 | | `pnpm --filter @objectstack/spec run check:error-code-provenance` | 0 | | `pnpm --filter @objectstack/spec run check:export-origins` | 0 | | `pnpm --filter @objectstack/spec run check:exported-any` | 0 | | `pnpm --filter @objectstack/spec run check:generated` | 0 | | `pnpm --filter @objectstack/spec run check:liveness` | 0 | | `pnpm --filter @objectstack/spec run check:llms-txt` | 0 | | `pnpm --filter @objectstack/spec run check:skill-examples` | 0 | | `pnpm --filter @objectstack/spec run check:skill-refs` | 0 | | `pnpm --filter @objectstack/spec run check:strictness-ledger` | 0 | | `pnpm --filter @objectstack/spec run check:variant-docs` | 0 | | `pnpm --filter @objectstack/spec run check:yaml-examples` | 0 | | `pnpm check:adr-anchors` | 0 | | `pnpm check:adr-symbol-anchors` | 0 | | `pnpm check:changeset-gate-self-tests` | 0 | | `pnpm check:ci-filter-parity` | 0 | | `pnpm check:closed-ceremony-text` | 0 | | `pnpm check:corpus-claim-drift` | 0 | | `pnpm check:cross-package-test-inputs` | 0 | | `pnpm check:dispatcher-error-vocabulary` | 0 | | `pnpm check:doc-anchors` | 0 | | `pnpm check:doc-authoring` | 0 | | `pnpm check:doc-frontmatter` | 0 | | `pnpm check:docs-audit-scope` | 0 | | `pnpm check:docs-redirects` | 0 | | `pnpm check:docs-single-h1` | 0 | | `pnpm check:docs-spec-enumerations` | 0 | | `pnpm check:docs-transcript-drift` | 0 | | `pnpm check:driver-memory-census` | 0 | | `pnpm check:dts-closure` | 0 | | `pnpm check:engine-double-contract` | 0 | | `pnpm check:error-status-conformance` | 0 | | `pnpm check:gitlink-declared` | 0 | | `pnpm check:init-service-contract` | 0 | | `pnpm check:issue-citations` | 0 | | `pnpm check:kernel-hook-pairs` | 0 | | `pnpm check:keyed-text-bounds` | 0 | | `pnpm check:lean-entry-closure` | 0 | | `pnpm check:logger-receiver-detach` | 0 | | `pnpm check:merge-driver` | 0 | | `pnpm check:nul-bytes` | 0 | | `pnpm check:object-def-param-keys` | 0 | | `pnpm check:objectql-double-limit` | 0 | | `pnpm check:optional-error-sink` | 0 | | `pnpm check:org-identifier` | 0 | | `pnpm check:package-naming` | 0 | | `pnpm check:page-declaration-shape` | 0 | | `pnpm check:platform-object-tenancy-census` | 0 | | `pnpm check:pm-expected-skips` | 0 | | `pnpm check:pm-prior-rulings` | 0 | | `pnpm check:published-files` | 0 | | `pnpm check:published-readme-links` | 0 | | `pnpm check:query-options-erasure` | 0 | | `pnpm check:react-page-adapter-contract` | 0 | | `pnpm check:refd-timer-probe` | 0 | | `pnpm check:registry-log-declared` | 0 | | `pnpm check:rest-log-spy-declared` | 0 | | `pnpm check:role-word` | 0 | | `pnpm check:settings-bind-window` | 0 | | `pnpm check:skill-identifier-liveness` | 0 | | `pnpm check:slot-lookup` | 0 | | `pnpm check:sourcemap-no-sources-content` | 0 | | `pnpm check:spec-docblock-symbol-anchors` | 0 | | `pnpm check:spec-parsed-alias` | 0 | | `pnpm check:startup-registry-verdict` | 0 | | `pnpm check:system-context-census` | 0 | | `pnpm check:test-source-alias` | 0 | | `pnpm check:tier-file-adoption` | 0 | | `pnpm check:type-check-coverage` | 0 | | `pnpm check:type-check-debt` | 0 | | `pnpm check:undeclared-dep-imports` | 0 | | `pnpm check:vendor-version-stamps` | 0 | | `pnpm check:vouch-for-reference-callers` | 0 | | `pnpm check:watch-hint-literal` | 0 | | `pnpm check:where-matcher` | 0 | | `pnpm check:dual-build-cjs-loads` | 0 | </details> Earlier heads ran the 118 then derived, all exit 0: `857a2e20` (after three prerequisites were met) and `ca5a0c11`. ## Acceptance notes **The five points carried from objectstack-ai#37329's contract review:** 1. **Metadata on hits.** The requirement that an adapter return the document's `metadata` is stated on `AdapterSearchOptions.scope` and on `KnowledgeHit.metadata` (`packages/spec/src/ai/knowledge-document.zod.ts`, added in the merge of `main` under the seat's claim amendment, review ruling (b)). It is pinned: the suite's metadata-term case and the parent case through the service both assert `hit.metadata.policy`. 2. **Ids compared as strings.** Pinned on `scopeCheck`, on the adapter in the suite, and through the service (a lookup stored as the number 7 matches `'7'`). Only strings and numbers compare. An object, `null` or a boolean never matches, so `'[object Object]'` cannot be matched by accident. 3. **An empty scope or an entry with no ids.** It is answered empty, never refused and never read as "no scope", and no adapter is asked. Why empty rather than refused: it reads as an empty set reads everywhere else in this contract (`organizationIds: []`). A caller that computes ids (the records on screen, a policy's children) then needs no special case for "none". The tool argument (objectstack-ai#37311) can still refuse at its own door. 4. **Bounds.** 10 entries and 500 ids per entry are stated on both TSDocs and pinned. The 500 ids of one term fit one `IN` list, and a search hands at most 5,000 ids in all. ⚑ This PR owes a ceiling-tier contract review (CONTRACT_REVIEW_TIER) for the new member. 5. **The opaque `filter`.** Finding for the seat to file: `KnowledgeSearchOptions.filter` / `AdapterSearchOptions.filter` has no producer in this tree. The one non-test caller of `IKnowledgeService.search`, `createKnowledgeTools`, passes none, and the service gives it no guarantee after the answer. This PR leaves it unchanged and builds nothing from it. Whether it retires is its own card. Carrier: none · noted, not filed. Dedupe words: knowledge opaque filter, AdapterSearchOptions filter retire, KnowledgeSearchOptions filter producer. **What the note left to this PR, decided here:** - **Refill.** `answered` stays the adapter's own count, so whether a source may hold more is still judged on what it returned. The refill after the permission filter counts records among the hits that passed both checks. - A person's search over an ignoring adapter therefore still reaches in-scope hits through the refill. - The system identity gets one round, and may answer fewer than topK (pinned). - **Log levels.** - An adapter whose hits the check drops: `warn`, once per adapter. It is a deployment defect, and rule 2 says nothing is skipped silently. - Two lookups to one parent: `warn`, once per source and object. It is an authoring defect. - A source a scope does not reach: `debug`, per search, because it is normal under a scope. - Counts appear in logs only, never in the answer. - **Entry shape.** An entry with another key (for example `field`) is refused rather than ignored. A `field` key is the note's deferred alternative, so it fails loud instead of silently reading as something else. An id that is not a non-empty string is refused: the contract types ids as strings, and a stored numeric value still matches its string id. **Surface and overlap:** - Outside the claimed file list: the two generated spec artifacts (`api-surface/contracts.json`, `export-origins/contracts.json`), required by `check:generated` for the new export. - `packages/spec/src/ai/knowledge-document.zod.ts`: one TSDoc sentence, inside the claim as the seat amended it. - `packages/core/src/security/second-object-read-exposure.pin.test.ts`: one `CALLERS` row, kind `not-a-served-read`, for `knowledge-search-scope.ts`, in its own commit `d1ca7f01`, after the maintainer approved it on the card thread (2026-11-25 22:48Z). The census pin requires every caller of `referenceTargetOf` to be classified; the seat's review agrees with the kind. The row cites the service case that a parent-scoped search makes no engine call naming the parent object. Run at `d1ca7f01`: `pnpm --filter @objectstack/core test:repo`, 8 files, 110 tests passed. - No `scripts/adr-anchors` entry: review ruling (c), not owed. - `knowledge-ragflow` does not run the suite and ignores `scope` (objectstack-ai#37004 retires it). The service's check keeps its answers in scope. A parent scope answers nothing from it if its hits carry no metadata. - objectstack-ai#37337 (objectstack-ai#37100, pgvector) merged before this PR's queue run, and `main` is merged again at `93c70347`. `searchWithRefusals` validates the scope first; the admitted sources are filtered by the scope, then by `groupBy`, then planned (`planSearches` carries each source's terms beside its fingerprint, `SearchTarget.scope`), and `searchRound` hands the adapter both `index` and `scope`. The suite's `implements`, the stubs, `knowledge-memory` and the protocol sample declare the generation keys and `scope`. - objectstack-ai#37335 (record-level return) merged first, and `main` was merged into this branch at `67f11a57`. `search()` validates the scope, `groupBy` and `granularity` first, then filters the admitted sources by the scope (`sourcesInScope`) and then by `groupBy` (`sourcesGroupableBy`). Every round of the record-level path goes through `searchRound`, so every round is handed the terms and checked. - `packages/plugins/knowledge-pgvector/**`: inside the claim as the seat widened it after objectstack-ai#37337 landed (objectstack-ai#37308 item 4): the scope filter in `search()`, `implements.scope`, and nothing else. - `overlap-check` at `760716bc`: `main`, objectstack-ai#37265 and objectstack-ai#37187 merge cleanly. ## Verification Read first: 1. `packages/services/service-knowledge/src/knowledge-search-scope.ts`: the whole module (bounds, term building, hit check). 2. `KnowledgeService.search` / `sourcesInScope` / `searchRound` / `checkScope` in `knowledge-service.ts`: the three-line change at the top of `search`, and the check after the answer. 3. The two TSDocs in `packages/spec/src/contracts/`. Two-minute check: run `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-search-scope.test.ts src/__tests__/knowledge-service.test.ts -t scope`. Then open the "search scope" describe and read the acceptance case "20 records, two of them in scope, topK 5". --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbZmjM1KubX3ZAoJPPm)_ <!-- signed: repo:cloud#1 · os-warren · session_01JQwxbZmjM1KubX3ZAoJPPm --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Warren · project thread
Fixes #37324
Clause-②: yes
Metadata-protocol: none
维护者速读
What changes
One file under
docs/adr/:0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md, 17 lines added and none removed againstmain(829a45e9). No schema, no code, no changeset.K8 item 17 of ADR-0161 ("A typed scope filter") reads "Deferred" with no final shape, and K8 rule 3 says a shape that cannot be built as written changes by "a dated note on this record". This PR is that note. It records the maintainer's ruling on Q3, record
7168192820on #37308: 「也能指定上级对象(制度)」. #37308 builds the member after this note merges; #37311 (row 12) adds thesearch_knowledgearguments.docs/adr/**is Tier H: the maintainer merges this PR; no seat approves, merges or enqueues it.Two additions, in the form PR #37263 used for the #37097 note:
Amendedbullet at the end of the header list, pointing at the note. TheStatus:line is byte-identical, so the generateddocs/adr/README.mddoes not change.What the note decides. Each ◆ is a shape the note decides past the ruling's words, for the approver to accept with the record or strike:
AdapterSearchOptions.scope?, a list of terms:{ kind: 'record', ids }(the document'ssourceRecordIdinids) or{ kind: 'metadata', field, ids }(the document'smetadata[field]inids, or a list with an element inids). The adapter gets resolved terms, never{ object, ids }: turning an object into a field needs the object's registered definition, which is the platform's (K1).organizationIds: absent ranks every document as before; present filters BEFORE ranking sotopKis filled from in-scope documents; an empty list ranks nothing and is never "no filter".organizationIds,scopeand the opaquefilterall apply.KnowledgeSearchOptions.scope(entries ofobjectandids), per source: the source's own object gives arecordterm; another object gives ametadataterm for themetadataFieldsmember that points at it; no such member, and the entry does not reach the source. A source no entry reaches is not searched; afileorhttpsource answers nothing under a scope.recordterm only; (3) onlylookupandmaster_detailare parent links, target read throughreferenceTargetOf; auserfield is not one; a withheld field is not one; (4) a source that lists two or more lookups to the entry's object is not reached by it, logged once per source naming the fields.KnowledgeHit.sourceRecordIdandKnowledgeHit.metadata[field], fail closed. No capability flag is added (K8 rule 5); the service logs once per adapter the first time its check drops a hit.metadataFieldsmember an index carries to be queryable by the caller, so "that field in ids" is a filter the caller could run on the object's own rows; the parent row is never read.filterstays as it is, handed through and checked by nothing in the service; whether it retires is its own card.runKnowledgeAdapterContract, per term kind, and one through a realKnowledgeServiceover an adapter that ignores the member.KnowledgeSearchOptions.scope(service-knowledge: search takes a record scope (scope: [{ object, ids }]) and hands adapters a typed filter they apply before ranking #37308, coded refusal, ADR-0112), the tool argument (search_knowledge: the one definition gains scope, granularity and groupBy, for the MCP door and the in-app agent alike #37311), record-level return (service-knowledge: search returns records, not chunks — granularity and groupBy #37103).One shape differs from #37324's body words. That body says the member on
AdapterSearchOptionsisscope: [{ object, ids }]. The note keeps[{ object, ids }]on the service option only and hands the adapter resolved terms, as #37308's item 1 and K8 item 17 itself say ("built by the service from"). The member name isscopeon both interfaces, with distinct types.Tests
No test changes: the diff is one Markdown file. The derived gate families were run at
8a64f99f, the head.Local gates at 8a64f99: 21 derived, 21 run, all exit 0
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 21 commands from the branch's change set (1 path against merge base829a45e9). Each was run with its output redirected to a file and its exit code read before any pipe.check:doc-formula-expressionsneeds@objectstack/formulaand@objectstack/lintbuilt: built first under the verify lock,VERDICT command-exit 0.node scripts/check-adr-links.mjsnode scripts/check-adr-links.mjs --self-testnode scripts/check-closing-keyword-parity.mjsnode scripts/check-closing-keyword-parity.mjs --self-testnode scripts/check-comment-mask-corpus.mjsnode scripts/ci/plan-test-core-shards.mjs --self-testpnpm --filter @objectstack/lint run check:doc-formula-expressionspnpm check:adr-anchorspnpm check:adr-indexpnpm check:adr-symbol-anchorspnpm check:ci-filter-paritypnpm check:closed-ceremony-textpnpm check:cross-package-test-inputspnpm check:doc-authoringpnpm check:driver-memory-censuspnpm check:gitlink-declaredpnpm check:nul-bytespnpm check:pm-governed-mergespnpm check:pm-prior-rulingspnpm check:refd-timer-probepnpm check:watch-hint-literalReconciliation,
node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ranwith the exit codes recorded:check:adr-symbol-anchorsresolves the note's fourpath#symbolcitations. Outside the derived set and not run locally: the governed-merges audit with workflow-only variables, CI's test-core shard planning steps, and the type-check lanes (the diff touches no TypeScript). CI carries them.Acceptance notes
metadataFieldstoday, so no measured consumer decides it; empty-now can open later without removing anyone's hits.userfield: excluded as a parent link. The visible cost:Field.lookup('sys_user')is a link whileField.user()is not. Nothing scopes by user today; it returns by a dated note with its reader.filterhas no producer in this tree (the one non-test caller ofIKnowledgeService.search,createKnowledgeTools, passes none) and gets no service guarantee. The note leaves it unchanged; whether to retire it is a question for its own card. Noted, not filed: carrier none.KnowledgeSearchOptions.scopeor an entry with no ids is answered empty or refused (the note fixes only that it never reads as "no scope"); the bound numbers; log levels.docs/adr/**publishes nothing; the PR carriesskip-changeset.scripts/adr-anchorsentry.pnpm check:adr-anchorsexits 0 without one; the code PR anchors the member it lands.Verification
Read first:
filterstays as it is" bullet.Two-minute check: open this PR's Files tab. It shows one file under
docs/adr/, +17 −0: oneAmendedbullet at the end of the header list, and one blockquote between the #37097 note and the paragraph that starts "What "capabilities" became.".Generated by Claude Code