Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .changeset/34770-query-skill-router.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
'@objectstack/skills': patch
---

docs(skills): the objectstack-query entry file becomes a router

Clause-②: no
Metadata-protocol: none

`skills/objectstack-query/SKILL.md` goes from 18.5 KB to 9.0 KB (429 lines to 154). It now holds seven things: four first checks (the installed version wins over the `compatibility` line; read the object's fields, declared or platform-injected, its relation fields and its `searchableFields`; read the contract and never recall a key or an operator; a query in code is judged only when it runs, query metadata by `os validate`), the calling convention as one type-checked block (a `find`, a system read, an `aggregate`) with the closed-set rule, the operator names as one list, seven traps, `## Full-Text Search`, the removed-keys table, and a table that says where to go for the rest. No rule's teaching changes. No text moved between files: what left the entry was cut, and this entry says what now answers it. The three rules files (`rules/filters.md`, `rules/aggregation.md`, `rules/pagination.md`) keep their text; `rules/filters.md` changes two pointers (below).

**What the entry keeps.** The seven traps, each a query that is accepted and answers, wrong or slow, with no error: a read with no `context` runs as whatever identity the caller carried, so org-scoping returns fewer rows; `$contains`, `$notContains`, `$startsWith` and `$endsWith` compare case-sensitively and typed text wants `$icontains`, and `$like` / `$ilike` match the whole value, so a pattern with no `%` is an exact match; a column with no value fails every ordering test, in `where`, a measure's `filter` and `having` alike, and `$null` misses a text field saved blank where `$empty` does not; `expand` reads the foreign key off each row, so a projection that drops it returns no related data, a key that is not a relation field is skipped, and of a nested value only `fields`, `where` and a further `expand` take effect; a page needs `orderBy` and a keyset `where` must match the sort key and its direction; `where` scopes rows before grouping, `having` filters groups and a measure's `filter` scopes that measure, with the rule for which side buckets a date under a non-UTC `timezone`; a date computed at module load freezes into the built artifact, with the tokens to write in its place, `{current_iso_week}` as a text week key, and the now-anchored comparand `{ $now: true, addDays }`. The search section keeps the bare-string form with `searchFields`, the term and option-label matching, the narrowing rule, that `count` and `aggregate` take the same pair, that `search` never traverses (a dotted path is refused at the protocol door and when it stands alone, and listed beside real fields the engine drops it silently; mirror the related title into a stored field and name it in `searchFields`), and the six knobs of the object form that validate and do nothing. The removed-keys table keeps all six rows. Traps 3, 6 and 7 state inline what the old entry left to the rules files (the `$or` with `$null` beside an ordering test, which side buckets a date under a `timezone`, the tokens and the week key); the rules files still hold the detail.

**What left, and what answers it now.**

- The table of each engine method's legal option keys and the `top` / `filter` alias folding: the contract, `node_modules/@objectstack/spec/src/data/data-engine.zod.ts` (`EngineQueryOptionsSchema`, `EngineAggregateOptionsSchema`, `EngineCountOptionsSchema`). The six driver passthrough keys (`transaction`, `tenantId`, `tenantIds`, `timezone`, `bypassTenantAudit`, `preserveAudit`) with the reason `count` and `aggregate` refuse them: that file does not hold them; the driver options contract does (`node_modules/@objectstack/spec/src/data/driver.zod.ts`), and which method takes them is the engine's own list. A key outside a method's set is refused by name, and the refusal prints that method's legal keys, the passthrough ones included. The entry states the closed-set rule without the three schema names; its first check 3 names the file. The old table's `count` row listed `context` and `where` only; the contract also takes `search` and `searchFields` there, and the entry now says so.
- From the execution-context section: that a context carrying no user, position or permission set is refused `403 PERMISSION_DENIED`, which is loud when hit, and that a write takes its context only as the trailing argument, which is the contract (`node_modules/@objectstack/spec/src/contracts/data-engine.ts`). Trap 1 keeps the silent half: fewer rows, with no error.
- From the removed-keys section: the second alternative for `array_agg` / `string_agg` (materialise the roll-up as a stored field), and the sentence dating the removal to `@objectstack/spec` 17. objectstack-upgrade, which the entry names, holds the register.
- The operator tables (purpose, SQL equivalent, value types), the implicit-equality and logical-operator examples, and the notes under the null and existence operators (a view filter's `is_empty` / `is_not_empty` lowers to `$empty`; a face that judges by declared type refuses `$empty` on a column it holds no declaration for): the contract, `node_modules/@objectstack/spec/src/data/filter.zod.ts`, where each operator's `.describe()` text says what it does. `rules/filters.md` § Operator Reference has one example of each operator, and https://objectstack.ai/docs/protocol/objectql/query-syntax has the tables.
- The relation-filter paragraph (the driver capability it needs, the three-relationship limit, the 1000-id cap, the caller's permissions at every hop, the two-step route) and the cross-field paragraph: `rules/filters.md` § Relation Filters, § Field References and § Now-Anchored Comparands, which already held all of it. The entry keeps the shape of a relation condition in the removed-keys row for `query.joins`.
- The "which filter dialect" table: the routing row for objectstack-ui, which names `VIEW_FILTER_OPERATORS`.
- The sorting rules (array order is sort priority, `order` defaults to `'asc'`), the offset-paging block and the "Pagination Pattern for APIs" block: `rules/pagination.md` (its § Sorting with Pagination also says why an unsorted page is not stable) and the contract. Index advice is the routing row for objectstack-data.
- The aggregation call-shape block and the "Dashboard Aggregation Pattern" block: the entry's one block shows a grouped call with a per-measure `filter`; the rest is `rules/aggregation.md` § Filtered Aggregation. Dashboards and reports are the routing row for objectstack-ui.
- From the expand section: that the engine resolves an expand with batched `$in` reads, and the nested-expand example. Nothing an author writes depends on the first; trap 4 states the three-level limit and the contract carries the shape. The old rule said an `expand` key must be a `lookup` or `master_detail` field; the engine resolves `user` and `tree` fields too, and trap 4 names all four.
- From the search section: the comment block that showed the expanded filter, the note that the protocol's `$searchFields` and the object form's `search.fields` spell the same narrowing (the entry says to write `searchFields`), the description of the default searchable set (name or title, short-text fields, fields marked `searchable: true`), the REST refusal of a name outside that set (`400 INVALID_FIELD`, loud when hit), and that `count` and `aggregate` apply the pair before counting or grouping (the contract's docblocks on those two option sets): the published page above, § Full-Text Search, and objectstack-data's Search Fields reference (`searchableFields`), which the entry names.
- The "Cross-Object Queries: Which Tool to Use?" table: trap 4 (`expand` to display; page or sort related records by querying the related object), the search section (the stored mirror), `rules/filters.md` § Relation Filters (filter by a lookup target's column, and a parent by its children in two steps) and the routing row for objectstack-ui (analytics across objects).
- The "Quick Reference" list: the routing table. The "Verify your work" and "References" sections: first checks 4 and 3. The `os build` spelling is objectstack-platform's (its "Verify your work" reference), a scaffolded project's `npm run validate` alias is in that project's own `package.json`, and the sentence on a dashboard widget whose dataset does not resolve is objectstack-ui's (its dashboard rules).
- The routing line to objectstack-ask: the frontmatter description, which is unchanged.

**`rules/filters.md`.** Two pointers named sections the entry no longer has. The line under the operator list sent the reader to the entry's "Filter Operators" section for purpose, SQL equivalent and case sensitivity; it now names the contract (`data/filter.zod.ts`) for what each operator does and the entry's trap 2 for case sensitivity. The sibling-keys note no longer points at the entry's "Logical Operators" section. The file is 21 bytes smaller and nothing else in it changed.

**Anchors that no longer exist in `SKILL.md`.** `#calling-convention--object-is-the-first-argument`, `#which-filter-dialect`, `#execution-context-context`, `#removed-keys--live-replacement`, `#quick-reference--detailed-rules`, `#filter-operators`, `#implicit-equality-shorthand`, `#comparison-operators`, `#set--range-operators`, `#string-operators`, `#null--existence-operators`, `#logical-operators`, `#filtering-by-a-related-record`, `#cross-field-comparisons`, `#sorting`, `#pagination`, `#aggregation`, `#expand-related-records`, `#common-patterns`, `#cross-object-queries-which-tool-to-use`, `#pagination-pattern-for-apis`, `#dashboard-aggregation-pattern`, `#verify-your-work`, `#references`. The new ones are `#first-checks`, `#calling-convention`, `#traps`, `#removed-keys` and `#where-to-go`; the title's anchor and `#full-text-search` are unchanged. No file in this repository linked an anchor of the old entry.
32 changes: 30 additions & 2 deletions scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,28 @@ export const CEILINGS = new Map([
// 「发布版 skills/objectstack-pm-dispatch 删」). A row for a file the walk cannot
// read is red, not a skip (#4690), so the rows go with the files; the bundle
// total drops by the two ceilings, which is the ratchet's ordinary direction.
['skills/objectstack-query/SKILL.md', 4607], // -17 (was 5569), then -5 A2′ (was 5552), then -940 to the measurement (was 5547)
// 4607 -> 2240 (#34770): the entry becomes a router. It keeps four first checks, the calling
// convention as one type-checked block (a find, a system read, an aggregate) with the
// closed-set rule and the operator names as one list, seven traps (each is accepted and
// answers, wrong or slow, with no error), `## Full-Text Search` (no rules file holds it and
// objectstack-ui names the section), the removal table the three rules files point at, and a
// routing table. Nothing MOVED: what left is CUT behind what already says it, the three
// rules files (rows below), the contract (`data/filter.zod.ts` describes each operator,
// `data/data-engine.zod.ts` holds each method's option keys, and the engine's refusal of an
// unknown key prints the legal ones) or the published query-syntax page. No row rises and
// no row is added; `rules/filters.md` falls 5 with it (row below). The router was first
// measured at 8989 bytes; the parity round then put back, paid in the entry, the
// `$icontains` example of the case-sensitivity trap and the stored-mirror prescription for a
// search by a related record's title. The review round then added, paid in the entry, that
// `$like` / `$ilike` match the whole value (8984 -> 8987 bytes, the same 2240 tokens), and
// the second review round, also paid in the entry, that the engine silently drops a dotted
// search field listed beside real ones (8987 -> 8984). The file is 18455 bytes (18428
// priced) -> 8984 (8957 priced) -> 2240 tokens, pinned AT the measurement; with the filters
// row the sum of all ceilings falls by 2372.
// Authority: the ruling of record that orders the entry file down to router size, decision
// record #34691 S3 = A.
// ceil(($(wc -c < skills/objectstack-query/SKILL.md) - 27) / 4) == ceil(8957 / 4)
['skills/objectstack-query/SKILL.md', 2240], // -17 (was 5569), then -5 A2′ (was 5552), then -940 to the measurement (was 5547), then -2367 (was 4607)
// 25125 -> 25143: the CRM UI Blueprint — the catalog's module-completeness
// list, and the only place an agent is told what a finished module contains —
// priced `src/views/**`, `src/apps/**`, dashboards and reports but never the
Expand Down Expand Up @@ -1912,7 +1933,14 @@ export const CEILINGS = new Map([
// bytes: 9876 landed -> 10382, +506 -> 127 tokens, the row's 4 tokens of
// headroom absorbed, ceiling +123, pinned AT the measurement.
// ceil($(wc -c < skills/objectstack-query/rules/filters.md) / 4) == ceil(10382 / 4)
['skills/objectstack-query/rules/filters.md', 2596],
// 2596 -> 2591 (#34770): LOWERED. Two pointers named SKILL.md sections the router no longer
// has. The line under the operator list said "Purpose, SQL equivalent, case sensitivity:
// SKILL.md, Filter Operators"; it now names the contract (`data/filter.zod.ts`) for what
// each operator does and the entry's trap 2 for case sensitivity. The sibling-keys note
// drops its "(SKILL.md, Logical Operators)" parenthesis. No teaching moved in or out:
// 10382 -> 10361 bytes (-21); the ceiling follows the file down to the measurement.
// ceil($(wc -c < skills/objectstack-query/rules/filters.md) / 4) == ceil(10361 / 4)
['skills/objectstack-query/rules/filters.md', 2591],
['skills/objectstack-query/rules/pagination.md', 1289], // -93 to the measurement (was 1382)

// objectstack-ui `rules/` — the five files the #14296 item 1 split created.
Expand Down
Loading
Loading