Skip to content

Commit da50177

Browse files
feat(ai): a context pack's related list takes where / orderBy / limit (ADR-0160 row 11) (#37354)
Fixes #37203 Clause-②: yes Metadata-protocol: added Skills-docs: follow-up #37177 ## 维护者速读 - 用户能看到什么变化:AI 读取记录资料包时,关联列表可以按作者写的条件筛选、排序并限制条数;条件或排序用到提问人不能查询的字段时,这一段被省略并附一句「部分资料对你不可见」,不再整次报错。 - 为什么做:记录范围 AI 问询专题的第 11 行(关联列表的筛选和排序),按维护者已同意的设计修订实现。 - 出错会怎样:最坏是某个关联段落被省略或条数不对,AI 回答少了资料;不会多给提问人无权看的数据;撤回此 PR 即恢复原行为。 - 要你做什么:无。 ## What changes **Spec (`packages/spec/src/ai/ai-context.zod.ts`).** A `related` entry gains three optional keys, per ADR-0160 D1 (second amendment): - `where`: the object filter form on the child's own fields, held to `AI_CONTEXT_WHERE_OPERATORS` (`$eq $ne $in $nin $gt $gte $lt $lte $null $exists`) joined by `$and` / `$or`. A bare value is `$eq`. Refused at parse: any other operator, a dotted path, a condition on a lookup's target, `{ $field }`, a `$now` anchor, a formula/object comparand, and a comparand that is one whole brace placeholder (matched by `FILTER_TOKEN_WRAPPED_RE`). Built as `FilterConditionSchema` plus one refinement walk, so the base form's own comparand refusals still apply. - `orderBy`: `SortNodeSchema[]` (`{ field, order }`, `direction` refused by name), with the field held to a snake_case own-field name. - `limit`: positive integer up to `AI_CONTEXT_MAX_RELATED_ROWS` (20). This is the one number. `RECORD_CONTEXT_RELATED_MAX_ROWS` in the service now reads it (ADR-0160 row 11: "the schema that bounds `limit` and the service that cuts the list read one number"). - `aiContextWhereFields(where)`: lists the fields a `where` names. The service and the lint rule both use it. - Near-miss aliases: `filter` → `where`, `sort` / `sortBy` → `orderBy`. The schema-level `guidance.filter` now points at the entry's `where`. **Render service (`packages/services/service-record-context`).** - The one capped child query is `where: { $and: [linkFilter, entry.where] }`, with `orderBy` and `limit: (entry.limit ?? cap) + 1`. A cut at `limit` is marked `truncated` and stated (`related_truncated`). Still one query. - Before that query, each `where` / `orderBy` field is judged. A field the child's published definition lacks leaves the section out with nothing stated (ADR point 20). A field the caller cannot query on drops the section with the one `not_visible` statement, and the field is never named (D3, point 19). Neither case refuses the call. - "Cannot query on" is the door's new optional `queryableFieldsOf` (the security service's `getQueryableFields`). Without that answer, the contract's fallback applies (`ISecurityService.getQueryableFields`): the field must be served, must not be withheld (`fieldVisibilityOf`), and must declare no `maskingRule`. A probe that throws drops the section with the statement. - Triage row 7154563681 on the card (a related child that *this caller* is not served is left out, not refused) is **not** in this PR. It was implemented and then reverted in `aa76b901b`, because turning it on flips the real-kernel parity pin in `packages/runtime` (landed in #37350, case titled "[today; ADR-0160 as amended says left out and stated]"), and `packages/runtime` is fenced here. Today's behaviour (the whole call is refused) is unchanged. It moves to a follow-up card. - The read set (`recordContextReadSet` / `planObjectsOf`) does not change (D4), and a test pins it with and without the keys. **Author surfaces (`packages/lint/src/validate-ai-context.ts`).** This extends the #37176 rule rather than adding a validator. A `where` or `orderBy` field the child does not define is reported as `ai-context-field-unknown` (warning) at save and by `os validate`, and the message says the list is left out. **Review delta S1/S2 (contract record 7177225249, on bb0107c).** - S1: `AI_CONTEXT_WHERE_MAX_DEPTH` (32) bounds `$and` / `$or` nesting in `where` at parse, refused at the list that would carry a condition past it. `aiContextWhereFields` walks to that same constant, so every field of a `where` that parsed is judged by the service and the lint rule. A test pins the bound: 32 parses and names the innermost field, 33 is refused once. - S2: an `orderBy` field the child's sortability projection calls unsortable (`resolveObjectSortability`: a formula, or `sortable: false`) is an author defect. The executor leaves the section out and states nothing, matching the "field the definition lacks" arm and ADR D1, instead of letting the door refuse the whole call with `INVALID_SORT`. `validateAiContext` reports it at save and by `os validate` as the new warning `ai-context-sort-field-unsortable`, with an `os explain` entry. HTTP door, read only (runtime is fenced): `recordContextMembers` → `bridge.query` → `callData('query')` → `protocol.findData` → `assertSortFieldsExist` refuses it with `400 INVALID_SORT` too (formula by the unmaterialized-type verdict, `sortable: false` by `assertSortFieldsAreOffered`), so before this fix both transports refused the call. After it, neither door is asked. **Liveness, example, generated.** `liveness/ai_context.json` gains `related.where`, `related.orderBy.{field,order}` and `related.limit`. The showcase `KIND_COVERAGE` pack `showcase_project_brief` now carries open tasks filtered by `status $ne done`, ordered by `due_date`, `limit: 10`. Regenerated: `dropped-refinements.baseline.json` (the `where` walk and the `orderBy` field check are refinements JSON Schema cannot carry; the build printed these rows), authorable-surface, api-surface, export-origins, declaration-map, reference docs, state-counts. ## Tests <details><summary>Local runs (final head bb0107c; the derived gate sweep re-run on bb0107c)</summary> - `pnpm --filter @objectstack/service-record-context test`: 2 files, 99 tests passed. The new describe block "a related list's where, orderBy and limit" has 18 cases. - `pnpm --filter @objectstack/spec exec vitest run src/ai/ai-context.zod.test.ts`: 23 passed (parse admits and refuses every bullet of What 1, and the nesting bound). - `pnpm --filter @objectstack/lint exec vitest run src/validate-ai-context.test.ts`: 18 passed. Whole package `pnpm --filter @objectstack/lint test`: 235 files, 9633 tests passed. - `pnpm --filter @objectstack/mcp exec vitest run src/mcp-record-context-tools.test.ts` (read-only run of the #37140 parity harness against the rebuilt service, at 16b86ef): 14 passed. CI Test Core at bb0107c runs it and the runtime real-kernel harness: green. - Typecheck: `@objectstack/spec`, `@objectstack/service-record-context` and `@objectstack/lint` all exit 0. - `pnpm --filter @objectstack/spec check:generated`: all 14 artifacts up to date. Ablations: five, each through `scripts/ablation-replace.mjs` with the blob restored to HEAD. Each suite imports `src`, so there is no dist step. 1. Skip `queryableAmong`: 6 cases red (the four unqueryable cases, the masking fallback, the throwing probe). 2. Drop the `$and` join: 4 cases red, including "no where reaches another root's rows". 3. S2, skip the executor's sortability check: 2 cases red (`sortable: false`, formula), the door's `INVALID_SORT` reached. 4. S1, drop the parse depth bound: 1 case red (the bound test). 5. S2, skip the lint verdict: 2 cases red (the rule test and its save-door family). A first attempt was refused by the tool as a no-op (ambiguous replacement) and re-run with a unique one. </details> ## Acceptance notes - **Parity on both transports with a `where` pack is not pinned here.** The #37140 harness is `packages/mcp/src/mcp-record-context-tools.test.ts`, which was fenced for this PR while sibling #37175 was in flight in `packages/runtime/**` and `packages/mcp/**`. Both doors hand the one executor a door whose `query` passes the options through (`recordContextMembers`, the stdio bridge's `query` already takes `orderBy`), and the existing harness runs green against this build. The pin is a follow-up for the report. - **Neither MCP door hands `queryableFieldsOf` yet**, so on real doors the contract fallback decides (masking-declared, hidden and withheld fields count as not queryable). A field that the security service's answer would exclude but the fallback admits (an agent acting on someone's behalf, or a computed field reading a hidden one) still reaches the engine guard, and the guard refuses the call. This is reported as a finding for the door lane. - Studio's `ContextPackRelatedEntries` does not offer the three keys yet; it preserves them on edit (note 7168171718). That goes to #37143. - `RecordContextNoteKind`'s doc line still says `related_truncated` is "cut at the row cap". It now also fires at `limit`. This is spec prose outside the claim's one spec file and is left as is. - A door whose own page cap is below `limit + 1` cuts silently. That is pre-existing for the cap too, and left as is. - `where` nesting is bounded (S1). No bound on the number of conditions or `$in` members was set; ADR row 11 allows one, but none was needed. ## Verification Two-minute check: `pnpm --filter @objectstack/service-record-context exec vitest run src/__tests__/record-context-tools.test.ts`. Expect it green, with the "a related list's where, orderBy and limit" block green. Read first: (1) `record-context-tools.ts`, the 4b block that judges `queried` fields before `relatedPlans.push`, and the `$and` query; (2) `ai-context.zod.ts`, `checkRelatedWhere`. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent db77cc4 commit da50177

