Repository navigation
feat(chatbot): draw verified record citations as chips that open the cited section - #37485
Conversation
…e record at the cited section Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 6098102 · 2026-11-26T08:33Z |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: PR #37485 (card #37365, epic #36996 row 10b). Declaration face: the paths decide no face, the changeset's ① Derived judgmentsVerdict in one line: no must-fix. Four should-fix, five nits. The security questions come out clean; the "never a wrong heading" claim does not hold as written (S1). 1. Security and leaks: clean.
2. 3. Point (a), the heading locator. S1 (should-fix) —
S2 (should-fix) — a second citation of the same record leaves the first mark on. Accepted as disclosed: the body is the first long-text field in field order whose outline issues the anchor, not the pack's 4. Point (b), surface beyond the claim: acceptable. The report lists the extra files under 5. Points (c) and (d).
S4 (should-fix) — the browser reading is NOT MEASURED and has no carrier. The substitute (the real 6. Point (e): #37487 is the right carrier. Open, S3 (should-fix) — the docs and the changeset claim more than the head delivers. Both say an answer "now draws" its citations and that "the list is drawn as it was persisted". On this head no producer emits 7. Locales: clean. Nits.
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha: Security came out clean:
S1–S3 close in this PR before ACCEPT. S4 needs a named carrier.
|
…s, and move the mark The record page's section locator now carries the outline's count of same-titled headings and opens the field, not a heading, when the drawn face draws a different number of them (a setext, quoted or listed duplicate, or an outline heading the face does not draw), and when the heading has no letter or digit. The focus cleanup takes the mark off, so a second citation leaves only its own section marked; each chip click carries a fresh history-state value, so the same chip opens its section again. The changeset and the two doc pages now say the console draws a verified citations part when an answer carries one, not yet after a reload. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X Contract reviewServed-tier: Delta round on PR #37485 (card #37365, epic #36996 row 10b), declaration face. It follows record 7186860933 on ① Derived judgmentsVerdict in one line: no must-fix. S1, S2 and S3 are closed, S4 is carried on #37487, N2 and N3 are closed. The S2 fix opens one new should-fix (S5): the focus now re-runs when a navigation drops the history state. Earlier findings. S1 (should-fix) — CLOSED. S2 (should-fix) — CLOSED, with S5 as its consequence. S3 (should-fix) — CLOSED. The changeset title and body, S4 (should-fix) — CARRIED on #37487. Seat comment 7186889924 on that card adds the booted-console check to its acceptance: chips drawn, a chip click opening N1 (nit) — OPEN, accepted by the seat as a deviation. Dot segments in New this round. S5 (should-fix) — a navigation that drops the history state re-opens the cited section. N6 (nit) — the count check narrows S1's fault, it does not exclude it. A body with one same-titled heading the outline does not list AND one listed heading the face does not draw has equal counts and can still resolve to the other heading; so can a face that drew its headings one at a time. The markdown face draws in one commit, and the real-view pin holds. The PR body is worded correctly; the two test titles that say "never that heading" claim slightly more than the rule gives. N7 (nit) — a heading with an empty reading opens the field only after the 4 s settle: Unchanged from the first round, re-read on this head. Security is clean: Check-runs on the head: 66 completed, 54 success, 12 skipped, 0 failed, as the area reports. ② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X 席位核对Head-sha:
|
|
repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc Landing: ACCEPT 7190174620 (delta contract record 7190126794, PASS) at head
Status: ready + auto-merge (merge queue). On MERGED, #37365 closes by |
…ited-section scroll to new clicks (objectstack-ai#37539) <!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg6tp7ABZkjrcw3mEU2eHGpS)_ Fixes objectstack-ai#37487 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:使用应用内 AI 的用户,刷新页面或重新打开对话后,回答下方的“引自记录”引用条仍然显示;从引用条打开记录后,再打开命令面板或编辑表单、返回,页面不再被拉回被引的那一节。 - 为什么做:记录 AI 问询专题的引用条跟进卡,原先引用条只在回答当场可见,刷新就消失,无法回头核对出处。 - 出错会怎样:引用条刷新后不显示,或页面多滚一次;记录和对话数据不受影响,撤回本次合并即可恢复原样。 - 要你做什么:无。 ## What changes Governing text: ruling Q1 on objectstack-ai#37144 (draw the persisted, already-verified list; never verify it again); PR objectstack-ai#37485 (merged 276174a) and its scope notes on objectstack-ai#37487 (S4 on the card, S5 in 7190147175). - **One allow-list of kept data parts** (`plugin-chatbot/src/toolResultParsers.ts`): `STORED_ANSWER_DATA_PARTS` names the data parts a stored answer keeps through a rebuild, keyed by the message field that carries each between rebuilds: `charts` (`data-chart`, positional) and `recordCitations` (`data-record-citations`). `storedAnswerParts(content, data)` writes them (the charts through the existing `chartAnswerParts`, then the citations list as one part with the stream's part id). It stays in the eager `/core` closure, so the part type is spelled there, not imported from `@objectstack/spec/ai`; a test pins it to `RECORD_CITATIONS_PART_TYPE`. - **Reader** (`plugin-chatbot/src/mapMessages.ts`): `storedAnswerData(parts)` reads every kept part back (`chartsFromParts` + `extractRecordCitations`, the same `RecordCitationsSchema` parse a live part goes through). A refused list is no list. - **The three rebuilds** now go through those two: the `/ai` history rebuild `hydratedMessagesToChatMessages` (`app-shell/src/console/ai/AiChatPage.tsx`, reader), the message cache `sanitizeChatMessagesForCache` (`app-shell/src/hooks/useChatConversation.ts`, writer; `CacheableChatMessage` gains `recordCitations`), and the `useObjectChat` `initialMessages` store rebuild (`plugin-chatbot/src/useObjectChat.ts`, writer). The table names the kept parts; a further kept part takes three edits (the entry, its write in `storedAnswerParts`, its read in `storedAnswerData`). - **S5** (`app-shell/src/views/RecordDetailView.tsx`, `recordSectionAnchor.ts`): the cited-section effect was keyed on the opened-state value or `''`, so any navigation that dropped history state re-ran it and scrolled back. Two parts: - within one mount, the key holds the last string value the state carried, replaced only when a new string arrives (state adjusted during render); - the booted console showed the record-form overlay (`?form=`) **remounts** the record page without the state, so a component-local memory is not enough. The page now keeps the section it last opened beside the component (`claimCitedSectionOpen`, `{ target: RECORD+ANCHOR, opened: CLICK }`), claimed at the moment the page would move (`focusRecordSection` gains an optional `mayScroll` callback, asked right before scrolling, so an effect re-run before that does not spend it). A redraw at a section already opened marks it again and scrolls nothing. The memory is dropped once no record page has stayed mounted (a zero-delay check after unmount), so a later visit to the same link opens its section again. - Exports (Clause-②: yes (widening), per seat record 7193217253 S1; level stays patch): `storedAnswerParts`, `STORED_ANSWER_DATA_PARTS` and the types `StoredAnswerData`, `StoredAnswerPart` from `@object-ui/plugin-chatbot/core` and the root; `storedAnswerData` from the root. Named in the changeset. - Docs: the sentence "a conversation reloaded from history does not redraw them yet" in `content/docs/frontend/plugins/plugin-chatbot.mdx` and `ui/packages/plugin-chatbot/README.md` was made false by this change and is rewritten. Changeset `.changeset/37487-citations-survive-reload.md` (patch, `@object-ui/plugin-chatbot`, `@object-ui/app-shell`). Read first, by risk: 1. `ui/packages/plugin-chatbot/src/toolResultParsers.ts`: `STORED_ANSWER_DATA_PARTS` and `storedAnswerParts`. 2. `ui/packages/app-shell/src/views/RecordDetailView.tsx`: `claimCitedSectionOpen` (module level, above the component) and the `sectionOpened` state and effect beside `holdsRouteRecord`. 3. `ui/packages/app-shell/src/hooks/useChatConversation.ts`: `sanitizeChatMessagesForCache`. ## Tests - `app-shell/src/console/ai/__tests__/AiChatPage.recordCitationsReload-37487.test.tsx` (6): server history and cache fallback each restore the chips the live answer draws (same quotes, same order; nothing fetched); a restored server answer re-caches with its list; CONTROL on both paths: a refused part (an alias key) draws nothing and is not cached. - `plugin-chatbot/src/__tests__/useObjectChat.recordCitationsReload-37487.test.tsx` (3): the `initialMessages` store rebuild draws the live chips; CONTROL: a refused list draws nothing (the store part is re-parsed, so the rebuild is no way round the contract); the allow-list entry equals the spec part type. - `app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx` (+2, 8 total): after a chip click, a state-dropping `replace` (the `useUrlOverlay` shape) and a pushed overlay followed by Back do not scroll; a pushed overlay that **remounts** the page, and Back, marks the section again and does not scroll; CONTROL in both: a new click after them scrolls. `afterEach` waits one macrotask after `cleanup()` so the page's memory is dropped between cases. `recordSectionAnchor.test.tsx` unchanged, 18/18. - Ablation, shared allow-list: writer and reader of the citations entry disabled → the three positive path tests fail (3 failed, 6 passed), restored → 9/9. Ablation, S5 in-mount: the key read back off the state as before → that test fails (1 failed, 6 passed). Ablation, S5 remount: `claimCitedSectionOpen` always claims → the remount test fails (1 failed, 7 passed); restored → 8/8. ## Acceptance notes - N6 / N7 of 7190147175 (the count check, and the empty-reading case opening the field only after the 4 s settle) live in `recordSectionAnchor.ts`'s `locateSection` and are not one line each; they stay open and are carried by objectstack-ai#37562. - On a phone, a chip in the dock sheet opens the record underneath and the sheet stays open over it, so the cited heading is scrolled and marked but hidden until the reader dismisses the sheet. Present since objectstack-ai#37485, not changed here; carried by objectstack-ai#37556. - On this boot `/ai/ask/CONVERSATION` resolves into the dock over the app's home page, so the dock and `/ai` were one surface in the browser check. - N1 of 7193217253: the allow-list jsdoc now says it names the kept parts without driving the code, and cites the test file that pins it. ## Verification - Local: `pnpm run type-check` in `ui/packages/plugin-chatbot` and `ui/packages/app-shell`, exit 0. The local whole-suite run of both packages (`vitest run packages/plugin-chatbot/ packages/app-shell/`) was stopped after 61 min with one failure, which was my own ablation edit made while it ran; the narrowing is declared, and CI's `Test UI` (all shards) is green on e2833f9. Rework head 40bb8ee (changeset, jsdoc only): CI check-runs 46 success, 10 skipped before this body edit; the PR-body guards rerun on the edit. - Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/console/ai/__tests__/AiChatPage.recordCitationsReload-37487.test.tsx packages/plugin-chatbot/src/__tests__/useObjectChat.recordCitationsReload-37487.test.tsx`, expected 9 passed. - S4 booted-console check, done on head 039bbc3 (the later head e2833f9 changes one test file only). Showcase app (`objectstack dev --seed-admin`) with the `ui/` console dev server pointed at it, driven by Playwright at 1360x900 and as an iPhone 13. **Injected, not produced**: no producer emits the part before cloud 10c, so the run serves the conversation-history read (`GET /api/v1/ai/conversations/ID`) with an answer carrying a `data-record-citations` part, and, because this boot has no model, serves a one-agent catalog (`GET /api/v1/ai/agents`) so the assistant shows. The cited record is a Field Zoo record whose `markdown`, `html` and `richtext` bodies each hold a cited heading below several screens of text. - Chips drawn: 3 (the three quotes), desktop and phone. After a page reload: the same 3, same order. - A chip click opens `/apps/com.example.showcase/showcase_field_zoo/record/ID?section=ANCHOR`; the cited heading is the one marked and sits just under the sticky record header (top 89 px desktop, 45 px phone): `contractor-scope` (markdown), `html-retention` (html), `rich-escalation` (richtext). - Refused part (an alias key): 0 chips. - S5: scrolled back to the top of the record, opening the command palette (`?palette=1`, replace) and closing it leaves the page there; opening the record form (`?form=ID`, push) and Back leaves the page there (before the remount fix it scrolled back, which is how the remount was found). A probe on `scrollIntoView` records no call. - Screenshots: `objectstack-seat5/ai-36996/shots-37487/` in the project files (9 images plus the script). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CY3qzEGtLEnwjFyRXG --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Fixes #37365
Clause-②: yes (a new reserved URL parameter
section)Metadata-protocol: none
维护者速读
What changes
Governing text: ADR-0160 D9 as amended by #37363; ruling 7177410380 on #37144 (Q1 A: draw the persisted, already-verified list, never re-verify; Q3 A: a related-row quote opens the root record).
plugin-chatbot/src/mapMessages.ts):extractRecordCitations(parts)reads the lastdata-record-citationspart (RECORD_CITATIONS_PART_TYPE) through the spec'sRecordCitationsSchema. A part the schema refuses, or an empty list, is no list (thedetectAnswerSourceprecedent).uiMessageToChatMessagecarries it asrecordCitations;chatMessageAdapter.tsnames the new render-only key.plugin-chatbot/src/RecordCitations.tsx, new; drawn inChatbotEnhanced.tsxbesideAnswerSourceBlock): one chip per citation showing the quote. A click callsonOpenRecord({ objectName: object, recordId: id, anchor });onOpenRecord's argument gains an optionalanchor. Nothing is fetched or verified on display.app-shell/src/console/ai/AiChatPage.tsx):openRecordtakes the optionalanchorand navigates torecordOpenTarget(app, …)=/apps/APP/OBJ/record/ID?section=ANCHOR. The dock and the/aipage both draw thisChatPane.app-shell/src/urlParams.ts):RECORD_SECTION_PARAM = 'section', inRESERVED_URL_PARAMSand the param table.RECORD_SECTION_OPENED_STATEis a history-state key, not a URL parameter (theRECORD_COMMENTS_PUSHED_STATEprecedent).app-shell/src/views/recordSectionAnchor.ts, new; wired inRecordDetailView.tsx): once the record is held, the spec'sheadingsOfruns on each long-text field (markdown,html/richtext,textarea) in field order; the first whose outline issues the anchor is the body. The heading element is found in that field's drawn face and scrolled to and marked (the linked-comment marking). The match is trusted only when the face draws exactly as many headings of that title as the outline lists. Atextareabody, a heading that is not drawn within 4 s, a count that differs, or a heading with no letter or digit scrolls to the field. A stale anchor opens the top. The cleanup takes the mark off, so opening another section moves the mark. Each chip click carries a fresh history-state value (RECORD_SECTION_OPENED_STATE), so the same chip clicked again opens its section again; a navigation that keeps the state, such as a tab switch, does not.plugin-detail/src/DetailSection.tsx): each detail row carriesdata-detail-field={field.name}, which is how the page finds a field. One attribute, no behaviour change.chatbot.recordCitations.titlein all 11ui/packages/i18nlocales.content/docs/frontend/plugins/plugin-chatbot.mdx,ui/packages/plugin-chatbot/README.md; changeset.changeset/37365-record-citation-chips.md(patch, four@object-ui/*packages).Read first, by risk:
ui/packages/app-shell/src/views/recordSectionAnchor.ts:locateSection(how a drawn heading is matched) andfocusRecordSection(observer and settle timer).ui/packages/plugin-chatbot/src/mapMessages.ts:extractRecordCitations(the parse gate).ui/packages/app-shell/src/views/RecordDetailView.tsx: the effect besideholdsRouteRecord.Tests
Head
c1b30e6a0b. Every run went throughscripts/pm/os-verify-lock.shon a shared box.plugin-chatbot/src/__tests__/ChatbotEnhanced.recordCitations-37365.test.tsx(lift through the spec schema; chips; a refused part draws nothing with a CONTROL leg; no fetch on display; related-row quote opens the root record; record-link grammar still refuses a fragment, with a CONTROL);app-shell/src/views/recordSectionAnchor.test.tsx(anchor derived as the server derives it; matching by reading with repeats; a same-titled heading the outline does not list, a listed heading the face does not draw, and a heading with no letter or digit each open the field, each with a CONTROL; textarea opens at the field; a heading never drawn settles on the field; stale anchor moves nothing, with a CONTROL; the cleanup unmarks, keeping a class the heading already had; the same section opened again scrolls and marks again);app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx(the REALRecordDetailViewand the real markdown face:?section=scopemarks and scrolls the first Scope,scope-2the second, a textarea body scrolls to the field, a stale anchor opens the top with a CONTROL, a setextScopeabove the cited# Scopeopens the field with a CONTROL, a second chip moves the mark and the same chip again scrolls again, CONTROL a state-keeping replace does not); a new describe inAiChatPage.recordLink-13037.test.tsx(the realChatPane: the chip opens/apps/APP/OBJ/record/ID?section=scopeunder a/_consoleand a root mount; each click carries a fresh opened-state value; a related-row quote opens the root record with no section).Whole suites of the four touched packages, at c1b30e6
@object-ui/plugin-chatbot:Test Files 104 passed (104) · Tests 1089 passed (1089)@object-ui/i18n:Test Files 111 passed (111) · Tests 2028 passed | 13 skipped (2041)@object-ui/plugin-detail:Test Files 419 passed | 1 skipped (420) · Tests 3968 passed | 18 skipped (3986)@object-ui/app-shell:Test Files 2437 passed | 1 skipped (2438) · Tests 23428 passed | 9 skipped (23437)VERDICT command-exit 0, each package exit 0.type-check: app-shell exit 0 atc1b30e6a0b. plugin-chatbot, plugin-detail and i18n exit 0 at60981028c; this round changes no source of theirs.exit 0(dispatch-gates --ran: "a DERIVED zero"),check:type-check-debtincluded.Ablation of the parse gate (round 1, at 6098102)
node scripts/ablation-replace.mjsreplaced theRecordCitationsSchema.safeParselines inextractRecordCitationswith a bareArray.isArraypass-through (anchor x1 to x0, blob0354c5b73c28to400078723215). The chip test then went red:Tests 5 failed | 9 passed (14); the failing tests were the four refused-part cases and "a part that fails the parse draws nothing". Restored: blob equals HEAD (0354c5b73c28) andgit diff HEADis empty. plugin-chatbot resolves tosrcthrough the vitest alias, so nodistrebuild was involved. This round does not touch that file.Mutation of the count check (round 2, at c1b30e6)
node scripts/ablation-replace.mjsreplaceddrawn.length === candidate.count ? drawn[candidate.ordinal] : undefinedinlocateSectionwithdrawn[candidate.ordinal](anchor x1 to x0, blob20eec4db25edtof4f48f4f6379). The two section test files then went red:Tests 3 failed | 21 passed (24). The failures were the same-titled unlisted heading and the listed-not-drawn heading pins inrecordSectionAnchor.test.tsx, and the setext pin inRecordDetailView.citedSection-37365.test.tsx. Restored withgit checkout HEAD --: blob equals HEAD (20eec4db25ed) andgit diff HEADis empty. app-shell tests import their ownsrc, so nodistwas involved.Acceptance notes
section, so the page cannot read the citation'scontextpack. It runsheadingsOfon every long-text field the record holds (markdown,html,richtext,textarea), in field order, and the first whose outline issues the anchor is the body. When the pack's body field holds the anchor, the result is the same. Another long-text field earlier in the field order that has a heading with the same anchor would be opened instead. The alternative, reading the pack'sbody.field, would needcontexton the URL as well; it was not taken.headingsOfdoes not list: setext headings, an empty#, headings inside a quote or a list, an indented ATX heading, and emptyh1-h6in html. The outline also lists headings the face does not draw, such as a#line inside a raw HTML block or a four-backtick fence. With a bare Nth-element rule, each of these shifts every later heading. The rule taken (locateSection) has two parts. First, among the field's drawn heading elements, it picks those whose letters and digits read the same as the outline's heading and indexes them by the outline's repeat count. Second, it trusts that index only when the face draws exactly as many headings of that reading as the outline lists. Otherwise it opens the field, and it also opens the field for a heading with no letter or digit. So a differing heading of another title shifts nothing. A same-titled one, or a listed one the face does not draw, opens the field rather than a heading that may be another. A heading whose raw text carries letters the face does not draw (a link's URL) reads differently and opens at the field too. Two headings that normalise alike (CandC++) are told apart by order, which both sides share.RECORD_SECTION_OPENED_STATEvalue on each chip click, and the record page keys the focus on record, anchor and that value. So the same chip clicked again (same URL) scrolls and marks again. The tab and comment writers replace the URL keepinglocation.state, so they do not re-scroll.ui/packages/plugin-detail/src/DetailSection.tsxgets onedata-detail-fieldattribute on each detail row. Without it the page has no way to find a field, so the textarea and not-drawn cases could not open at the field. (2)ui/packages/plugin-chatbot/src/chatMessageAdapter.tsgets one key onRuntimeOnlyMessageKeys, the declared place for a new render-only message key. (3) The new helperui/packages/app-shell/src/views/recordSectionAnchor.ts. (4) The chatbot docs page and README. overlap-check is clean againstorigin/mainand against feat(spec,ui): a field can be read-only by hand at the console while writes keep it (uiReadonly / uiReadonlyWhen) #37436, which sharesDetailSection.tsxand the 11 locale files (disjoint hunks), and feat(spec)!: form is a metadata type of its own, and the form doors read a form over both types #37422, which shares the 11 locale files./aipage rebuilds history, it drops anydata-*part other than charts:hydratedMessagesToChatMessages, thenuseObjectChat'sinitialMessagesrebuild, then the browser display cache (sanitizeChatMessagesForCache). So a persisted citation list does not come back after a reload yet; 37365 跟进:刷新或重开对话后,AI 回答下方的引用消失 #37487 carries it. Nothing onmainemits the part before cloud 10c. The changeset and both doc pages say so: the console draws a verified citations part when a live answer carries one.onOpenRecord's argument gains an optional member (widening). No spec file changed.Verification
html/richtextbodies. In its place,RecordDetailView.citedSection-37365.test.tsxrenders the real record page with the real markdown face.data-record-citationspart covers (cloud 10c). Click a chip. Expected: the address is/apps/APP/OBJ/record/ID?section=ANCHOR, the cited heading is scrolled into view with the accent ring, and an edited-away heading opens the record at its top.Generated by Claude Code