Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
8096ec9
docs(skills): teach the {current_iso_week} period key in the query fi…
claude Nov 20, 2026
47fe010
chore(changeset): patch note for the query skill's period-key text
claude Nov 20, 2026
03b9383
docs(skills): data-hooks teaches the hook and job js-body compile ref…
claude Nov 20, 2026
1c7ceba
docs(skills): a master_detail child is a record-page body table by de…
claude Nov 20, 2026
b3b374b
docs(skills): a seed record with a blank key field is refused at load…
claude Nov 20, 2026
20c06ad
docs(skills): a saved seed must name an existing object (seeds.md)
claude Nov 20, 2026
1ea279a
docs(skills): shorten the record-page eval text
claude Nov 20, 2026
0c9f76e
docs(skills): the regex-pattern warning says what main says; eval cas…
claude Nov 20, 2026
782485e
Merge the query-filter period-key teaching (filters.md) into the skil…
claude Nov 20, 2026
d6849ff
Merge the data-hooks compile-refusal teaching into the skills docs fold
claude Nov 20, 2026
26380c1
Merge the two seed refusals (seeds.md) into the skills docs fold
claude Nov 20, 2026
201463a
Merge the master_detail body-table teaching into the skills docs fold
claude Nov 20, 2026
0c80caa
chore(changeset): one patch note for the folded skills text
claude Nov 20, 2026
ee231bb
docs(skills): eval case 34 no longer forbids the spellings its own an…
claude Nov 20, 2026
5e17107
Merge main (f44758b21) into the skills docs fold
claude Nov 20, 2026
370465f
docs(skills): the body table is drawn after the open field sections
claude Nov 20, 2026
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
35 changes: 35 additions & 0 deletions .changeset/35496-skills-teach-five-landed-behaviours.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
'@objectstack/skills': patch
---

docs(skills): the data, query and ui skills teach five landed refusals and behaviours

Clause-②: no
Metadata-protocol: none

Five pieces of published skill text, one per landed behaviour the skills did not teach. Each comes with its own eval case.

**The `{current_iso_week}` period key.** objectstack-query's `rules/filters.md`, section "Date Macros", now names the period key beside the date macros and the session tokens. `{current_iso_week}` (or `${current_iso_week}`) resolves to today's ISO week key, `YYYY-Www`, in the workspace time zone: Monday-start weeks, the ISO week-year at year edges. It is text, for a text field that stores week keys. A `date`, `datetime` or `time` field refuses it with `INVALID_FILTER` / 400, as it refuses the literal key; a date dashboard filter's `defaultValue` and `calendar.initialDate` refuse it too. On a date field write `{current_week_start}` / `{current_week_end}`. The section also names `resolveFilterPlaceholders()` as the client resolver for all three vocabularies and `isKnownFilterToken()` as the one spelling check. One eval case covers the text-field / date-field split.

**A hook or job `js` body that does not compile is refused.** objectstack-data's `references/data-hooks.md`, "Sandbox restrictions":

- A new bullet says a `js` source is compiled, without being run, inside the `(async (ctx) => { … })` wrapper the runtime runs it in, where `ctx` is already declared. `const ctx = ctx.input || {};` (or `let ctx`, one name declared twice, any syntax error) is `hook-body-does-not-compile`: an error from `os validate`, `os build`, `os lint` and a runtime hook save (`422 INVALID_METADATA`), naming the hook, the `SyntaxError` and its line. The fix is to use `ctx` as it is or rename the local (`const input = ctx.input || {};`). A job's `js` body runs in the same wrapper and is `job-body-does-not-compile` from the three commands. A regular-expression pattern the checking engine refuses is a warning: the runtime may accept it.
- Six restatements in the same file were removed to pay for the new text; the file is four lines shorter and no larger in tokens than before.

`evals/hooks-security-seeds-datasources.json` gains one case on the refusal and its fix.

**A seed record with a blank key field is refused at load, and a saved seed naming an unknown object is refused 422.** objectstack-data's `references/seeds.md`:

- "`externalId` selection" says every record carries a value for each `externalId` field (each field of a list, or `name` when the seed names none), and that a record leaving one blank (no value, `null` or `''`; whitespace is a value) is refused at load in every mode: the load result names the object, the record index, the field and the fix, and the other records still load. The `externalId` row of the field table points at it.
- The note under the field table says a `seed` saved at runtime names its `object` itself, and that one resolving to nothing is refused with `422 INVALID_METADATA` at `object` ("which is not defined"). The fix is the object's full name (`crm_lead`, not `lead`) or creating the object first: a draft of it is enough for a draft seed, a live seed needs it published. The `object` row points at the note.
- Three restatements in the same file were removed to pay for part of the new text: the `columns` row's shape literal, the one-row best-practices table (now a sentence) and the second telling of what a refused seed value leaves behind.

`evals/hooks-security-seeds-datasources.json` gains one case on each refusal.

**A `master_detail` child is a record-page body table by default.** The record page draws a `master_detail` child as a full-width body table whenever its FK declares no `relatedList`. The skills still tied that to `inlineEdit`. They now teach the rule the runtime applies.

- objectstack-data's `rules/relationships.md`, "Detail-page related lists": a `master_detail` child is a body table by default and a `lookup` child is a panel. `inlineEdit` governs entry in the parent's form only. The `relatedList` list reads `'primary'` (the `master_detail` default), `true` (the `lookup` default) and `false`. The example no longer writes `inlineEdit` and `relatedList: 'primary'` on a `master_detail` field to get the table.
- objectstack-ui's `rules/record-page.md`, step 2: the same defaults, the body table is drawn after the open field sections (it used to say after the first one), and "put the tasks first" is the parent's `relatedLists`. The example field drops its `relatedList: 'primary'`.
- objectstack-ui's `evals/record-page.json`, case 1: the expected answer adds no placement flag to a `master_detail` field, and an answer that authors `inlineEdit` fails the case. `evals/README.md` follows.

Both of those rules files are shorter than before, and neither one's token ceiling moves.
35 changes: 33 additions & 2 deletions scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,21 @@ export const CEILINGS = new Map([
// paragraph (home: SKILL.md, String Operators) and a second `$between` Date
// example (home: the operator table's `$between` row). Arithmetic in bytes:
// 9925 -> 9892 (-33 net) -> ceil(9892 / 4) = 2473; headroom 0 tokens.
['skills/objectstack-query/rules/filters.md', 2473],
// 2473 -> 2596 (#35496): the `{current_iso_week}` period key in § Date Macros
// (its `YYYY-Www` value, the text-field-only rule, the `INVALID_FILTER` / 400
// refusal on date / datetime / time fields, the two date-only surfaces that
// refuse it) and the client resolver that covers all three vocabularies.
// Raise path the standing ruling 「A:先削重复,余额按实测提高」 (ruling record
// 6513306068, letter B). PAID DOWN FIRST — five restatements cut in the same
// section: the wrapper regex beside the prose that already says both
// spellings parse, the code comment repeating the sentence above its block,
// the second date-macro comparison in the session-token example (the week key
// takes its place), the two per-vocabulary predicates (one predicate answers
// for all three) and the driver sentence's list of value kinds. Arithmetic in
// 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],
['skills/objectstack-query/rules/pagination.md', 1382],

// objectstack-ui `rules/` — the five files the #14296 item 1 split created.
Expand Down Expand Up @@ -1846,7 +1860,24 @@ export const CEILINGS = new Map([
// 6984 -> 6570 after the cuts (-414); the teaching nets +466 -> 7036 ->
// ceil(7036 / 4) = 1759; headroom was 0, so the ceiling moves +13, the
// measured remainder only. Pinned AT the measurement.
['skills/objectstack-data/references/seeds.md', 1759],
// 1759 -> 1812: `### externalId selection` says every record carries a value
// for each `externalId` field and that a blank one is refused at load, and the
// `externalId` row points at it. Raise path the standing ruling
// 「A:先削重复,余额按实测提高」 (ruling record 6513306068, letter B). PAID DOWN
// FIRST — restatement cut in the same file: the `columns` row's shape literal
// (its own section shows it), the one-row best-practices table (a sentence
// now) and the second telling of what a refused seed value leaves behind.
// Arithmetic in bytes: 7033 -> 6905 after the cuts (-128); the teaching nets
// +340 -> 7245 -> ceil(7245 / 4) = 1812; headroom was 0, so the ceiling moves
// +53, the measured remainder only. Pinned AT the measurement.
// 1812 -> 1898: the note under the field table says a `seed` saved at runtime
// names an object that exists or the save answers `422 INVALID_METADATA` at
// `object`, and that a draft object is enough for a draft seed; the `object`
// row points at it in place of "never write manually". Same raise path and
// the same paydown as the step above (one PR, the cuts are its deletion):
// 7245 -> 7590 bytes (+345) -> ceil(7590 / 4) = 1898; headroom was 0, so the
// ceiling moves +86, the measured remainder only. Pinned AT the measurement.
['skills/objectstack-data/references/seeds.md', 1898],
// 1351 -> 1343: the body-pin values left the count (#31115, ruling B; see
// BODY_PIN_REPIN); the file's count fell by the same 8, headroom unchanged.
['skills/objectstack-platform/references/bootstrap.md', 1343],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
"must_not_contain": []
}
},
{
"id": 34,
"prompt": "Our `sales_team` seed is `upsert`, keyed on `externalId: 'code'`. Two of its ten records have no `code` yet; we want to load all ten now and fill those two codes in later. Write the seed.",
"expected_output": "Redirects: the two records cannot load without a `code`. Every record carries a value for each `externalId` field, and a record that leaves one blank (no value, `null` or `''`) is refused at load: the load result names the object, the record index, the blank field and the fix, and the other eight records still load. So the answer gives those two records a real `code` now (`defineSeed(SalesTeam, { externalId: 'code', mode: 'upsert', records })` with ten codes), or keys the seed on a field every record carries. It does not write `code: ''` or `code: null`, does not pad the key with whitespace to pass, and does not switch the mode: `ignore`, `upsert` and `update` all refuse the record.",
"files": [],
"assertions": {
"must_contain": ["defineSeed", "externalId", "refused"],
"must_not_contain": []
}
},
{
"id": 35,
"prompt": "In the running app I saved a draft `seed` item with `object: 'lead'` and three records, through the metadata save. The save answered 422. Our lead object is `crm_lead`, still a draft in the same package. What is wrong, and what do I save instead?",
"expected_output": "The seed names an object that does not exist: the save door refuses a `seed` whose `object` resolves to nothing with `422 INVALID_METADATA`, one finding at `object` saying the seed loads its records into object 'lead', which is not defined, so publishing it would load no record. The fix is the object's full name: save the seed with `object: 'crm_lead'`. The draft `crm_lead` is enough for a draft seed, so nothing has to be published first; a live (published) seed needs the object published. Does not create a second `lead` object to satisfy the save and does not retry the same body.",
"files": [],
"assertions": {
"must_contain": ["422", "crm_lead", "not defined"],
"must_not_contain": []
}
},
{
"id": 5,
"prompt": "Finance may edit a contract's legal terms (`governing_law`, `liability_cap`) while it is a draft, not once approved, signing or active; legal still edits them.",
Expand Down Expand Up @@ -326,6 +346,16 @@
"amount_paid: 2000"
]
}
},
{
"id": 33,
"prompt": "`os validate` reports an error on this `beforeInsert` hook on `lead`, and I cannot see why: `body: { language: 'js', source: \"const ctx = ctx.input || {}; if (!ctx.status) ctx.status = 'new';\", capabilities: [] }`. What is wrong, and what should the source be?",
"expected_output": "The `js` source is compiled inside the wrapper the runtime runs it in, `(async (ctx) => { … })`, where `ctx` is already the parameter: `const ctx = …` declares it a second time, a SyntaxError before any statement runs. The finding is `hook-body-does-not-compile`, an error from `os validate`, `os build` and `os lint`, and a runtime save of the hook is refused with `422 INVALID_METADATA`. Fix: use `ctx` as it is (`if (!ctx.input.status) ctx.input.status = 'new';`) or give the local another name (`const input = ctx.input || {}; if (!input.status) input.status = 'new';`). Does not suppress the rule, and does not move the logic to a deprecated `handler`.",
"files": [],
"assertions": {
"must_contain": ["hook-body-does-not-compile", "input.status"],
"must_not_contain": []
}
}
]
}
34 changes: 15 additions & 19 deletions skills/objectstack-data/references/data-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ const myHook = defineHook({

### Key Properties Explained

#### `body` — Implementation

A `source` of statements against `ctx`; a throw aborts the write
([Sandboxed Hook Bodies](#sandboxed-hook-bodies-body--what-the-sandbox-ctx-can-call)).

#### `condition` — Declarative Filtering

Skip the hook if the condition is false. Author it as a **CEL
Expand Down Expand Up @@ -155,9 +150,7 @@ made total over the object's **declared** fields (`null` when a declared field i
in neither). So:

- Reference **any** declared field, not just the ones this update touches —
`record.done == true` works on an update that only sets `status`. (This is
unlike `ctx.input` / `ctx.result` inside the body, which stay partial — see
Gotcha 1.)
`record.done == true` works on an update that only sets `status`.
- `record` describes the record's **state**, not the diff. `record.done == true`
fires on every update of an already-done record, not only on the update that
set it. **For the transition, compare against `previous`**:
Expand Down Expand Up @@ -344,6 +337,15 @@ The body runs in an isolated QuickJS VM, **not** Node:
a name bound at module scope, e.g. a `const slugify = …` helper sitting next to
the hook. A `body` must be **self-contained**: inline the helper, or keep that
hook as a bundled (deprecated) `handler`.
- **Refused when it does not compile:** a `js` source is compiled, unrun, inside
its `(async (ctx) => { … })` wrapper, where `ctx` is already declared. So
`const ctx = ctx.input || {};` (or `let ctx`, one name declared twice, any
syntax error) is `hook-body-does-not-compile`: an **error** from `os validate`,
`os build`, `os lint` and a runtime hook save (`422 INVALID_METADATA`), naming
the hook, the `SyntaxError` and its line. Fix: use `ctx` as it is, or rename
the local (`const input = ctx.input || {};`). A job's `js` body runs in the
same wrapper: `job-body-does-not-compile`, from the three commands. A regex
pattern the checking engine refuses is a warning: the runtime may accept it.

> **A deadline stamped from an hours table is calendar hours** — nights, weekends and
> holidays count. Name it `*_CALENDAR_HOURS` (`SLA_CALENDAR_HOURS`, or its camelCase)
Expand Down Expand Up @@ -450,8 +452,7 @@ interface HookContext {
// Execution context
session?: {
userId?: string;
organizationId?: string; // Active org — the single blessed name. Matches the
// `organization_id` column + `current_user.organizationId` (RLS).
organizationId?: string; // Active org — the single blessed name.
// The former `tenantId` alias was removed in v16.
// Privilege is judged by the security service,
// never by a session claim.
Expand Down Expand Up @@ -660,11 +661,8 @@ const cascadeAccountUpdate = defineHook({

A `body` cannot do this: it writes back only `ctx.input`, and its `ctx.result` is a snapshot.

> For **static** field masking (a field is always hidden/masked for a permission
> set or position), prefer declarative **field-level metadata** (secret/masked
> fields) — it applies on every read path automatically. Use an `afterFind` hook
> only for masking that depends on runtime logic the field metadata can't
> express.
> Static masking is declarative **field-level metadata** (secret/masked fields);
> an `afterFind` hook is only for masking that depends on runtime logic.

```typescript
const maskSensitiveData = defineHook({
Expand All @@ -674,7 +672,6 @@ const maskSensitiveData = defineHook({
handler: async (ctx) => {
// Exempt the engine's own elevated reads (`isSystem`) — internal writes
// and self-reads must see the real values.
// ⚠️ Never a session claim (`ctx.session.roles` is gone, ctx table above).
const isElevated = ctx.session?.isSystem === true;

if (!isElevated) {
Expand Down Expand Up @@ -777,9 +774,8 @@ the layout both real hook modules in the repo use.

## Best Practices

✅ **DO** — use `before*` for validation and `after*` for side effects; set
`async: true` for non-critical background work; go through `ctx.api` for
cross-object operations; refuse a business rule by a
✅ **DO** — set `async: true` for non-critical background work; go through
`ctx.api` for cross-object operations; refuse a business rule by a
[declared code](#declared-refusals-refusals); test hooks in isolation.

❌ **DON'T** — do expensive work in `before*` (it blocks the transaction); write
Expand Down
24 changes: 16 additions & 8 deletions skills/objectstack-data/references/seeds.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export const SeedData = [statusSeed, categorySeed];

| Field | Default | Purpose |
|:------|:--------|:--------|
| `object` | derived | Auto-set from `objectDef.name` — never write manually |
| `externalId` | `'name'` | Stable business key (or field list) every mode matches on |
| `object` | derived | Auto-set from `objectDef.name`; hand-written only in a runtime save (below) |
| `externalId` | `'name'` | Stable business key (or field list) every mode matches on; required in every record (below) |
| `mode` | `'ignore'` | Import strategy (see below) |
| `columns` | — | Per-column write policy, keyed by field: `{ FIELD: { applyOn: 'create' } }` (below) |
| `columns` | — | Per-column write policy, keyed by field (below) |
| `env` | `['prod','dev','test']` | Environments where the seed loads |
| `locale` | — (every locale) | BCP-47 tags it loads for; a locale no set of the object names gets none |
| `fallback` | — | `true` on ONE `locale` set per object: also loads for a locale no set names |
Expand All @@ -56,6 +56,12 @@ export const SeedData = [statusSeed, categorySeed];

Full Zod shape: `node_modules/@objectstack/spec/src/data/seed.zod.ts`.

A `seed` saved at runtime names its `object` itself. One that resolves to
nothing is refused: `422 INVALID_METADATA` at `object`, "which is not defined".
Correct the name to the object's full name (`crm_lead`, not `lead`) or create
the object first: a draft of it is enough for a draft seed; a live seed needs
it published.

### Import modes

| Mode | Behavior | Use for |
Expand Down Expand Up @@ -95,6 +101,11 @@ defineSeed(Invoice, {
**Never use `id`** for generated UUIDs — they
differ across environments.

Every record carries a value for each `externalId` field (each field of a
list; `name` when the seed names none). One left blank (no value, `null` or
`''`; whitespace is a value) is refused at load in every mode: the result names
the object, record index, field and fix, and the other records still load.

| Scenario | Key |
|:---------|:----|
| Named entities (country, currency) | `'code'` / `'slug'` |
Expand Down Expand Up @@ -165,13 +176,10 @@ produce byte-identical `dist/objectstack.json`.

### Seed best practices

| Practice | Why |
|:---------|:----|
| TypeScript: `defineSeed()`, never `SeedSchema.parse()` | Lose compile-time field checks otherwise |
In TypeScript use `defineSeed()`, never `SeedSchema.parse()`: it loses compile-time field checks.

**Fictional is fine; malformed is not.** A seed row passes the same field
validation as a user's insert; a refused value leaves the table short or empty
while sibling rows point at records that do not exist.
validation as a user's insert; a refused value drops the row its siblings point at.
`os validate` / `os build` refuse such a value first, at the
record's field — run them before trusting the load. So never mask or
placeholder a sample value: no `138****4207`,
Expand Down
Loading
Loading