23 files changed

Lines changed: 1092 additions & 52 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/service-record-context': minor
4+
'@objectstack/lint': minor
5+
---
6+
7+
feat(ai): a context pack's related list takes `where`, `orderBy` and `limit` (ADR-0160 second amendment)
8+
9+
Clause-②: yes
10+
Metadata-protocol: added
11+
12+
A `related` entry of an `ai_context` pack may now choose, order and cut the child rows it carries:
13+
14+
```yaml
15+
related:
16+
- object: policy_revision
17+
field: policy
18+
fields: [version, published_at]
19+
where: { is_current: { $eq: true } }
20+
orderBy: [{ field: sort_no, order: asc }]
21+
limit: 5
22+
```
23+
24+
- **`where`** is the object filter form on the child's own fields: `$eq`, `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$null` and `$exists` (`AI_CONTEXT_WHERE_OPERATORS`), joined by `$and` / `$or` nested at most `AI_CONTEXT_WHERE_MAX_DEPTH` (32) deep. A bare value reads as `$eq`. Refused at parse: any other operator (`$not`, `$between`, `$contains`, …), a dotted path or a condition on a lookup's target, a field-to-field comparand (`{ $field }`), a `$now` anchor, a formula, and a comparand that is one whole `{…}` placeholder (`{today}`, `{current_user_id}`, `${record_id}`, or an unknown one), and `$and` / `$or` nested deeper than the bound.
25+
- **`orderBy`** is `{ field, order }[]` (the sort node; `direction` is refused by name) on the child's own fields.
26+
- **`limit`** is a positive integer, at most `AI_CONTEXT_MAX_RELATED_ROWS` (20). Over it the pack is refused at parse, never lowered at call time. `RECORD_CONTEXT_RELATED_MAX_ROWS` in `@objectstack/service-record-context` is now this one number.
27+
28+
`get_record_context` reads such a list in the one capped child query, as the caller: the link filter and `where` joined with `$and`, ordered by `orderBy`, cut at `limit` (else the row cap), and a cut is stated in the notes. The filter grants nothing: a row the caller's row rules hide stays absent. A `where` or `orderBy` field the caller cannot query on (outside the security service's `getQueryableFields`; without that answer, any field that declares a `maskingRule`, or that the caller's schema hides or field-level security withholds) drops the whole section with the one "some material is not visible" statement, and the field is never named. A field the child does not define leaves the section out and states nothing; `os validate` and the save-time check report it as `ai-context-field-unknown`. So does an `orderBy` field the child does not offer as a sort (a formula, or a field that declares `sortable: false`, which the record doors refuse with `INVALID_SORT`): the section is left out and nothing is stated, and `os validate` and the save-time check report it as the new warning `ai-context-sort-field-unsortable`. The call's read set does not change. A door may hand the executor the caller's queryable fields through the new optional `RecordContextDoor.queryableFieldsOf`.
29+

