From 00cef83a2fbbee2d7ff3703a925f6efe76330dfc Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:37:47 +0000 Subject: [PATCH 1/3] docs(skills): objectstack-formula teaches the list-equality refusal and the null-guarded membership test Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../36217-formula-skill-list-equality.md | 12 +++++++++ skills/objectstack-formula/SKILL.md | 26 ++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 .changeset/36217-formula-skill-list-equality.md diff --git a/.changeset/36217-formula-skill-list-equality.md b/.changeset/36217-formula-skill-list-equality.md new file mode 100644 index 00000000000..24326247114 --- /dev/null +++ b/.changeset/36217-formula-skill-list-equality.md @@ -0,0 +1,12 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): `objectstack-formula` says that `==` / `!=` between a list-valued field and a scalar is refused, and teaches the null-guarded membership test + +Clause-②: no +Metadata-protocol: none + +The CEL cheat-sheet of the `objectstack-formula` skill gains a note under its operator table: `==` / `!=` between a list-valued field (`multiselect`, `checkboxes`, `tags`, or a `select` / `lookup` / `user` field with `multiple: true`) and a scalar literal is refused by the validator as `list-equality` ("list compared with a scalar"), because CEL compares the whole list and the expression answers one constant on every row. The note shows the refused form and the two forms that replace it, `record.tags != null && 'vip' in record.tags` for `==` and `record.tags == null || !('vip' in record.tags)` for `!=`, and says why the null guard is there: `in` and `.exists()` fault on a `null` list. This is the behaviour `@objectstack/formula` already ships; the skill only teaches it. + +Paid for by deletion in the same file, with the token ceiling unchanged (6008): six restatements were cut, each keeping another home — the `has()` section's opening sentence (the cheat-sheet `Key existence (NOT null-safety)` row and the paragraph that follows it), the Salesforce-flavor block's `os build` / runtime clause (the `Verify your work` section), the sentence saying hook conditions and validation predicates bind the same two roots (the `previous` table under it), the sentence saying record-change flow triggers ride the same dispatch (the same table's `after*` row), the closing "It is a refusal" sentence of the 10 000-row paragraph (that paragraph's own "the platform refuses"), and the translation table's `"abc"` row (the cheat-sheet `String literal` row). diff --git a/skills/objectstack-formula/SKILL.md b/skills/objectstack-formula/SKILL.md index 5740844212e..271a6aa0eb1 100644 --- a/skills/objectstack-formula/SKILL.md +++ b/skills/objectstack-formula/SKILL.md @@ -82,15 +82,22 @@ transforms — see objectstack-data), not an expression dialect. | Key existence (NOT null-safety) | `has(record.foo)` | | Null check | `record.foo == null` or `isBlank(record.foo)` | +**`==` / `!=` between a list field and a scalar is refused** (`list-equality`, "list compared with a +scalar": one constant on every row) — `multiselect` / `checkboxes` / `tags`, or `select` / `lookup` / +`user` with `multiple: true`. Test membership behind a null guard; `in` and `.exists()` fault on `null`: + +```text +record.tags == 'vip' # REFUSED +record.tags != null && 'vip' in record.tags # RIGHT, or … && record.tags.exists(t, t == 'vip') +record.tags == null || !('vip' in record.tags) # RIGHT, replaces != 'vip' +``` + The org context is `{ id, tier }` — there is no `os.org.slug` or `os.org.name`. The evaluator also binds the current user as `current_user` (alias `user`) per ADR-0068 — spec field docs write predicates like `current_user.positions`. ### `has()` is NOT a null check -`has(record.x)` is **true whenever the key exists**, even when its value is -`null`. - Every server-evaluated predicate — validation rules, `requiredWhen`, option `visibleWhen`, `readonlyWhen`, hook `condition`, the flow trigger record — reads a `record` (and, where §5 binds it, a `previous`) that is **total over @@ -278,8 +285,7 @@ P`!isBlank(record.po_number)`; Conditional requiredness: [objectstack-data](../objectstack-data/SKILL.md#conditional-field-rules). -❌ Salesforce-flavor — **fails CEL compile**: `os build` errors with a -located message, and the flow engine throws if it ever reaches runtime: +❌ Salesforce-flavor — **fails CEL compile**: ```ts "status = 'qualified'" @@ -321,8 +327,7 @@ P`previous.status != 'escalated' && record.status == 'escalated'` `record` is the record's **state**, not this write's diff: stored row ⊕ payload, so `record.status == 'escalated'` is true on *every* update of an already-escalated record. Comparing against `previous` is the only way to say -"just became". Hook `condition`s and validation predicates bind the same two -roots — one scope, one meaning, whichever surface reads it. +"just became". **Where `previous` is bound, and where it is not:** @@ -356,8 +361,7 @@ P`previous.status != 'done' && record.status == 'done'` A predicate (`multi: true`) write is N record changes, so every record-scoped declaration on it is evaluated **per row** — `previous` is that row's own pre-write state, `record` its real state, not the bare payload (ADR-0058, -bulk-write Addenda I and II). Record-change flow triggers ride the same -dispatch. `before*` is no exception to the *condition*; the asymmetry is what a +bulk-write Addenda I and II). `before*` is no exception to the *condition*; the asymmetry is what a `before*` handler WRITES: one `updateMany` takes one SET clause, so every row's dispatch carries the one payload and a rewrite made on any row applies to every matched row (D3). A rewrite *decided* per row must assign the same key set on @@ -369,8 +373,7 @@ batch whole, before any write, when two rows disagree Above 10 000 matched rows the platform refuses a predicate write on an object with per-row hooks in either phase — one ceiling for `before*` and `after*`, checked before the first dispatch (ADR-0058 Addendum II, D6) — rather than fan -out that many handler runs inside one write; paginate the write. It is a -refusal, never a silent downgrade to one hook call. +out that many handler runs inside one write; paginate the write. --- @@ -388,7 +391,6 @@ When migrating Salesforce-flavor metadata, apply these rules in order: | `AND` | `&&` | | `OR` | `\|\|` | | `NOT(x)` | `!x` | -| `"abc"` | `'abc'` | | `IF(c, a, b)` | `c ? a : b` | | `ISBLANK(x)` | `isBlank(record.x)` | | `CONCAT(a, b)` | `coalesce(a, '') + coalesce(b, '')` | From d319685aa5739f11b7f7330d687e790a02d5b79d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 07:57:50 +0000 Subject: [PATCH 2/3] docs(skills): one eval case exercises the list-equality teaching Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../evals/cel-predicates-formulas.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/skills/objectstack-formula/evals/cel-predicates-formulas.json b/skills/objectstack-formula/evals/cel-predicates-formulas.json index 704dafc4c22..cf1c1a00364 100644 --- a/skills/objectstack-formula/evals/cel-predicates-formulas.json +++ b/skills/objectstack-formula/evals/cel-predicates-formulas.json @@ -120,6 +120,16 @@ "must_contain": ["isoDate(addDays(record.borrow_date, 7))", "F`"], "must_not_contain": ["timestamp(record.borrow_date)", "{record."] } + }, + { + "id": 13, + "prompt": "On `ticket`, `labels` is a `tags` field. Write the hook `condition` that is true when the ticket carries the `urgent` label.", + "expected_output": "`P`record.labels != null && 'urgent' in record.labels``. `labels` holds a list, so `record.labels == 'urgent'` compares the whole list with a scalar and is refused (`list-equality`): it answers `false` on every row. Test membership with `in`, behind a `!= null` guard, because `in` faults on a `null` list.", + "files": [], + "assertions": { + "must_contain": ["record.labels != null", "in record.labels", "P`"], + "must_not_contain": ["record.labels == 'urgent'", "{record."] + } } ] } From 5dfda715190af861e741ef5b76ab8e8639ebd9a5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 15:34:49 +0000 Subject: [PATCH 3/3] docs(skills): objectstack-formula teaches the list-equality rewrite each site takes The note under the CEL cheat-sheet now shows the three spellings the validator's refusal prescribes: the has()-guarded `in` test where the expression is evaluated as CEL, the bare-name form at a flow condition, and `.contains()` at a sharing rule's condition, which compiles to a query filter where `in` with the literal first does not lower. Each rewrite is parenthesised whole, for == and for !=. The list of list-valued fields names every type that takes `multiple`. Paid for by six more same-file cuts of restatement; ceiling unchanged. Eval case 13's reference answer now passes its own assertions, and case 14 exercises the sharing-rule spelling. Claude-Session: https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY Co-authored-by: Claude --- .../36217-formula-skill-list-equality.md | 14 +++++-- skills/objectstack-formula/SKILL.md | 42 +++++++++---------- .../evals/cel-predicates-formulas.json | 14 ++++++- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/.changeset/36217-formula-skill-list-equality.md b/.changeset/36217-formula-skill-list-equality.md index 24326247114..56c7b83b5df 100644 --- a/.changeset/36217-formula-skill-list-equality.md +++ b/.changeset/36217-formula-skill-list-equality.md @@ -2,11 +2,19 @@ '@objectstack/skills': patch --- -docs(skills): `objectstack-formula` says that `==` / `!=` between a list-valued field and a scalar is refused, and teaches the null-guarded membership test +docs(skills): `objectstack-formula` says that `==` / `!=` between a list-valued field and a scalar is refused, and teaches the membership test each site takes Clause-②: no Metadata-protocol: none -The CEL cheat-sheet of the `objectstack-formula` skill gains a note under its operator table: `==` / `!=` between a list-valued field (`multiselect`, `checkboxes`, `tags`, or a `select` / `lookup` / `user` field with `multiple: true`) and a scalar literal is refused by the validator as `list-equality` ("list compared with a scalar"), because CEL compares the whole list and the expression answers one constant on every row. The note shows the refused form and the two forms that replace it, `record.tags != null && 'vip' in record.tags` for `==` and `record.tags == null || !('vip' in record.tags)` for `!=`, and says why the null guard is there: `in` and `.exists()` fault on a `null` list. This is the behaviour `@objectstack/formula` already ships; the skill only teaches it. +The CEL cheat-sheet of the `objectstack-formula` skill gains a note under its operator table: `==` / `!=` between a list-valued field (`multiselect`, `checkboxes`, `tags`, or a `select` / `radio` / `lookup` / `user` / `file` / `image` field with `multiple: true`) and a scalar literal is refused by the validator as `list-equality` ("list compared with a scalar"), because CEL compares the whole list and the expression answers one constant on every row. The note shows the refused form and the rewrite the refusal prescribes at each site, null-guarded (`in` faults on a `null` list) and parenthesised whole, for `==` and for `!=`: -Paid for by deletion in the same file, with the token ceiling unchanged (6008): six restatements were cut, each keeping another home — the `has()` section's opening sentence (the cheat-sheet `Key existence (NOT null-safety)` row and the paragraph that follows it), the Salesforce-flavor block's `os build` / runtime clause (the `Verify your work` section), the sentence saying hook conditions and validation predicates bind the same two roots (the `previous` table under it), the sentence saying record-change flow triggers ride the same dispatch (the same table's `after*` row), the closing "It is a refusal" sentence of the 10 000-row paragraph (that paragraph's own "the platform refuses"), and the translation table's `"abc"` row (the cheat-sheet `String literal` row). +- where the expression is evaluated as CEL: `(has(record.tags) && record.tags != null && 'vip' in record.tags)` and `(!has(record.tags) || record.tags == null || !('vip' in record.tags))`; the `has()` covers a sparse action row and a `previous` that is `null`; +- a bare name in a flow condition: `(tags != null && 'vip' in tags)` and `(tags == null || !('vip' in tags))`, since `has()` takes no bare name; +- a sharing rule's `condition`, which is compiled to a query filter: `(record.tags != null && record.tags.contains('vip'))` and `(record.tags == null || !record.tags.contains('vip'))`, since `has()` and an `in` with the literal first do not lower there. + +This is the behaviour `@objectstack/formula` already ships; the skill only teaches it. + +Paid for by deletion in the same file, with the token ceiling unchanged (6008): twelve restatements were cut, each keeping another home — the `has()` section's opening sentence (the cheat-sheet `Key existence (NOT null-safety)` row and the paragraph that follows it), the Salesforce-flavor block's `os build` / runtime clause (the `Verify your work` section), the sentence saying hook conditions and validation predicates bind the same two roots (the `previous` table under it), the sentence saying record-change flow triggers ride the same dispatch (the same table's `after*` row), the closing "It is a refusal" sentence of the 10 000-row paragraph (that paragraph's own "the platform refuses"), the translation table's `"abc"` row (the cheat-sheet `String literal` row), the stdlib intro's "there is no `src/` to read" clause (the same sentence's "ships `dist` only"), the "use `daysBetween` / two `datetime(…)`" sentence of the date-arithmetic note (the table under it), the sub-day-offset row's "the calendar helpers land on UTC midnight" (the `today()` / `daysFromNow` / `daysAgo` rows), the "`previous.status`, where `previous` is `null`" parenthesis of the unevaluable-condition warning (the `previous` table's insert row), the second transition-condition example (the section's first example, the same shape), and the first half of the translation table's `previous.x` warning (the `OLD.x` and `ISCHANGED(x)` rows above it and the same insert row). + +Two eval cases exercise the note: a hook `condition` over a `tags` field (the CEL spelling) and a sharing rule `condition` over the same field (the `.contains()` spelling). diff --git a/skills/objectstack-formula/SKILL.md b/skills/objectstack-formula/SKILL.md index 271a6aa0eb1..a845dd92564 100644 --- a/skills/objectstack-formula/SKILL.md +++ b/skills/objectstack-formula/SKILL.md @@ -82,14 +82,22 @@ transforms — see objectstack-data), not an expression dialect. | Key existence (NOT null-safety) | `has(record.foo)` | | Null check | `record.foo == null` or `isBlank(record.foo)` | -**`==` / `!=` between a list field and a scalar is refused** (`list-equality`, "list compared with a -scalar": one constant on every row) — `multiselect` / `checkboxes` / `tags`, or `select` / `lookup` / -`user` with `multiple: true`. Test membership behind a null guard; `in` and `.exists()` fault on `null`: +**`==` / `!=` between a list field and a scalar literal is refused** (`list-equality`, "list compared +with a scalar": one constant on every row) — `multiselect` / `checkboxes` / `tags`, or `select` / +`radio` / `lookup` / `user` / `file` / `image` with `multiple: true`. Test membership, null-guarded +(`in` faults on `null`) and parenthesised, per site — the `==` rewrite, then the `!=` one: ```text -record.tags == 'vip' # REFUSED -record.tags != null && 'vip' in record.tags # RIGHT, or … && record.tags.exists(t, t == 'vip') -record.tags == null || !('vip' in record.tags) # RIGHT, replaces != 'vip' +record.tags == 'vip' # REFUSED +# evaluated as CEL; has() covers a sparse action row and a null `previous` +(has(record.tags) && record.tags != null && 'vip' in record.tags) +(!has(record.tags) || record.tags == null || !('vip' in record.tags)) +# bare name in a flow condition (has() takes no bare name) +(tags != null && 'vip' in tags) +(tags == null || !('vip' in tags)) +# SharingRule `condition`: compiled to a query filter, where has() and a literal-first `in` do not lower +(record.tags != null && record.tags.contains('vip')) +(record.tags == null || !record.tags.contains('vip')) ``` The org context is `{ id, tier }` — there is no `os.org.slug` or `os.org.name`. @@ -147,8 +155,7 @@ has(record.viewer) && has(record.viewer.can_approve) && record.viewer.can_approv ## ObjectStack CEL standard library -Registered automatically by `@objectstack/formula`, which ships `dist` only — -there is no `src/` to read in an installed app. Its exported +Registered automatically by `@objectstack/formula`, which ships `dist` only. Its exported `CEL_STDLIB_FUNCTIONS` is the advertised bare-callable subset, pinned by two tests: every entry resolves at runtime, and this table documents them all. @@ -173,7 +180,7 @@ tests: every entry resolves at runtime, and this table documents them all. > **No date arithmetic.** The build refuses `date + n` and `end - start`: a > date or date-time mixed with a number, or minus another, reads `null`, and -> `today()` / `now()` minus a date field reads `{}`. Use `daysBetween(a, b)` for whole days, two `datetime(…)` for hours (row below). +> `today()` / `now()` minus a date field reads `{}`. | Want | Write — never bare `end - start`, `date + n`, `today() + 30` | |:---|:---| @@ -181,7 +188,7 @@ tests: every entry resolves at runtime, and this table documents them all. | Shift a date | `daysFromNow(n)` / `addDays(d, n)` / `addMonths(d, n)` | | Tenure in years | `daysBetween(record.hire_date, today()) / 365` | | Hours between | `double((datetime(record.end_at) - datetime(record.start_at)).getMinutes()) / 60.0` | -| Sub-day offset | `now() + duration("3h")` — the calendar helpers land on UTC midnight | +| Sub-day offset | `now() + duration("3h")` | **Numbers** @@ -341,7 +348,7 @@ already-escalated record. Comparing against `previous` is the only way to say | `before*` hook `condition` on a predicate (`multi: true`) write | **that row's pre-write row** — `beforeUpdate` / `beforeDelete` dispatch once PER MATCHED ROW too, each on a single-record-shaped context whose `input.id` names the row (ADR-0058 Addendum II, D1/D2); `record` is that row's state, stored ⊕ payload, as on any update. Only the *payload* stays batch-scoped — see below the table | ⚠️ **An unevaluable condition ABORTS the operation.** A column read off -`previous` on an insert (`previous.status`, where `previous` is `null`) — like +`previous` on an insert — like a typo'd key (`record.stauts`), a retired field, or a comparison CEL has no overload for — does **not** degrade to "the hook did not fire": it **fails the write**, with an error naming the hook and the key — `before*` and `after*` @@ -350,13 +357,7 @@ the condition is evaluated before any handler runs). **A transition condition needs no special handling for bulk writes.** Write it once, on a `before*` or an `after*` event, and it means the same thing -whether the write carries an id or a predicate: - - -```ts -import { P } from '@objectstack/spec'; -P`previous.status != 'done' && record.status == 'done'` -``` +whether the write carries an id or a predicate. A predicate (`multi: true`) write is N record changes, so every record-scoped declaration on it is evaluated **per row** — `previous` is that row's own @@ -399,9 +400,8 @@ When migrating Salesforce-flavor metadata, apply these rules in order: | `ISCHANGED(x)` | `previous.x != record.x` | | `MONTH_DIFF`, `MID`, `LEFT`, `RIGHT`, `SUBSTITUTE` | _not in stdlib — propose addition_ | -> ⚠️ `OLD.x` and `ISCHANGED(x)` both land on `previous.x`, which is `null` on an -> insert event and **fails the write** there unless guarded by `previous != null -> &&` (§5). +> ⚠️ `previous.x` **fails the write** on an insert unless guarded by +> `previous != null &&` (§5). > ⚠️ **Flow conditions are the exception to row 1.** The engine spreads the > trigger record's fields, nulls included, to top level wherever no flow variable diff --git a/skills/objectstack-formula/evals/cel-predicates-formulas.json b/skills/objectstack-formula/evals/cel-predicates-formulas.json index cf1c1a00364..7f17ee7694a 100644 --- a/skills/objectstack-formula/evals/cel-predicates-formulas.json +++ b/skills/objectstack-formula/evals/cel-predicates-formulas.json @@ -124,11 +124,21 @@ { "id": 13, "prompt": "On `ticket`, `labels` is a `tags` field. Write the hook `condition` that is true when the ticket carries the `urgent` label.", - "expected_output": "`P`record.labels != null && 'urgent' in record.labels``. `labels` holds a list, so `record.labels == 'urgent'` compares the whole list with a scalar and is refused (`list-equality`): it answers `false` on every row. Test membership with `in`, behind a `!= null` guard, because `in` faults on a `null` list.", + "expected_output": "`P`(has(record.labels) && record.labels != null && 'urgent' in record.labels)``. `labels` holds a list, so `record.labels == 'urgent'` compares the whole list with a scalar and is refused (`list-equality`): it answers `false` on every row. A hook `condition` is evaluated as CEL, so membership is `in`, behind a `!= null` guard, because `in` faults on a `null` list.", "files": [], "assertions": { "must_contain": ["record.labels != null", "in record.labels", "P`"], - "must_not_contain": ["record.labels == 'urgent'", "{record."] + "must_not_contain": ["P`record.labels == 'urgent'", "{record."] + } + }, + { + "id": 14, + "prompt": "On `ticket`, `labels` is a `tags` field. Write the sharing rule `condition` that matches the tickets carrying the `urgent` label.", + "expected_output": "`P`(record.labels != null && record.labels.contains('urgent'))``. A sharing rule's `condition` is compiled to a query filter, not evaluated as CEL, so membership is `.contains()`: `has()` and an `in` with the literal first do not lower there, and the rule would grant nothing. `record.labels == 'urgent'` compares the whole list with a scalar and is refused (`list-equality`).", + "files": [], + "assertions": { + "must_contain": ["record.labels != null", "record.labels.contains("], + "must_not_contain": ["P`record.labels == 'urgent'", "has(record.labels) &&", "{record."] } } ]