Repository navigation
Commit 70194ff
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
- .changeset
- content/docs
- data-modeling
- protocol/objectql
- references
- api
- data
- system
- docs/qa/platform-checklist/areas
- packages
- cloud-connection/src
- drivers/driver-sql/src
- metadata-core/src
- objects
- metadata-protocol/src
- platform-objects/src
- apps/translations
- audit
- identity
- system
- plugins
- plugin-audit/src
- objects
- plugin-sharing/src/objects
- qa/dogfood/test
- services
- service-automation/src
- service-messaging/src/objects
- service-realtime/src/objects
- spec
- authorable-surface
- liveness
- state-counts
- src/data
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
| 622 | + | |
622 | 623 | | |
623 | 624 | | |
624 | 625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
509 | 510 | | |
510 | 511 | | |
511 | 512 | | |
512 | | - | |
| 513 | + | |
| 514 | + | |
513 | 515 | | |
514 | 516 | | |
515 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
622 | | - | |
| 622 | + | |
623 | 623 | | |
624 | | - | |
625 | | - | |
| 624 | + | |
| 625 | + | |
626 | 626 | | |
627 | 627 | | |
628 | 628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
968 | 968 | | |
969 | 969 | | |
970 | 970 | | |
971 | | - | |
| 971 | + | |
972 | 972 | | |
973 | 973 | | |
974 | 974 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
0 commit comments