Repository navigation
Commit 4211f50
feat(app-shell,components): Open the full form on an AI chat update card applies its proposed changes, before → after; a record in a list drawer is the chat's record in view (#31477)
<!-- claude-projects-attribution: {"github_login":"os-zhuang"} -->
_Requested by **Sam** · [project
thread](https://claude.ai/code/project/chan_01GsBogozeZG5sdpAARrN7HP?thread=cmsg_01GsBogozeZG5sdpAARrN7HPEvrGVfJq9tc5dC5mUCKJAd)_
Closes #28106
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:AI 聊天里的「修改记录」卡片点「打开完整表单」时,编辑页现在带着 AI 建议的新值打开:每个字段显示原值和新值,标「AI
建议」,可以逐个还原,不会自动保存。另外,列表页右侧抽屉打开某条记录时,聊天也会知道「这条」指的是哪条记录。
- 为什么改:之前点「打开完整表单」只打开原记录,AI 建议的修改要用户重新输入一遍;抽屉里问「把这条电话改成……」时 AI 不知道是哪条记录。
- 风险与回滚:只改控制台界面(三个前端包),不动规格和服务端;值走路由状态,不进网址。回滚即还原本 PR。
-
先看:`ui/packages/components/src/renderers/form/form.tsx`(建议值的应用、原值行和还原按钮)、`ui/packages/app-shell/src/views/RecordFormPage.tsx`(编辑页读取建议值)、`ui/packages/app-shell/src/layout/chatSurfaceContext.ts`(抽屉记录)。
- 两分钟验证:`cd ui && pnpm exec vitest run
packages/components/src/renderers/form/__tests__/form-aiSuggestedMark-28104.test.tsx`,预期
11 个用例全部通过。
- 需要你做的:无,席位落地。
## What changes
The card's premise was re-measured before any code; two of its four
items had already moved:
- **Item 1 (record page sends the ask context) was already done** by
objectstack#30043: the console dock sends `context.surface = { artifact:
{ type: 'object', name }, selection: { kind: 'record', id } }` on every
record route (`ui/packages/app-shell/src/layout/chatSurfaceContext.ts`,
`ConsoleLayout.tsx`), and cloud reads it
(`service-ai/src/turn-grounding.ts`, whose record-focus block points the
agent at `update_record`). What was still open is the record **drawer**:
`?recordId=` over a list was read off the pathname only, so the dock
sent the object alone. That gap is closed here.
- **Item 2 (`open_record` with `proposedValues`) has no producer any
more.** cloud#3565 removed that arm from `open_record` ("one way to
propose a change, not two",
`service-ai-studio/src/tools/open-record.tool.ts` header). An edit from
chat is now `update_record`, rendered as the record-write card. A
consumer for `proposedValues` would be dead code, so it is not built.
- **What survives of items 2 and 3**, accepted by the dispatching seat:
the update card's "Open the full form" opened `/record/:id/edit` on the
stored record alone, so every change the card proposed had to be typed
again. It now carries the card's proposed values there, through the
router-state carrier objectstack#28104 introduced, and the edit form
shows each as before → after, marked with the same 「AI 建议」 mark, with a
per-field revert, and never submits on its own.
### The changes
1. **Drawer context** (`chatSurfaceContext.ts`, `ConsoleLayout.tsx`): on
the three list routes (`:objectName`, `:objectName/data`,
`:objectName/view/:viewId`), a non-empty `?recordId=`
(`RECORD_DRAWER_PARAM`) makes the surface name the object and that
record, exactly the shape the record page sends. The New page, a record
page and pages with no artifact read as before. Same `context.surface`
shape, no second one.
2. **Carrier** (`utils/recordFormAiDraft.ts`): `recordWriteFormTarget`
gives an update the same `recordFormAiDraft` state key, now with the
`recordId` the values were proposed for. Every named field is kept, an
empty one included (clearing a field is a change).
`readRecordFormAiChanges(state, recordId)` reads it for that record
only; `readRecordFormAiDraft` (the create reader) ignores a draft that
names a record. Nothing is added to the URL.
3. **Edit page** (`views/RecordFormPage.tsx`): in edit mode it reads the
changes for its own record and provides them through the new
`SuggestedFieldChangesContext`, and shows the same one-line notice the
create page shows (`form.aiDraftNotice`). It still opens on the stored
record: no create values, no `SuggestedFieldsContext`.
4. **Form renderer** (`components/src/renderers/form/form.tsx`,
`suggested-fields-context.ts`): the new host slot
`SuggestedFieldChangesContext` (field name → proposed value) is the
edit-form sibling of #28104's `SuggestedFieldsContext`. The renderer
applies each proposed value **once**, on the first reset that brings the
record, **after** the reset window, with `setValue(…, { shouldDirty:
true })`: the form reads dirty, the discard guard hears it, the value
channels report it, and the save payload (which diffs against the loaded
record) writes it, exactly as the person's own edit would. A proposal
equal to the stored value, for a field the form does not draw, or for a
statically read-only, disabled or hidden field is not applied. While the
control holds the proposed value the field shows the #28104 mark
(`form.aiSuggested`, the same span), a `Was: …` line with the stored
value (option label, a lookup's name, a list joined, `empty` for none),
and a **Revert** button that puts the stored value back; the person's
own edit or the revert takes all three away.
5. **i18n**: `form.aiBefore`, `form.aiBeforeEmpty`, `form.aiRevert` in
all eleven locale packs (no quote characters, so the de quote-pair count
is unchanged).
No `packages/spec` path, no new metadata key: both contexts are host
slots, and the update card's own buttons and labels are unchanged.
## Why
The record-write card (cloud#3565) is how chat proposes a change to one
record; its "Open the full form" is the path for a person who wants to
see the change in the whole form before saving. Opening that form
without the change throws away what the card showed. And a record open
in a list's drawer is as much "this record" as a record page.
## Tests
Pins, each with a CONTROL:
-
`ui/packages/app-shell/src/layout/__tests__/chatSurfaceContext-30043.test.ts`:
new describe, drawer `?recordId=` on all three list routes, encoded id;
controls for no or empty param, the view selection without a drawer, the
New page, a record page, pages with no artifact and host routes.
-
`ui/packages/app-shell/src/layout/__tests__/ChatDock.requestContext-30043.test.tsx`:
new describe, the REAL dock's chat POST body names the drawer record,
and the next turn after the drawer closes names the object only.
-
`ui/packages/app-shell/src/utils/__tests__/recordFormAiDraft-28104.test.ts`:
the #28104 "an update carries no draft" case now pins the update's
state; new describe for nothing in the URL, empty (clearing) values
kept, binding to the record, and a create page never reading it.
-
`ui/packages/app-shell/src/views/RecordFormPage.aiDraft-28104.test.tsx`:
new describe, the edit page hands the form the changes and shows the
notice once, through a real `navigate(to, { state })` with nothing after
the edit path, still opens on the stored record; controls for another
record's draft, a create's draft, no state, and a create page given an
update's state.
-
`ui/packages/components/src/renderers/form/__tests__/form-aiSuggestedMark-28104.test.tsx`:
new describe, a proposed change lands in the control, marked, with `Was:
…` (option label for a select); a proposal equal to the stored value
shows nothing; revert restores the stored value and removes mark, line
and button; the person's own edit removes the mark; the form reports
dirty; a read-only and an undrawn field are left alone and the save
payload carries neither change; mounting submits nothing and Save
submits the applied change; control with no provider.
### Ablation
Each leg mutated through `scripts/ablation-replace.mjs` (anchor hit x1 →
x0, distinct marker x0 → x1, restore proven by blob == HEAD and an empty
`git diff HEAD`; the ui vitest config aliases `@object-ui/*` to `src`,
so no build sits between the mutation and the run). The direction was
written in each test file's header before the run.
| leg | mutation | red | green |
|---|---|---|---|
| A renderer | skip every proposal in the apply loop | lands-marked,
revert, dirty/read-only, Save payload (4) | the five #28104 cells, the
own-edit cell, CONTROL |
| B edit page | edit mode reads no changes | hands-the-form,
navigate-with-state (2) | the six #28104 cells, stored-record, CONTROL |
| C drawer | ignore `?recordId=` | the drawer pin, the dock wire pin (2)
| the other 15 |
| D carrier | update target drops its state | the two update-state pins
(2) | the other 6 |
In leg A the own-edit cell stayed green because it then asserted only
the absence of the mark after an edit; it now first asserts the mark is
present, so it reds under the same mutation.
## Acceptance notes
- `open_record`'s `proposedValues` arm is gone from cloud (cloud#3565),
so item 2's 「修改 X(N 个字段)→」 card variant is not built: no producer emits
it. The update card keeps its own title and its "Open the full form"
label.
- A proposal is applied only to a field the form draws and the person
could edit: not read-only, disabled or hidden by its config, and not
locked by a `readonlyWhen` rule on the stored record (the same
`readonlyFieldNames` verdict the save strips by). cloud's
`update_record` already proposes only fields the user may write
(`record-draft-validation.ts`, rule 1).
- Each proposal is tried once per field, on the first pass where the
form draws that field. An edit wizard draws one step at a time, so a
step-2 proposal lands and is marked when step 2 opens, and a step-1
field the person reverted is not re-applied on Next or Back.
- The `Was: …` line formats the stored value without a lookup read: an
option field reads its option label, an expanded lookup its name, a bare
lookup id is shown as the id.
- Router state belongs to the tab's history entry, as for #28104: reload
or Back to that entry reopens the proposals, a copied link opens the
stored record.
- Serial behind objectstack#28104: opened after #31445 landed, with
`main` merged into this branch by a merge commit (`229de9fb`); the delta
over `main` is this card's alone.
## Verification
All readings on `objectstack-ai/objectstack` at head `229de9fb` (main
`a40eb02e` merged, which carries #31445 as `bb618728`), after `pnpm
install --frozen-lockfile` and a rebuild of the `@object-ui/app-shell`
dependency closure (`turbo run build
--filter='@object-ui/app-shell^...'`, 66/66), every heavy run under
`scripts/pm/os-verify-lock.sh`.
<details><summary>Type check and tests</summary>
- `pnpm run type-check` in `ui/packages/components`, `ui/packages/i18n`,
`ui/packages/app-shell` (both `tsc --noEmit` and `tsconfig.test.json`):
exit 0 ×3.
- `vitest run packages/components/`: Test Files 478 passed, 1 skipped
(479); Tests 4584 passed, 24 skipped.
- `vitest run packages/i18n/`: Test Files 99 passed (99); Tests 1804
passed, 13 skipped.
- `vitest run packages/app-shell/src/layout/
packages/app-shell/src/utils/ packages/app-shell/src/console/ai/
packages/app-shell/src/views/RecordFormPage`: Test Files 256 passed, 1
skipped (257); Tests 2134 passed, 8 skipped. DECLARED NARROWING: the
whole app-shell package is 2,218 test files, over an hour at two workers
on this box; the full package runs in CI's `Test UI`.
- The five files this PR edits, before the merge: Test Files 5 passed
(5), Tests 46 passed.
</details>
<details><summary>Ablation</summary>
Run on the pre-merge head (`ebd61fef`/`cb1a8535`), whose delta over the
#28104 content is byte-identical to this PR's delta over `main` (checked
per conflicted file during the merge). Results in the Tests section
above.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands` on `229de9fb` derives 39
families; all 39 ran locally, each exit captured before any pipe, all
exit 0 (`check:type-check-debt` under the lock: 0 ledger entries
re-measured above their number). `--ran` reconciliation: 39 derived, 39
run, 0 NOT-MEASURED (a derived zero), 0 UNRUN. One finding on the way:
`check:test-source-alias` asked `ChatDock.requestContext-30043.test.tsx`
to load `@objectstack/lint` at module top (the layout reaches it through
a dynamic import); fixed in `d6b726d7`. The repo-wide scans (`pnpm lint`
first) and the families outside the derived list are CI's.
</details>
## Review round 1 (head `79a39a9c`)
The seat review asked for two items, now done in `e50be7b9`. `79a39a9c`
merges `main` `a1d243e0`, which carries the raised eager
`i18n-locale-en` ceiling from objectstack#31465. These runs supersede
the Verification readings above, which were taken at `229de9fb`.
### (1) Wizard: proposals tried per field
`suggestedChangeAttemptsRef` is a `Set<string>`. Each proposal is tried
once, on the first pass where the form draws that field, and never
again. A layout effect on `drawnFieldNames` covers a step change that
brings no reset. The before line and the revert read
`appliedChangeBefore`, which holds the stored value per applied field.
They do not read `defaultValues`, because the wizard refills it at every
step boundary.
The pin is a new file,
`ui/packages/plugin-form/src/WizardForm.aiProposedChanges-28106.test.tsx`.
It is an edit wizard with name on step 1 and phone on step 2:
- Step 1: name is applied and marked, then reverted.
- Next: phone is applied and marked on step 2, "Was: 13900001111".
- CONTROL: Back, then Next and Back again. Name stays reverted.
### (2) readonlyWhen
This was cheap, so it is done rather than left as a limit. The apply
loop also skips `readonlyFieldNames.has(name)`, the same verdict the
save strips by. That check is gated on `previousValues`, which both
RecordFormPage edit and WizardForm edit supply.
The pin is a new cell in `form-aiSuggestedMark-28104.test.tsx`: a field
locked by `readonlyWhen: "previous.status != 'draft'"` beside an
unlocked one.
### Ablation
Run on the committed round with `scripts/ablation-replace.mjs`. Every
leg was restored to HEAD (blob 5675c91).
| Leg | Mutation | Red (as predicted) |
|---|---|---|
| A | old single try: attempt recorded before the drawn check | the
wizard cell, on step 2's phone (expected 13800000000, got 13900001111) |
| B | attempts not recorded | the wizard CONTROL (expected 张伟, got 李四) |
| C | rule lock not consulted | the readonlyWhen cell |
| restored | — | none: 13/13 green |
### Runs
**Round head 2650aa2d** (its tree is identical to 43b7e4f): `vitest run
packages/components packages/plugin-form
packages/app-shell/src/views/RecordFormPage.aiDraft-28104.test.tsx`
- Test Files: 704 passed, 1 skipped
- Tests: 7055 passed, 25 skipped
**Merged tree 79a39a9:**
- `turbo run build --filter=@object-ui/console^...` (72/72), then `vite
build` of apps/console.
- `pnpm --dir ui run check:eager-closure`: exit 0.
- `i18n-locale-en` is 60,065 gzip bytes against the 61,000 ceiling, so
**935 bytes of headroom**.
- The aggregate closure is 2185.2 KB against 2431.6 KB.
- `pnpm run type-check`: exit 0 in components, plugin-form, app-shell
and i18n.
- `vitest run` on `packages/components/src/renderers/form`,
`packages/plugin-form`, `packages/i18n`, and in app-shell
`views/RecordFormPage`, `layout`, `utils` and `console/ai`:
- Test Files: 665 passed, 1 skipped
- Tests: 6996 passed, 39 skipped
- `dispatch-gates --commands`: the same 39 families as before the merge.
`--ran`: 39 run, 0 NOT-MEASURED, all exit 0.
- DECLARED NARROWING (unchanged): the whole app-shell package runs in
CI's Test UI.
All heavy runs went through `scripts/pm/os-verify-lock.sh`. Their wall
times are shared-box seconds.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(no `packages/spec` path)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (CI-owned, see
Verification)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QUs3BvstGvKpRZPWDGvLmz
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QUs3BvstGvKpRZPWDGvLmz)_
<!-- signed: repo:cloud#3 · os-zhuang · session_01QUs3BvRcDHXqRU4TSVE4u6
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e516cf2 commit 4211f50
26 files changed
Lines changed: 857 additions & 54 deletions
File tree
- .changeset
- ui/packages
- app-shell/src
- console/ai
- layout
- __tests__
- utils
- __tests__
- views
- components/src
- renderers/form
- __tests__
- i18n/src/locales
- plugin-form/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1752 | 1752 | | |
1753 | 1753 | | |
1754 | 1754 | | |
1755 | | - | |
1756 | | - | |
1757 | | - | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1758 | 1760 | | |
1759 | 1761 | | |
1760 | 1762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
203 | 205 | | |
204 | | - | |
205 | | - | |
| 206 | + | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
81 | 91 | | |
82 | 92 | | |
83 | 93 | | |
84 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
85 | 97 | | |
86 | 98 | | |
87 | 99 | | |
88 | 100 | | |
| 101 | + | |
89 | 102 | | |
90 | 103 | | |
91 | 104 | | |
| |||
96 | 109 | | |
97 | 110 | | |
98 | 111 | | |
99 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
100 | 118 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
16 | 22 | | |
17 | 23 | | |
18 | 24 | | |
| |||
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
52 | | - | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
56 | 62 | | |
57 | | - | |
| 63 | + | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| |||
71 | 78 | | |
72 | 79 | | |
73 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
27 | 35 | | |
28 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
29 | 41 | | |
30 | 42 | | |
31 | 43 | | |
| |||
61 | 73 | | |
62 | 74 | | |
63 | 75 | | |
| 76 | + | |
| 77 | + | |
64 | 78 | | |
65 | 79 | | |
66 | 80 | | |
| |||
70 | 84 | | |
71 | 85 | | |
72 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
73 | 126 | | |
74 | 127 | | |
75 | 128 | | |
76 | 129 | | |
77 | | - | |
| 130 | + | |
| 131 | + | |
78 | 132 | | |
79 | 133 | | |
80 | 134 | | |
| |||
87 | 141 | | |
88 | 142 | | |
89 | 143 | | |
90 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
91 | 147 | | |
92 | 148 | | |
93 | 149 | | |
| |||
0 commit comments