diff --git a/.changeset/38939-data-skill-rate-table-unit-config.md b/.changeset/38939-data-skill-rate-table-unit-config.md new file mode 100644 index 00000000000..959abe248df --- /dev/null +++ b/.changeset/38939-data-skill-rate-table-unit-config.md @@ -0,0 +1,18 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): the objectstack-data skill names the platform's exchange-rate table and teaches `unitConfig` + +Clause-②: no +Metadata-protocol: none + +The data skill never said that the platform ships the rate table and the unit vocabulary, so an app built from it alone declared its own exchange-rate object with a conversion hook, and a free-text or picklist unit field. The engine's conversion at write and its unit-code check then never ran for that app. Both facts were only in `objectstack-project`'s platform catalog, which a reader of the data skill does not load. + +`skills/objectstack-data/rules/field-types.md`, § Currency: the rates `currencyConfig.homeAmount` converts with are the platform's `sys_exchange_rate`, which an administrator keeps in Setup. An app declares no rate object and no conversion hook. A foreign amount with no rate on or before its `rateDate` is refused with `ERR_EXCHANGE_RATE_MISSING`. + +The same file gains § Unit of measure, with one type-checked example of the three shapes of `unitConfig`: `{ unitMode: 'code' }` on a `text` field that holds a unit code with no quantity pointing at it, and on a `number` field `{ unitMode: 'fixed', unit: 'KGM' }` or `{ unitMode: 'record', unitField: 'unit_code' }`, where `unit_code` is a `text` field of the same object with no `unitConfig` or `valueDomain` of its own. `unitMode` has no default. A record stores the unit as a code in exact uppercase: a standard UN/ECE Recommendation 20 code (`H87` for a piece, `KGM`, `XBX` for a box; the table is `STANDARD_UNITS` in `@objectstack/spec/data`), or one the organization adds to the platform's `sys_unit` in Setup, which a `fixed` unit cannot name. The write refuses any other value with `ERR_UNIT_CODE_UNKNOWN` (`pcs`, `kg`, and `C62` or `EA` for a piece), and a quantity beside a blank code with `ERR_UNIT_CODE_REQUIRED`. `unitDimension` limits a `record` or `code` field to the units of one dimension. Free text stored before the declaration is converted with `os migrate unit-codes`. The `text` and `number` rows of the type tables point at the section. + +`skills/objectstack-data/SKILL.md`: in the "Where to go" table, the Field Types row now names exchange rates (`sys_exchange_rate`) and units of measure (`unitConfig`). The sentence above the table is gone: the table's "Open first" column header says the same. + +Two token ceilings move, each after restating text in the same file was deleted first, by the measured remainder: `rules/field-types.md` from 4200 to 4566 (two parentheticals that repeated the `secret` row and the entry's first trap are cut), and `SKILL.md` from 2224 to 2233 (the sentence above the routing table is cut). The entry file is 8958 bytes. diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index 2d96caafde5..9bc7c2e1b96 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -1036,7 +1036,18 @@ export const CEILINGS = new Map([ // `readonly: true` binds, which that section now carries. 8983 -> 8923 bytes (8956 -> // 8896 priced), -60, -> 2224 tokens, pinned AT the measurement. // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8896 / 4) - ['skills/objectstack-data/SKILL.md', 2224], + // 2224 -> 2233 (#38939): the routing table's Field Types row names what the platform ships + // for money and units, exchange rates (`sys_exchange_rate`) and units of measure + // (`unitConfig`), so a request to build a rate object or a free-text unit field is sent to + // `rules/field-types.md`, where both are taught (+71 bytes). PAID DOWN FIRST, in the same + // section: the table's lead sentence ("Open the file for your task first."), which the + // table's own `Open first` column header restates (-36 bytes). 8923 -> 8958 bytes (8896 -> + // 8931 priced), +35, -> 2233 tokens, zero headroom, the row moves +9, the measured + // remainder, pinned AT the measurement; the entry stays inside the 9 KB budget its row above + // pinned. Raise path: ruling record 6513306068, letter B; the standing ruling (2026-10-27, + // verbatim and untranslated): 「A:先削重复,余额按实测提高」. + // ceil(($(wc -c < skills/objectstack-data/SKILL.md) - 27) / 4) == ceil(8931 / 4) + ['skills/objectstack-data/SKILL.md', 2233], // 5997 -> 6008 (the formula skills follow-ups of PRs #34443 and #34447): the // `label(record.f)` row teaches a multi-select (`multiple: true`) reading each // selected label in stored order, joined with `, `, and the built-ins line @@ -1637,7 +1648,23 @@ export const CEILINGS = new Map([ // while the change was open (its row 3541 -> 3540); the same two sections arrive on top of it, // 2639 bytes as before. 14160 -> 16799 bytes -> 4200 tokens, pinned AT the measurement. // ceil($(wc -c < skills/objectstack-data/rules/field-types.md) / 4) == ceil(16799 / 4) - ['skills/objectstack-data/rules/field-types.md', 4200], + // 4200 -> 4566 (#38939): § Currency names the platform's rate table (`sys_exchange_rate`, + // kept in Setup; never an app rate object or a conversion hook) and the refusal of a foreign + // amount with no rate (`ERR_EXCHANGE_RATE_MISSING`); a new § Unit of measure teaches + // `unitConfig` in its three shapes (`'code'` on a `text` field; `'fixed'` with `unit` and + // `'record'` with `unitField` on a `number` field) in one checked example, the stored code + // (exact uppercase; standard UN/ECE Rec 20 codes, `H87` and `KGM` named; an organization's + // own in `sys_unit`), the two write refusals, `unitDimension` and the free-text conversion + // run; the `text` and `number` rows point at it. +1560 bytes. PAID DOWN FIRST by two + // same-file restatement cuts, 97 bytes (45 + 52): the `secret` parenthetical under `## + // Choosing a type` (home: the `secret` row, which says encrypted at rest and names ADR-0100) + // and the parenthetical under `## Changing a field that has data` that repeated the entry's + // trap 1, which the same line already points at. `wc -c` = 18262 bytes (+1463) -> + // ceil(18262 / 4) = 4566 tokens, zero headroom, ceiling +366, the measured remainder, pinned + // AT the measurement. Raise path: ruling record 6513306068, letter B; the standing ruling + // (2026-10-27, verbatim and untranslated): 「A:先削重复,余额按实测提高」. + // ceil($(wc -c < skills/objectstack-data/rules/field-types.md) / 4) == ceil(18262 / 4) + ['skills/objectstack-data/rules/field-types.md', 4566], ['skills/objectstack-data/rules/indexing.md', 2495], // -746 to the measurement (was 3241) // 1590 -> 1909 (#32364, 2026-11-11): § Sealing (`seal`) teaches `lifecycle.seal` // (+1574 B). PAID DOWN FIRST by three same-file restatements (-296 B): the ❌ diff --git a/skills/objectstack-data/SKILL.md b/skills/objectstack-data/SKILL.md index e3f1f1b4da7..d901fd27a36 100644 --- a/skills/objectstack-data/SKILL.md +++ b/skills/objectstack-data/SKILL.md @@ -59,12 +59,10 @@ definition as code. ## Where to go -Open the file for your task first. - | Authoring | Open first | |:--|:--| | An object's other keys, a starter object, field groups, `protection`, an extension | [examples-objects.md](./references/examples-objects.md) | -| A field's type and config, a default, changing a field that has data | [Field Types](./rules/field-types.md) | +| A field's type and config, a default, exchange rates (`sys_exchange_rate`), units of measure (`unitConfig`), changing a field that has data | [Field Types](./rules/field-types.md) | | Names; labels in the request's language | [Naming](./rules/naming.md) | | `lookup` or `master_detail`, junctions, delete behaviour, roll-ups, line items | [Relationships](./rules/relationships.md) | | Validation rules, state machines, uniqueness, conditional field rules | [Validation](./rules/validation.md) | diff --git a/skills/objectstack-data/rules/field-types.md b/skills/objectstack-data/rules/field-types.md index b2eed5cbf5b..701e2e1bbb6 100644 --- a/skills/objectstack-data/rules/field-types.md +++ b/skills/objectstack-data/rules/field-types.md @@ -33,7 +33,7 @@ const fields = { | Type | When to Use | Config | |:-----|:------------|:-------| -| `text` | Single-line strings (names, codes, titles) | `maxLength`, `minLength`, `defaultValue` | +| `text` | Single-line strings (names, codes, titles) | `maxLength`, `minLength`, `defaultValue`, `unitConfig` (→ Unit of measure) | | `textarea` | Multi-line plain text (notes, descriptions) | `maxLength`, `minLength` | | `email` | Email addresses — format validated | `required`, `unique` | | `url` | Web URLs — format validated | `required` | @@ -48,7 +48,7 @@ const fields = { | Type | When to Use | Config | |:-----|:------------|:-------| -| `number` | Numeric value | `min`, `max`, `precision`, `scale` | +| `number` | Numeric value | `min`, `max`, `precision`, `scale`, `unitConfig` (→ Unit of measure) | | `currency` | Monetary amounts | `currencyConfig` (→ Currency) | | `percent` | Percentage; stored as a fraction (0-1) unless the field declares `max` above 1 (`max: 100`), then whole points; seeds, defaults, API values use that scale | `min`, `max`, `precision`, `percentDisplay` — the read-only face: unset or `'bar'` draws a progress bar, `'plain'` the number alone, for a rate or a probability | @@ -182,7 +182,10 @@ a run with neither. `homeAmount` (`'record'` only, all three required): the engine stores the home-currency amount in `field` (a `'dynamic'` `currency`) at the `rateDate` (`date`/`datetime`) rate, and that rate in `rateField` (`number`), both -`readonly: true`. Cross-currency totals sum `field`. +`readonly: true`. Cross-currency totals sum `field`. The rates are the +platform's `sys_exchange_rate`, which an administrator keeps in Setup: never +an app rate object or a conversion hook. A foreign amount with no rate on or +before `rateDate` is refused (`ERR_EXCHANGE_RATE_MISSING`). **A roll-up of the home field.** A `sum` / `min` / `max` / `avg` `summary` over a child's `homeAmount.field` declares `currencyMode: 'dynamic'`, no `defaultCurrency` @@ -215,6 +218,32 @@ Once a line follows it, the invoice's `currency_code` cannot change (`VALIDATION_FAILED`; a first code over a blank one passes) until none does: delete the lines and purge the recycle bin, or move them to another invoice. +### Unit of measure + + +```typescript +import { Field } from '@objectstack/spec/data'; + +const fields = { + uom: Field.text({ unitConfig: { unitMode: 'code' } }), // a unit code, no quantity + weight: Field.number({ unitConfig: { unitMode: 'fixed', unit: 'KGM' } }), + quantity: Field.number({ unitConfig: { unitMode: 'record', unitField: 'unit_code' } }), + unit_code: Field.text(), // no `unitConfig` or `valueDomain` of its own +}; +``` + +A unit is never free text, a picklist or an app unit object: it is +`unitConfig`, on a `number` field (a quantity) or on a `text` field no quantity +points at, and `unitMode` has no default. A record stores the code in exact +uppercase: a standard UN/ECE Rec 20 code (`H87` piece, `KGM` kilogram, `XBX` +box; `STANDARD_UNITS` in `@objectstack/spec/data`), or one the organization +adds to the platform's `sys_unit` in Setup (not under `'fixed'`). The write +refuses any other value (`ERR_UNIT_CODE_UNKNOWN`: `pcs`, `kg`, `C62`, `EA`) and +a quantity beside a blank code (`ERR_UNIT_CODE_REQUIRED`). `unitDimension` +(`'mass'`, `'count'`, …; `'record'` and `'code'`) limits the codes to one +dimension. The quantity stays a bare number. Convert free text stored earlier +with `os migrate unit-codes`. + ### Lookup (One-to-Many) ```typescript @@ -274,8 +303,7 @@ The `format` is literal text interleaved with `{...}` tokens: ## Choosing a type -Beyond `SKILL.md` § Field Type Selection (`secret` is encrypted at rest per -ADR-0100): +Beyond `SKILL.md` § Field Type Selection: - A yes/no flag, `{ type: 'boolean', defaultValue: false }`, is any `is_*`, `has_*`, "done?" or "active?". An unchecked box is @@ -291,7 +319,7 @@ ADR-0100): ## Changing a field that has data -Beyond `SKILL.md` trap 1 (the sync only adds; the column wins at write time): +Beyond `SKILL.md` trap 1: | Change | Existing DB on restart | |--|--|