Skip to content
Closed
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
10 changes: 10 additions & 0 deletions .changeset/35496-skills-filters-iso-week-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/skills': patch
---

docs(skills): the query skill teaches the `{current_iso_week}` period key

Clause-②: no
Metadata-protocol: none

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.
16 changes: 15 additions & 1 deletion 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
10 changes: 10 additions & 0 deletions skills/objectstack-query/evals/filters-pagination-search.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
"must_contain": ["timezone: 'Asia/Taipei'", "dateGranularity: 'month'", "zonedDateBucketing", "in memory", "in the database"],
"must_not_contain": ["date_trunc"]
}
},
{
"id": 10,
"prompt": "A dashboard widget over `supply_plan` must always show the current week. `plan_week` is a text field holding ISO week keys such as `2026-W47`; `ship_date` is a date field. Write the widget filter on `plan_week`, then the same week as a filter on `ship_date`.",
"expected_output": "`{ plan_week: '{current_iso_week}' }` — the period-key token resolves to today's ISO week key (`YYYY-Www`, workspace time zone, Monday-start weeks), so it matches a text field that stores those keys. It is text, not a date: on `ship_date` it is refused (`INVALID_FILTER` / 400), so the date field takes the week's boundaries, `{ ship_date: { $gte: '{current_week_start}', $lte: '{current_week_end}' } }`. No hand-computed key or date, which would freeze into the metadata.",
"files": [],
"assertions": {
"must_contain": ["plan_week: '{current_iso_week}'", "{current_week_start}", "{current_week_end}"],
"must_not_contain": ["{current_week}", "ship_date: '{current_iso_week}'"]
}
}
]
}
27 changes: 17 additions & 10 deletions skills/objectstack-query/rules/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ pages — cannot run code, so they use **date macro tokens** instead
(defined in `@objectstack/spec` `data/date-macros.zod.ts`):

```typescript
// List-view / dashboard filter values
where: {
signal_at: { $gte: '{30_days_ago}' },
published_at: { $gte: '{last_quarter_start}' }
Expand All @@ -164,24 +163,33 @@ where: {
`{next_year_start}` (and bare aliases like `{month_start}`).
- **Parameterised tokens:** `{N_<unit>_ago}` / `{N_<unit>_from_now}` with
units `minute|hour|day|week|month|year` — e.g. `{2_weeks_from_now}`.
- **Both spellings parse:** `{today}` and `${today}` are the same token
(`DATE_MACRO_WRAPPED_RE` is `/^\$?\{([a-zA-Z0-9_]+)\}$/`, and the context
tokens share it).
- **Both spellings parse:** `{today}` and `${today}` are the same token, in
every vocabulary here.

**Period key** (`PERIOD_KEY_TOKENS`, not a date macro): `{current_iso_week}`
is today's ISO week key, `YYYY-Www`, in the workspace time zone — Monday-start
weeks, the ISO week-year at year edges (2027-01-01 is `2026-W53`). It is text,
for a text field storing week keys. A `date` / `datetime` / `time` field
refuses it (`INVALID_FILTER` / 400) like the literal key — use
`{current_week_start}` / `{current_week_end}` there — as do a date dashboard
filter's `defaultValue` and `calendar.initialDate`; a text dashboard filter
may default to it. There is no last- or next-week key.

**Session tokens:** the same value positions accept `{current_user_id}` and
`{current_org_id}` (defined in `data/context-tokens.zod.ts`) — the signed-in
user's id and the active organization id.

```typescript
where: { owner_id: '{current_user_id}', close_date: { $gte: '{current_year_start}' } }
where: { owner_id: '{current_user_id}', cost_week: '{current_iso_week}' }
```

**Scope:** tokens expand on **both** sides of the wire — client-side by
`resolveDateMacros()` / `resolveContextTokens()` in `@object-ui/core`,
`resolveFilterPlaceholders()` in `@object-ui/core` (`resolveDateMacros()`,
`resolvePeriodKeyTokens()` and `resolveContextTokens()` in one call),
server-side by `resolveFilterTokens()` in `@objectstack/core`, wired into the
ObjectQL read AND write paths (`find`/`findOne`/`count`/`aggregate`/`update`/
`delete`) plus the analytics dataset executor. The driver only ever sees ISO
strings and concrete ids. So use tokens in a hand-issued engine query too:
`delete`) plus the analytics dataset executor. The driver only ever sees
resolved values. So use tokens in a hand-issued engine query too:
computing "today" at module load freezes the date into the built artifact.

A **flow node's** `config.filter` takes these tokens too. What a dropped
Expand All @@ -200,8 +208,7 @@ indistinguishable from "there is no data". Near-misses, not tokens:
(a real `titleFormat` interpolation) and `{organization_id}` (the column name);
the error names the correction. A value that merely *contains* braces is left
untouched — `'user-{current_user_id}'` is a literal. Check a spelling with
`isDateMacroToken(tok)` / `isContextToken(tok)` from `@objectstack/spec/data`,
WITHOUT braces.
`isKnownFilterToken(tok)` from `@objectstack/spec/data`, WITHOUT braces.

**`*_end` is a calendar DAY; an upper bound means the WHOLE day.**
`<= {current_year_end}` already reaches the final instant of Dec 31
Expand Down
Loading