‎content/docs/references/ai/ai-context.mdx‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Ai Context schema — AI Protocol reference
33
navTitle: Ai Context
4-
description: "Ai Context schemas of the ObjectStack AI Protocol: AiContext, AiContextBody, AiContextRelated — each property with its type, default and a TypeScript example."
4+
description: "Ai Context schemas of the ObjectStack AI Protocol: AiContext, AiContextBody and 2 more — each property with its type, default and a TypeScript example."
55
---
66

77
{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
@@ -13,8 +13,8 @@ description: "Ai Context schemas of the ObjectStack AI Protocol: AiContext, AiCo
1313
## TypeScript Usage
1414

1515
```typescript
16-
import { AiContextSchema, AiContextBodySchema, AiContextRelatedSchema } from '@objectstack/spec/ai';
17-
import type { AiContext, AiContextBody, AiContextRelated } from '@objectstack/spec/ai';
16+
import { AiContextSchema, AiContextBodySchema, AiContextRelatedSchema, AiContextRelatedWhereSchema } from '@objectstack/spec/ai';
17+
import type { AiContext, AiContextBody, AiContextRelated, AiContextRelatedWhere } from '@objectstack/spec/ai';
1818

1919
// Validate data
2020
const result = AiContextSchema.parse(data);
@@ -32,7 +32,7 @@ const result = AiContextSchema.parse(data);
3232
| **label** | `string` | ✅ | Pack display name — the header of the tool answer |
3333
| **object** | `string` | ✅ | The root object: a pack reads one record of it |
3434
| **fields** | `string[]` | optional | The root object's fields handed to the model, in order (at most 30). A lookup among them is answered with the name of the record it points at |
35-
| **related** | `{ object: string; field?: string; fields?: string[] }[]` | optional | Child lists that point at the record (at most 3), one level deep |
35+
| **related** | `{ object: string; field?: string; fields?: string[]; where?: any; … }[]` | optional | Child lists that point at the record (at most 3), one level deep |
3636
| **body** | `{ field: string }` | optional | The one long-text field read as the record's body |
3737
| **_lock** | `Enum<'none' \| 'no-overlay' \| 'no-delete' \| 'full'>` | optional | Item-level lock — controls overlay & delete (ADR-0010). |
3838
| **_lockReason** | `string` | optional | Human-readable reason shown when a write is refused by _lock. |
@@ -49,6 +49,9 @@ const result = AiContextSchema.parse(data);
4949
| **object** | `string` | ✅ | A child object with a reference field (lookup, master-detail, user or tree) that points at the pack's root object |
5050
| **field** | `string` | optional | The child's reference field that points at the root. Required when the child has several such fields; with one, it may be omitted. Resolved once, on the published definition |
5151
| **fields** | `string[]` | optional | The columns read for each row, in order (at most 10). A lookup among them is answered with the name of the record it points at. Omit to read the row's name only |
52+
| **where** | `any` | optional | Which child rows the list carries: a filter on the child's own fields, in the object filter form. A bare value is `$eq`; the operators are $eq, $ne, $in, $nin, $gt, $gte, $lt, $lte, $null, $exists, joined by $and / $or nested at most 32 deep. Comparands are literal values: no dotted path, no field-to-field comparand, no $now anchor and no `{…}` placeholder. Joined to the link with $and and read as the caller, so it grants nothing |
53+
| **orderBy** | `{ field: string; order?: Enum<'asc' \| 'desc'> }[]` | optional | The order of the rows: `{ field, order }[]` on the child's own fields, `order` `asc` (the default) or `desc`. Without it the rows come in the data engine's order. A field the child does not offer as a sort (it declares `sortable: false`, or is a formula) leaves the list out of every answer |
54+
| **limit** | `integer` | optional | The most rows the list carries (at most 20, the default). A list cut at it says so in the answer |
5255

5356
### Nested Shape: `AiContext.body`
5457

@@ -79,6 +82,16 @@ const result = AiContextSchema.parse(data);
7982
| **object** | `string` | ✅ | A child object with a reference field (lookup, master-detail, user or tree) that points at the pack's root object |
8083
| **field** | `string` | optional | The child's reference field that points at the root. Required when the child has several such fields; with one, it may be omitted. Resolved once, on the published definition |
8184
| **fields** | `string[]` | optional | The columns read for each row, in order (at most 10). A lookup among them is answered with the name of the record it points at. Omit to read the row's name only |
85+
| **where** | `any` | optional | Which child rows the list carries: a filter on the child's own fields, in the object filter form. A bare value is `$eq`; the operators are $eq, $ne, $in, $nin, $gt, $gte, $lt, $lte, $null, $exists, joined by $and / $or nested at most 32 deep. Comparands are literal values: no dotted path, no field-to-field comparand, no $now anchor and no `{…}` placeholder. Joined to the link with $and and read as the caller, so it grants nothing |
86+
| **orderBy** | `{ field: string; order?: Enum<'asc' \| 'desc'> }[]` | optional | The order of the rows: `{ field, order }[]` on the child's own fields, `order` `asc` (the default) or `desc`. Without it the rows come in the data engine's order. A field the child does not offer as a sort (it declares `sortable: false`, or is a formula) leaves the list out of every answer |
87+
| **limit** | `integer` | optional | The most rows the list carries (at most 20, the default). A list cut at it says so in the answer |
88+
89+
90+
---
91+
92+
## AiContextRelatedWhere
93+
94+
**Type:** `Record<string, any> & { $and?: any[]; $or?: any[]; $not?: any }`
8295

8396

8497
---

‎content/docs/references/index.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Protocol reference — every schema by module
33
navTitle: Protocol Reference
4-
description: Every schema published by @objectstack/spec — 1732 schemas across 14 protocol modules
4+
description: Every schema published by @objectstack/spec — 1733 schemas across 14 protocol modules
55
---
66

77
{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
@@ -20,7 +20,7 @@ counts are sums of the rows they head. Regenerate with
2020

2121
| Module | Pages | Schemas | Description |
2222
| :--- | ---: | ---: | :--- |
23-
| [AI Protocol](/docs/references/ai) | 16 | 99 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. |
23+
| [AI Protocol](/docs/references/ai) | 16 | 100 | Agents, tools, skills, RAG and knowledge sources, model registry, conversations. |
2424
| [API Protocol](/docs/references/api) | 37 | 524 | REST contracts, endpoints, routing, realtime, batch, discovery. |
2525
| [Automation Protocol](/docs/references/automation) | 16 | 82 | Flows and their nodes, approvals, ETL pipelines, webhooks, state machines, execution records. |
2626
| [Data Protocol](/docs/references/data) | 35 | 197 | Objects, fields, queries, filters, datasources and drivers — the ObjectQL layer. |
@@ -34,20 +34,20 @@ counts are sums of the rows they head. Regenerate with
3434
| [Studio Protocol](/docs/references/studio) | 3 | 35 | Studio designer metadata — the authoring surfaces for the protocols above. |
3535
| [System Protocol](/docs/references/system) | 40 | 298 | The runtime environment — logging, jobs, cache, metrics, notifications, i18n and compliance. |
3636
| [UI Protocol](/docs/references/ui) | 16 | 184 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. |
37-
| **Total** | **221** | **1732** | 14 protocol modules |
37+
| **Total** | **221** | **1733** | 14 protocol modules |
3838

3939
---
4040

4141
## AI Protocol
4242

43-
**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **16 pages, 99 schemas**
43+
**Source:** `packages/spec/src/ai/` · **Import:** `@objectstack/spec/ai` · **16 pages, 100 schemas**
4444

4545
Agents, tools, skills, RAG and knowledge sources, model registry, conversations.
4646

4747
| File | Schemas |
4848
| :--- | :--- |
4949
| [`agent.zod.ts`](/docs/references/ai/agent) | `AIModelConfig`, `Agent`, `StructuredOutputConfig`, `StructuredOutputFormat`, `TransformPipelineStep` |
50-
| [`ai-context.zod.ts`](/docs/references/ai/ai-context) | `AiContext`, `AiContextBody`, `AiContextRelated` |
50+
| [`ai-context.zod.ts`](/docs/references/ai/ai-context) | `AiContext`, `AiContextBody`, `AiContextRelated`, `AiContextRelatedWhere` |
5151
| [`build-progress.zod.ts`](/docs/references/ai/build-progress) | `BuildProgressFrame`, `BuildProgressPhase` |
5252
| [`conversation.zod.ts`](/docs/references/ai/conversation) | `CodeContent`, `ConversationAnalytics`, `ConversationContext`, `ConversationMessage`, `ConversationSession`, `ConversationSummary`, `FileContent`, `FunctionCall`, `ImageContent`, `MessageContent`, `MessageContentType`, `MessagePruningEvent`, `MessageRole`, `TextContent`, `TokenBudgetConfig`, `TokenBudgetStrategy`, `TokenUsageStats`, `ToolCall` |
5353
| [`dataset-tools.zod.ts`](/docs/references/ai/dataset-tools) | `DatasetNextStep`, `DatasetNextStepDecision`, `DatasetProvenance`, `DatasetTermCandidate`, `DatasetTermMatch`, `DatasetTermMatchedOn`, `DatasetToolCatalogDimension`, `DatasetToolCatalogEntry`, `DatasetToolCatalogMeasure`, `ListDatasetsInput`, `ListDatasetsOutput`, `QueryDatasetInput`, `QueryDatasetOutput` |

‎examples/app-showcase/src/ai/record-context.ai-context.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,31 @@ import type { AiContext } from '@objectstack/spec/ai';
88
*
99
* `showcase_project_brief` is the full shape: the project's own fields (one
1010
* of them a lookup, so the account's display name is read through it), and
11-
* its tasks as a related list capped by the service. `showcase_task_notes`
11+
* its open tasks as a related list: filtered (`where`, on the task's own
12+
* fields), ordered by due date and cut at ten (`limit`), all inside the one
13+
* child query read as the caller. `showcase_task_notes`
1214
* adds a body: a long `notes` text comes back whole, or as an outline whose
1315
* sections are read one at a time by anchor.
1416
*
1517
* A pack never widens a read: a field the caller may not read is left out
16-
* and the answer says so, and a related object the caller may not read
17-
* refuses the whole call.
18+
* and the answer says so, a related object the caller may not read
19+
* refuses the whole call, and a `where` grants nothing — the caller's row
20+
* rules still decide which rows arrive.
1821
*/
1922
export const ShowcaseProjectBriefContext: AiContext = {
2023
name: 'showcase_project_brief',
2124
label: 'Project brief',
2225
object: 'showcase_project',
2326
fields: ['name', 'account', 'status', 'health', 'budget', 'spent', 'end_date', 'owner'],
2427
related: [
25-
{ object: 'showcase_task', field: 'project', fields: ['title', 'status', 'priority', 'due_date', 'assignee'] },
28+
{
29+
object: 'showcase_task',
30+
field: 'project',
31+
fields: ['title', 'status', 'priority', 'due_date', 'assignee'],
32+
where: { status: { $ne: 'done' } },
33+
orderBy: [{ field: 'due_date', order: 'asc' }],
34+
limit: 10,
35+
},
2636
],
2737
};
2838

‎examples/app-showcase/src/coverage.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export const KIND_COVERAGE: Record<MetadataType, KindCoverage> = {
217217
status: 'demonstrated',
218218
files: ['src/ai/record-context.ai-context.ts'],
219219
notes:
220-
'Two context packs (ADR-0160): a project brief (own fields, a lookup read through to the account, tasks as a related list) and a task with its notes as a body (whole, or an outline read by anchor). Read by `get_record_context` over MCP; the service is wired in objectstack.config.ts plugins.',
220+
'Two context packs (ADR-0160): a project brief (own fields, a lookup read through to the account, its open tasks as a related list, filtered, ordered by due date and cut by `where` / `orderBy` / `limit`) and a task with its notes as a body (whole, or an outline read by anchor). Read by `get_record_context` over MCP; the service is wired in objectstack.config.ts plugins.',
221221
},
222222
skill: {
223223
status: 'waived',

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ export {
384384
AI_CONTEXT_FIELD_UNKNOWN,
385385
AI_CONTEXT_RELATED_LINK_UNKNOWN,
386386
AI_CONTEXT_BODY_NOT_LONG_TEXT,
387+
AI_CONTEXT_SORT_FIELD_UNSORTABLE,
387388
} from './validate-ai-context.js';
388389
export type { AiContextFinding, AiContextSeverity } from './validate-ai-context.js';
389390

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6060,6 +6060,19 @@ const AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION: RuleExplanation = {
60606060
],
60616061
};
60626062

6063+
const AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION: RuleExplanation = {
6064+
rule: 'ai-context-sort-field-unsortable',
6065+
covers: 'which fields may order a related list of a context pack',
6066+
paragraphs: [
6067+
'A related list\'s `orderBy` runs in the one query that reads the list. A field the object does not offer as ' +
6068+
'a sort, a formula (computed on read, no column to order by) or a field whose author declared ' +
6069+
'`sortable: false`, is refused by the record doors (`INVALID_SORT`), so `get_record_context` leaves the whole ' +
6070+
'list out of every answer rather than read it in another order.',
6071+
'Order the list by a field that is offered as a sort, or remove the field from `orderBy`.',
6072+
AI_CONTEXT_PACK_SILENCE,
6073+
],
6074+
};
6075+
60636076
// ── Assignment rules (`validate-assignment-rules.ts`) ──
60646077

60656078
const ASSIGNMENT_RULE_USER_TARGET_EXPLANATION: RuleExplanation = {
@@ -7049,6 +7062,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
70497062
[AI_CONTEXT_FIELD_UNKNOWN_EXPLANATION.rule]: AI_CONTEXT_FIELD_UNKNOWN_EXPLANATION,
70507063
[AI_CONTEXT_RELATED_LINK_UNKNOWN_EXPLANATION.rule]: AI_CONTEXT_RELATED_LINK_UNKNOWN_EXPLANATION,
70517064
[AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION.rule]: AI_CONTEXT_BODY_NOT_LONG_TEXT_EXPLANATION,
7065+
[AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION.rule]: AI_CONTEXT_SORT_FIELD_UNSORTABLE_EXPLANATION,
70527066
[ASSIGNMENT_RULE_USER_TARGET_EXPLANATION.rule]: ASSIGNMENT_RULE_USER_TARGET_EXPLANATION,
70537067
[ASSIGNMENT_RULE_QUEUE_UNSTAFFED_EXPLANATION.rule]: ASSIGNMENT_RULE_QUEUE_UNSTAFFED_EXPLANATION,
70547068
[SEED_VALUE_OUTSIDE_STATE_MACHINE_EXPLANATION.rule]: SEED_VALUE_OUTSIDE_STATE_MACHINE_EXPLANATION,

0 commit comments

Comments
 (0)