Repository navigation
fix(chat): restore the kit's #widget layout for inline visualizations - #2001
Conversation
Fragments are written straight into the shell body, and the visualize skill asks for a single id'd root element, so neither the body nor that root ever spaced its children. The kit's #widget gap does not apply in PI-Desktop because there is no #widget, and headings and paragraphs have zero block margins, so titles, controls, charts, legends, and captions touched (reproduced with deepseek-flash in 2 of 3 quicksort runs). The kit now stacks the blocks of the body and of a sole root container with the 12px #widget gap. The rule has zero specificity, so a fragment that lays out its own root keeps it, and it only applies to containers with a block child so inline-only roots keep flowing inline. Existing cards pick it up on their next load.
vastsa
left a comment
There was a problem hiding this comment.
原始间距问题真实存在,但当前改动会改变已经自行布局的片段,暂不能合入。
独立使用本机 Electron/Chromium 加载 main 与候选的完整 visualize.css,片段为 <div id="root" style="display:flex;gap:8px"><div style="width:100px;height:40px">A</div><div style="width:100px;height:40px">B</div></div>。main 的两个块横排(dx=108, dy=0,flex-direction=row);候选变成竖排(dx=0, dy=48,flex-direction=column)。未指定布局的同样根容器,块间距确实从 0 变为 12px;显式 grid 两列的对照仍保持两列。
原因是 :where 的零优先级按属性分别参与层叠:片段自己的 display:flex 和 gap:8px 并不会覆盖新增 flex-direction:column。现有 E2E 只切换 display:block,无法检测这一回归。请把默认排版限制在尚未自行布局的容器,或采用不会改变已有布局方向的间距方案;不要要求已有片段补写 flex-direction:row。请加入 display:flex + gap、依赖默认 row 的根容器回归,同时覆盖普通无布局单根、多顶层块和显式 grid/column,确认现有片段保持布局。
本轮已完成上述真实 Chromium 几何测量及 diff --check。尝试的五文件本地单测因复用环境中 shared 构建导出陈旧等错误未全部通过,不能作为验证通过,也不据此判断为本 PR 引入。尚未运行完整本地 GenUI 用户路径 E2E;已有独立可复现的布局回归,先请完成修复方向。没有修改或推送贡献者代码。
The visualization kit adapted from ZCode styles its fragment through a #widget container that spaces top-level blocks, but the PI-Desktop shell wrote fragments straight into the document body, so those rules never applied. The skill also asked for one id'd root, so models wrapped every block in a single unstyled div and the title, controls, chart, legend, and captions touched. The shell now places the fragment inside #widget, which stacks its top-level blocks with a 12px top margin instead of the earlier :where() flex column that could turn a default-row flex root into a column (review on vastsa#2001). Roots that lay themselves out, inline controls, and fragment margins keep their geometry. The upstream reset of #widget children is dropped so it does not strip fragment styling, and the skill now asks for top-level blocks rather than one wrapper.
|
@vastsa 谢谢 review,你说得对。第一版用 这次没有在原方案上继续打补丁,而是修了根上的问题:kit 本来就约定由外壳把片段放进
你提到的回归场景都加进了 E2E: 用 deepseek-flash 跑了 6 个 query × 2 次:12/12 都写成了顶层块,块间距基本都是 12px。分支已合入最新 main,测试和数据见 PR 描述。 |
|
感谢更新。当前 flow-root + 顶层 margin 的方案已解决上次发现的默认 flex-row 变 column 问题;本机完整 GenUI Electron E2E 在 831ef26 和合入最新 main c85251b 后均通过,包含 native Host、交互/隔离及新增七种布局。 但 Linux CI 仍有可重复的布局断言失败,暂不能合入。我重跑了失败任务,结果为:
这不是日志里的 dbus 警告;实际失败是按钮纵向位置不同。目前还不能断定为纯测试时序。请在失败断言输出 iframe/guest viewport 宽度、按钮的 computed display/width 和容器宽度,检查 fixture:loaded 是否早于嵌入 frame 完成尺寸同步。如果是测量时序,应等到实际 guest viewport 达到夹具预期宽度后再测量,保留同行/不拉伸断言;如果稳定宽度下仍失败,需要修复对应布局。 本地五文件单测以 source hook 规避旧 shared/i18n 构建后为 55/56,其中不相关脚本错误消息测试仍受到 Vite 使用旧 shared 导出的影响,未计为通过。没有更改贡献者代码或放宽测试,也没有把本机通过当作 Linux 门禁通过。请修复并让 Electron CI 通过后继续合入验证。 |
The new layout checks measured the guest as soon as the fixture reported loaded. On Linux CI the inline controls landed on two lines (top 12 vs 40, then 47 vs 83) while every local run kept them on one, which points at measuring before the card had settled the frame's width. The checks now measure the frame serving that fixture, wait until the guest viewport matches the mounted iframe width for two frames, and assert that it did. Failures report the viewport, #widget width, and each element's box, display, and parent width so a real layout fault can be told apart from timing.
|
@vastsa 谢谢重跑和定位。按你的建议处理了(42119b6c5,只改了 E2E,布局代码和断言都没动):
这次 Linux 上的 Trusted extensions Electron E2E 通过了,6 项 CI 全绿。本机连续跑了 3 次 需要说明的是,CI 只通过了一次,还不能证明之前的失败就是测量时序造成的。如果之后再失败,日志里会带上上面这些宽度数据。如果那时 viewport 已经是稳定宽度、按钮仍然换行,就说明是真的布局问题,我会去修布局,不会放宽断言。 |
vastsa
left a comment
There was a problem hiding this comment.
已复核最新 E2E 修订:按 URL 选择目标 guest,并等待实际 iframe 与 guest viewport 宽度同步,原有几何断言全部保留。此前已验证缺少 widget 容器的真实问题及默认 flex-row 回归;当前 flow-root 方案同时解决两者,保留片段自身布局。
已非破坏性合入最新 main c85251b 并推送 bfc9be4(maintainer edits 已开启)。该候选本机完整 GenUI Electron E2E 通过,覆盖真实 native Host、七种布局、交互、生命周期及跨会话隔离。复用现有依赖、renderer CSS 和 native binary,没有真实模型调用。初次 pnpm 自动安装因 symlink hoist 目录退出;改用 node 直接执行,补齐 shared/dist 复用链接后通过。语法及 diff 检查通过。
GitHub 实际合入候选与本地测试候选 tree 相同:122b58da39ca11db5a9f4cf69cc00f0c3aa24e1b。最终以本提交全部 CI 门禁通过为合入条件。旧单根包裹卡片保持原布局的取舍已记录;没有修改贡献者产品代码或放宽断言。
背景
内联可视化卡片里,标题、按钮行、图表、图例、说明文字经常贴在一起,看起来很挤。
原因
我们的 kit 改编自 ZCode。kit 的布局约定是:外壳把片段放进
<div id="widget">,再由#widget让顶层块竖排、相互留出 12px 间距。PI-Desktop 移植时,外壳没有加这个容器,片段直接进了<body>,所以#widget这套规则从来没有生效。另外两个因素叠在了一起:
div。h1–h6、p的margin-block清成了 0。结果是 body 这一层、根容器里面这一层都没有任何竖向间距。
改动
第一版用
:where()把 body 或唯一的根容器改成 flex 竖排。评审指出,这会把模型自己写的、默认横排的display:flex根元素改成竖排。现在改为恢复 kit 原本的约定:gen-ui-document.ts):片段放进<div id="widget">,kit 的 tooltip/tabs 运行时仍在容器外。visualize.css):#widget改为flow-root,直接子块之间用 12px 上边距隔开,不用 flex。这样不会改变任何元素的排列方向,也不会拉伸顶层的行内控件。#widget直接子元素的强制重置(margin/padding/border均带!important)。这条规则以前没有生效,现在生效的话会清掉片段自己的样式。visualize.md):要求把标题、控件、图、图例、说明直接写成顶层块,不要整体包一层;需要脚本操作的元素各自加 id。改后 12240 B,仍在 12 KiB 上限内。unreleased.md和 E2E 计划的 Coverage。取舍: 之前生成的“整体包一层根 div”的旧卡片会保持原样,不会自动拉开间距。要给它们做兼容就得重新猜测布局,在横排 flex 下还会造成错位,所以没有做。
测试
E2E(
scripts/e2e/gen-ui-main.mjs)对 7 种布局断言了位置和间距:#widget内;相邻块间距 ≥ 8px;.viz-controls里的按钮仍在同一行display:flex; gap:8px默认横排(评审给的例子)flex-direction: column; gap: 5px实测
方法: 在本地真实构建的 PI-Desktop 里,通过 renderer IPC 发起对话,开启
inlineVisualizations,卡片宽度 700px,在 app 里用真实的pi-genui://iframe 渲染、截图,并测量顶层块之间的间距。模型:
deepseek-flash,DeepSeek 官方 API,以自定义 OpenAI 兼容 provider 接入;thinking 关闭(请求带thinking: {type: "disabled"}),权限设为 auto。测试 query(每个跑 2 次):
结果:
margin:0、margin-top:4px),按设计以片段为准。pie未定义、把 D3 selection 当成 DOM 节点、读取undefined.pivot,以及一处语法错误。这些错误都会显示在卡片内。语法错误那一张,Write 检查本来能发现,但最终文件里的错误像是之后的 Edit 引入的,而 Edit 的结果目前不做检查。验证
pnpm test:e2e:gen-ui:通过(包含上面的 7 种布局断言)visualize-skill/gen-ui-protocol/gen-ui-runtime/gen-ui-file-safety/gen-ui-card):56/56 通过pnpm lint、desktop typecheck、node scripts/check-architecture.mjs、node scripts/check-release-docs.mjs、check-pr-base(已合入最新 main 30f3c52):全部通过未覆盖 / 后续