Skip to content

feat(chat): render inline generative UI visualizations - #1826

Merged
vastsa merged 13 commits into
vastsa:mainfrom
zszz3:feat/gen-ui-inline-visualization
Oct 23, 2026
Merged

vastsa merged 13 commits into
vastsa:mainfrom
zszz3:feat/gen-ui-inline-visualization

Conversation

@zszz3

@zszz3 zszz3 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

实现 #1825:对话里的内联可视化卡片。

模型把一个 HTML 片段写进会话专属目录,回复末尾加一行 ::visualize{"path":"…","title":"…"},对话区就把它渲染成一张可交互的卡片(滑块、悬停提示、标签页、D3 图表),跟随主题、高度自适应,可展开查看。

截图

真实模型(StepFun step-5-preview)在 PI-Desktop 中生成的卡片:

热力图(悬停查看数值) 冒泡排序动画(按钮 + 速度滑块)
heatmap bubble sort

展开查看(标签页切换柱状图 / 数据表):

expanded

改动

  • host-core:本地会话新增第二个受控目录 <data_dir>/visualizations/<sessionId>/(与 scratch 并列,修订 D114)。Write/Edit 只允许该目录下直接一层的 .html 片段,免确认;Edit 的 MV 目标出界会正常弹确认。数据目录位于工作区内时同样按受控目录处理。会话删除时一并清理,启动时只清理孤儿目录,不按时间过期。fork 只复制被引用的片段并改写路径。远程工作区和合约会话没有该目录。
  • Electron Main:新增 pi-genui: 协议(只有 standard + secure 权限,无 fetch/CORS)。读取时校验真实路径、O_NOFOLLOW、2 MB 上限,拒绝完整 HTML 文档,错误只返回固定错误码。外壳带严格 CSP(default-src 'none',脚本只允许内联和 pi-genui://assets,无 connect/frame/form)和 Permissions-Policy;权限请求一律拒绝。主窗口 CSP 只新增 frame-src pi-genui:。
  • 样式套件:apps/desktop/resources/gen-ui/ 改编自 ZCode visualize 插件(Apache-2.0,见 NOTICE.md):样式表 + tooltip/标签页运行时,外加离线 D3 7.9.0、Floating UI,按清单从 pi-genui://assets 提供;固定版本的 CDN 地址被改写为本地地址,其他远程地址一律被拦。约 380 KB。
  • 渲染层:引用行在 Markdown 渲染前被拆出(跳过代码块,兼容 Windows 单反斜杠路径),流式输出时隐藏未完成的引用行。卡片 URL 只按所属会话 id + 文件名生成。iframe 为 sandbox="allow-scripts",同时最多 8 个活跃帧,离开视口时让出、回来时自动重载。主题经 postMessage 下发,只在变化时推送。滚轮转发给对话区(避免跟随模式回拉)。展开弹窗带焦点陷阱,iframe 内按 Esc 也能关闭。错误显示为本地化的"不可用"卡片(9 种语言)。
  • Runtime / skill:系统提示给出可视化目录;内置 pi-desktop/visualize skill(约 11 KB,改编自 ZCode 并精简)。skill 被禁用或会话为远程时,不提供目录,也不出现在 / 命令里。
  • 文档:ADR gen-ui-inline-visualization、D671、03-tools-and-permissions.md §4b.1、04-data-storage.md、E2E 场景 E2E-GENUI-inline-visualization-card、unreleased,以及对应的 zh-CN 镜像。

验证

  • 真实应用(隔离数据目录 + 本分支 host-core + StepFun step-5-preview,"每次询问"模式):10 个可视化提示词(柱状/折线双轴/环形/散点/热力图/甘特/树/时序/排序动画/复利计算器)全部出卡片;写 .html 不弹窗,写 .txt 被拒绝;沙箱内 fetch、parent.document、localStorage、window.open 均被拦截;主题切换实时生效;展开弹窗居中;缺失、软链接、目录外路径都显示"不可用"卡片。
  • 新增测试:packages/shared/src/gen-ui.test.ts;apps/desktop/test/gen-ui-{protocol,card,runtime,permissions,composer-command}.test.mjs、visualize-skill.test.mjs、jev-session-launch.test.mjs(skill 禁用时不给目录);host-core rpc/visualization_tests.rs(14 个)+ fork 复制测试。
  • 变基到最新 main 后:desktop typecheck 通过;shared 1296/1296;agent-runtime 331/331;host-core 978 通过 / 1 失败(data_relocation::tests::relocated_project_memory_remains_readable_through_the_repository,在未改动的 main 上同样失败);cargo fmt --check 通过;clippy 只有 3 条原有警告。
  • desktop 全量按批次运行:本 PR 新增和改动的测试全部通过。已知无关失败:auto-update.test.mjs(main-pane 断言)、live-work-concrete-adapters.test.mjs(gemini-live socket)、settings-inline-import-user-path.test.mjs(worktree 未构建 renderer);live-voice-gemini-adapter.test.mjs 在本机被系统 kill。这些都不涉及本 PR 的文件。

已知限制

  • WebRTC:Chromium 目前不执行 CSP 的 webrtc 'block',卡片脚本理论上仍能发 STUN 包。主窗口的实时语音依赖 WebRTC,无法在整个进程里关闭;已在 ADR 中记为残留风险(ZCode 也没有处理这一点,且它还放行了 CDN)。
  • v1 不支持控件状态持久化、代发后续消息、外链、CDN、图标库和参数微调面板。

closes #1825

@zszz3
zszz3 force-pushed the feat/gen-ui-inline-visualization branch from 8c474da to 44eff5a Compare October 22, 2026 14:57
zszz3 added 6 commits October 23, 2026 14:36
The desktop shell, host-core, and agent runtime need one definition of
where visualization fragments live and how a reply refers to them, so
the reference format and URL scheme cannot drift between processes.

This adds the `pi-genui:` URL helpers, the session directory and file
name rules, the `::visualize{...}` reference parser (outside code
blocks, tolerant of Windows paths), the guest message types, and the
VISUALIZATION_HTML_ONLY error code.

refs vastsa#1825
Visualizations need a host-owned place the model can write without a
permission prompt that is still clearly separated from the project and
from disposable scratch files.

Local sessions get `<data_dir>/visualizations/<sessionId>/` as a second
contained root next to scratch (amends D114). Write/Edit there accept
only direct `.html` fragments, an Edit move out of the contained roots
still asks, and the root wins over a workspace that contains the data
directory. The directory is removed with its session, only orphans are
swept at startup, and forks copy the fragments they reference so cards
survive deleting the parent. Remote and contract sessions get no root.

refs vastsa#1825
The renderer must be able to frame a model-written fragment without
granting it network, host, or same-origin access, and without the
fragment reaching outside the session's visualization directory.

Main registers `pi-genui:` (standard and secure only, no fetch or
CORS), resolves `pi-genui://session/<id>/<file>` against the real
session directory with O_NOFOLLOW and a 2 MB cap, rejects full HTML
documents, and reports failures as fixed error codes. Responses wrap
the fragment in a shell with a strict CSP and Permissions-Policy, a
small host runtime for size, theme, view, wheel, and Escape messages,
and a styling kit adapted from ZCode's Apache-2.0 visualize plugin.
Bundled D3 and Floating UI are served from `pi-genui://assets`, pinned
CDN URLs are rewritten to them, and every other remote asset is
blocked. The main window CSP gains only `frame-src pi-genui:` and
permission requests from the scheme are denied.

refs vastsa#1825
A model only produces visualizations if it knows where to write them,
what the sandbox allows, and how to reference the result.

Local sessions advertise the visualization directory in the system
prompt next to scratch, and a built-in `pi-desktop/visualize` skill
(condensed from ZCode's Apache-2.0 skill) describes the fragment
format, theme tokens, kit classes, and the reference line. Remote
workspaces get neither the directory nor the skill, including in the
`/` menu and send-time command expansion, and disabling the skill
also withholds the directory.

refs vastsa#1825
Completed assistant messages should show a referenced visualization as
an interactive card instead of a raw `::visualize{...}` line.

The transcript splits reference lines out before Markdown rendering
and hides an unfinished one while streaming. Each card frames the
fragment from its owning session in a `sandbox="allow-scripts"`
iframe, follows the app theme through postMessage, sizes itself from
the guest, forwards wheel scrolling to the transcript, and can expand
into a focus-trapped dialog. At most eight frames stay live; cards
release their slot off-screen and reload on return. Missing, invalid,
remote, or oversized fragments show a localized unavailable card.

refs vastsa#1825
Captures the decision and its trade-offs so later changes to the
sandbox, storage root, or fork behavior can be reviewed against them.

Adds ADR gen-ui-inline-visualization and D671, the session
visualization directory in the tools-and-permissions and data-storage
specs, the VISUALIZATION_HTML_ONLY error code, the
E2E-GENUI-inline-visualization-card scenario, an unreleased note, and
the matching zh-CN mirrors.

closes vastsa#1825
@zszz3
zszz3 force-pushed the feat/gen-ui-inline-visualization branch from 44eff5a to bdafc1b Compare October 23, 2026 06:41
@vastsa vastsa closed this Oct 23, 2026
@vastsa vastsa reopened this Oct 23, 2026
@vastsa

vastsa commented Oct 23, 2026

Copy link
Copy Markdown
Owner

维护者已明确特许本次 feat,属于贡献类型限制的例外。已恢复 PR,后续审查仅依据代码实现、实际效果及相关安全/兼容性/测试门槛;此前的政策关闭结论不再适用于本 PR。

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

主功能实测可用,但当前版本不能合入:发现 3 个 P1(启动清理越界删数据、Ask 写入确认绕过、Windows 正常 Write/Edit 被拒绝)及 4 个 P2(迁移后分叉丢卡片、响应未强制 sandbox、目录身份/祖先换链越界、FIFO 阻塞 Main 文件线程池)。具体触发条件、证据和最小修复方向见逐行评论。不要求重写该功能;请在现有实现上修复这些边界,并补对应回归测试。

验证候选:b41a732d98cbff8a6b16bf26a6a77286fc80da95;base main:1ddfd7203fe58cd970fc6f929218253369706de7;PR head:bdafc1b71c2dcab9db3da3e659071346da851e58。

已通过:候选依赖/desktop 构建、Desktop typecheck、pnpm lint、git diff --check;Desktop 定向测试 84/84、Shared 1296/1296、Agent Runtime 1433/1433、Rust 定向测试及 fmt/clippy(仅原有警告);真实 Chromium 转录区回归;隔离 Electron 的流式引用、离线 D3、滑块、主题、展开/guest Esc、离屏释放/重载、远程/缺失文件降级、卸载清理交互探针。GenUI 资源复制阶段在 mac/win/linux 配置下验证通过。软链越界、FIFO 阻塞、跨帧读取及 Rust 安全/分叉探针确认了现有测试未覆盖的缺陷。远端全部检查已绿:此前证书 E2E 启动超时,经单项重跑通过。

Windows 问题是确定的源码路径结论,未在 Windows 实机复现。未调用付费模型、未连接用户运行中的应用、未做完整签名安装包测试;独立 stdio 附加探针的超时未计作通过。未修改或重写贡献代码。

非阻塞小项:8 帧上限未计入展开弹窗(实测 8 张内联卡片展开后为 9 个 iframe),另有一条 P3 评论。WebRTC/STUN 残留是 PR 已披露的 v1 限制,不作为本次新缺陷重复报告。

Comment thread crates/host-core/src/visualizations.rs Outdated
/// references them.
pub fn sweep(data_dir: &Path, live_session_ids: &HashSet<String>) {
let base = base_dir(data_dir);
let Ok(entries) = std::fs::read_dir(&base) else {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 清理前必须验证 visualization 基目录的真实边界。若 <data_dir>/visualizations 是指向另一目录的软链,read_dir(&base) 会直接遍历目标;下面的 entry.file_type() 只检查子项,不能阻止父目录链接。名称不在 live session 集合中的真实子目录随后会被 remove_dir_all 删除。直接调用候选 sweep 的探针中,链接目标里的 family-photos/important.txt 连同目录被删除。这是启动时自动发生的数据丢失,而不只是拒绝展示的问题。请对 base 的链接/边界做验证,保证清理不会穿过重定向的基目录,并覆盖基目录软链的回归用例。

Comment thread crates/host-core/src/rpc/mod.rs Outdated
&& args
.get("path")
.and_then(Value::as_str)
.is_some_and(|path| roots.lexical_root(path).is_some())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 词法归属不足以跳过 Ask 写入确认。将 visualizations/<sessionId> 链接到项目目录,再 Write 该词法根下的 index.html,这里自动允许;执行器又把软链的目标作为合法 visualization 根,直接覆盖项目文件。真实 RPC 源码探针返回 ok:true / root:visualization,permission 通知为空,项目文件被写成 unapproved replacement,不需要竞态。请在免确认判定及执行侧验证 visualization base/session 根未被链接重定向;否则拥有受控目录路径并不代表操作还在受控目录内。

Comment thread crates/host-core/src/tools/mod.rs Outdated
let direct_child = roots
.iter()
.find(|root| root.kind == ToolRoot::Visualization)
.and_then(|root| std::fs::canonicalize(&root.path).ok())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 这里需与 resolver 使用同一个 canonicalizer。Windows 盘符路径的 std::fs::canonicalize 返回 \\?\C:\...,但 workspace::resolve_with_existing_ancestor 使用 simple_canonicalize,按 workspace.rs:4-24 的规则返回普通 C:\...。下一行直接比较 resolved.parent() 与这里的 root,因此正常的直接子 .html Write/Edit 也会得到 VISUALIZATION_HTML_ONLY,整个 Windows 可视化生成路径失效。请改用同一规范化规则并加入 Windows 用户路径用例。这项是源码路径确认,未冒充 Windows 实机测试。

let target = guard.destination.join(entry.file_name());
let source_path = path.to_string_lossy();
let target_path = target.to_string_lossy();
let referenced = rewrite(records, compactions, &source_path, &target_path);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 分叉复制不能依赖当前 data_dir 的完整路径文本。数据目录迁移不改写旧 transcript,源卡片仍可按尾部 session/file 身份加载,但这里仅匹配当前目录拼出的绝对路径。比如 Bash 生成片段后留下旧绝对路径的 ::visualize 文本,没有包含新路径的结构化 Write 行时,rewrite 返回 false,现存片段不会复制给子会话。真实分叉探针模拟迁移后的等价状态:源文件存在、fork 成功,但 child_file_exists=false;canonical/alias 拼写不同也可复现。请按有效 visualization 引用的 session/file 身份定位和复制,再改写路径,覆盖迁移后分叉的用户路径。

export function genUiResponseHeaders(): Record<string, string> {
return {
"content-type": "text/html; charset=utf-8",
"content-security-policy": GEN_UI_CONTENT_SECURITY_POLICY,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 响应头需要强制 sandbox,不能只信任 GenUiFrame 调用方。所有 session 文档共享 pi-genui://session origin;renderer 插件的 ES module 在应用 renderer 内运行,可以创建未加 sandbox 的 iframe。用实际主窗口 CSP 创建两个这样的 iframe,攻击 fragment 通过 parent.frames[1].document 成功读到另一会话的 CROSS_SESSION_PRIVATE_MARKER。关闭 Fetch/CORS 不阻止同源 DOM 读取。普通 sandboxed 卡片本身不能直接利用这个绕过,但其他协议调用方可以。对照探针仅在响应 CSP 头追加 sandbox allow-scripts,相同读取即变成 SecurityError。请在协议响应上强制 opaque-origin sandbox,并覆盖未加 sandbox 的调用方;sandbox 指令应放响应头而不是仅放 meta。

realpath(visualizationsRoot),
realpath(sessionDir),
]);
if (!isInside(realRoot, realSessionDir) || realSessionDir === realRoot) return NOT_FOUND;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 总根内包含关系既不能证明会话身份,也没有固定后续 open 的祖先目录。visualizations/alias -> visualizations/victim 会通过此判断,请求 alias URL 实际返回 victim 内容。另一个确定性文件系统边界探针在 realpath 完成后、lstat 前,将会话目录改名并替换成指向根外目录的软链;真实 lstat/open/read 随后成功返回 OUTSIDE_MARKER。O_NOFOLLOW 仅保护最后的文件组件,不保护父目录。这两条复现已独立重跑确认。请拒绝会话目录别名,并将文件读取绑定到已验证的目录身份,不能只对一个字符串路径做先检查后打开。

// the read cannot redirect it.
const filePath = join(realSessionDir, location.fileName);
// O_NOFOLLOW is unavailable on Windows; keep the lstat check there.
if ((await lstat(filePath)).isSymbolicLink()) return NOT_FOUND;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 要在阻塞 open 之前排除非普通文件,并防检查后被换成 FIFO。当前 lstat 只拒绝 symlink,mkfifo pipe.html 会在后面的 O_RDONLY open() 持续 pending,根本到不了 handle.stat().isFile()。实测四个并发卡片请求占满默认 libuv 的四个文件线程,连无关的 readFile 都被阻塞;打开 FIFO 写端后四个请求才返回 404,无关读取恢复。请先验证普通文件,并采用不会因 FIFO 卡住的打开/句柄复验方式,覆盖重复卡片请求不会拖死其他 Main 文件 I/O 的回归用例。

</div>
)}
</div>
{expanded ? <GenUiDialog url={url} title={title} onClose={closeDialog} /> : null}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3 / 非阻塞] 展开弹窗的 GenUiFrame 没有计入 live-frame pool。真实 Electron 探针中,8 张内联卡片同时 live 时展开一张,DOM 内出现 9 个 iframe,而 pool 仍报告 8。这样 GEN_UI_MAX_LIVE_FRAMES 并不是注释声明的跨所有 pane 的 mounted guest 上限。可以让展开帧参与同一资源配额,或明确这只是内联帧上限;此项不单独作为阻塞合入的理由。

Visualization paths must not grant implicit access through redirected
roots or let startup cleanup remove unrelated data. Validate owned roots
at authorization and execution, preserve Windows canonical spelling, and
keep fork references independent of a relocated data prefix.

Serve fragments through pinned native directory capabilities instead of
raceable path snapshots. Enforce response-level sandboxing and one frame
quota, preserving inline state while expanded. Add regression and real
Host/Electron coverage without changing renderer or plugin permissions.

refs vastsa#1826
The native Host can spend about thirty seconds initializing without an
Electron bridge, so the smoke client's thirty-second handshake races its
own cold start. Match the shared harness's forty-five-second setup budget
while retaining thirty-second deadlines for ordinary requests.

Cover both deadlines with a controlled clock and real NDJSON streams so
candidate smoke validation does not fail before exercising task code.
The remote base advanced during candidate validation. Incorporate it
without rewriting the contributor's commits so the final candidate and
PR checks validate the code that will actually land.
@vastsa

vastsa commented Oct 23, 2026

Copy link
Copy Markdown
Owner

已按维护者要求在原 PR 分支补修,未重写作者提交、未强推。

新增修复提交:4970dfa90、5eb24960c;并已非破坏性整合最新 main 0252ca2,当前候选 5d53309。

已处理审查问题:

  • BASE/SESSION 根校验同时用于授权、执行和清理,阻止软链根免确认写入及越界清理;保留普通显式外部审批。
  • Windows 可视化路径使用一致规范化;分叉按 session/file 身份复制并改写,支持迁移、别名与 JSON 转义,不改原始工具字符串或代码示例。
  • Main 不再按绝对路径读取片段:私有 Host RPC 使用 Unix openat / Windows 固定目录链,消除祖先换链与 ABA,FIFO 不阻塞读取。返回值有界校验,未增加 renderer IPC 或 Plugin SDK 权限。
  • 响应头强制 opaque sandbox;弹窗与内联共用 8 帧配额并保护原控件状态。
  • 补齐真实 Host/Electron E2E、Windows 可视化/文件边界 CI;另修复阻塞本地 smoke 的 30 秒握手预算,普通请求预算不变。

已执行:Host 全量 1021 通过 / 1 忽略;可视化 55/55;Desktop 定向 92/92 + smoke 时钟回归 2/2;Shared 1298/1298;最新 Agent Runtime 1434/1434;构建、typecheck、lint、架构、fmt/clippy、文档/locale 检查通过(clippy 仅原有警告)。

候选 5d53309、base 0252ca2 上的本地集成检查:Host smoke 23/23(2 个付费 live-provider 用例未授权,明确跳过);Electron boot、Chromium transcript 四阶段、GenUI 十项实际交互/隔离检查全部通过。无付费模型调用,未连接用户运行中的应用。

现在等待并验证实际 PR 集成候选及全部远端检查,包括新增 Windows 运行时测试;通过后再合入。原 PR 已披露的 WebRTC ICE/STUN v1 限制仍保留,不宣称已消除。

Attribute-only directory handles do not participate in Windows sharing
accounting, leaving ancestors replaceable during fragment reads. Request
list/read access so the existing no-write/no-delete sharing policy pins
the entire canonical chain for the duration of each read.

Exercise the actual native reparse operation and preexisting mutation
handles, with an unpinned victim control. Correct cmd junction fixture
quoting and DOS spelling so these tests reach the filesystem boundary.
Incorporate the latest validated Composer fixes without rewriting the contributor's commits so the final PR candidate contains current main.
@vastsa

vastsa commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Windows CI 补修已追加为 bd2e390,未删改安全断言:

  • 目录改用 LIST_DIRECTORY | READ_ATTRIBUTES,使禁止写入/删除共享真正参与 Windows 共享计数。
  • 修正 cmd junction 夹具的引号和 DOS 路径;覆盖带空格及 verbatim 路径。
  • 验证完整祖先链的 DATA / APPEND / GENERIC_WRITE / DELETE 冲突,已有可变句柄拒绝读取;新增 FSCTL_SET_REPARSE_POINT 控制,释放句柄后真实重定向到 victim,固定期间则拒绝。

已非破坏性整合最新 main 36e19eb,候选 6d08e7a。本地 55 项可视化测试、Windows MSVC check/Clippy、Linux check、格式检查通过;新基线下 32 项针对性测试及 smoke/boot/transcript/GenUI 四个 E2E 全部通过。Windows 实际运行仍以本次 CI 为准,通过前不合入。

Windows permits attribute-only handles to change reparse points despite
read sharing pins, as the real FSCTL control demonstrated. Open canonical
ancestors and every owned child relative to retained native directory
handles so no absolute child path can be redirected during serving.

Keep the successful attribute-junction attack as a regression control at
session, base, and data boundaries. Preserve bounded same-handle reads,
reparse validation, normal ACLs, and the existing private RPC contract.
Keep the shared contributor history intact while incorporating current main for the final native Windows and Electron integration checks.

# Conflicts:
#	docs/project/unreleased.md
@vastsa

vastsa commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Windows 实测进一步证明:FILE_WRITE_ATTRIBUTES 可以在共享固定期间执行 FSCTL_SET_REPARSE_POINT。因此补修 54824dd 已用真正的 NtCreateFile RootDirectory 相对打开替换绝对子路径读取,共享限制仅保留为附加防护。

保留成功攻击作为正向控制:同一 FSCTL 将 session/base/data 目录变为 junction,旧绝对读取读到 victim,新相对读取不得泄漏;未跳过安全断言。新增 NT ABI/名称约束测试,无新依赖、权限或 IPC/SDK 接口。

已整合最新 main e7d8765,候选 e012b68。本地 macOS 可视化 55 项、Windows MSVC / Linux GNU 编译与 clippy、文档/格式检查通过;新基线串行构建、30 项相关测试、smoke/boot/transcript/GenUI 四个候选 E2E 全部通过。此前 Electron 长历史一次失败在原提交单独重跑已通过,未改无关 UI。

仍以本轮 Windows 实际 CI 为最终安全门槛,全部门槛通过后再合入。

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在原作者提交上完成补修并保留其历史。Unix/Windows 原生目录能力、真实 FSCTL 攻击控制、会话分叉与清理、响应 sandbox 和帧配额均已回归验证。候选 e012b68 / base e7d8765 与实际 PR 集成树一致;全部 CI 通过,包括 Windows 60 项可视化测试和 Electron 集成复跑。本地四个 E2E 已通过,两个付费模型场景明确跳过。原有已披露 WebRTC ICE/STUN v1 限制仍保留。

@vastsa
vastsa merged commit 3f374a8 into vastsa:main Oct 23, 2026
9 of 10 checks passed
vastsa added a commit that referenced this pull request Oct 25, 2026
…#1796)

* fix(asktool): keep card drafts across session switches

The AskTool card kept its question index and draft answers in component
state, so switching sessions unmounted the card and returning to the same
pending ask reset every answer. Store the draft by requestId instead and
let the card read and write that entry, dropping it when the ask is
resolved, dismissed, or removed.

Amends the asktool card spec's request-transition rule and adds
E2E-ASKTOOL-draft-survives-session-switch.

* fix(persistence): drop empty assistant rows regardless of status

The transcript guard only dropped empty messages whose status was error or
aborted. An empty complete assistant message therefore reached the outbox
on every provider retry, growing the request body and feeding the EMPTY
loop. Drop empty assistant rows whatever their status, while keeping
messages that carry an error payload, a tool row, or a steering
reservation.

Adds empty-assistant-persistence tests for each of those cases.

* fix(chat): open worktree references from the branch copy

An isolated session's files live in its worktree, but chat references can
still carry a path from the parent checkout: project instructions, MCP tools,
or a reference captured before isolation. The resolver rejected that path as
outside its roots, and the renderer then handed the file view a relative path
that it resolved against the parent checkout, so the click either failed or
opened the main-branch copy.

Rebase an absolute parent-checkout reference onto the same relative path in
the worktree when that file exists, and keep the worktree's absolute path in
the renderer so the file view opens the branch copy. Paths that exist only in
the parent still report outside-allowed-roots.

fixes #1747

* fix(transcript): let an unpinned bookmark own the pane reveal

Follow mode can still read pinned when a send or retry hid the pane. On the
next reveal the scroll hook then bottomed the transcript before the
reading-position hook could restore the recorded bookmark, so a reader who
had scrolled up returned to the newest turn.

Route the reveal through one shared ownership rule: an unpinned bookmark or a
pending restore keeps the edge, a genuinely pinned pane bottoms, and an
unpinned pane without a bookmark reapplies its retained offset. Both hooks
now agree on which one acts.

fixes #1771

* fix(agent-runtime): stop waiting for tools host-core cannot cancel

The abort listener returned immediately unless the tool was Bash or
GenerateImages, so Stop was a no-op for every other tool, and
tools.execute was awaited with no deadline. One report measured a Grep
running 21m39s after six Stop clicks.

The listener now applies to every tool. Bash and GenerateImages keep
sending tools.abort and get a bounded 10s grace window for the partial
output the host collected before the kill; every other tool abandons the
wait the moment the signal fires and returns TOOL_ABORTED without a
tools.abort RPC (the host cannot act on it, and the 60s tombstone it
would leave could be inherited by a later Bash reusing the call id).

Both paths race the execute call against the abort, so losing the race
abandons the wait rather than the host call: the orphaned call settles on
its own and its result is discarded.

Fixes #1767

* fix(agent-runtime): release in-flight tools from the stop itself

A stop can reach the runtime without reaching the tool it was meant to
cancel. The executor then keeps awaiting `tools.execute`, the turn never
settles, and `abort()` — which awaits that settlement — never returns. The
renderer awaits the abort RPC before it clears "processing", so the session
stayed pinned even though the ledger had already recorded the turn as
aborted: three turns in one field report were `aborted` while the tool's
process was still alive minutes later.

`abort()` now drives the in-flight tools directly instead of relying only on
the signal each one was handed: it walks the active abort handlers and runs
the same path a signal abort would. Cancellable tools still send
`tools.abort` and get the grace window; every other tool abandons the wait
at once.

Refs #1767

* fix(composer): search past a truncated file index for @ mentions

The file index keeps only the shallowest 8000 entries, so in a large
workspace — a Unity project, where every asset has a .meta sibling — a
script several folders down matches no query at all, even though the
truncation note invites the reader to refine it (#1781).

While the snapshot is truncated, a non-empty query is now also searched
over the workspace's full listing through the read-only fs/search channel,
after a short typing pause, and the best rows merge with the index's own
matches. The listing is the git list the index already builds, or a deeper
ignore-set walk when the index came from the walk. A complete index never
searches, and a remote session keeps its snapshot because the remote file
protocol has no search operation.

fixes #1781

* fix(work-panel): keep the active tab's close button inside the strip

The close button is a sibling of the tab button inside the tab wrapper, but
scroll-into-view targeted only the button. With `inline: "nearest"` a button
that is already visible scrolls zero pixels, so the sibling close button
stayed clipped outside the strip's overflow edge — the tab looked like it had
no close control at all (issue #1762).

Scroll the wrapper instead (falling back to the button), and reserve the
close button's width at the inline end via `scroll-padding-inline` so
sub-pixel rounding cannot reintroduce the clip.

* fix(mcp): fail loudly when a server has no DCR endpoint

#1782: when discovery returns no registration endpoint, the login flow fell
back to a literal client id:

    } else {
      clientId = "pi-desktop";
    }

No authorization server has ever registered that id, so the app opened
`<authorize>?client_id=pi-desktop` and the user landed on a bare 404 — with
no explanation and no way forward. It is not a GitHub-specific failure: any
OAuth MCP server without Dynamic Client Registration is affected.

Throw before opening anything, naming what is missing and the two real ways
out. A settings field for a client id does not exist yet, so the message does
not promise one.

The test drives the real startLogin through a mocked discovery that omits
registration_endpoint, and asserts both the message and that openExternal was
never called. Verified against the old code: the test does not merely fail,
it hangs until the 300s timeout, because the previous flow waited for a
callback that could never arrive — the same experience the report describes.

Verification: mcp-oauth.test.mjs 20/20, mcp-oauth-discovery.test.mjs pass,
tsc --noEmit clean.

* fix(settings): keep the last successful market list when a query fails

A failed catalog query used to drop the list back to built-in picks,
discarding what the user was just looking at (issue #1692 follow-up).
Both markets now keep the last successful result for the same query on
screen — under the failure with a timestamped note, and during the
retry that follows — until a retry succeeds or the query changes.

The snapshot never answers a different query, an empty successful
answer is not a failure to cover, and Load more refreshes it.

* fix(e2e): escalate to SIGKILL when the certificate probe hangs

#1751's Electron E2E job ran 30m18s and was cancelled by the job budget with
no failing step to read. The cause is this runner's only timeout:

    const timer = setTimeout(() => child.kill(), 60_000);

SIGTERM is a request. An Electron child still initialising its renderer can
ignore it, and the 'close' event this script awaits then never arrives, so the
step holds the job until GitHub cancels it. The runner's own 60s budget is
never enforced.

Escalate: SIGTERM at 60s, SIGKILL at 65s, and report which one fired. A probe
that cannot start now fails this step in about a minute with its output
attached, instead of burning the job budget.

Verified: normal path still passes ("provider client certificate E2E
passed"); with a child that ignores SIGTERM the escalation force-kills it at
~800ms in an isolated harness, so the timeout path terminates rather than
hanging.

* perf(sessions): cache file-derived session summaries by file identity

native.session.list() re-read, re-hashed and re-parsed every session file
on each call: nativePiSnapshot() does readFileSync + SHA-256 + per-line
JSON.parse, and list() then rebuilt SessionManager + branch +
buildSessionContext per file. Cost grew linearly with session count and
file size, all of it synchronous on the host main thread.

Cache only the facts that come from one file's bytes (header identity,
cwd, title, message count, timestamps, model, thinking level, structural
flags), keyed by (dev, ino, size, mtimeMs). Any append, rotation or
replacement changes the key and re-parses; projections for files a scan
no longer sees are dropped.

Nothing live is cached. Ownership, project trust, provider availability
and cwd existence are recomputed on every call, and every write path
still hashes the full bytes through nativePiSnapshot(), so external
rewrite detection and lease validation are unchanged.

The list path also stops needing a full snapshot to prove ownership: a
missing .pi-desktop.lock already means the lease is acquirable, so the
snapshot is only materialized when a lock file exists.

Measured on a real ~/.pi/agent/sessions tree (28 sessions, one file at
21 MB): list() 826/807/933 ms before, 802 ms cold and 21/16 ms warm
after. The cold round still parses every file, as before.

* fix(runtime): size the output cap from the folded request transcript

Long sessions accumulate one system-transcript snapshot per instruction
change. Unless a model declares mid-conversation system support, every
adapter folds them into a single leading message, but the output-cap
estimate charged each superseded snapshot again. The clamp collapsed to
1 and the provider floor (16) went on the wire while the request was far
from the window, so reasoning models were cut off and the turn ended as
EMPTY_MODEL_RESPONSE without compaction ever triggering.

The parent and subagent stream paths now fold the transcript the way
the adapter will before clamping, and hand that same transcript to
pi-ai so its own streamSimple clamp agrees. Context calibration and the
compaction budget keep their existing basis.

* feat(transcript): add display modes and thinking shimmer

Add a persisted 	ranscriptDisplayMode setting with flat, command-first,
and fully-folded layouts. Fully-folded keeps the v0.20.0 command grouping,
command-first keeps run rows standalone, and flat removes nested activity
groups while preserving one outer process.

Make Thinking rows default expanded in flat and command-first, collapse to
a whole-run TextShimmer indicator, and use the same shimmer for the hidden
reasoning live indicator. Keep fully-folded's existing Thinking defaults.
Deprecate keepCommandsExpanded; it remains readable for compatibility.

Cover mode segmentation, settings normalization and sync, and renderer
wiring; update transcript and settings specs and ADRs.

* test(transcript): align turn-process probe with Thinking defaults

Open the completed process and Thinking disclosure before asserting the
retained reasoning text now that a collapsed Thinking row shows only its
label. Also assert flat mode keeps one outer process without nested
activity groups or standalone run wrappers.

* fix(agent-runtime): skip expired OS trust anchors when merging the CA set

The sidecar merges the operating system's trust store into Node's default CA
set at startup. Those stores are a cache and keep entries that already
expired: Windows still lists Let's Encrypt's `ISRG Root X2` and `R3` with a
2025-09-15 expiry long after the fact.

Merging one of those makes OpenSSL accept an expired certificate as the anchor
for any chain that names it as issuer. A chain like

    leaf -> YE2 -> Root YE -> ISRG Root X2 -> ISRG Root X1

stopped at the expired `ISRG Root X2` instead of walking up to the valid
`ISRG Root X1`, so the handshake failed with `CERT_HAS_EXPIRED` even though
the provider's own chain was valid. The failure is reported as a TLS category
error and is correctly not retried, so the provider is unusable until the
expired entry leaves the store.

Every provider behind such a chain failed, which is why the report looked
provider-specific (issue #1393). Reproduced on Windows 11 with Electron 43.6.0:
`tls.getCACertificates("system")` returned 146 certificates, 17 of them
expired, and the same host handshakes fine with the bundled roots alone.

An anchor that has already expired can verify nothing, so it is never merged.
The bundled and `NODE_EXTRA_CA_CERTS` sets are untouched, and chain,
expiration and hostname validation stay enabled - this narrows the merge, it
never disables verification.

- `system-ca.ts`: filter the system store by `validTo` before merging.
- `system-ca.test.ts`: assert no expired system anchor reaches the defaults.
- `e2e-provider-certificates.mjs`: the trust probe now measures the usable
  system roots, because the previous "every system certificate is present"
  expectation cannot hold once expired entries are excluded.

* test(transcript): mock TextShimmer in session reference probe

The shared transcript module now imports the Thinking shimmer. Keep the
session-reference renderer probe's dependency table complete so it can
continue exercising message references without loading the app store.

* fix(e2e): test certificate probe kill escalation

Keep the normal Electron path unchanged while asserting that a child
ignoring SIGTERM receives SIGKILL after the grace period.

* fix(mcp): localize missing DCR recovery

Fail before opening OAuth with an unregistered client, and send a
stable error code so settings can show translated recovery guidance.

* fix(transcript): fall back to the bookmarked offset when its row is unmounted

Stacked on #1783, which fixes who owns the reveal edge but not this path.

A reveal mounts only a trailing slice of history (TRANSCRIPT_INITIAL_MOUNT 15,
then TRANSCRIPT_WINDOW_MIN 60, lib/transcript-window.ts:23-28), so an older
bookmark routinely names a row that is not in the DOM. restoreTranscriptReading
Position reported that as false, and the alignment loop returns on false without
arming the deadline that would clear pendingRef (use-transcript-reading-
position.ts:99). While a restore is pending, useTranscriptScroll discards every
scroll event (:384-387), so the reader cannot travel up to mount the row either:
no restore, no scrolling, permanently.

The bookmark already recorded the absolute offset it was taken at
(TranscriptReadingPosition.scrollTop, captured at :59/:68), but the restore path
never read it. Use it as the fallback: an approximate place is strictly better
than a pane that can neither scroll nor restore. A bookmark with no usable
offset (NaN, negative, infinite) still reports failure, and a pane with no
layout box is still refused outright.

Tests: transcript-reading-position-fallback.test.mjs (5) covers the mounted-row
path, the unmounted-row fallback, a zero-height row, unusable offsets, and the
no-layout refusal. Related suites: 42/42. typecheck clean after a workspace
build.

* fix(host-runtime): expect the platform scratch separator in the launch-resolver test

join(dataDir, ...) yields native separators and the assertion hardcoded the POSIX spelling, so the suite failed on every Windows checkout while Linux CI stayed green. Mirror the production expression instead.

* fix(agent-runtime): tolerate the Windows symlink privilege in the sessionDir tests

The #1732 tests create real file symlinks, which EPERMs on an unprivileged Windows checkout and crashes the fixtures (storage-directory-migration already degrades the same way). Catch EPERM and keep the remaining assertions, which hold without the alias; privileged runs and CI keep the full coverage.

* feat(composer): toggle background task output from the whole row

The background-tasks bar only opened a task's log through its "Output"
button, so the row itself — the state dot, the command and the meta text —
looked clickable but did nothing, and the click target was a few pixels
wide.

The row lead is now the toggle: mouse click, Enter and Space all flip the
log, with aria-expanded on the interactive region. Stop and dismiss keep
their own buttons outside that region, and a source test pins the split so
a later refactor cannot regress the click target.

* docs(spec): restore the missing rationale cell on D669

The D669 decision row landed with three cells in a four-column table in
both languages, so `pnpm --filter @pi-desktop/docs test` fails on
`origin/main` with a page-structure error.

Fill in the rationale the decision actually records: the shallowest-8000
entry index matched nothing for a script several folders down, which is
what issue #1781 reported. The table parses again.

* fix(e2e): bound the client certificate baseline fetch

Electron's direct fetch rejects before reaching the TLS fixture on macOS,
but can stall at the same client-certificate negotiation on Linux. Bound
the baseline probe and accept its abort as the platform-specific outcome,
while still requiring that no HTTP request reached the fixture.

This keeps the certificate discovery, proxy, redirect, and cancellation
assertions running instead of letting the child process time out.

* fix(e2e): bound the client certificate baseline probe

Electron's direct fetch can remain pending during client-certificate
negotiation on Linux, and its AbortSignal does not reliably interrupt
that platform request. Race the baseline probe against a short deadline;
keep the process alive for the remaining discovery checks, then exit
Electron after the fixture has been verified.

A successful fetch still fails the test, and the fixture must receive no
HTTP request before the certificate error or platform timeout.

* fix(chat): parse positioned and ambiguous file references safely

Fixes #1722

Tested: pnpm lint && node --test apps/desktop/test/chat-links.test.mjs apps/desktop/test/chat-ref-resolve.test.mjs && pnpm --filter @pi-desktop/agent-runtime exec vitest run src/runtime.test.ts && node scripts/e2e-file-ref-line-scroll.mjs && pnpm docs:check
passed (exit code 0)

* fix(transcript): keep activity details visible after turns settle

Fixes #1806

Tested: pnpm test:e2e:transcript && node --test apps/desktop/test/thinking-ui.test.mjs apps/desktop/test/transcript-display-modes-ui.test.mjs && pnpm typecheck
passed (exit code 0)

* test(transcript): align search test with group defaults

* fix(window): restrict recovery pinning to macOS

Bounds recovery could leave Windows and Linux windows always-on-top
because only the macOS watchdog releases the temporary recovery pin.
Keep pin acquisition on the platform that owns its cleanup.

Regression coverage protects normal focus and hidden or minimized state
while preserving the existing macOS recovery behavior.

* fix(transcript): keep running marker inline

The shimmer styles were inserted after the first half of the running-label selector, so the active label inherited inline-grid and the pulse marker became an auto-placed grid item. Separate the marker and shimmer selectors again so the marker stays in the label's inline flow and does not disturb truncation.

* fix(transcript): center running marker

The live dot was generated content inside the running label. A selector collision with the shimmer rule turned that label into a grid and pushed the dot onto a second row; even with the selectors separated, the inline pseudo-element sat below the row centre and could be clipped by the label's ellipsis box.

Render the marker as a real flex sibling so the header's existing align-items centres it, and keep the label's text truncation untouched.

* chore(models.dev): refresh catalog before beta.5

Refresh the bundled provider catalog so the 0.21.0-beta.5 test build packages the current models.dev snapshot.

* test(provider): align DeepSeek window with catalog

The refreshed models.dev snapshot publishes a 1,048,576-token window for deepseek-v4-flash; update the endpoint metadata assertion so the release verification pins the shipped catalog.

* chore(release): v0.21.0-beta.6

* feat(transcript): flatten edit rows and restore group hierarchy

A review-backed Edit or Write now renders as a single tool-level review row: the file header is the only disclosure header, with its diff body directly beneath it. This removes the duplicate generic tool row while keeping rollback and adding a copy action for the hunks.

The command-first and fully-folded group bodies restore the released v0.20.1 12px child indent and left hover/focus collapse rail, so non-command tools keep their two-level hierarchy without adding a third disclosure.

* fix(settings): size segmented controls to their content

Keep translated display-mode labels on one line instead of squeezing them
into the fixed field column. Allow settings controls and whole options
to wrap when the available pane width is limited.

* feat(chat): rework the top-level turn fold header

The turn header now reads as a hairline row: status, recorded duration and tool count stay in one left-aligned run, with the disclosure caret trailing the metadata instead of sitting at the far edge of the transcript. Hovering only strengthens the text colour, and the issue count is no longer repeated at this level because the status already names a failure.

Nested activity-group headers and their hover fill stay unchanged so the transcript hierarchy below the turn fold is not flattened.

* fix(chat): keep the hairline header on the transcript edge

The top-level row no longer bleeds into the gutter, so its fill starts at the prose edge while nested group and run fills keep their 4px hover bleed. The shared 5px gap keeps the turn title on the same text line as the nested titles, and the transcript E2E probes the new content edge and full-width hairline.

* fix(e2e): measure the turn hairline against its process band

The probe compared the header with the padded fixture root, so a correct full-width row could never match. Measure the header against the turn process that owns it instead.

* feat(chat): show per-turn token usage capsule

Completed assistant turns now show the model, average generation speed, and total tokens on one quiet row. Hovering or focusing the capsule reveals cache-read, input, and output counts without opening the composer inspector, while the composer remains the last-request occupancy authority.

The capsule aggregates every parent assistant message in the visual turn, so its total answers what the round consumed rather than what the newest request occupied. Subagent spend stays out of the per-message usage contract.

* fix(agent-runtime): preserve executions when providers reuse tool IDs

Repeated provider IDs were mistaken for replayed history, dropping real
results and freezing the outgoing request. Assign execution IDs before
Pi journals each response and retain completed pairs at the request
boundary. Keep identity reservations across compaction and model fallback.

Fixes #1815

* fix(live-voice): repair Gemini work setup and report protocol failures

Gemini rejects the additionalProperties keyword in its setup Schema.
Use its supported schema subset while keeping OpenAI and Host validation
strict. Reject failed setup immediately and retain the first socket
failure's diagnostics in the provider log without exposing them over IPC.

Fixes #1812

* fix(desktop): keep toasts clear of the work panel

Anchor the global toast stack to the live main-content bounds so docked and resized work panels remain usable while notifications are visible. Preserve viewport fallback placement outside the chat shell and cover resize and horizontal-shift geometry in the question-notification journey.

Refs #1820

* test(e2e): control toast focus transitions

Drive the focus and blur lifecycle through explicit DOM events so the countdown coverage does not depend on operating-system window activation. Keep native keyboard input coverage in Electron.

* fix(transcript): wait for history before applying fallback

A bookmarked anchor can be outside the mounted window while its bounded
history lookup is pending. Start viewport alignment only after the lookup
succeeds so the fallback deadline cannot cancel it.

Cover delayed lookup and document the approximate offset behavior.

* fix(persistence): retain one trusted empty completion row

Drop ordinary empty assistant rows to stop provider retries growing the transcript, while preserving the one-shot silent reply allowed by a Host-verified completion notice. Spend or revoke that exception on the first completed response, accepted steering, and turn settlement.

fixes #1766

* fix(mcp-market): retain source badges in stale results

The retained list is rendered after the current remote entries are cleared, so source badges must follow the displayed snapshot. Keep the existing provenance visible until a retry replaces it.

* test(work-panel): cover tab close reachability after resize

Make the geometry fixture shrink the actual scrollport and reset it between stages so resize and hover are independently exercised. Update the bilingual E2E scenario to document both paths.

* fix(agent-runtime): cancel pending tools safely

Stop immediately only when the active work is read-only or has a host cancellation path. Cancel pending approvals and remote reads, while waiting for started mutations and extension calls to settle before reporting the turn stopped.

* fix(test): stub the turn usage capsule in the session reference fixture

The session reference UI test transpiles the real shared transcript module and asserts every dependency is stubbed. Importing the new capsule broke that fixture graph, so the fixture now provides a capsule stub and the breakdown helper Mock.

* feat(chat): show project breadcrumb and inline title editing

The conversation top bar only named the task, so the project a task
belongs to was hidden in a tooltip. Put the session's project beside the
title as a quiet crumb and let the title be renamed in place, matching
the rest of the app's direct-manipulation surfaces.

The crumb resolves from the active session rather than the globally
selected workspace, so a task opened from another project stays labeled
correctly. Remote and scheduled transcripts keep a plain title because
their titles are host-owned, and the inline editor keeps the existing
title limit, IME behavior, and error path.

Update the component spec and its source-contract test to match.

* docs(spec): sync the Chinese topbar description

The English component spec now describes the project breadcrumb, the
inline title editor, and the expanded state table. Mirror those changes
in the Chinese page so the locale pair keeps the same table and fence
structure and the docs checks stay green.

* feat(chat): keep the workspace crumb on an empty chat

An empty chat has no session yet, so the crumb previously disappeared
even though the app still has an active project. Fall back to the
workspace name only in that state; temporary sessions keep the plain
title because they belong to no project.

Extend the topbar rendering test and both spec pages.

* fix(ci): realign stale store and adapter contracts

Recent main changes added AskTool drafts and persistence bookkeeping without updating every fixture, moved the empty-message guard into session-transcript, and changed the AppShell section attributes and host-core cancellation shape. The stale assertions failed all PR checks, including unrelated branches.

The Gemini Live close handler also assumed a reason buffer always exists; a close event without one now keeps the adapter's teardown path instead of throwing.

* chore(models.dev): refresh catalog before beta.7

Refresh the packaged provider catalog to the current models.dev snapshot so the prerelease ships the same model metadata the release workflow packages.

* chore(release): v0.21.0-beta.7

* feat(shared): add inline visualization contracts

The desktop shell, host-core, and agent runtime need one definition of
where visualization fragments live and how a reply refers to them, so
the reference format and URL scheme cannot drift between processes.

This adds the `pi-genui:` URL helpers, the session directory and file
name rules, the `::visualize{...}` reference parser (outside code
blocks, tolerant of Windows paths), the guest message types, and the
VISUALIZATION_HTML_ONLY error code.

refs #1825

* feat(host-core): add a session visualization root

Visualizations need a host-owned place the model can write without a
permission prompt that is still clearly separated from the project and
from disposable scratch files.

Local sessions get `<data_dir>/visualizations/<sessionId>/` as a second
contained root next to scratch (amends D114). Write/Edit there accept
only direct `.html` fragments, an Edit move out of the contained roots
still asks, and the root wins over a workspace that contains the data
directory. The directory is removed with its session, only orphans are
swept at startup, and forks copy the fragments they reference so cards
survive deleting the parent. Remote and contract sessions get no root.

refs #1825

* feat(desktop): serve visualizations through a sandboxed pi-genui scheme

The renderer must be able to frame a model-written fragment without
granting it network, host, or same-origin access, and without the
fragment reaching outside the session's visualization directory.

Main registers `pi-genui:` (standard and secure only, no fetch or
CORS), resolves `pi-genui://session/<id>/<file>` against the real
session directory with O_NOFOLLOW and a 2 MB cap, rejects full HTML
documents, and reports failures as fixed error codes. Responses wrap
the fragment in a shell with a strict CSP and Permissions-Policy, a
small host runtime for size, theme, view, wheel, and Escape messages,
and a styling kit adapted from ZCode's Apache-2.0 visualize plugin.
Bundled D3 and Floating UI are served from `pi-genui://assets`, pinned
CDN URLs are rewritten to them, and every other remote asset is
blocked. The main window CSP gains only `frame-src pi-genui:` and
permission requests from the scheme are denied.

refs #1825

* feat(agent-runtime): teach agents to write inline visualizations

A model only produces visualizations if it knows where to write them,
what the sandbox allows, and how to reference the result.

Local sessions advertise the visualization directory in the system
prompt next to scratch, and a built-in `pi-desktop/visualize` skill
(condensed from ZCode's Apache-2.0 skill) describes the fragment
format, theme tokens, kit classes, and the reference line. Remote
workspaces get neither the directory nor the skill, including in the
`/` menu and send-time command expansion, and disabling the skill
also withholds the directory.

refs #1825

* feat(chat): render visualization references as inline cards

Completed assistant messages should show a referenced visualization as
an interactive card instead of a raw `::visualize{...}` line.

The transcript splits reference lines out before Markdown rendering
and hides an unfinished one while streaming. Each card frames the
fragment from its owning session in a `sandbox="allow-scripts"`
iframe, follows the app theme through postMessage, sizes itself from
the guest, forwards wheel scrolling to the transcript, and can expand
into a focus-trapped dialog. At most eight frames stay live; cards
release their slot off-screen and reload on return. Missing, invalid,
remote, or oversized fragments show a localized unavailable card.

refs #1825

* docs: record inline generative UI visualizations

Captures the decision and its trade-offs so later changes to the
sandbox, storage root, or fork behavior can be reviewed against them.

Adds ADR gen-ui-inline-visualization and D671, the session
visualization directory in the tools-and-permissions and data-storage
specs, the VISUALIZATION_HTML_ONLY error code, the
E2E-GENUI-inline-visualization-card scenario, an unreleased note, and
the matching zh-CN mirrors.

closes #1825

* fix(agent-runtime): emit extension context before every request

Trusted extensions never saw the first provider request of a run: the
context event was emitted from prepareNextTurn, which pi-agent-core
only calls after a completed turn. A reply without tool calls was
never shown to context handlers at all, unlike pi-coding-agent, which
fires the event before every LLM call.

Emit context from transformContext instead, so each request is shaped
once and the replacement stays a per-request view instead of becoming
the run's working context. A runtime test covers the first request,
the follow-up after a tool result, and the persisted transcript.

fixes #1838

* fix(gen-ui): harden contained roots and native fragment serving

Visualization paths must not grant implicit access through redirected
roots or let startup cleanup remove unrelated data. Validate owned roots
at authorization and execution, preserve Windows canonical spelling, and
keep fork references independent of a relocated data prefix.

Serve fragments through pinned native directory capabilities instead of
raceable path snapshots. Enforce response-level sandboxing and one frame
quota, preserving inline state while expanded. Add regression and real
Host/Electron coverage without changing renderer or plugin permissions.

refs #1826

* fix(test): allow standalone host cold-start handshake

The native Host can spend about thirty seconds initializing without an
Electron bridge, so the smoke client's thirty-second handshake races its
own cold start. Match the shared harness's forty-five-second setup budget
while retaining thirty-second deadlines for ordinary requests.

Cover both deadlines with a controlled clock and real NDJSON streams so
candidate smoke validation does not fail before exercising task code.

* fix(composer): drop stale failure restores from superseded submits

restoreDraftForKey guards only an empty slot, so a late accepted=false from an older submit repainted that message, attachments included, once a newer submit's clear had emptied the composer again (#1809). clearDraftForKey already refuses to clear a draft it does not own; give the restore the same staleness guard with a submit epoch, and let only the newest rejection restore.

* fix(composer): track the submit epoch without a renderer-owned ref

remote-unified-chat drives the submit hook outside a renderer, where useRef throws, so the #1809 guard moves into a module-scope Map keyed by draft slot. Per-slot keys also keep two composers (home/docked, plugin panes) from invalidating each other's restores, and the epoch survives re-renders the way a fresh closure could not.

* fix(composer): release stale submit restore ownership

Only the newest unresolved submission may restore a rejected draft. Unique
submission tokens prevent older requests from regaining ownership after
settlement, and completed entries are released so draft slots do not accumulate
in a module-level map.

A controlled async regression test protects the user-visible draft behavior.

* fix(chat): open turn usage popover upward

The capsule sits at the end of a completed turn, where the next answer or the composer follows immediately. Opening the breakdown upward keeps that content visible, so the capsule now uses the placement helper's above-first default and the unused below-preference option is removed.

* fix(gen-ui): establish Windows directory share pins

Attribute-only directory handles do not participate in Windows sharing
accounting, leaving ancestors replaceable during fragment reads. Request
list/read access so the existing no-write/no-delete sharing policy pins
the entire canonical chain for the duration of each read.

Exercise the actual native reparse operation and preexisting mutation
handles, with an unpinned victim control. Correct cmd junction fixture
quoting and DOS spelling so these tests reach the filesystem boundary.

* fix(browser): keep session pages available in the background

Decouple browser execution from side-panel presentation so switching
conversations, collapsing the panel, or reloading the renderer no longer
interrupts a session's page. Preserve trusted session routing and sandbox
boundaries while retaining a hidden native backing host for Chromium.

Cover background input, capture, renderer recovery, and resource cleanup
with regression and native Electron tests.

* fix(gen-ui): bind Windows fragment reads to native directories

Windows permits attribute-only handles to change reparse points despite
read sharing pins, as the real FSCTL control demonstrated. Open canonical
ancestors and every owned child relative to retained native directory
handles so no absolute child path can be redirected during serving.

Keep the successful attribute-junction attack as a regression control at
session, base, and data boundaries. Preserve bounded same-handle reads,
reparse validation, normal ACLs, and the existing private RPC contract.

* fix: preserve explicit model reasoning effort overrides

Let a saved model binding opt into reasoning_effort for compatible gateways
without removing the automatic DeepSeek protection. Preserve the choice
through Host persistence, runtime projection, copying and configuration sync.

Add the tri-state settings control, request-body and persistence regressions,
and real renderer save/reopen coverage across locales and window sizes.

Fixes #1821

* feat(chat): make inline visualizations an opt-in setting

Inline visualization cards were on for every local session, so a model could
write fragments and the transcript would frame them without the user ever
asking for the feature. The new `AppSettings.inlineVisualizations` switch is
absent and false by default, which keeps the transcript unchanged for anyone
who does not opt in.

One helper decides what the process treats as disabled, so the session launch,
the `/` menu, and the on-demand `Skill` tool cannot disagree. While the switch
is off the prompt advertises no visualization directory, the `visualize` skill
is withheld from the catalog, and the renderer still strips reference lines —
a historical reply must not show its absolute path as text — but produces no
card, so nothing is read from disk or framed.

* feat(models): infer custom endpoint auth from optional API keys

Let custom endpoints work without a key instead of requiring a separate
no-auth switch. Preserve stored keys on blank edits and stage explicit
key removal until Save, including anonymous model discovery.

Cover credential transitions and localized setup paths while retaining
the existing host storage and runtime no-auth contracts.

* feat(chat): scope background tasks to their session and share one dock with todo (#1844)

* feat(chat): scope background tasks to their session and share one dock with todo

Background commands belonged to the host, not to the session that started them:
the list was global, the tab was global, and deleting a session left its servers
running. Todo and the task bar were also two stacked surfaces, so a running task
competed with the plan and ask rows for the same vertical space.

Tasks now carry a per-session concurrency limit of 10, refusals name that limit,
a process-wide ceiling stays only as a host safety net, and a spawn is rejected
when its session is already gone. Deleting a session signals its running tasks
through the existing per-session cleanup path; archiving does not, because
archiving is reversible. Both are covered by host tests.

The renderer keeps the wire contract session-agnostic and filters locally, so
switching sessions changes only what is displayed. Todo and tasks share one
container whose header carries the progress summary, the live count, the tab
list and the disclosure: collapsing hides only the panels, so tabs stay
reachable, and a newly started task raises a badge on its tab instead of
stealing the tab. Removal is a view action gated on a terminal state in the
state layer, so a running or still-settling task can never be dropped from the
list while its process lives.

* docs(chat): record the task-dock plan behind the shared container

The layout was settled by building it and clicking through it, so the reasoning
belongs with the change rather than in a chat log. The interactive prototypes
live outside the repository and are linked from the pull request.

The plan records the decisions that shaped the result and the ones rejected
along the way: why the per-session limit is 10 while a process-wide ceiling stays
behind it, why the wire contract keeps returning every task and the renderer
filters, why deletion signals stop while archiving does not, and why the header
became a row of siblings instead of one button.

* docs(chat): point the plan at the uploaded prototype

The prototypes are an uploaded artifact, not repository content, so the plan
must not describe a docs/demos tree that does not exist. It now links the single
chosen page and records which alternatives it beat and why: an inline tab list in
the header won because it is the only form that keeps the tabs reachable while
collapsed without introducing a second header state.

* fix(chat): expand the dock when a collapsed tab is clicked

The container advertised a behaviour it did not implement: clicking a tab
while collapsed only swapped the remembered tab, so the panel stayed
hidden and the click looked like it did nothing (D15). A tab click now
goes through selectTab, which writes the tab and the expansion together,
making the user's intent one operation instead of two that could disagree.

The badge rule also decided visibility with its own copy of the tab logic
and passed a hard 	rue for the todo side, so it could disagree with the
panel actually on screen. Both paths now call the same rule, and the hook
takes the todo side from the container that already reads it.

dock-state.ts had no direct tests, which is how the two defects survived.
It now has a suite covering the collapse-tab rule, the fallback for an
emptied side, and the badge/visibility agreement.

---------

Co-authored-by: v_wyxgwang <[email protected]>

* chore(release): v0.21.0-beta.8 (#1854)

* docs(changelog): note session-scoped tasks and the shared dock

The 0.21.0 catalog is the in-app whats-new source for the beta that ships
these two user-visible changes, so testers can read them without a network
fetch. English stays the source of truth and the other eight catalogs
carry the same two entries in the same position.

* chore(release): v0.21.0-beta.8

* fix(models): place saved-key clear icon beside the input

Keep credential controls on one row instead of spending another row on
key removal. Retain the localized tooltip, accessible name, and existing
staged credential-removal behavior.

Exercise the rendered icon geometry, target size, focus restoration,
and localized setup journeys.

* fix(transcript): continue restored reading ranges automatically (#1850)

Restored reading ranges should preserve their bookmark without leaving
readers behind a manual history paging control. Continue bounded pages
near the viewport boundary and rejoin live output only after the gap closes.

Keep explicit search paging isolated, preserve the viewport and model
input, and cover continuation, retries, and hidden-pane cleanup.

Co-authored-by: Lan <[email protected]>

* fix(provider): send reasoning_effort to official DeepSeek endpoints (#1849)

* fix(provider): send reasoning_effort to official DeepSeek endpoints

deepseekRequestCompat() forced supportsReasoningEffort off for every
DeepSeek-family Completions row so relays would stop rejecting the field
(#1701 / #1664). Official api.deepseek.com rows document reasoning_effort
next to thinking, so they only ever sent the thinking toggle and low,
high, and max all produced the same request — the selected level was
silently ignored (#1821).

Keep the suppression for non-official endpoints, where the field was
reported rejected, and leave official rows to pi-ai's URL detection. The
per-model supportsReasoningEffort selection added for #1846 still wins in
both directions, so a user can omit the field on an official row too.

Probed api.deepseek.com live with deepseek-flash and deepseek-v4-pro:
every level the runtime can send (low, medium, high, xhigh, max) returns
200 and the request body carries the selected value; off sends only
thinking: {type: "disabled"}. Recorded as D672 amending D389.

refs #1821

* chore(ci): rerun checks after a runner-side Electron E2E hang

The previous run failed only in the trusted-extensions Electron E2E at
scripts/e2e-provider-client-certificate.mjs: the mTLS fixture probe hung
and was killed by SIGKILL after 65s. The same job on main prints the same
"Electron 43 net.fetch failed before HTTP" baseline line and passes, so
the failure is runner-side rather than caused by this branch.

Rerun is not available to this account (workflow_dispatch and run rerun
both require repository admin rights), so this empty commit retriggers
the workflow without changing any content.

* fix(provider): match official DeepSeek hosts precisely

Substring matching can classify a relay as an official DeepSeek endpoint and disable the relay compatibility guard. Match parsed hostnames so only deepseek.com and its subdomains use the official endpoint behavior.

---------

Co-authored-by: Lan <[email protected]>
Co-authored-by: vastsa <[email protected]>

* fix(chat): 切回缓存会话时保留阅读页,修复误显示【加载后续消息】(#1851) (#1852)

* fix(chat): keep the returned reading page across session revalidation

Switching back to a retained session committed its cached page and then
replaced it with a bounded history read around the bookmark, because the
"bookmark already loaded" short-circuit was gated on selectingSessionId
not matching the target session. During a warm return that condition is
always false, so the 60-row window replaced the 100-row page and painted
the load-later affordance even though no newer row was missing, while
live turns arriving afterwards were not merged.

Publish the retained page as the reading range when it already holds the
bookmark, which keeps the anchor and the reader's offset across the
revalidation swap. Fall back to the bounded read only when the anchor is
outside the loaded page, as ADR 0137 intends.

fixes #1851

* fix(chat): preserve active transcript navigation

Automatic reading position restoration must not replace an explicit search or navigation that already owns the transcript view. Check focused or loading state before accepting a bookmark already present in the current page.

---------

Co-authored-by: vastsa <[email protected]>

* fix(transcript): make automatic folding deterministic

A pointer press or a nested disclosure toggle recorded every enclosing
level's current state as a permanent choice, so automatic folding stopped
applying for the rest of the pane's life and a reveal could pin a level
closed. Activity groups also folded as soon as they stopped owning the
live segment, hiding work mid-run and folding away reasoning the reader
had just asked to see.

Disclosure ownership is split in two: an explicit header or rail choice
stays local to its level, while focus or a selection holds a level and
its ancestors open only until the reader leaves. Group defaults now
follow the turn, and visible reasoning keeps its group open. The
activity issue counter becomes one inline chip instead of an unstyled
span that wrapped its icon and count in narrow bands.

* fix(composer): keep the task dock collapse across session switches

The Todo/background-task container stored its collapse inside the
per-session entry, so every session the user switched to started from
its own default and reopened a container they had just closed.

Move the collapse out of the per-session state: it is one container-wide
condition that survives session switches, while the tab choice and the
badge stay per session. The container now also starts collapsed, so the
composer keeps its room until the user opens it, and the state is no
longer pruned together with dead sessions.

* chore(release): v0.21.0

Promote the 0.21 preview line to a stable desktop release. Align all
workspace version surfaces, refresh the bundled model catalog, and
complete the shipped release notes in every supported locale.

* fix(agent-runtime): do not treat connection abort wording as user Stop (#1865)

A bare abort match classified socket and stream failures such as
"software caused connection abort" and "stream aborted" as
TURN_ABORTED. Those turns skipped provider retry and rendered as a
user Stop.

Message text is a cancellation only for the fixed runtime and
AbortError phrases. Connection-abort wording stays a retriable
NETWORK_ERROR, and stream-abort wording stays a retriable
STREAM_FAILED.

Co-authored-by: xpeng5278-web <[email protected]>

* fix(file-manager): theme editor search controls (#1861)

CodeMirror kept light control defaults while the dark file view inherited white text, making find and replace content invisible. Rebuild the vendored view with explicit theme surfaces, ship a bounded hotfix version, and cover the light/dark user path in Electron.

Co-authored-by: vastsa <[email protected]>

---------

Co-authored-by: liubai <[email protected]>
Co-authored-by: zszz3 <[email protected]>
Co-authored-by: blackEvil217 <[email protected]>
Co-authored-by: muzimu217 <[email protected]>
Co-authored-by: CJLY-0915 <[email protected]>
Co-authored-by: spacker-343 <[email protected]>
Co-authored-by: v_wyxgwang <[email protected]>
Co-authored-by: luoshang <luoshang@local>
Co-authored-by: Lan <[email protected]>
Co-authored-by: vastsa <[email protected]>
Co-authored-by: liuzixiang <[email protected]>
Co-authored-by: xieqiying <[email protected]>
Co-authored-by: Xuese <[email protected]>
Co-authored-by: TioitWang <[email protected]>
Co-authored-by: Seraph-x <[email protected]>
Co-authored-by: Tony <[email protected]>
Co-authored-by: new-Beginner <[email protected]>
Co-authored-by: xpeng5278-web <[email protected]>
Co-authored-by: xpeng5278-web <[email protected]>
Co-authored-by: Tony <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 对话内联可视化卡片(GenUI)

2 participants