Skip to content

[feat] canvas: group toolbar, group colors, and no more node locking - #415

Merged
princepride merged 5 commits into
mainfrom
feat/group-toolbar
Nov 21, 2026
Merged

princepride merged 5 commits into
mainfrom
feat/group-toolbar

Conversation

@princepride

@princepride princepride commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

选中分组后,分组上方显示一条专属工具栏:运行工作流、解除编组、布局、背景色、下载。右键菜单去掉了锁定和图层顺序这两类用户难以理解的功能。

动机。 以前选中分组只能看到重命名、复制、删除,右键菜单里却有锁定/解锁、移到顶层/上移一层/下移一层/移到底层,用户不清楚这些功能的用途。锁定后分组和子节点基本都操作不了,右键菜单也弹不出来。另外,右键里的"自动排列"只移动顶层节点,对分组成员不起作用。

改动。

  • 分组工具栏(NodeSelectionToolbar.tsx):节点类型为分组时显示以下按钮,原来的重命名、复制、删除仍保留在右键菜单里。
    • 运行工作流:运行组内(含嵌套分组)已配置模型、并且有提示词或参考输入的生成节点。调度逻辑在 groupWorkflow.ts:节点要等它引用的组内成员生成成功后才开始,没有依赖关系的节点同时运行;某个节点失败,其下游节点跳过;循环引用的节点也跳过。结束时提示成功、失败、跳过的数量。为此 prepareGeneration 改为返回已接受的 jobId,再通过 creationClient.listen 等待这些任务进入终态。
    • 解除编组:复用现有的 ungroupSelection。
    • 布局:网格、横向、纵向三种。新增的 layoutGroup 按当前阅读顺序排列分组的直接成员,并把分组缩放到刚好容纳它们。
    • 背景色:默认加 7 种预设颜色。
    • 下载:组内所有素材和文本打包成一个 ZIP(复用 createZip),只有一个文件时直接下载。
  • 分组颜色:前后端完整打通。
    • 后端:CanvasItemBase 新增可选字段 color(#RRGGBB),canvas.update 也接受该字段,传空字符串表示恢复默认;契约文件已重新生成。
    • 前端:CanvasNode.color 经 creationProjection 同步到后端;storage 增加校验;sameNode 比较时纳入颜色,否则只改颜色的修改会被当成无变化而不保存。
    • 渲染:通过 CSS 变量 --cw-group-fill 和 --cw-group-border 给分组着色。
  • 兼容历史记录:CanvasPresentationUpdate.color 未设置时不参与序列化。否则 "color": null 会改变所有历史 canvas.update 命令的指纹,读取历史时整个项目会被判定为"工程提交记录缺失或损坏"而无法读写。本地部署时实际遇到过这个问题,第二个提交修复并加了回归测试。
  • 移除锁定:右键菜单删掉锁定/解锁和四个图层顺序项。同一浏览器第一次打开项目时,已锁定的节点会按"父分组在前"的顺序自动解锁一次并保存,因为后端会拒绝修改祖先已锁定的节点。打开之后再通过 API 或 Agent 加的锁仍然按原逻辑生效。后端的 locked 字段和相关规则保持不变,本 PR 只移除界面入口并迁移已有数据。
  • 中英文文案同时提供。

Review 后的修复(第 4 个提交)

独立 review 后修复了以下问题:

  • 工作流
    • 下游节点会等到上游结果真正显示在画布上才开始。之前"文本 → 图片(空提示词,用文本当提示词)"这类链路里,下游会因为读到旧的空文本,在预检时就失败。
    • 依赖关系经过非生成节点(主体、堆叠等)中转时,也会被识别。
    • 提交改为逐个进行,并且每次都使用最新渲染里的函数,避免同时开始的节点互相覆盖本地配置,也避免用到点击那一刻的旧状态。项目的命令队列本来就是串行的,这不会增加等待时间。
    • 切换项目后,运行中的工作流会结束,不再一直挂起。
    • 不把只有空 promptContent 或只有编辑来源连线的节点当作可运行节点。
  • 锁定
    • 右键菜单平时不显示任何锁定项,只有选中节点确实处于锁定状态时才出现"解锁"。被 Agent 或 API 锁住、或者撤销了打开时的自动解锁之后,节点仍然能解开。
    • 打开时的自动解锁也覆盖打开时为空的项目。
    • 分组内有锁定成员时,布局不再移动它们(之前会导致后续自动保存全部失败)。
    • 因为其它原因被禁用的按钮,不再提示"请先解锁"。
  • 其它
    • 颜色菜单项改为 menuitemradio,并用 aria-checked 标出当前颜色。
    • ZIP 内的文件名去重不再区分大小写。

验证:

  • 前端 941 个单测通过;
  • 本地按 CI 方式跑 isolated 浏览器套件,25/25 通过;
  • 在本机部署上用无头浏览器验证:分组锁定时右键菜单出现"解锁",点击后服务端变为未锁定,菜单项随之消失。

尚未处理(后续可另开 PR):

  • 同时运行嵌套分组时,共享节点会被报告为失败;
  • ZIP 不包含堆叠成员;
  • 同时运行的节点数没有上限;
  • 工作流编排目前只在前端,Agent 不能调用。

第二轮 review 后的修复(第 5 个提交)

  • 下游节点只有在上游结果被服务端采用、并且已经显示在画布上时才会继续。上游结果没被采用(只作为候选,或运行期间输入被修改),或等待超过三分钟时,这一步按失败处理,不再空等 60 秒后用旧内容继续跑下游。
  • 工作区卸载时,等待任务和等待显示的轮询也会停止。
  • 颜色菜单项(menuitemradio)可以用键盘操作了(SelectionToolbarMenu 的焦点和方向键之前只认 menuitem)。
  • 旧数据里的锁,在同一个浏览器里每个项目只自动解锁一次(用 localStorage 标记),不再每次打开都解锁,这样 Agent 或 API 后来加的锁刷新页面后仍然有效。
  • 分组被锁定时,"运行工作流"和"解除编组"按钮会被禁用,之前是可以点但什么也不做。

验证:前端 941 个单测、tsc、isolated 浏览器套件 25/25 均通过。

Linked issue

  • 无对应 issue

Labels

  • Labels applied(type:feat、area:canvas)

Test plan

本地 worktree 基于 main(bf473614),Python 3.12、Node.js 24。

检查 命令 结果
前端单测 node --test tests/*.test.ts 941 passed。新增覆盖:layoutGroup 的横向/纵向/网格排列和分组尺寸;groupDescendants;工作流调度(无依赖节点并发、依赖顺序、失败后跳过下游、循环引用、步骤抛错);颜色变化算作内容变化,非法颜色被 parseDocument 拒绝
后端(creation / canvas / contract) python -m pytest tests -k "creation or canvas or contract" -q 764 passed
后端新增 tests/test_creation_canvas_service.py::test_group_color_is_set_reset_and_validated、test_canvas_update_without_color_keeps_its_historical_fingerprint passed:设置颜色、修改颜色、用空字符串恢复默认、拒绝非法颜色;未设颜色的 canvas.update 序列化结果与加字段前完全一致(去掉修复时该测试失败)。另用修复后的代码校验了本地一个有 500 条提交记录的真实项目,全部通过
类型检查 / 构建 tsc --noEmit、vite build 通过
静态检查 python -m pre_commit run --from-ref upstream/main --to-ref HEAD 通过
浏览器(isolated lane) 按 release-checks.yml 启动 creation_server.py 和 vite 后运行 node scripts/run-browser-suite.mjs 25/25 通过(timeline workflow 因本机 PATH 没有 python 而单独补跑,通过)。首次 CI 失败的 editor save 和 canvas text Markdown 依赖打开后再加的锁,第三个提交改为只在打开项目时解锁一次后均通过
  • Left to CI: Release checks 的 python、frontend、voice、assistant lanes。

Evidence that it works

在本机部署的实例上,用无头 Chromium 对一个临时项目做了验证(验证后已删除该项目):

  • 新建两个文本节点,⌘G 编组,选中分组后,上方出现「运行工作流 / 解除编组 / 布局 / 背景色 / 下载」工具栏。

  • 选择「布局 → 横向排列」后,两个成员并排,分组宽度随之变为 688px。

  • 选择「背景色 → 蓝色」后分组着色;刷新页面后颜色仍在,后端快照中 color == "#3e63dd"。

  • 右键分组,菜单里已没有锁定和图层顺序项。

  • 通过 API 把分组及两个子节点设为锁定后重新打开项目,三者都被自动解锁并写回(locked == false),右键菜单正常弹出。

  • 整个过程中页面没有 pageerror。

  • Media attached(截图稍后补充)

Provider verification

  • 没有真实 provider 调用。工作流调度只用模拟步骤做了单测,没有在真实模型上端到端运行过「运行工作流」。

Bilingual UI

  • 新增的 zh-CN 和 en-US 文案同时提供。

🤖 Generated with Claude Code

- Selecting a group shows its own toolbar above it: run workflow, ungroup,
  layout (grid / row / column, resizing the group to fit), background color,
  and download (all group assets as one ZIP).
- Run workflow generates the group's configured nodes in reference order:
  a node waits for the members it references, independent nodes run
  concurrently, and a failure skips its downstream nodes.
- Groups store an optional #rrggbb color (canvas item `color`; '' in
  canvas.update restores the default). Node equality includes the color so
  a color-only edit is saved.
- The context menu no longer offers lock/unlock or layer reordering. Nodes
  locked in older projects are unlocked on open, parents first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation type:feat New capability or behaviour labels Nov 20, 2026
princepride and others added 4 commits November 20, 2026 16:19
CanvasPresentationUpdate.color dumped as null when unset, which changed the
fingerprint of every canvas.update recorded before the field existed. History
validation then rejected those commits and blocked the whole project
("工程提交记录缺失或损坏"). An unset color is now omitted from the dump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clearing every lock whenever one appeared also cleared locks applied later
through the API or Agent, which the editor-save and text-card browser
journeys rely on. Locked nodes are now unlocked once, when the project
opens, as described in the PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Workflow
- A downstream step waits until the canvas shows its upstream result, so a
  step that uses generated text as its prompt no longer fails its precheck.
- Dependencies carried through non-step nodes (subject, stack) order steps.
- Submissions run one at a time through the latest render's entry point, so
  concurrent steps no longer overwrite each other's local configuration or
  use stale running state.
- A project switch ends a running workflow instead of leaving it pending.
- Reference-less prompt content and edit-provenance edges no longer make a
  node a step that will only fail.

Locks
- The context menu offers Unlock only when the selection is locked (by the
  Agent, the API, or an undo of the open-time unlock), so locks stay
  recoverable without exposing locking.
- The open-time unlock also covers projects that open empty.
- Group layout refuses to move locked members instead of failing autosave.
- Actions disabled for other reasons no longer say "unlock first".

Other: the color menu uses menuitemradio/aria-checked, and ZIP entry names
are de-duplicated case-insensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A downstream step continues only when the service adopted the upstream
  result and the canvas shows it; an unadopted (candidate-only or edited
  during the run) result or a three-minute stall fails the step instead of
  running downstream on stale content after a fixed wait.
- Job and display waits also stop when the workspace unmounts.
- Color menu items (menuitemradio) are reachable by keyboard again.
- Legacy locks are released once per project in this browser instead of on
  every open, so later Agent or API locks survive reloads.
- Run workflow and Ungroup are disabled on a locked group instead of doing
  nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@princepride
princepride merged commit 1ee7d9c into main Nov 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:canvas Canvas, nodes and direct manipulation type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant