Skip to content

Commit 70194ff

Browse files
feat(audit): the activity stream shows each changed field's old → new values by default, served only for fields the reader may read (#36399)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCxiFE11rsKwyNffJZKYqJs)_ Part of #36290 PR 1 of 3 (spec + server). PR 2 draws per-field rows on the record page from the served change code, and PR 3 adds the per-field history card (`Fixes #36290`). Shape approved by the seat (option B: a new key, `enable.fieldHistory`, with no default), per ruling 7076513167. Clause-②: yes (widening) Metadata-protocol: semantic Skills-docs: carried by #36419 ## 维护者速读 - 记录的动态里,每个被修改的字段现在默认显示「字段:旧值 → 新值」,所有对象都一样;对象写 `enable: { fieldHistory: false }` 可整体关闭,字段写 `fieldHistory: false` 可单独关闭。成员只能看到自己有权读取的字段的修改,不开放 `sys_audit_log`。 - 属于「记录页字段修改历史」:以前只有逐个字段写了 `trackHistory: true` 才显示值,其余修改只写字段名。新开关没有默认值,所以已构建或已存储的对象升级后直接生效,不需要重新构建。 - 若出错,可能表现为成员看到不该看到的字段值(读取侧已按字段逐条收窄并有测试钉住),或某条动态写入失败(摘要已按 500 字符上限截断)。可整体撤回,已写入的动态行不受影响。 - 升级注意:`trackHistory: false`(对象上或字段上)都不再关闭值显示。要关闭,对象请写 `enable.fieldHistory: false`,字段请写 `fieldHistory: false`。字段设计器以前每次保存都会写 `trackHistory: false`,所以这个值不能当作关闭开关;仓库内 44 个平台对象已补上对象级开关。 ## What changes **Spec** (`packages/spec/src/data/object.zod.ts`, `field.zod.ts`, forms): - New `ObjectCapabilities.fieldHistory: z.boolean().optional()` with no default. Absent: values show. `false`: values off for the object. It has no default on purpose: `ObjectSchema.parse` materializes every defaulted `enable` key whenever an `enable` block exists, so a default would be written into every built artifact and stored definition (measured: 33 of 38 hotcrm objects carry an `enable` block). With no default, an upgraded install gets values with no rebuild. - `enable.trackHistory` keeps its schema and meaning (default `false`; with `true` the default record page reads the compliance ledger and the derived `history` verb is served). Its describe now says that value display is `fieldHistory`'s question. - New `FieldSchema.fieldHistory: z.boolean().optional()`, no default: the field's off switch. Absent: values show. `false`: the change is named by label only. `true`: values show, a media or JSON type included. Under an object with `enable.fieldHistory: false`, values stay off whatever the field says. - Field `trackHistory` keeps its schema. `false` now reads like absent (values show): the field designer wrote `trackHistory: false` on every save while the key meant nothing (`FieldDesigner.tsx`, persisted by `MetadataFieldsPage.tsx`), so a stored `false` cannot be told from a choice. `true` keeps one job: it opts a media or JSON field in. - Object form `enable` composite offers `fieldHistory`; the object form's `fields` repeater and the field form offer the field `fieldHistory`. Each row's help text says that unset means on, although the switch shows off. Liveness entries `object.json#fieldHistory` and `field.json#fieldHistory` (live, evidence `audit-writers.ts#changeValuesShownFor`). - The two closures over every `FieldSchema` key classify the new key: driver-sql `FIELD_KEY_STORAGE_CLASS` (`presentation`: `createColumn` never reads it) and metadata-core `FIELD_REFERENCE_POSITIONS` (`keep`: a boolean that names no field). The metadata-protocol `field` property count moves 84 → 85. **Writer** (`packages/plugins/plugin-audit/src/audit-writers.ts`): - `changeValuesShownFor(objectDef)` decides per changed field: off when the object writes `enable.fieldHistory: false`, or the field writes `fieldHistory: false`, or the field is a credential (`collectMaskedReadFields`: `secret`, and `password` off better-auth objects — both sides would be the same mask). Media and structured-JSON types (`image`, `file`, `avatar`, `video`, `audio`, `signature`, `composite`, `repeater`, `record`, `location`, `address`, `code`, `json`, `vector`) show values only with an explicit `fieldHistory: true` or `trackHistory: true`. Everything else is on, including a field that writes `trackHistory: false`. - `renderTrackedChangeSummary` and `planTrackedLookupReads` take that predicate instead of reading `trackHistory === true`. - The stored summary is fitted to `sys_activity.summary`'s `maxLength` (500) by `fitStoredChangeSummary`: each side is cut to 60 characters first, then trailing changes are left out (`; …`). Before this, the tracked branch was not fitted, so a long value would fail the insert under default-on. The `summary_message` code keeps every change, each side capped at 1,000 characters. **Read side** (`activity-field-redaction.ts`, `activity-summary-message.ts`, `audit-plugin.ts`): - The `fieldChanges` code (`metadata.summary_message`) is now served to readers, narrowed change by change with the same `resolveServedFields` answer as `metadata.old` / `metadata.new`. A reference field's change is kept only for a reader served the referenced record's title (`referenceTitlesPerRead`). Any other code is still stripped for non-system readers, and `text_sources` stays stripped. - When a reader is not served the stored summary, it is recomposed from the narrowed changes in the reader's locale instead of dropped whole. A row whose every change is withheld is still withheld as a row. - The summary-locale middleware is now registered before the redaction middleware, so redaction runs inside it and the locale composer sees the narrowed code. **44 in-repo objects** that wrote `trackHistory: false` now also write `fieldHistory: false`, so their "no history" holds: cloud-connection `sys-cloud-binding-credential`; metadata-core `sys-metadata-audit`, `sys-metadata-commit`, `sys-metadata-history`; platform-objects `sys-attachment`, identity `sys-account`, `sys-device-code`, `sys-jwks`, `sys-oauth-access-token`, `sys-oauth-client-assertion`, `sys-oauth-client-resource`, `sys-oauth-consent`, `sys-oauth-refresh-token`, `sys-oauth-resource`, `sys-personal-view`, `sys-session`, `sys-two-factor`, `sys-user-preference`, `sys-verification`, system `sys-lifecycle-state`, `sys-migration-journal`, `sys-migration`, `sys-platform-setting-audit`, `sys-platform-setting`, `sys-recycle-bin`, `sys-secret`, `sys-seed-landed-key`, `sys-setting-audit`, `sys-setting`, `sys-trusted-key`; plugin-audit `sys-activity`, `sys-audit-amendment`, `sys-audit-checkpoint`, `sys-audit-log`, `sys-audit-signing-key`, `sys-comment-reaction`; plugin-sharing `sys-share-link`; service-automation `sys-connector-connection`, `sys-connector-credential`, `sys-flow-credential`; service-messaging `channel-account`, `channel-user-link`, `user-device`; service-realtime `sys-presence`. hotcrm at `689166c`: 0 objects write `trackHistory: false` (reported to the seat; nothing pushed there). **Files that moved because the default flipped** (approved by the seat as growth within the ruling): - *Object-form translation bundles, 11 locales* (`packages/platform-objects/src/apps/translations/*.metadata-forms.generated.ts`): the new `enable.fieldHistory` label, and the two `trackHistory` help texts, which still said "opt-in per field". Why it moved: the form offers a new row, and the old help text is now false. Since review round 1 they also carry the field `fieldHistory` row labels and the new help texts. Count pins move with them: `object-collapsed-sections-echo-decisions.test.ts` (panel leaves 117 → 119, capabilities 11 → 13, open leaves 128 → 130) and `object-lifecycle-panel-echo-decisions.test.ts` (positive control 756 → 759). - *Two dogfood files*: `field-history-tracking-activity.dogfood.test.ts`, whose website-only leg pinned the label-only frame and now reads `Website: https://before.example → https://after.example` (why: `website` declares no `trackHistory`, so it is on). `activity-label-display-field.dogfood.test.ts`: its `REF_TITLED` fixture gets `enable: { fieldHistory: false }`. Why: those pins read the update frame that names the record by its label (the referenced title). With values on, the update's summary would be `Name: titled → titled again`, which names no record label, so the withheld/served pair would pass without testing anything. With values off, the frame still names the record label, so the pins keep testing whether the title is served. - *Checklist item* `records-forms.field-history-tracking` rev 16: title, acceptance[1], negative[0], automated.ref and source[1] said values were opt-in per field. Why: they now describe the shipped default. - *Four hand-written docs*: `protocol/objectql/security.mdx` §7, `data-modeling/objects.mdx` flag table, `data-modeling/fields.mdx` and `data-modeling/validation-rules.mdx` `trackHistory` rows. Why: each said values were opt-in. ## Review round 1 (L2 7078144432 FAIL, L1 7078132570 REWORK) - **M1, designer-saved `trackHistory: false`.** Closed by a field key of its own instead of a conversion (seat OK'd). A stored-row conversion was measured and rejected: `applyConversionsToStoredItem` (`packages/spec/src/conversions/stored.ts`) replays the whole chain on every read with `includeRetired: true` and no version window. So a conversion that drops field `trackHistory: false` would also erase every deliberate opt-out saved after the upgrade, on every load. With `fieldHistory` as the off switch, a stored `trackHistory: false` reads like absent, so fields already saved through the designer show values after the upgrade with no conversion. Census: no code-authored field in `packages/**` or `examples/**` writes `trackHistory: false`; all 45 occurrences are object-level `enable` blocks (44 objects plus a comment). - **S1, two-state switch.** Each `fieldHistory` row and the field `trackHistory` row now have help text. Renderer, read at this head: `SchemaForm.tsx` draws a boolean as `<Switch checked={!!value} onCheckedChange={(c) => onChange(c)} />`. So an untouched switch writes nothing, and only a toggle writes `true` or `false`. It cannot show unset apart from `false`: an unset `fieldHistory` shows as off while values show. The help text says this. A third state is a renderer change that no PR on this card carries. - **Nits.** The field describe now says an object `enable.fieldHistory: false` wins over a field `true` (pinned). Not taken: `tree` changes still show a stored id, and multi-value option types show stored values joined by commas. The card's acceptance names select, lookup and user, and those three resolve. - **L1.** `Skills-docs: carried by #36419`. #36419's step 1 still names field `trackHistory: false` as the field's off switch. At this head it is field `fieldHistory: false`, and the seat owns that card's text. ## Census: every reader of `enable.trackHistory` (seat rider) None of these reads changes meaning, because `trackHistory` is untouched: - objectstack `packages/spec/src/data/api-derivation.ts` (`history` verb, `=== true`). - ui `RecordDetailView.tsx` (`historyEnabled`: `!== true` → no ledger read); `appObjectScope.ts` (`recordStreamObjectNames`, `=== true`); `ObjectSettingsPanel.tsx` (opt-in toggle; writes an explicit boolean; a `fieldHistory` toggle is PR 2). - `plugin-approvals` `approval-service.ts` (type only); cli `explain.ts` (doc example); metadata-core `object-schema-fls-references.ts` (key list). - Not readers: database-loader's `trackHistory` is an unrelated loader option; driver-sql `builtin-column-collision` is a name map; hotcrm has comments only. - UI producers of the field key: `FieldDesigner.tsx` writes `trackHistory: data.trackHistory === true` on create and edit (so every save writes an explicit `false`), and `ObjectFieldInspector.tsx` reads `!!def.trackHistory`. Since this head that `false` reads like absent, so it no longer changes behaviour. PR 2 moves both producers to `fieldHistory`. ## Tests - `audit-writers.test.ts`, new describe `[#36290] a changed field shows old → new unless the object or the field turns it off`: absent → on; `enable.fieldHistory: false` → label only; `enable.trackHistory: false` alone → still on (the upgrade note); field `fieldHistory: false` → label only; field `trackHistory: false` (what the designer wrote) → values still show; object `enable.fieldHistory: false` wins over field `fieldHistory: true`; `json` with `fieldHistory: true` → on; credential → label only; `json` → only with `true`; a long value inserts at ≤ 500 with each code side capped at 1,000 and `…`; 30 changes fit with `; …`. - `activity-field-redaction.test.ts`, `[#36290]` code pins: a system reader gets the full code; a masked reader's code omits the masked field; an unserved reader's code and recomposed summary omit the unserved field; the control reader gets it all; a non-`fieldChanges` code is still not served; a reference change is kept only under the title rule. These fail if the per-change narrowing is removed (each asserts the absent field is absent from summary, code and old/new). - `spec/src/data/object.test.ts`: a parsed `enable` block carries no `fieldHistory` key, and `false` survives parse. - Fixtures that pin the label-only frame now say so (field `fieldHistory: false` or `enable.fieldHistory: false`): `audit-milestone-summary`, `audit-lookup-summary`, `audit-writers` (amount, campaign, person_qualification), `activity-lookup-name-field-label-34055`, `activity-summary-reader-locale.integration`. ## Verification Head `aa362ba1`: a merge of main after #36449 (#36425 `showOnCreate`) landed. Against main, the PR's diff changes in two places only: the metadata-protocol `field` count (85 → 86) and the generated liveness count (`field` 115). Re-run at `aa362ba1`: metadata-protocol pin 18, driver-sql closure 11, metadata-core FLS 63, platform-objects translations 610, spec `src/data` 6713, plugin-audit writers + redaction 181, `check:generated`, checklist and i18n-bundle checks all pass. Before that, `d531553a` was `c43a42bb` plus one changeset line naming `@objectstack/driver-sql` at patch (L1 7080045587); the figures below were measured at `c43a42bb`, and this commit changes no source. Round 2 (`6e416547` the field key, `17772933` the metadata-protocol count, `c43a42bb` the two key closures) on top of round 1 (`851997e6`). - plugin-audit full suite: 109 files / 1809 tests passed (round 2). - spec `src/data` 187 files / 6708 passed; platform-objects translations 610 passed; metadata-core full suite 27 files / 1048 passed; driver-sql `builtin-column-collision` 2 files / 18 passed; metadata-protocol `meta-types-degenerate-derivation` 18 passed; lint `validate-security-posture` + `rule-explanations` 232 passed; cli `data-model-rules` 65 passed; service-messaging and metadata-core `builtin-column-storage-attributes` 18 passed. - Ablations at round 2 (each restored, `git diff HEAD` empty after): removing the field `fieldHistory === false` check of `changeValuesShownFor` reds 4 tests in `audit-writers.test.ts`; making field `trackHistory: false` an off switch again reds the `designer_saved` pin; removing the driver-sql `fieldHistory` row reds `classifies EVERY FieldSchema key, and invents none`. Round 1's ablations (per-change narrowing 9 of 40, `enable.fieldHistory` branch 8 of 139) still hold. - `dispatch-gates --commands` at round 2: 128 commands, every one exit 0; `dispatch-gates --ran`: 128 derived, 128 run, 0 NOT-MEASURED. This sweep does not derive the driver-sql and metadata-core key closures; CI's Test Core 3/10 and 10/10 found them at `17772933`, fixed in `c43a42bb`. - Full dogfood battery at `c43a42bb`, after rebuilding driver-sql and metadata-core under the verify lock (build VERDICT command-exit 0): `vitest run` lock VERDICT command-exit 0, Test Files 484 passed / 3 skipped (487), Tests 4107 passed / 68 skipped (4175), no failures. The same battery at `6e416547` + `17772933` gave the same counts. - CI at `c43a42bb`: 70 check-runs completed, 60 success and 10 skipped, none failed (Test Core 10/10, Test UI 16/16, Type Check UI and workspace, every Lint lane, Build Core, Build Docs, Live E2E UI, Check Changeset, PR-body guards, Spec property liveness). - `overlap-check` at `aa362ba1`: clean against `origin/main`. #36449 has landed and is merged in. #36392 now conflicts only in the generated `liveness/state-counts/field.md`. Two-minute check: `pnpm --filter @objectstack/plugin-audit exec vitest run src/audit-writers.test.ts src/activity-field-redaction.test.ts -t 36290`. Read first, by risk: 1. `packages/plugins/plugin-audit/src/activity-field-redaction.ts`: the per-change narrowing of `summary_message` and the recomposed summary. 2. `packages/plugins/plugin-audit/src/audit-writers.ts`: `changeValuesShownFor` and `fitStoredChangeSummary`. 3. `packages/plugins/plugin-audit/src/audit-plugin.ts`: the middleware order. --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jRCdMrPNTumXfsr1mw <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jRCdMrPNTumXfsr1mw --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0a6af56 commit 70194ff

92 files changed

Lines changed: 831 additions & 118 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/plugin-audit': minor
4+
'@objectstack/platform-objects': patch
5+
'@objectstack/metadata-core': patch
6+
'@objectstack/driver-sql': patch
7+
'@objectstack/cloud-connection': patch
8+
'@objectstack/plugin-sharing': patch
9+
'@objectstack/service-automation': patch
10+
'@objectstack/service-messaging': patch
11+
'@objectstack/service-realtime': patch
12+
---
13+
14+
feat(audit): a record's activity stream shows each changed field's old → new values by default, with a new `fieldHistory` off switch on the object and the field, and a reader is served only the changes of fields they may read
15+
16+
Clause-②: yes (widening)
17+
Metadata-protocol: semantic
18+
19+
A record's activity stream now shows `Field: old → new` for every changed field, on every object, unless the object or the field turns it off. Before, values showed only for a field that declared `trackHistory: true`. Every other change was named by its field label alone.
20+
21+
- **New `enable.fieldHistory`, with no default.** Absent: values show. `false`: off for the object, and a change names its fields only. It has no default so that a parsed body never writes one. A built artifact or a stored definition therefore gets values when it is upgraded, with no rebuild.
22+
- **`enable.trackHistory: false` alone no longer turns values off.** The flag keeps its meaning: with `true`, the default record page shows the compliance ledger's field changes to a reader the ledger serves, and the derived `history` API verb is served. To keep an object's activity free of values, write `enable: { fieldHistory: false }`. Every platform object that wrote `trackHistory: false` now also writes `fieldHistory: false`.
23+
- **New field `fieldHistory`, with no default: the field's off switch.** Absent shows the values, `false` names the change without them, `true` shows them (a media or JSON type included). Under an object with `enable.fieldHistory: false`, values stay off whatever a field says.
24+
- **Field `trackHistory: false` no longer means anything: it reads like absent, so the values show.** The field designer wrote it on every save while the key meant nothing, so a stored `false` cannot be told from a choice. `trackHistory: true` keeps one job: it opts a media or JSON field in. A credential field (`secret`, and `password` off better-auth objects) never shows values, because both sides are the same mask. A media or structured-JSON field (`image`, `file`, `avatar`, `video`, `audio`, `signature`, `composite`, `repeater`, `record`, `location`, `address`, `code`, `json`, `vector`) shows them only with an explicit `true` (`fieldHistory` or `trackHistory`).
25+
- **The new field key is classified where every `FieldSchema` key is.** The SQL driver counts `fieldHistory` as a presentation key, so creating a column never reads it. The field-level-security scrub keeps it as written, because a boolean names no field.
26+
- **Who reads a value:** the field-change code (`metadata.summary_message`) is now served to readers. It is narrowed change by change with the same field answer as `metadata.old` and `metadata.new`. A reference field's change is kept only for a reader served the referenced record's title. When a reader is not served some of a summary's changes, the summary is rebuilt from the changes they are served instead of being dropped whole. The full audit ledger is not widened.
27+
- **A long value no longer fails the activity insert.** The stored summary is fitted to `sys_activity.summary`'s `maxLength` (500): each side is cut first, then trailing changes are left out. The code keeps every change, with each side capped at 1,000 characters.
28+
29+
To keep an object's activity free of values, set `enable: { fieldHistory: false }` on it. For one field, set `fieldHistory: false` on that field; `trackHistory: false` does not turn values off.

‎content/docs/data-modeling/fields.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ Database indexes are declared at the object level in the object's `indexes[]` ar
618618
| Property | Type | Default | Description |
619619
| :--- | :--- | :--- | :--- |
620620
| `requiredPermissions` | `string[]` | — | Capabilities required to read/edit this field — masked on read, denied on write unless the caller holds all of them (ADR-0066 D3) |
621-
| `trackHistory` | `boolean` | — | Render this field's value changes as entries on the record activity timeline |
621+
| `trackHistory` | `boolean` | — | Opt a media or JSON field into old → new values on the record activity timeline; other fields show them already, and `false` does not hide them |
622+
| `fieldHistory` | `boolean` | — | This field's old → new values on the record activity timeline: absent shows them, `false` turns them off |
622623
623624
For values that must be encrypted at rest (API keys, tokens, DB passwords), use the
624625
`secret` field type — see the [Field Type Gallery](/docs/data-modeling/field-types#secret).

‎content/docs/data-modeling/objects.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ enable: {
9292
| Flag | Default | Description |
9393
| :--- | :--- | :--- |
9494
| `trackHistory` | `false` | Field history tracking for audit compliance |
95+
| `fieldHistory` | — (on) | Field-change values (`old → new`) on the activity stream; `false` turns them off for the object |
9596
| `searchable` | `true` | Index records for global search |
9697
| `apiEnabled` | `true` | Expose object via automatic APIs |
9798
| `apiMethods` | all | Whitelist over the six primitives (`get/list/create/update/delete/bulk`); derived verbs (search/export/upsert/…) follow automatically. `undefined` = all, `[]` = none |

‎content/docs/data-modeling/validation-rules.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ These properties apply to **all** field types and are validated by the base `Fie
2929
| `readonly` | `boolean` | `false` | Blocks user edits in UI forms; server-enforced on **both create and update** — a non-system write to the field is silently dropped from the payload (system-context writes such as import/seed/migration are exempt) |
3030
| `sortable` | `boolean` | `true` | Whether field appears in list view sort options |
3131
| `externalId` | `boolean` | `false` | Not read: nothing matches on it. A seed dataset names its match field in its own `externalId`, an import in its mapping's `upsertKey` |
32-
| `trackHistory` | `boolean` | — | Render this field's value changes as entries on the record activity timeline |
32+
| `trackHistory` | `boolean` | — | Opt a media or JSON field into old → new values on the record activity timeline; other fields show them already, and `false` does not hide them |
33+
| `fieldHistory` | `boolean` | — | This field's old → new values on the record activity timeline: absent shows them, `false` turns them off |
3334
| `visibleWhen` | `string \| Expression` | — | CEL predicate; field is shown only when `TRUE` |
3435
| `readonlyWhen` | `string \| Expression` | — | CEL predicate; field is read-only when `TRUE` |
3536
| `requiredWhen` | `string \| Expression` | — | CEL predicate; field is required when `TRUE` |
@@ -509,7 +510,8 @@ For sensitive data, use the properties and types the platform actually enforces:
509510
| Property | Type | Default | Description |
510511
|:---|:---|:---|:---|
511512
| `requiredPermissions` | `string[]` | — | Capabilities required to read/edit the field — masked on read, denied on write unless the caller holds all of them (ADR-0066 D3) |
512-
| `trackHistory` | `boolean` | — | Render the field's value changes as entries on the record activity timeline |
513+
| `trackHistory` | `boolean` | — | Opt a media or JSON field into old → new values on the record activity timeline; other fields show them already, and `false` does not hide them |
514+
| `fieldHistory` | `boolean` | — | This field's old → new values on the record activity timeline: absent shows them, `false` turns them off |
513515

514516
For reversible encrypted-at-rest values (API keys, tokens, DB passwords), use the
515517
`secret` field type — it is the type with an enforced encryption/masking code path

‎content/docs/protocol/objectql/security.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ Set `deterministicEncryption: true` to allow equality queries on the ciphertext,
619619

620620
## 7. Auditing & Field History
621621

622-
Object- and field-level history is opt-in metadata, not a free-form `enable.audit` block.
622+
Object- and field-level history is declared metadata, not a free-form `enable.audit` block.
623623

624-
- **Object history** — set `enable.trackHistory: true` on the object (the `ObjectCapabilities` block in `object.zod.ts`) to surface the record's field changes. On the default record page they join the one Timeline stream (its Changes filter); an assigned page shows them where it places a `record:history` block.
625-
- **Per-field history** — set `trackHistory: true` on an individual field to render that field's value changes on the record activity timeline. (The former per-field `auditTrail` flag was pruned in 2026-06 — it had no runtime consumer.)
624+
- **Field-change values** — a record's activity stream shows `Field: old → new` for every changed field by default. Set `enable.fieldHistory: false` on the object to name changes by their field label only, or `fieldHistory: false` on one field to do that for the field (`trackHistory: false` does not turn values off). Credential fields never show values, and media or structured-JSON fields show them only with `fieldHistory: true` or `trackHistory: true`. A reader is served only the changes of fields they may read.
625+
- **Object history** — set `enable.trackHistory: true` on the object (the `ObjectCapabilities` block in `object.zod.ts`) to surface the compliance ledger's field changes. On the default record page they join the one Timeline stream (its Changes filter); an assigned page shows them where it places a `record:history` block. `enable.trackHistory` does not turn field-change values on or off. (The former per-field `auditTrail` flag was pruned in 2026-06 — it had no runtime consumer.)
626626
- **RLS audit** — removed (2026-07, ADR-0056 D8): the `RLSAuditConfigSchema`/`RLSAuditEventSchema` shapes were never emitted or read by the runtime RLS path and were deleted from the spec. Enforcement decisions surface today through the security plugin's fail-closed warnings and the standard audit log (`plugin-audit`), not a dedicated RLS event stream.
627627

628628
```yaml

‎content/docs/references/api/metadata.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ Metadata query with filtering, sorting, and pagination
968968
| **editMode** | `Enum<'modal' \| 'page'>` | optional | Edit-interaction intent for records of this object: 'modal' opens the edit form as a dialog over the current view; 'page' navigates to a dedicated full-page edit route. Absent = the renderer picks its own default (objectui defaults to modal). Cross-renderer intent, not pixel styling (family). |
969969
| **listViews** | `Record<string, { name?: string; label?: string \| Record<string, string>; type?: Enum<'grid' \| 'kanban' \| 'gallery' \| 'calendar' \| 'timeline' \| 'gantt' \| 'map' \| …>; data?: object \| object \| object; … }>` | optional | Built-in named list views (segmented tabs) shipped with the object schema — "views" mode, dropdown userFilters allowed, no page-only tabs (ADR-0047) |
970970
| **searchableFields** | `string[]` | optional | Fields the `$search` query matches against (ADR-0061). Canonical default for the record picker, list quick-search and global search; views may narrow it. When unset, search auto-defaults to the name/title field plus short-text fields. Entries must name a STORED column: a virtual `formula` field is computed on read and materializes no column, so searching it can never match and it is refused — mirror the value onto a stored text field and declare that. |
971-
| **enable** | `{ trackHistory?: boolean; searchable?: boolean; apiEnabled?: boolean; apiMethods?: Enum<'get' \| 'list' \| 'create' \| 'update' \| 'delete' \| 'bulk'>[]; … }` | optional | Enabled system features modules |
971+
| **enable** | `{ trackHistory?: boolean; fieldHistory?: boolean; searchable?: boolean; apiEnabled?: boolean; … }` | optional | Enabled system features modules |
972972
| **sharingModel** | `Enum<'private' \| 'public_read' \| 'public_read_write' \| 'controlled_by_parent'>` | optional | Org-Wide Default record visibility (OWD) for INTERNAL users. Canonical four only (legacy aliases removed, ADR-0090 D4): private (owner-only) \| public_read (everyone reads, owner writes) \| public_read_write (everyone reads+writes) \| controlled_by_parent (derived from the master record). A CUSTOM object that omits this resolves to private at runtime (ADR-0090 D1). |
973973
| **sharing** | `{ controlledByParent?: object }` | optional | Per-object sharing opt-ins that refine the org-wide default sharingModel declares. controlledByParent.ownerMayEdit: on a controlled_by_parent detail, the row's owner may update it with read access to the master (ADR-0055 §3 amendment). controlledByParent.writeRequiresMasterRead: anyone who reads the master may write the detail under the detail's own permissions. |
974974
| **defaultRowScope** | `{ name: string; label?: string; description?: string; operation: Enum<'select' \| 'insert' \| 'update' \| 'delete' \| 'all'>; … }` | optional | The object's default row scope: one row-level security policy, written like a permission set's `rowLevelSecurity` entry without `object` (the declaring object is implied; writing `object` is refused). The security plugin's row-policy collection, the one step every read, write and explain passes through, applies it when no permission set the caller holds carries a row policy for this object and the operation: a held policy for every object (`'*'`) counts, while one for another operation, switched off, or outside the caller's positions does not. A policy an authored set carries for the object is used as authored, with this default not added to it; a principal whose superuser bypass skips row policies is unaffected; an object that declares none keeps the behaviour it has without the key. The default is judged like a held policy: its `operation`, `positions` and `enabled` decide where it applies, and a `using` the row-filter compiler cannot lower makes every read it governs return no rows, with one warning in the server log. `os validate`, `os build` and `os lint` judge this predicate as they judge a permission set's policy and report one that cannot lower; saving the object through the server does not run that check, so keep it inside the lowerable subset. Explain names an applied default as the object's own, not a permission set's. |

‎content/docs/references/data/field.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const result = CurrencyConfigSchema.parse(data);
105105
| **currencyConfig** | `{ currencyMode?: Enum<'dynamic' \| 'fixed' \| 'record'>; defaultCurrency?: string; currencyField?: string; homeAmount?: object }` | optional | Which currency an amount is in: for a currency field, for a formula field whose returnType is currency, and for a summary that rolls up, through a master_detail, child amounts that follow this record's currency (`currencyMode: 'record'` naming this object's own code field). A summary that rolls up an amount in the home currency (a child `currency` field in `dynamic` mode, a stored home amount included) declares `currencyMode: 'dynamic'`, with no `defaultCurrency`, and shows in the organization's home currency. A summary may otherwise declare only `currencyMode: 'fixed'`, when every amount it reads is in that one currency; a `count` summary, any other `dynamic` summary and any other `record` roll-up are refused, by `defineStack` and by a single-object save or publish on a running server alike. Absent: dynamic mode, and no currency on a summary. |
106106
| **unitConfig** | `{ unitMode: 'fixed'; unit: Enum<'KGM' \| 'GRM' \| 'MGM' \| 'TNE' \| 'LBR' \| 'ONZ' \| 'MTR' \| 'MMT' \| 'CMT' \| 'KMT' \| …> } \| { unitMode: 'record'; unitField: string; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> } \| { unitMode: 'code'; unitDimension?: Enum<'mass' \| 'length' \| 'area' \| 'volume' \| 'time' \| 'count' \| 'package'> }` | optional | Which unit a quantity is in, or that a text field holds a unit code (units of measure). On a `number` field: `{ unitMode: 'fixed', unit }`, one standard UN/ECE Recommendation 20 code checked at build (e.g. `KGM`, `MTR`, `H87`), or `{ unitMode: 'record', unitField, unitDimension? }`, where each record names its own unit in the sibling `text` field `unitField` names. On a `text` field that holds a unit code with no quantity pointing at it: `{ unitMode: 'code', unitDimension? }`. The quantity stays a bare number; a record stores the unit CODE in exact uppercase, never an id. At write, a code must be a standard code or one of the organization's own non-retired units (`sys_unit`), of the restricted dimension when one is declared, and a quantity beside a blank code is refused. Refused on every other field type, `formula` and `summary` included. Absent: the number has no unit. |
107107
| **dimensions** | `integer` | optional | Vector dimensionality (e.g., 1536 for OpenAI embeddings) |
108-
| **trackHistory** | `boolean` | optional | Render this field's value changes as human-readable entries on the record activity timeline (ADR-0052 §5b). Opt-in per field. |
108+
| **trackHistory** | `boolean` | optional | Opt a media or structured-JSON field into old → new values on the record activity timeline (ADR-0052 §5b). Every other field shows them already, so true changes nothing there. false and absent read the same: values show. false is not an off switch; turn a field's values off with fieldHistory: false. |
109+
| **fieldHistory** | `boolean` | optional | This field's old → new values on the record activity timeline. Absent: they show (a media or structured-JSON type only with true). false: off, the change names the field's label only. true: on, a media or JSON type included. Off whatever this says when the object sets enable.fieldHistory: false; a credential field never shows values. Who reads a value is this field's read rule. |
109110
| **group** | `string` | optional | Older spelling of field-group membership, still read: the key of one of the object's fieldGroups (e.g. "contact_info"); the field joins that group in field declaration order. New metadata lists members on the group instead (fieldGroups[].fields), which also sets their order. A field a group lists may not name a different group here; a field naming a group whose fields list leaves it out follows the listed ones. |
110111
| **visibleWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is shown only when TRUE (else hidden). e.g. P`record.type == 'invoice'`. On a `required` field the server reads it on every write: where it is not TRUE (FALSE, or null such as an unset boolean) the field is not required for that write, and a predicate the server cannot evaluate counts as shown, so the field stays required. Reads the record's own columns, with `formula` fields computed over the record being written, as the form computes them over the record being edited; a read THROUGH a reference field, or a formula that reads through one, calls label(), calls can() on a write that picks no permission-gated option, or reads current_user on a system write with no user, cannot be evaluated there. |
111112
| **readonlyWhen** | `string \| { dialect: Enum<'cel' \| 'cron' \| 'template'>; source: string; ast?: any; meta?: object }` | optional | Predicate (CEL) — field is read-only when TRUE. e.g. P`record.status == 'paid'`. Reads the bound record's OWN columns: the field level never reads a related record, so a read THROUGH a reference field (`record.account.tier`) faults on every row and refuses every update that writes the field — `objectstack validate` refuses it. Put such a check in a `validations[]` `script` rule, whose `condition` is read one hop through a reference. |

0 commit comments

Comments
 (0)