/boxel-skills:bxl-authoringfrom boxel-skills
Use when writing or reviewing a BXL expression in a Boxel card — a computeVia built from expression(), the fx / jq tags, spreadsheet-formula fields, aggregations over linked or query-backed collections. Covers which tag to reach for, what the derive profile refuses outright, the silent traps (a stream where an aggregate was meant, jq interpolation in a plain string, & on a blank field, dates and "today"), and why an indexed computed can differ from the one the viewer sees. Activates on expression(, fx`…`, jq`…`, "BXL", "formula field", "computed field with Excel functions", "sum the linked cards".
Ships in boxel-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
BXL is the workspace's expression language: readable spreadsheet syntax and Excel
formula libraries on top of a jq engine. In a card it drives computeVia.
import { expression, fx, jq } from '@cardstack/bxl';
export class Claim extends CardDef {
@field paidAmount = contains(NumberField);
@field reserveAmount = contains(NumberField);
@field incurredAmount = contains(NumberField, {
computeVia: expression(fx`ROUND((PaidAmount + ReserveAmount) * 100) / 100`),
});
}
expression is the factory (bxl and expr are aliases); it compiles the
source once when the class body runs, then evaluates it against the card
instance on each read.
The rest of this skill is the decision layer and the trap list. For the full syntax surface — labels, row selectors, predicates, the Excel function matrix — read bxl.boxel.site.
| Source contains | Reach for | Why |
|---|---|---|
\(…) jq interpolation | jq`…` | A plain string drops the backslash — see trap 4 |
Excel functions (ROUND, IFS, SUM) | fx`…` | Readable-syntax compilation, explicit at the call site |
Bare PascalCase field labels (PaidAmount) | fx`…` | The compiler resolves them to .paidAmount |
Pure jq (.claims | length) | jq`…` | Skips the readable-syntax compile step |
Quoted multi-word labels ("Line Item") | fx + schema | Label resolution needs the schema — see trap 3 |
A plain string compiles exactly like fx`…`. Prefer a tag: it tells the next
reader which dialect they are in, and it is the only form that survives \(…).
Mixing dialects inside one source is fine — fx`IF(.status == "Open", 1, 0)`
and fx`if Status == "Open" then 1 else 0 end` both work. Case is the
dispatch: IF(cond, t, f) is the Excel function, if cond then … end is the jq
construct.
derive profile — what a computed may not doexpression() validates against the derive profile when the field is
defined, so a violation throws while the card module loads rather than
producing a wrong value. The diagnostic names the rule:
computeVia expression violates the derive profile:
derive-call-banned: Profile.derive is for deterministic write/index-time
computation and cannot use call TODAY: volatile calls are not stable write-time
derivations.
Refused: volatile calls (TODAY, NOW, RAND, RANDBETWEEN, and the two
clock-reading validator helpers isAfter / isBefore) · request, actor and
mutation context (@User, @Env, $new, $old) · user-defined def helpers ·
jq try / catch · error · label / break · assignment (=, |=) ·
recursive descent (..) · format filters (@csv) · control and side-effect
calls (debug, env, input, stderr, halt) · runtime metadata
(builtins).
Allowed and useful: IFERROR / IFNA · optional access (.a?) · aggregates
(SUM, AVERAGE, COUNT, NPV) · validator helpers (isEmail, isDate) ·
LET · bindings (. as $x | …) · explicit folds (reduce, foreach) ·
structural ops (keys, to_entries, group_by, unique, tojson).
isAfter and isBefore are the surprise on that list: they sit among the
validator helpers, they look like ordinary date comparisons, and they default
their second argument to the current time — so the profile classes them with
NOW. Compare two stored dates with the operators instead
(fx`StartDate < EndDate`), which is deterministic and needs no helper.
The boundary is determinism: a derived value comes from the record snapshot, not from the clock, the viewer, or the request. It is computed once server-side and stored in the search doc, so anything ambient would bake one viewer's answer in for everyone.
The single most expensive trap. jq function arguments are streams, so navigating into an array field and handing that straight to an aggregate calls the aggregate once per element — and the field receives an array of per-element results instead of one number. Nothing errors.
// WRONG — compiles to SUM(.claims[].paid); with two claims the field gets [10, 5]
computeVia: expression(fx`SUM(Claims[].Paid)`);
// RIGHT — collect first, then aggregate: 15
computeVia: expression(fx`SUM([Claims[].Paid])`);
// RIGHT — the jq spelling, with a fallback for the empty case
computeVia: expression(jq`[.claims[] | .paidAmount] | add // 0`);
Same for AVERAGE, COUNT, MAX, MIN, SUMIF. Collect the argument that
iterates, and only that one — the rule is narrower than "wrap everything", and
wrapping the wrong thing is its own bug:
SUM([Claims[].Paid]),
SUMIF([Claims[].Paid], ">6").SUM(Amounts) over a
containsMany(NumberField) is correct as it stands.SUM(Paid, Reserve) compiles to
SUM([.paid, .reserve]), and even SUM(Claims[].Paid, 0) becomes
SUM([.claims[].paid, 0]). Write the […] anyway — the single-argument form
is what an author reaches for next.ROUND([1.234], 2) and
NPV([0.1], CashFlows) hand an array to a function that wants a number; each
returns null.Passing a schema is the other way to get this right — with field metadata, the
compiler collects implicitly, so SUM("Line Item"."Line Total") compiles to
SUM([.lineItems[].lineTotal]). Without a schema, quoted multi-word labels fail
loudly (Cannot index string with string) and a bare PascalCase label resolves
to a single camelCase path segment. A card gets no schema unless the expression
passes one.
Check the compiled jq when in doubt — the factory exposes it:
expression(fx`SUM([Claims[].Paid])`).bxl;
// { source, compiledSource: 'SUM([.claims[].paid])', warnings, deps, memoize }
\(…) in a plain string is silently inertA JS string literal and an untagged template both drop the backslash before (,
so the runtime never sees the interpolation and the field renders the literal
text (.bpSystolic)/(.bpDiastolic). No lint pass in a realm flags this.
// WRONG — yields "(.bpSystolic)/(.bpDiastolic)"
computeVia: expression('"\(.bpSystolic)/\(.bpDiastolic)"');
// RIGHT — the tag passes the raw source through
computeVia: expression(jq`"\(.bpSystolic)/\(.bpDiastolic)"`);
Either tag preserves it — both read the raw strings, so fx`"\(.bpSystolic)"`
interpolates too. The plain string is the one broken form.
Inside \(…) you are in jq, and the readable-syntax pass does not reach in:
a PascalCase label there is read as a function call, and
fx`"\(PaidAmount) paid"` throws 'PaidAmount/0' is not defined the first
time the field is read. Write the path — fx`"\(.paidAmount) paid"`.
Missing and null operands are tolerated rather than fatal, which means a wrong answer is quiet. The model, for a card whose numeric fields are unset:
| Expression | Result | Reason |
|---|---|---|
fx`Paid + Reserve` | null | null propagates through arithmetic |
fx`Paid + 5` | 5 | a null addend contributes nothing |
fx`SUM(Paid, Reserve)` | 0 | aggregates skip blanks, Excel-style |
fx`ROUND(Paid + Reserve)` | 0 | ROUND absorbs a null operand |
fx`Premium / 0` | null | division by zero yields null, not #DIV/0! |
jq`[.claims[] | .paid] | add` | null | add over an empty array is null |
jq`.name | startswith("a")` | false | string predicates on null are false |
Guard with //, the jq alternative operator: (Paid // 0) + (Reserve // 0),
add // 0. Because division by zero produces null rather than an error,
IFERROR does not rescue it — guard the divisor instead.
& renders a blank operand as the text null. fx`Name & " (" & Tier & ")"` on a card with no tier yields Acme (null). Write
fx`Name & " (" & (Tier // "") & ")"`, or use CONCAT / TEXTJOIN, which
drop blanks.
Sentinels (#N/A, #DIV/0!, #VALUE!, #REF!, #NUM!) are raised as values
inside evaluation and caught at the factory boundary, which returns null. That
much is safe: fx`INDEX(Rows, 99)` leaves one blank field rather than
failing the card.
A sentinel blanks the whole expression, not the sub-call that raised it — it
propagates out through every enclosing call until the boundary catches it.
fx`ROUND(NA()) + 5` is null, not 5, even though ROUND absorbs a null
operand. Catch it where you want the fallback:
fx`IFERROR(VLOOKUP(Sku, Rows, 2, FALSE), "unlisted")`,
fx`IFNA(NA(), "none")`. An AVERAGE over an empty collection raises
#DIV/0! and therefore lands as null.
Anything that is not a sentinel does fail the card. A misspelled function
name compiles happily and throws on the first read — fx`SUMM([Amounts])`
gives 'SUMM/1' is not defined — and so does a structural operation applied to
the wrong shape (jq`unique` over an object rather than an array). Those
surface as an indexing error on the instance, not as a blank field, so a typo in
a formula is a broken card and not a quiet null.
Paths traverse links, including several hops: jq`.policy.customer.name`
reads across two linksTo edges, and a missing hop anywhere yields null.
A query-backed linksToMany — the inverse side, derived from a filter rather
than stored on the card — behaves differently from a stored link, and this is
the part worth understanding before you aggregate over one:
Claim reindexes that claim;
the Policy whose inverse contains it keeps the aggregate from its last visit
until something revisits the policy. Aggregates over an inverse are eventually
consistent by design.COUNT([Claims[]]) over 600 claims is 500.Guidance: aggregate over query-backed inverses for display and reporting; do not
treat such a field as a promptly-correct index-time fact, and do not build a
filter or sort that depends on it being current. Before reducing over one,
check the match count against the rows in hand:
getRelationshipMembershipState(this, 'claims') reports totalMatchCount and
isPartial. A count-shaped rollup should read totalMatchCount rather than
aggregate at all, which sidesteps the page ceiling entirely; where the rows
themselves are needed, the field must declare a page big enough to hold them —
see query-backed-relationships.
When the aggregate must be index-accurate, put the edge on the aggregating card
(a stored linksToMany) so a write to either side invalidates it. Where you accept the lag, say so in a
comment at the field — the indexed value is server-computed and may differ from
the one on screen, and the next reader has no other way to tell that was a
choice.
Card graphs are legitimately cyclic (a claim links to its policy, the policy's
inverse contains the claim); jq's data model is not. Re-entering a card already
on the traversal path yields a bounded { id } reference — the same clip a
search doc applies — so jq`[.claims[] | .policy.id]` reads one id per
claim, and the policy's other fields read null from that direction. Structural operations
(unique, tojson, ==) terminate and stay field-aware, comparing cards by
their materialized values.
Two consequences for data modeling:
.policy.annualPremium is fine; a policy reaching
.claims[].policy.annualPremium gets null.tojson,
to_entries, . == . over . — re-enters the field it is producing. That
in-flight read is blank, the spreadsheet circular-reference surface, so
jq`tojson` on a card yields {"a":1,"derived":null} rather than
recursing. jq`keys` is safe for the opposite reason: it reads the field
names, never their values, so nothing re-enters. jq`unique` over .
is not a self-reference problem at all — it throws, because unique wants an
array and a card is an object.Indexing evaluates computeds server-side; a browser evaluates them in the
viewer's zone. Date functions are anchored so that they answer the same in
either place: DATE, EDATE, EOMONTH, WEEKDAY, DATEVALUE, YEARFRAC,
DAYS, NETWORKDAYS and friends give one answer across host zones. Serial
arithmetic and explicit Y/M/D construction are the safe idioms.
TODAY and NOW are not available in a computed at all — the derive profile
refuses them, because an indexed value computed once from the clock is wrong for
every later read. Nor are isAfter / isBefore, which look like plain date
comparisons but default their second argument to the current time; compare
stored dates with the operators (fx`StartDate < EndDate`). So:
expression() caches its result per card instance until the current microtask
ends, which collapses the repeated synchronous reads a serialization or search
pass makes. Glimmer flushes re-renders synchronously at the end of an action, so
an action that reads a formula and then writes one of that formula's inputs in
the same burst paints once with the cached value. It heals on the next change
to that card. Write-only actions never see it.
Pass memoize: false for a formula an action reads before writing its inputs:
@field statusPanel = contains(PanelField, {
computeVia: expression(jq`{ label: .status }`, {
as: PanelField,
memoize: false,
}),
});
{ as: FieldDef } for structured outputAn expression yields plain JSON. When the field's type is a FieldDef, pass
as so the value is rebuilt as an instance the serializer can identify — object
keys map to the field def's @field names, nested contains values materialize
as their own field-def instances, and each element of an array output gets the
same treatment. Scalars and null pass through untouched.
export class RiskBandField extends FieldDef {
static displayName = 'Risk Band';
@field label = contains(StringField);
@field score = contains(NumberField);
@field flags = containsMany(StringField);
}
@field riskBand = contains(RiskBandField, {
computeVia: expression(
jq`{
label: (if .lossRatio >= 0.8 then "High" else "Low" end),
score: ((.lossRatio * 100) | round),
flags: (if .lossRatio >= 0.8 then ["review"] else [] end)
}`,
{ as: RiskBandField },
),
});
// containsMany — one materialized instance per element
@field claimBands = containsMany(RiskBandField, {
computeVia: expression(
jq`[.claims[] | { label: .severityBand, score: .paidAmount }]`,
{ as: RiskBandField },
),
});
Without as, a structured value reaches the serializer as an anonymous object
and fails to identify.
SUM([Claims[].Paid]),
never SUM(Claims[].Paid) — and no scalar parameter is.\(…) source is tagged, and every label inside \(…) is a jq path.& on a blank-able operand
is guarded or rewritten as CONCAT / TEXTJOIN.totalMatchCount instead of aggregating.FieldDef-typed field
has { as: … }.In cardstack/boxel, the behavior above is locked down by tests, which are the
place to check a detail or add a case:
packages/bxl/tests/boxel/authoring-skill-claims.ts — this skill's own drift
guard: for each claim above it asserts the snippet still appears in this file
and still behaves as described. Editing an example here means editing that
suite too.packages/host/tests/helpers/cards/bxl-tracking.ts — the worked example this
skill draws on: an insurance domain exercising all three tags, linked and
query-backed traversal, null tolerance, sentinels, and { as: … }.packages/host/tests/integration/bxl-expression-test.gts — the factory on
real cards, including the memoization contract.packages/host/tests/integration/bxl-platform-module-test.gts — the platform
module end to end, and the query-backed first-pass/converge contract.packages/host/tests/integration/bxl-cyclic-graph-test.gts — the { id }
clip and structural operations across a cycle.packages/bxl/tests/boxel/ — null tolerance, tag dispatch, the \(…)
preservation rule, sentinel catching, and as materialization over plain
objects.packages/bxl/docs/ — syntax-modes.md (call-site modes), profiles.md
(the derive contract), formulas.md (the Excel matrix),
realm-composition.md (threading inputs into child field defs).Query-backed linksToMany and inbound-reference lookups —
boxel-patterns, pattern
automate-linked-to-me-lookup.
Field types, formats, and templates — boxel.
Silent-failure traps outside BXL —
boxel-workspace-cardinal-rules.
Why a card failed to index or holds broken links —
boxel-environment.
A where predicate in a realm policy, which validates against the policy
profile rather than derive — membership spelling, the refused partial-match
builtins, and what compiles to a search filter —
realm-policy-authoring §6–§8.
The engine itself — the compiler, the jq runtime, the formula libraries, the
mutation and authorization profiles — is documented in packages/bxl/docs/ and
is not this skill's subject.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
boxel-skills@cardstack-boxel is listed by cardstack/boxel — review the source before installing
npx claudepluginhub cardstack/boxel --plugin boxel-skills27 skills in this plugin
/api-integrationsUse when a card needs data from, or sends data to, a third-party API — "show my GitHub pull requests in a card", "pull my open issues", "a card that calls the weather API with my key", "integrate with Stripe/Twilio/OpenAI", "how often can this card poll", "build a PR inbox". Takes a card author from "I want data from this vendor" to a working card: classifying the integration (no key, a key the workspace shares, the user's own key, a key that can write), choosing a live card or a scheduled pipeline (and why private data takes the pipeline), declaring the `callApi` operations with labels and credential slots, estimating polling cost, and recipes for GitHub (GraphQL, a GitHub App or a read-only fine-grained token, the PR inbox as a pipeline and as a live card), for a plain API key sent in a header, and for images from an AI vendor called with the user's own key (an automation run's own AI requests carry text only). Activates on "third-party API", "vendor API", "integration", "pipeline", "live card", "On a schedule and when the card is opened", "poll", "GitHub API", "GraphQL", `callApi`, `{{userKey}}`, `{{apiKey}}`, "image generation", "AI vendor key", "automation image"./api-keysUse when a card or the AI assistant needs a user's API key, or a key shared into a workspace — "this card needs my GitHub token", "the forecast operation was refused binding-not-approved", "let the user add their key", "share my key with this workspace", "add a key button". Also "sign in to GitHub from this card", "connect my account", "the operation was refused credential-rejected", "the service rejected my key", "should I register a GitHub App or an OAuth App". Covers getting a key from the user only through Boxel's secure window, with the open-secure-window tool: opening it from a card through `@context.toolContext` or from the assistant, its modes (enter a key, replace the key an operation sends, share a key, connect an account through OAuth, approve a card's requests for scheduled pipelines or also for when the card is opened, review what changed in them), passing only the operation the card is blocked on and letting the window gather the card's other operations into one approval, what the tool answers, the blocked-popup fallback, telling the user to check the address bar, what to do when the service rejects a key (stop polling, offer Try again, and Reconnect, which opens the window to replace the key), OAuth clients and connections (when to use a connection rather than a static key, what the card declares, opening connect mode, `credential-rejected` and its reasons, sharing a client into a workspace, and why GitHub takes a GitHub App), and never asking for a credential in the chat or building a form for one. Also covers asking first with `@context.keyReadiness` — the answers (`ready`, `needs-connect`, `needs-approval`, `needs-reapproval`, `needs-admin`, `needs-sign-in`, `rate-limited`, `over-budget`), what a card shows for each and what the secure window can fix, and treating `undefined` as "not known yet" so prerendered HTML never shows Connect. Also covers a call refused for the key owner's limits (`rate-limited`, `over-budget`, `rate-limit-unavailable`): backing off by `retryAfterSeconds` and saying the limit is reached without naming a budget. Activates on "approve", "Allow", "review changes", `needs-approval`, `needs-reapproval`, `open-secure-window`, `OpenSecureWindowTool`, `keyReadiness`, "secure window", "API key", "enter a key", "replace a key", "share a key", "OAuth", "connect", "Reconnect", "GitHub App", `{{userKey}}`, `{{apiKey}}`, `binding-not-approved`, `interactive-use-not-approved`, `anonymous-use-not-approved`, "On a schedule and when the card is opened", "people who aren't signed in", "anonymous cap", `credential-rejected`, `rate-limited`, `over-budget`.