Compare commits

...

53 Commits

Author SHA1 Message Date
suzmii d0b15dbc54 AGC 生成任务侧栏:收起也补上退场动画,退场期间内容不跳
Project CI / Frontend tests (pull_request) Waiting to run
Project CI / Repository checks (pull_request) Waiting to run
Project CI / AI game creator shell web tests (pull_request) Waiting to run
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m52s
Project CI / AI game creator shell Rust smoke (pull_request) Has started running
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 2m58s
Project CI / AI game creator shell Rust crates (pull_request) Has started running
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 2m59s
Project CI / Backend tests (pull_request) Has started running
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 3m2s
Project CI / Native shell tests (pull_request) Has started running
- 进场本来就有动画(`…-enter`),收起却是瞬间卸载,观感上"闪一下没了"。现在收起先播退场再卸载:`open` 变 false 后进入 `leaving`,根节点挂 `is-leaving` 播 `…-leave`(与进场同向反向,160ms,`pointer-events: none`),播完才卸载
- 时长在组件与 CSS 两处各写一次,组件导出 `RESOURCE_CANVAS_ASSET_GENERATION_TASKS_LEAVE_MILLIS` 并由用例钉住两处一致
- 减动效偏好下 CSS 已关掉动画,组件那边同步按 0ms 处理,收起立即卸载,不白等 160ms
- 退场期间沿用收起前那一份列表(`lastRenderedRef`):宿主会在同一帧里收起侧栏并把在途任务收口,直接吃新 props 会让退场动画里的内容跳一下;滚动区的空态分支也改读这份冻结快照,不能读实时 `ordered`(这是本批调试时用假时钟用例抓到的真问题)
- 用例:面板用例新增「收起时先播完收起动画再卸载,动画期间列表内容不跳」;样式用例新增「is-leaving 挂上收起动画、pointer-events: none、减动效同样关掉」;既有生成任务相关性用例改为等退场动画走完再断言(新增 `waitForTasksSidebarLeaveAnimationToFinish`)
- 文档:AGC 入口矩阵与 decision-log 同步退场动画口径

验证:tsc --noEmit 通过;appSurface 全量 441 条通过;侧栏面板 9 条、样式 10 条、开合与入口 3 条通过;变异验证:把早返回改回「立即卸载」与把 CSS 的 `is-leaving` 选择器写错,对应断言分别变红
2026-09-14 23:01:35 +08:00
suzmii 96971403ee AGC 资源画布:定位到素材后把视口居中到该卡
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m38s
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
- 根因:`handleResourceSelect` 只改选中、不移动画布,而这张画布是 transform 平移的、资源卡不在任何滚动容器里;既有的 `card.scrollIntoView()` 碰不到滚动祖先,卡在视口外时用户看到的就是「定位过去了但依然见不到素材」
- 新增 `centerResourceCanvasOnResource`:读该卡在当前布局位置表里的 x/y 与卡片尺寸,按 `canvasSize / 2 − 卡中心 × scale` 求视口平移量;缩放保持不变(定位不改用户缩放预期,与 `ensureResourceBookContentVisible` 同口径)
- 聚焦链在「选中新资源」那一步之后调用它;`scrollIntoView` 保留(栏目页仍有带滚动条的祖先)
- 用例:新增「centers the canvas viewport on the located asset so it is actually visible」,用渲染进 DOM 的真实画布尺寸断言 `viewportX + 卡中心 × scale = 画布中心`
- 文档:decision-log 补「失去焦点即收起」与「定位必须让素材真的可见」两条决策;AGC 入口矩阵同步自动收起、入口顺序与定位居中口径

验证:tsc --noEmit 通过;appSurface 全量 441 条通过;变异验证:把定位链里的居中调用摘掉,新用例变红(450 vs 400,正好是画布宽 800 的一半与旧视口之差)
2026-09-14 22:36:32 +08:00
suzmii 45ccc58969 AGC 生成任务侧栏:失去焦点自动收起、入口挪到排列方式之前
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m4s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 1m53s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 2m2s
Project CI / AI game creator shell Rust smoke (pull_request) Failing after 1m32s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 1m58s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m56s
Project CI / Repository checks (pull_request) Successful in 3m45s
Project CI / Frontend tests (pull_request) Successful in 4m12s
Project CI / Native shell tests (pull_request) Failing after 4m48s
Project CI / Backend tests (pull_request) Successful in 7m7s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m17s
- 侧栏展开时挂 document 级 pointerdown 捕获监听:点在侧栏内部与工具条那枚开合按钮以外的地方(画布、其他工具条按钮、对话框)即自动收起侧栏
- 排除开合按钮本身:它自己负责 toggle,若在「点外部」里也命中会先收起再被 toggle 打开,表现为按钮失灵
- 工具条「生成任务」入口加 data-resource-generation-task-toggle 标记,供上面的判定排除
- 「生成任务」入口从资源排列方式之后挪到之前:动作在前、排列方式(依赖 / 类型)收在行尾;入口抽成可复用元素,资源页签与运行页签各渲染一次,同一时刻只渲染一处
- 新增 tests/resourceCanvasGenerationTasksSidebarDismiss.test.tsx:点外部收起、点内部与开合按钮不收起且仍能 toggle、入口排在依赖/类型之前

验证:tsc --noEmit 通过;vitest(新用例 3 条 + 生成任务侧栏 8 条 + 侧栏样式 9 条 + 画布手动布局 9 条)通过;变异验证:关掉自动收起 effect 与把入口挪回排列方式之后,对应断言分别变红
2026-09-14 22:29:16 +08:00
suzmii 9e709ce727 AGC 资源工作台交互收口:补充改动前三处截图对照图
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 2m1s
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m7s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 2m19s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m18s
Project CI / Repository checks (pull_request) Successful in 3m30s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 2m16s
Project CI / AI game creator shell Rust smoke (pull_request) Failing after 2m2s
Project CI / Native shell tests (pull_request) Failing after 4m28s
Project CI / Frontend tests (pull_request) Successful in 4m13s
Project CI / Backend tests (pull_request) Successful in 7m9s
Project CI / AI game creator shell web tests (pull_request) Successful in 2m59s
- 新增 docs/technical/assets/agc-resource-workbench-ui-before-20260914/:任务侧栏两个关闭入口、左侧贴边折叠把手、顶部播放按钮居中悬浮三张改动前截图
- 新增该目录 README,逐图说明改动前的问题与同步过的文档口径,供 PR 与后续回归对照
2026-09-14 22:02:54 +08:00
suzmii 96ae3db1df AGC 资源工作台三处交互收口:侧栏关闭入口合并、删除折叠把手、播放左对齐
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m14s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 2m9s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 2m53s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 2m46s
Project CI / AI game creator shell Rust smoke (pull_request) Failing after 1m53s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m5s
Project CI / Frontend tests (pull_request) Successful in 4m28s
Project CI / Native shell tests (pull_request) Failing after 4m57s
Project CI / Repository checks (pull_request) Successful in 3m30s
Project CI / Backend tests (pull_request) Successful in 7m19s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m21s
- 「生成任务」侧栏头部右上角由返回箭头(ChevronLeft / aria-label=收起生成任务)改为关闭 X,并与底部那枚重复的 X 统一为同一个 aria-label=关闭生成任务
- 删除「生成任务」侧栏底部 footer(关闭按钮 + border-top 分割线):关闭入口只留头部一枚
- 删除「生成任务」侧栏折叠态的左侧贴边竖排把手(handle 及其标签 / 在途角标 / 进场动画 / 悬停位移):折叠后组件不再渲染任何常驻入口
- 清理上述删除留下的悬空样式:focus-visible 分组选择器、480px 窄屏媒体查询与 prefers-reduced-motion 块里的把手分支
- 工具条「生成任务」入口移出 `mode === 'resources'` 分支:两个页签下都常驻。侧栏本体本来就是无条件渲染的浮层,运行态可见;入口只留资源页签时,切到运行关掉侧栏就再也打不开(此前靠左侧贴边把手兼作运行态入口)
- 工具条把「播放」移到「资源管理 / 运行」右侧并左对齐:新增 .game-workbench-view-tabs 作为左侧控件组,播放按钮由 absolute + left:50% + translateX(-50%) 的居中悬浮改为 static;相应删除 max-width:1000px 里的居中兜底规则
- 播放按钮并进按钮基础外观与 focus-visible 规则列表:新位置不再命中 .game-workbench-tabs / .game-workbench-view-actions 的选择器,漏掉会掉成零圆角、零内边距、无边框、默认字号的裸按钮(颜色规则仍生效,肉眼容易漏)
- 播放按钮保持两个页签下都常驻(回到改动前的可见性):运行视图空态与预览失败态要靠它重跑
- 同步更新断言:侧栏关闭入口唯一且 footer 不存在、折叠态不渲染任何按钮或把手、样式表不残留被删类名、播放按钮声明为左对齐静态定位且仍在基础外观/焦点环规则内
- 生成任务用例补回机器证据:折叠后工具条按钮的 data-resource-generation-task-count 归零、重开后头部「在途生成任务 0」徽标跟上收口结果、运行页签下侧栏仍能重开(先用 aria-selected 钉住真的切了页签);用例夹具新增 runnable 开关把首个原型标成完成
- 同步文档现状:PRD 顶部播放按钮与任务侧栏进度面两条、AGC 栏目画布底部工具栏入口矩阵的侧栏形态、decision-log 的进度面形态决策

验证:tsc -p apps/ai-game-creator-shell/tsconfig.json --noEmit 通过;vitest appSurface 全量 440 条通过、生成任务侧栏 8 条与侧栏样式 9 条通过;check-encoding 通过;prettier --list-different 未新增命中(project-development/index.tsx 属基线既有非格式化文件);变异验证:还原播放按钮基础外观规则、还原折叠把手与 footer、还原折叠态早返回、把「生成任务」入口退回 mode 分支,对应断言均变红
2026-09-14 22:00:06 +08:00
kdletters 1877aea33c 修复 Windows verbatim AppData 路径权限识别
Project CI / AI game creator shell Rust shard 1/4 (push) Failing after 2m2s
Project CI / AI game creator shell Rust shard 2/4 (push) Failing after 2m15s
Project CI / AI game creator shell Rust shard 3/4 (push) Failing after 2m13s
Project CI / AI game creator shell Rust shard 4/4 (push) Failing after 2m13s
Project CI / AI game creator shell Rust smoke (push) Failing after 1m44s
Project CI / AI game creator shell Rust crates (push) Successful in 2m58s
Project CI / Native shell tests (push) Failing after 4m10s
Project CI / Frontend tests (push) Successful in 4m10s
Project CI / Repository checks (push) Successful in 3m4s
Project CI / AI game creator shell web tests (push) Successful in 2m32s
Project CI / Backend tests (push) Successful in 6m55s
归一化 \\?\ 与 \\?\UNC\ 路径后再判断受管 ACL scope

补充 verbatim AppData 回归测试
2026-09-14 21:04:01 +08:00
kdletters 2bdee990a2 AGC 开发态补齐后台 Web 启动与端口汇总,端口归属探测从 WMI 换成 netstat
- dev-port.mjs 新增 resolveAgcAdminWebEndpoint:后台 Web 端口按 Linux 用户端口段 start + 3、非 Linux 优先 3102 解析,ADMIN_WEB_PORT 可显式指定,并把已解析的 AGC Vite 端口列为保留端口
- start-dev-stack.mjs 随 AGC 一起拉起 apps/admin-web(AGC_DEV_ADMIN_WEB=0 关闭):与 AGC Vite 一样由启动器直接持有并纳入信号与退出收束,不走会整体重写 .app/dev-stack.json 的 dev:admin-web
- start-dev-stack.mjs 新增启动汇总行,一次给出前端、后端、后台、数据库与 bgfilter-worker 的实际地址,端口漂移后以该行为准
- start-dev-stack.mjs 端口归属探测改用 netstat -ano 取端口到 PID、.NET Process 读可执行文件路径,仅在核对 SpacetimeDB --data-dir 归属时按 PID 取命令行并做 5 分钟 TTL 缓存:本机实测单轮探测由约 43 秒降到 0.37 秒,agc:serve 的 starting backend stack 到 backend ready 由约 80 秒降到 16.7 秒
- 后台 Web 端口解析或启动失败只告警,不阻断也不连带停止 AGC 客户端与配套后端
- tests/dev-port.test.ts、tests/start-dev-stack.test.ts 补充用例覆盖后台 Web 端口解析与严格占用、失败软化、启动汇总、netstat 探测脚本与命令行缓存失效
- docs/【开发运维】与 docs/technical 同步 AGC 开发态启动口径,pitfalls.md 记录 WMI 慢速探测的实测数据、netstat 改法与 PID 取最后一列的易错点
2026-09-14 21:02:08 +08:00
suzmii 330e4d6c5b Merge pull request 'AGC 画布:生成期间可退出与任务侧栏(高优)、画布手动整理、透明底判据、素材类型独立入口' (#358) from fix/agc-canvas-acceptance-batch into master
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 4m41s
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 4m38s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m34s
Project CI / AI game creator shell Rust shard 3/4 (push) Successful in 4m25s
Project CI / AI game creator shell Rust shard 4/4 (push) Successful in 4m34s
Project CI / AI game creator shell Rust crates (push) Successful in 2m30s
Project CI / Frontend tests (push) Successful in 4m9s
Project CI / Repository checks (push) Successful in 3m15s
Project CI / Backend tests (push) Successful in 6m49s
Project CI / Native shell tests (push) Successful in 6m28s
Project CI / AI game creator shell web tests (push) Successful in 3m15s
2026-09-14 20:31:21 +08:00
suzmii aeac6c7b74 合并 origin/master(279a5e8e0,#356 UI 编辑器返回后资源画布平移)到验收批次
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Successful in 4m55s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m32s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Successful in 4m43s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Successful in 4m38s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Successful in 4m15s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m3s
Project CI / Frontend tests (pull_request) Successful in 3m56s
Project CI / Repository checks (pull_request) Successful in 3m28s
Project CI / Native shell tests (pull_request) Successful in 6m19s
Project CI / Backend tests (pull_request) Successful in 7m32s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m0s
- 合并最新 master,使 PR #358 的头包含当前 master 顶端(CI 门禁要求)
- 冲突按「两侧语义都保住」解:
  - docs/project-memory/shared-memory/pitfalls.md:保留我方新增的「严格 IPC 桩缺登记新命令」
    与上游新增的「UI 编辑器返回后资源画布滚轮平移失效」两条,只删除冲突标记行
  - index.tsx / tests/appSurface/harness.ts / project-development.suite.ts:保留本批生成任务与
    资源画布改动,同时并入上游的资源画布平移回归用例与共享 ResizeObserver 桩
- 工作树里另有 5 个版本号改动(package.json / Cargo.toml / Cargo.lock / tauri.conf.json /
  package-lock.json,0.1.29 → 0.1.34)属发布动作,**本次刻意未提交**,原样留在工作树
2026-09-14 20:27:05 +08:00
k88936 279a5e8e0e Merge pull request '修复 UI 编辑器返回后资源画布平移' (#356) from fix/cant-pan-after-ui-editor into master
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 4m53s
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 4m26s
Project CI / AI game creator shell Rust shard 3/4 (push) Successful in 4m27s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m37s
Project CI / AI game creator shell Rust shard 4/4 (push) Successful in 3m59s
Project CI / AI game creator shell Rust crates (push) Successful in 2m10s
Project CI / Repository checks (push) Successful in 3m5s
Project CI / Frontend tests (push) Successful in 4m3s
Project CI / Backend tests (push) Successful in 7m8s
Project CI / Native shell tests (push) Successful in 6m37s
Project CI / AI game creator shell web tests (push) Successful in 3m23s
Reviewed-on: #356
Reviewed-by: 孔令弘 <ink29535@proton.me>
2026-09-14 20:13:28 +08:00
suzmii 2292ae1fc1 Merge branch 'master' into fix/agc-canvas-acceptance-batch
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Successful in 4m48s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m35s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Successful in 4m29s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Successful in 4m25s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Successful in 4m33s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 3m8s
Project CI / Frontend tests (pull_request) Successful in 4m30s
Project CI / Repository checks (pull_request) Successful in 3m2s
Project CI / Backend tests (pull_request) Successful in 6m51s
Project CI / Native shell tests (pull_request) Successful in 6m28s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m2s
2026-09-14 19:59:44 +08:00
lhk229 a5dfa322cb Merge branch 'master' into fix/cant-pan-after-ui-editor
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Successful in 5m12s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Successful in 5m18s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Successful in 5m22s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Successful in 5m23s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m39s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 3m21s
Project CI / Frontend tests (pull_request) Successful in 4m18s
Project CI / Native shell tests (pull_request) Successful in 6m7s
Project CI / Repository checks (pull_request) Successful in 3m1s
Project CI / Backend tests (pull_request) Successful in 7m41s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m4s
2026-09-14 19:56:40 +08:00
suzmii b077cb5277 更正 decision-log:「整理画布」最终位置固定在「生成素材」之后、「管理未完成编辑」之前(不在行尾)
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
2026-09-14 19:30:02 +08:00
suzmii 8ad0487b8d 合并 fix/agc-resource-layout-manual:「整理画布」移入资源动作簇(离开行尾)
- 冲突解在 index.tsx 工具条动作区:两侧都要在同一位置插入按钮(WS1 的「生成任务」入口 +
  WS2 把「整理画布」从行尾移到「生成素材」之后),按「两侧语义都保住」解——
  「整理画布」在前(紧邻「生成素材」,满足其 previousElementSibling 断言与「不是行尾」断言),
  「生成任务」紧随其后,共用同一个闭合标签;行尾那份旧「整理画布」由 WS2 的删除 hunk 干净应用
- 已核对:ria-label="整理画布" 与 ria-label="生成任务" 在文件中各恰好一处
- 合并后实测:gc:typecheck 通过;resourceCanvasManualLayout 9 + appSurface 439 = 448 passed
2026-09-14 19:29:51 +08:00
suzmii 417b5ec630 「整理画布」移入资源动作簇:排在「生成素材」之后,不再挂在这一行行尾
- index.tsx:把「整理画布」从 game-workbench-view-actions 行尾(排序 tab 之后)
  移到「生成素材」之后、「管理未完成编辑」之前,与其它资源动作同类相邻,
  标签仍为 aria-label=\"整理画布\",零 CSS 改动
- index.tsx:语义与行为一字未改——disabled={!resourceLayoutReady}、
  aria-busy={resourceLayoutSaving}、onClick 仍调 activeResourceLayout.rederiveNow(),
  反馈仍走既有 resourceLayoutNotice / resourceLayoutSaving,changed 门保留
- resourceCanvasManualLayout.test.tsx:位置断言改为钉新位置——该行最后一个按钮不是它、
  它在「生成素材」之后(previousElementSibling)、在排序组左侧;
  继续保留「资源排列方式」组内只有「按依赖 / 按类型」与本按钮不在该组 /
  不在 .game-resource-sort-tabs 内的断言
2026-09-14 19:25:21 +08:00
k88936 174b6dd347 抽取共享 ResizeObserver 测试桩
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Successful in 4m59s
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
让项目开发测试复用统一 observer 安装 helper

保留 observer 创建与断开计数断言
2026-09-14 19:24:23 +08:00
suzmii 5adc16fbda Merge branch 'feat/agc-generation-task-progress' into fix/agc-canvas-acceptance-batch 2026-09-14 19:16:16 +08:00
suzmii 6c98c19c12 更正 decision-log:「整理画布」是资源工具条动作区里的独立动作按钮,不在「资源排列方式」分组内 2026-09-14 19:11:33 +08:00
lhk229 a7c40da6cf 修复自动切分问题节点恢复与临时文件清理
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Successful in 5m3s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Successful in 4m46s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Successful in 4m46s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Successful in 4m4s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m33s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m3s
Project CI / Frontend tests (pull_request) Successful in 4m13s
Project CI / Repository checks (pull_request) Successful in 3m26s
Project CI / Native shell tests (pull_request) Successful in 6m30s
Project CI / Backend tests (pull_request) Successful in 7m27s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m14s
Project CI / AI game creator shell Rust shard 1/4 (push) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (push) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (push) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (push) Has been cancelled
Project CI / AI game creator shell Rust smoke (push) Has been cancelled
Project CI / AI game creator shell Rust crates (push) Has been cancelled
Project CI / Backend tests (push) Has been cancelled
Project CI / Native shell tests (push) Has been cancelled
Project CI / Frontend tests (push) Has been cancelled
Project CI / Repository checks (push) Has been cancelled
Project CI / AI game creator shell web tests (push) Has been cancelled
将 problematic_nodes 纳入失败判定并保留恢复状态
清理完成或放弃流程产生的 processed 和 binding 临时文件
2026-09-14 19:11:27 +08:00
suzmii 41c59a37a0 style(agc): 「生成任务」侧栏做视觉与信息层级收口(行为与语义一个不动)
- 新增 `resourceCanvasAssetGenerationTasksSidebar.css`:侧栏样式独立成文件,取值全部走平台设计 token
  (`--platform-subpanel-fill/-border`、`--platform-panel-shadow`、`--platform-text-muted`、`--platform-line-soft`、
  `--platform-neutral-*`、`--platform-accent`、`--platform-success-*`、`--platform-button-danger-*`、
  `--platform-input-focus-ring`),不硬编码任何颜色,也不新增第二套色板
- 条目卡片化:素材名为主信息(加粗、单行省略)、阶段文案为次要信息(muted、小一号)、
  已耗时 `font-variant-numeric: tabular-nums` + 右对齐(秒数跳动不抖)、失败原因 `overflow-wrap: anywhere`
  折行不截断、「定位到素材」轻量下划线按钮 + hover 换色
- 状态徽标成体系:`data-tone` 四档——排队中 `--platform-neutral-*`(中性)、生成中 `--platform-accent`
  (品牌色 + 呼吸感圆点,**不做百分比**)、已完成 `--platform-success-*`、失败 `--platform-button-danger-*`;
  tone 映射提到模型层 `resourceCanvasAssetGenerationTaskTone`(组件只导出组件与常量,保住 react-refresh 边界)
- 分栏标题小字 + 条数胶囊,两栏之间用 `--platform-line-soft` 分隔;空态只给一句简短文案
- 侧栏容器圆角 + 边框 + `--platform-panel-shadow` + `backdrop-filter: blur(10px)`;展开/折叠各有进场动画
  (位移 + 淡入,不做宽度 reflow 抖动);折叠把手是竖向标签 + 在途数量胶囊;列表滚动条细样式
- 无障碍与降级:`:focus-visible` 用 `--platform-accent` 焦点环 + `--platform-input-focus-ring`;
  `@media (prefers-reduced-motion: reduce)` 关掉全部 animation / transition 与 hover 位移;
  `@media (max-width: 480px)` 下侧栏撑满可用宽度、把手收窄,不挡画布操作
- 测试:新增 `resourceCanvasAssetGenerationTasksSidebarStyle.test.ts`(用仓库既有 `tests/styleCascade.ts`
  按真实层叠断言:四档 tone 互不相同且只引平台 token、tabular-nums + 右对齐、卡片圆角与 hover、
  过渡与把手、细滚动条、360px 降级、reduced-motion 关动效、焦点环);
  侧栏行为用例补「四种状态各自输出对应 data-tone」,并把原先断言 Tailwind 类名的部分交还给样式用例
- 未改任何行为:分栏、条数、已完成封顶 20、折叠不清列表、提交后自动展开、入口在途计数、
  定位终局化、非模态(无遮罩 / 无焦点陷阱 / 不进模态遮挡判据)全部保持原样
2026-09-14 19:11:21 +08:00
suzmii a6de1b5570 Merge remote-tracking branch 'origin/master' into fix/agc-canvas-acceptance-batch 2026-09-14 19:07:46 +08:00
suzmii 444bf9bc24 Merge branch 'fix/agc-resource-layout-manual' into fix/agc-canvas-acceptance-batch 2026-09-14 19:07:45 +08:00
suzmii 21c85c4dd1 「整理画布」移出「资源排列方式」分组,成为独立动作按钮
- index.tsx:把「整理画布」从 aria-label=\"资源排列方式\" 的 role=group 里搬出来,
  紧跟排序 tab 之后、作为 game-workbench-view-actions 动作区里的独立按钮,
  外观直接复用该容器既有动作按钮样式(有边圆角 + secondary 填充),不新增 CSS
- index.tsx:语义与行为一字未改——aria-label=\"整理画布\"、disabled={!resourceLayoutReady}、
  aria-busy={resourceLayoutSaving}、onClick 仍调 activeResourceLayout.rederiveNow(),
  成功/失败反馈仍复用既有 resourceLayoutNotice / resourceLayoutSaving,changed 门保留
- resourceCanvasManualLayout.test.tsx:新增结构断言——「资源排列方式」分组里只有
  「按依赖 / 按类型」两枚按钮、「整理画布」不在该容器内也不在 .game-resource-sort-tabs 里,
  同时仍是动作区内可用按钮(布局就绪后不再 disabled)
2026-09-14 19:07:22 +08:00
k88936 a0b5a84d61 Merge branch 'master' into fix/cant-pan-after-ui-editor
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Has been cancelled
2026-09-14 19:00:47 +08:00
k88936 a8aacb27bd 修正资源画布回归测试 IPC 桩
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
使用 manifest projectId 匹配真实布局读取契约

补充初始化布局更新命令回执
2026-09-14 18:53:52 +08:00
suzmii a45172e055 同步文档:生成进度面收敛为常驻可折叠侧栏、提交即关面板、定位终局化、类型选项纵向列表
- PRD §3.10:进度面由「非模态浮层」改为「常驻画布的可折叠任务侧栏」(折叠把手带在途计数、两个分栏、已完成封顶 20、左侧覆盖式、提交后自动展开);定位动作终局化(跨栏目先切栏目 / 不在投影给结论 / 3 秒有界兜底)
- PRD §3.10 面板形态:改为「点「生成」即同步关闭面板、面板内不出现阶段文案;只有点击瞬间失败才带草稿重开;受理后失败只在侧栏收口」
- 栏目画布入口矩阵 §4/§4a:同步上述两条,并把 4a 标题由「「生成任务」面板」改为「「生成任务」侧栏」
- decision-log:新增 2026-09-14 条目(进度面收敛为常驻可折叠侧栏 + 提交即关面板 + 定位终局化,含位置取舍与覆盖式理由、五条变异证据);并在「素材类型」条目补记选项形态修订(纵向单选列表、radio 语义、方向键只移焦点、行列与滚动口径、建议后续抽 PlatformRadioList)
2026-09-14 18:50:48 +08:00
suzmii e6d92b2d98 Merge branch 'feat/agc-generation-task-progress' into fix/agc-canvas-acceptance-batch 2026-09-14 18:50:00 +08:00
suzmii ec02c39a5d feat(agc): 「生成任务」改造成常驻画布的可折叠侧栏(分栏 / 计数 / 自动展开 / 折叠不影响任务)
- ResourceCanvasAssetGenerationTasksPanelView 由非模态浮层改造成任务侧栏:展开时是贴边
  `<aside>`(`role="region"`、`aria-label="生成任务"`、不铺遮罩、不做焦点陷阱、不进模态遮挡判据),
  折叠时只留一个可点的贴边把手(`aria-label="展开生成任务"`)并带在途数量角标
- 位置取舍:右侧是「智能创作」对话面板、底部是栏目工具栏、顶部是栏目标题栏,所以挂在**左侧、标题栏
  之下、工具栏之上**(`top-16 / bottom-24 / left-3 / w-[300px]`)且是**覆盖式**而不是把画布挤窄——
  画布视口数学与资源卡排布都不被 reflow 动到,收起即完全让出画布;不再保留原来的浮层形态,没有平行入口
- 两个分栏:「排队/生成中」与「已完成」各带条数,只做客户端分组;「已完成」条数封顶 20 条(超出给出
  还剩多少条的说明),列表自身 `overflow-y-auto`,侧栏高度有界
- 入口按钮常驻可见并显示在途数量(`生成任务 · N`,无在途时仍是「生成任务」,`aria-label="生成任务"` 保留),
  把手上的角标同步;提交受理后侧栏自动展开(对齐网页端排队提交后主动弹任务栏)
- index.tsx:新增在途数量派生;侧栏常驻渲染并受同一个开合开关控制,折叠只影响这个视图,
  任务本身仍活在账本与本地队列里
- 测试:任务侧栏用例改为侧栏形态并补「两个分栏 + 条数」「高度有界 + 列表滚动 + 已完成封顶 20」
  「折叠后把手带上在途计数(0 / 2)」;AppSurface 补「提交后自动展开」「折叠期间任务照常推进、
  在途计数归零、再展开仍能看到结果」
2026-09-14 18:49:22 +08:00
suzmii 14a0286f70 fix(agc): 生成面板点击即关闭、面板内不再出现阶段文案,只有即时失败才把草稿带回来
- ResourceCanvasAssetGenerationPanelView:删掉 `phaseDetail` 通道与整套在途状态(`submitting` /
  禁用输入 / 「后台运行并关闭」),主按钮文案恒为动作名;提交时**同步**调用 onSubmit 并 onClose,
  面板不等 IPC、不等排队、不等生成。新增 `draft` / `error` 两个入参:只有「后端从未受理」的即时
  失败重开时,宿主才把草稿与原因带回来(`role="alert"` 可见、改完即可重试)
- index.tsx:`submitResourceAssetGeneration` 改为同步返回(不再 await 终局),记录本次提交上下文
  (taskId / action / 草稿 / 是否本来就该立刻派发),提交后自动开任务面板并给一次提示条;
  收尾回调里区分两类失败:`record === null` 且本来就该立刻派发 → 重开提交面板并带回草稿;
  受理之后才失败 → 不重开面板,只在任务面板收口为失败 + 提示条
- index.tsx:删掉只为旧「在途阶段文案」服务的 `resourceAssetGenerationPanelTaskIdRef` 与成功后的
  自动收面板逻辑(面板此时已关闭)
- 测试:`resourceCanvasAssetGenerationBackgroundClose.test.tsx` 的图片类用例改写为「点击即关闭 +
  面板 DOM 里从不出现 排队中。/正在生成。/提交中…」+「即时失败重开带回草稿与原因」;音频面板用例不变
- 测试:`resourceCanvasBottomToolbar.test.tsx` 的失败重试用例按新语义改写(点击即关闭、重开时显示原因)
- 测试:AppSurface 新增三条(同步关闭且面板无阶段文案、后端未受理时重开并保留草稿、受理后失败不重开
  只在任务面板收口),并把既有生成任务 e2e 的提交步骤改为「点击即关闭」
- 顺带按仓库规范修正以上文件的 eslint import sort 与 prettier 格式(未触碰无关文件)
2026-09-14 18:35:11 +08:00
k88936 c485ce94a1 修复 UI 编辑器返回后资源画布平移
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Has been cancelled
Project CI / AI game creator shell Rust smoke (pull_request) Has been cancelled
Project CI / AI game creator shell Rust crates (pull_request) Has been cancelled
Project CI / Backend tests (pull_request) Has been cancelled
Project CI / Native shell tests (pull_request) Has been cancelled
Project CI / Frontend tests (pull_request) Has been cancelled
Project CI / Repository checks (pull_request) Has been cancelled
Project CI / AI game creator shell web tests (pull_request) Has been cancelled
资源管理卸载重挂时重新绑定画布 wheel 监听

补充 UI 编辑器返回后的资源画布平移回归用例

记录资源画布事件监听重挂排障经验
2026-09-14 18:30:33 +08:00
suzmii 2f47540eeb fix(agc): 「定位到素材」每次点击都终局化,不再卡在「正在定位生成的素材…」
- index.tsx 新增 `resourceAssetGenerationFocusRequest` 序号并加进聚焦 effect 的依赖:手动点定位不改画布
  任何状态,原依赖一个都不变 → effect 不重跑、intent 永远没人消费,这正是「点了没反应 + 提示条永久
  停在中转文案」的根因
- index.tsx `focusResourceAssetGenerationTask` 重写:先按当前投影与清单判一次目标——不在投影里就当场给
  结论(素材已不在项目里 / 已登记但尚未同步),不挂 intent 也不留中转提示;在别的栏目先切栏目再定位;
  挂 intent 后推进聚焦请求序号,并起一个 3 秒有界兜底:仍停在中转文案就收口成可执行提示,intent 被判
  invalid 被静默清掉时也给一条「定位请求已失效」的结论,绝不留下悬而未决的状态
- index.tsx 聚焦 effect 的 `focusedCommitIdsRef` 提前返回分支补 `setResourceWorkbenchNotice('')`:
  已聚焦过时把中转提示一并收掉,不再永久留在提示条上(自动落卡那条链同源问题)
- index.tsx `resourceAssetGenerationContextRef` 扩到带 `manifest` / `resources` / `activePageCategory`
  并在每次渲染刷新:定位回调据此取权威目标与栏目,不再依赖可能过期的闭包值
- 新增 4 条 AppSurface 用例(同栏目直点定位并选中卡片、素材在另一个栏目先切栏目再定位、被搜索挡住时给出
  既有「清除搜索并定位」、素材不在项目里时给明确结论且清掉中转提示)
2026-09-14 18:20:50 +08:00
suzmii a2b016bb9b Merge branch 'feat/agc-generation-task-progress' into fix/agc-canvas-acceptance-batch 2026-09-14 18:18:45 +08:00
suzmii b898590c7d 合并 feat/agc-resource-type-entry:类型选项改纵向单选列表
- 合并 WS4 追加修复(928a0ea13:类型选项由横排 PlatformSegmentedTabs 改为 role=radiogroup 纵向单选列表,
  复用共享 PlatformNavigableListItem,列表有界独立滚动,rogiving tabindex + 方向键移焦点、Enter 落盘)
- 同时并入 origin/master a70ef2d6e(PR #354 Windows sccache / CI 分片改「一片一 job」)
- decision-log.md / pitfalls.md 冲突按「上游改写优先、我方新增保留」解:
  保留我方新增的「放开手工图片生成本地并发」「素材类型独立入口」「退役同步命令」三条与
  「严格 IPC 桩缺登记新命令」一条;AGC 壳 Rust 套件条目采用上游改写后的新标题(「一片一 job」),
  删掉被它取代的旧标题(旧正文早已被上游替换),不留自相矛盾的两条
2026-09-14 18:18:30 +08:00
suzmii 4e277798b8 Merge remote-tracking branch 'origin/master' into feat/agc-resource-type-entry 2026-09-14 18:17:10 +08:00
suzmii 928a0ea13e 素材类型选项改成纵向单选列表,不再横排成一条
- ResourceTypePanel:选项区从 PlatformSegmentedTabs(3~6 列网格,6 项正好挤成一行)换成纵向单选列表,复用共享的 PlatformNavigableListItem 作行骨架
- ResourceTypePanel:容器改为 role="radiogroup" + aria-label,每项 role="radio" + aria-checked,选中态与读屏读的是同一个属性
- ResourceTypePanel:roving tabindex(只有选中项 tabIndex=0)与方向键在选项间移动焦点,走到头不越界;方向键不顺手选中,Enter/Space 才落盘(选中=一次 CAS 写盘,浏览选项不该连环写盘)
- ResourceTypePanel:选中行额外渲染勾选图标作为第二视觉线索,图标 aria-hidden 不污染可读名字
- resourceTypePanel.css:选项容器改成单列网格(grid-template-columns: minmax(0, 1fr) + grid-auto-flow: row + align-content: start),一行一个选项
- resourceTypePanel.css:选项行补 width/min-width/min-height: 44px 与 overflow-wrap,移动端热区与窄屏换行都不依赖共享件的工具类
- resourceTypePanel.css:选中态由 [aria-checked='true'] 驱动并显式提权到 (0,3,0) 以上(含覆盖 :hover:not(:disabled)),避免被共享列表行的悬停底色顶掉
- resourceTypePanel.css:滚动从 body 挪到选项列表(列表现有 max-height: min(320px, 40dvh) + overflow-y: auto),body 改为 auto/minmax(0,1fr)/auto 三段,标题、素材名与错误提示不跟着滚
- 测试:新增「选项区是纵向单列列表」用例,按 styleCascade 解析真实生效声明(360/390/1440 三档宽度都是单列、行满宽、热区 44px),并断言 6 项都是 radiogroup 的直接子元素
- 测试:新增「单选语义与键盘」用例(radiogroup/radio + aria-checked + roving tabindex,方向键只移焦点不落盘,Enter 才写盘)
- 测试:新增「选中态由 aria-checked 驱动并压过共享列表行悬停底色」用例
- 测试:把「面板有高度上界且中间行可滚动」改成「选项区有上界并独立滚动,标题与错误提示不滚」
- 测试:集成用例的类型选项查询从 button/aria-pressed 改为 radio/aria-checked
2026-09-14 18:16:56 +08:00
suzmii cdc0e3d163 fix(agc): 生成任务读门禁用合法 command id、中断任务按清单核对不谎报未完成,并同步注释事实
- asset_generation_tasks.rs:`list_local_project_asset_generations` 的读门禁 command id 由 `asset.read`
  改为契约里真实存在的 `asset.list`(`asset.read` 不在命令表里,写进 `denied_commands` 也不可能命中
  → 原门禁恒不生效);补用例把 `asset.list` 放进项目策略 `denied_commands` 后读账本必须被拒
- asset_generation_tasks.rs:中断任务收口改为与 manifest 交叉核对(新增账本字段 `output_path`,serde 默认值
  兼容旧账本):能找到本次请求的精确落点 → 按事实收口为已完成并带上 assetId;落点存在但清单里没有
  → 报「目标素材未登记,生成未完成」;没有精确落点或清单读不到 → 只报「状态未知(可能已完成)」,不再
  对「素材已登记、账本还停在 running」的窗口谎报「生成未完成」
- asset_generation_tasks.rs:补四条用例(已登记→已完成、未登记→未完成、无落点→状态未知、读门禁可拒绝),
  并把既有的两条中断用例按新语义改为断言「状态未知」
- resourceCanvasBottomToolbarModel.ts:两处注释的入口命令名改为 `start_local_project_asset_generation`
- check-config.mjs:`generate_local_project_asset` 白名单注释改为「没有生产调用方,只有 Rust 集成测试与
  commands.rs 单测在调,待后续批次删除或改为转调 start_local_project_asset_generation」
- resourceCanvasAssetGenerationTaskModel.ts / resourceCanvasAssetGenerationQueue.ts:把「远端 single-flight
  输出槽会拒绝并发」这个已不成立的排队理由改为当前事实——本地 durable 输出槽已按精确动作指纹分槽,
  本批仍按「同一时刻只派发一条」排队是**提交节流**,真并行派发需要并发收口设计,留待下一批
2026-09-14 18:13:12 +08:00
suzmii 8ac77cb090 同步共享记忆与专题文档:并发槽身份、素材类型入口、退役同步命令
- PRD §3.10 本地排队一条:删掉已失效的「共用 single-flight 输出槽」理由,改为「本地槽已按精确动作指纹分槽(具备并行能力),本批前端仍按单条在途排队,真并行派发留待下一批」
- 栏目画布底部工具栏入口矩阵 §4a:同上更正,并写明槽身份材料的 8 个字段与旧槽懒迁移
- decision-log:追加三条 2026-09-14 条目(放开手工图片生成本地并发 / 素材类型拆成独立入口 / 同步命令 generate_local_project_asset 退役为仅测试调用)
- decision-log:更正同日「图片类生成后台化」条目里已被同批次推翻的两处表述(槽身份、本地排队的理由),并给 2026-09-11 的类型选择器入口决策加「已被取代」标记
- decision-log/pitfalls:把「严格 IPC 桩缺登记新命令」的排障经验记入共享记忆(unhandled rejection 与不相干提示断言的组合症状、桩必须返回数组、形状错会「看着绿」)
- 端到端验收用例 S12:更正「用户手动设置 category 已移除」与「面板内删除资源是唯一入口」两处与当前实现不符的描述
2026-09-14 17:52:27 +08:00
suzmii 7240b3793f Merge branch 'feat/agc-generation-task-progress' into fix/agc-canvas-acceptance-batch 2026-09-14 17:50:40 +08:00
suzmii 4fff733516 fix(agc): 生成任务账本读不到时不再抛未处理拒绝,改为保留本地状态并给出提示
- resourceCanvasAssetGenerationTaskModel.applyLocalProjectAssetGenerationRecords:入参在函数入口归一化,
  非数组(undefined / null / 字符串 / 数字 / 对象)一律按「没有后端记录」处理,数组内的垃圾条目
  (null / 数字 / 缺 taskId)逐条丢弃;类型放宽为 `readonly …[] | null | undefined`
- resourceCanvasAssetGenerationQueue:轮询 `list_local_project_asset_generations` 的 IPC 拒绝与非数组
  返回值都在本地接住,按「本轮读不到」计数;到上限后按「账本不可用」与「账本里没有这条」两种原因分别收口;
  派发循环再补两道兜底(dispatch 意外抛出、宿主 onSettled 抛出),保证 `void (async …)()` 不产生未处理拒绝、
  也不会把任务永远卡在「已派发但未终态」
- index.tsx 恢复任务账本的 effect:IPC 拒绝与返回非数组都落到既有提示条
  「生成任务列表读取失败,暂时无法恢复历史任务」,本地任务列表保持原样不清空
- 测试:模型层补「undefined / 非数组 / 垃圾条目不抛错且列表不变」,驱动器层补
  「轮询返回 undefined」「轮询 IPC reject」两条(收口原因、不产生未处理拒绝、后续排队任务照常补发)
- AppSurface 补两条:账本返回 undefined / 读取被拒绝时视图照常渲染、生成入口还在、提示可见
- AppSurface 既有的「布局读时提示」用例显式登记 `list_local_project_asset_generations` 返回空账本:
  该命令是只读的独立链路,严格桩把它判成 unexpected invoke 会让新提示混进「没有任何提示」的断言
2026-09-14 17:47:03 +08:00
suzmii 5d336bf147 Merge branch 'fix/agc-resource-layout-manual' into fix/agc-canvas-acceptance-batch 2026-09-14 17:40:50 +08:00
suzmii 3d6d51737c 测试 harness 登记 WS1 新增的后台生成任务账本 IPC
- resourceCanvasManualLayout.test.tsx:installLayoutTauri 登记
  list_local_project_asset_generations(工作台打开 / 切项目时由 WS1 的生成任务面板读取),
  回空账本,形状按 src-tauri/src/asset_generation_tasks.rs 的
  list_local_project_asset_generations 返回值核对为数组(Vec<AssetGenerationTaskRecord>),
  与前端 invoke<LocalProjectAssetGenerationTaskRecord[]> 一致,不是 { tasks: [] }
- 保留 unexpectedCommands 断言不放宽,也不删除:这条门禁继续拦截意外 IPC
2026-09-14 17:38:21 +08:00
suzmii 1de661df10 Merge branch 'feat/agc-generation-concurrency' into fix/agc-canvas-acceptance-batch 2026-09-14 17:31:40 +08:00
suzmii 6b5f67d207 Merge branch 'feat/agc-generation-task-progress' into fix/agc-canvas-acceptance-batch 2026-09-14 17:31:32 +08:00
suzmii 74b3760d0f docs(prd): 同步功能画布生成入口的后台化事实
- 头部更新时间改为 2026-09-14 并说明本次同步内容,2026-09-13 的原口径与其余合同保持不变的声明保留
- §3.10 实现状态补 2026-09-14 后台化口径(提交即返回 + 项目内任务账本 + 本地排队 + 非模态「生成任务」面板)
- §3.10 接线:图片类入口由 `generate_local_project_asset` 改写为 `start_local_project_asset_generation` + `list_local_project_asset_generations`
  + 项目内账本 `.agent/runtime/asset-generation-tasks/tasks.json`;音频 / 上传两条接线不变
- §3.10 新增「本地排队与进度可见」一条:第二条停在本地队列不调用提交 IPC、阶段文案由后端账本提供、
  非模态「生成任务」浮层与按素材卡定位
- §3.10 面板形态:补「提交期间面板不锁关闭」(×/遮罩/Esc/「后台运行并关闭」),并明确关闭不等于取消请求
- §3.10 前置规范图:命令名同步,并明确「后台化没有改这条前置判据」(`ui-prototype` / `art-spritesheet` 判据不变)
- §7.9 第 3 条:改写为 `start_local_project_asset_generation` 的载荷与「提交即返回」事实,
  保留「原载荷字段名与取值口径逐字不变」的说明,并补 `projectId` / `taskId` 两个新增字段
- §7.9 第 6 条:配对读改为「发生在该任务收口之后(提交命令不再等待生成)」,音频入口描述不变
- §7.9 新增第 8 条:生成期间可退出、面板关闭后进度可见、第二条本地排队(IPC 次数 1→2)、
  两条各自完成后各走一次「配对读 + 落卡」且 revision 单调
2026-09-14 17:30:08 +08:00
suzmii 53026fe8f3 放开 AGC 手工图片生成的 durable 输出槽并发生成限制
- canvas_generation.rs:standalone 图片生成的 durable 输出槽身份改为由精确动作身份派生(run_id = slot-<actionFingerprint>),同一项目里不同 prompt/素材名/参数的生成各自独立成槽,可以同时在途
- canvas_generation.rs:动作指纹材料逐字节保持升级前取值,新增 legacy_standalone_platform_art_generation_run_id 复现升级前 {outputPath, requireSlices} 槽公式,只用于定位升级前遗留账本
- canvas_generation.rs:在取得 durable guard 之后、任何远端 POST 之前调用旧槽账本一次性迁移
- external_generation_state.rs:新增 adopt_legacy_standalone_platform_art_generation_runtime_state_at,在项目写锁内把仍属于本次精确动作的旧 slot- 账本迁移到新身份路径并保留原 idempotencyKey 与 operationId;属于其他动作的旧账本原样保留,不迁移、不删除、不阻塞
- external_generation_state.rs:新增三个 #[cfg(test)] 只读访问器,供跨模块用例断言账本身份
- canvas_generation.rs:新增两条不同动作并发都成功且远端各 POST 一次、不同动作的 durable 槽互不阻塞、旧槽账本仅被同一精确动作迁移三组用例;同动作并发冲突用例改用同一精确动作以钉住幂等语义
2026-09-14 17:30:00 +08:00
suzmii bb7cbae118 feat(agc): 图片类生成后台化,生成面板可随时关闭并新增「生成任务」进度面板
- Rust 新增 asset_generation_tasks.rs:图片类生成拆成「提交即返回任务记录 + 后台 spawn 生成」,
  生成本身仍转调既有 generate_platform_art_asset_with_options_at(不复制生成 / 幂等 / 登记逻辑)
- 任务账本落项目内 .agent/runtime/asset-generation-tasks/tasks.json(复用 agent runtime sidecar 原语),
  阶段文案 phaseDetail 由后端拥有,读取时把上次运行留下的非终态记录收口为「中断失败」,账本上限 50 条
- Rust 新增 IPC start_local_project_asset_generation / list_local_project_asset_generations 并在 main.rs 注册;
  同步命令 generate_local_project_asset 保留不动
- 新增前端纯模型 resourceCanvasAssetGenerationTaskModel.ts:任务状态机、在途判据、账本恢复、耗时文案
- 新增 resourceCanvasAssetGenerationQueue.ts:本地排队驱动器,第二条不发提交 IPC、前一条终态后自动补发,
  状态与阶段一律以后端账本为准,账本查不到该任务时按上限停止等待
- 两块生成浮层在提交期间放开 × / 遮罩 / Esc,次按钮在途时改为「后台运行并关闭」(关闭不等于取消请求),
  图片类面板的在途文案改为渲染后端 phaseDetail
- 新增非模态「生成任务」面板(不铺遮罩 / 不做焦点陷阱 / 不进模态遮挡判据),显示状态、后端阶段、
  已耗时与素材名,已完成条目复用 pendingResourceFocusRef 聚焦链定位素材卡
- index.tsx 宿主接线:任务列表状态与 ref、提交回调不再读面板状态、按项目恢复任务账本、
  工具栏「生成任务」入口按钮与面板渲染点
- check-config.mjs:把已无前端调用方的同步命令 generate_local_project_asset 登记进 native-only 白名单
- 测试:新增「生成面板提交期间可关闭」「本地排队驱动器」「生成任务面板」三组用例;
  appSurface 生成载荷断言改为 start_local_project_asset_generation + list 轮询桩
- 文档:入口矩阵补 §4a 与验证命令、V3 验收 S11a 判据、decision-log 记录本次决策
2026-09-14 17:26:36 +08:00
suzmii 0b3bf3e52d 合并 fix/agc-resource-layout-manual:资源画布改为手动整理口径
- 合并 WS2 分支(新素材不再自动重排 + 显式「整理画布」+ 生成后自动聚焦)
- index.tsx 与 useProjectResourceCanvasLayout.ts 自动合并成功,无需手工介入
- decision-log.md / pitfalls.md 冲突按「两侧语义都保住」解:保留 origin/master 新增的
  「AGC 壳 Rust 套件分片并行」与「根门禁 label 字面量契约」两条,同时保留 WS2 新增的
  「AGC 资源画布改为手动整理」与「不要恢复无条件重派生」两条,只删除冲突标记行
- 新增 tests/resourceCanvasManualLayout.test.tsx
2026-09-14 17:16:58 +08:00
suzmii 6d5cd51649 Merge branch 'fix/agc-preview-alpha-background' into fix/agc-canvas-acceptance-batch 2026-09-14 17:16:30 +08:00
suzmii 181e364d80 AGC 资源卡棋盘格底改按图像真实 alpha 判定
- 原生预览新增头部级 alpha 判据:`LocalProjectImagePreview.hasAlpha`(PNG colorType 4/6 或 tRNS、WebP VP8X/VP8L alpha 标志;JPEG 恒 false),只读签名与 chunk 头、不做像素解码。
- 前端预览 payload 增加可选 `hasAlpha`,并在 `materializeProjectResourceCardPreview` 的两条分支里透传。
- 资源卡根节点新增排障属性 `data-preview-has-alpha`:只有预览已加载且判据为真才写 `'true'`,其余一律不写(缺属性与不透明同档)。
- 棋盘格底选择器加 `[data-preview-has-alpha='true']` 条件;无 alpha 时退回卡片既有纯色底,不引入第二套底色。
- 新增 TS 用例(真渲染资源卡 + styles.css 声明级层叠求值)与 Rust 用例(PNG/WebP/JPEG 头部判据、tRNS、坏文件失败关闭、非解码证明、IPC 字段序列化契约)。
- 验收文档补记 `data-preview-has-alpha` 判据与「真假棋盘格」取证脚本,便于现场区分真透明底与 AI 画出的假棋盘格。
2026-09-14 17:13:43 +08:00
suzmii 3b8ecb02d4 记录 AGC 资源画布「手动整理」口径变更
- decision-log:追加 2026-09-14 条目,记录默认 preserve、显式「整理画布」、
  依赖侧关系图首次就绪的一次性重派生、新素材按 manifest 新增 id 聚焦四条决策与变异验证
- pitfalls:追加「不要恢复无条件重派生」条目,含 changed 门、ready 时序、
  项目作用域 flag 与新素材基线四个易错点
2026-09-14 17:08:00 +08:00
suzmii d02d0ed7a4 AGC 资源画布:新素材不再自动重排,改为显式「整理画布」并在生成后自动聚焦新素材
- useProjectResourceCanvasLayout:资源写意图新增 rederive 标记,显式整理那一笔按 rederive
  策略重算自动坐标(手动坐标原样保留),自动同步仍是 preserve 只补新卡
- useProjectResourceCanvasLayout:新增 rederiveNow(),复用既有写队列 / sidecar 写回链路,
  只在坐标确有变化时落盘,成功复用既有「布局已保存」提示
- index.tsx:两个排序模式的 rederiveAutomaticPositions 都固定 false,画布不再因为资源
  协调签名变化(新增素材、改标签、改分类、拓扑重建)整体重排
- index.tsx:依赖侧「关系图首次就绪」改为按项目作用域的一次性 flag,等该侧 sidecar ready
  后调用一次 rederiveNow(),之后一律只补新卡(切排序 tab 不重新武装)
- index.tsx:依赖/类型 tab 组新增「整理画布」按钮,作为整张画布重排的唯一显式入口
- index.tsx:新增 manifest.assets 新增 id 检测(seenManifestAssetIdsRef),把新卡交给既有
  pendingResourceFocusRef + advanceFocusGeneration() 裁决链聚焦;首次打开 / 切项目只登记
  基线不聚焦,重命名不改 id 天然不触发,已有同目标意图时不重复挂
- 新增 tests/resourceCanvasManualLayout.test.tsx(8 条):新素材入库后既有自动坐标逐值不变、
  依赖侧首次就绪后不再重排、新素材自动聚焦、被搜索挡住走既有「清除搜索并定位」、
  「整理画布」重算并保留手动坐标、已经整齐时再按一次不写盘、首次打开与切项目不聚焦
2026-09-14 17:07:55 +08:00
suzmii ef3e783ab1 Merge remote-tracking branch 'origin/master' into feat/agc-resource-type-entry 2026-09-14 17:07:36 +08:00
suzmii 7ce4a3a9c6 把素材类型从「编辑素材标签」面板拆成独立入口
- 新增 ResourceTypePanel(src/view/project-development/ResourceTypePanel.tsx):类型选一项即落盘,category 传用户选中值、tags 逐字回传落盘原值,保存在飞时沿用 closeOnBackdrop/closeOnEscape = !saving
- 新增 resourceAssetDisplayName.ts:两块面板共用同一个素材名副标题口径(localPath basename),不再各写一份
- 新增 resourceTypePanel.css:类型面板的弹窗骨架与信息浮层「分类」行入口样式,按 AGC 内独立文件约定,不动 packages/** 与 styles.css
- ResourceClassificationPanel 删掉类型 chip 与 categoryChoice:保存时恒回传 gameCreationAppAssetPersistedCategory(asset),「只改标签不动分类」由结构保证
- index.tsx 新增 resourceTypeAssetId 与 resourceTypeAsset;工具条在「编辑标签」旁新增「素材类型」按钮(Shapes 图标)
- index.tsx 用合并后的 resourceClassificationOverlayOpen 纳入点外部/Esc 浮层遮挡判据,并同步 useEffect 依赖项
- index.tsx 渲染新面板:保存成功后由宿主收起面板并沿用 manifest 重载路径,让卡片立刻落到新栏目
- 信息浮层「分类」行接出第二入口:按钮渲染在 dd 之外,不污染 dt/dd 字段读取口径;非 manifest 资产不给入口
- resourceCanvasInfoModel 导出 RESOURCE_INFO_CATEGORY_FIELD_LABEL,模型与入口共用同一行标识
- 新增 tests/resourceTypePanel.test.tsx:选中即落盘、tags 逐字回传、没碰过不写盘、显式待归类、失败回退、saving 锁、Esc/遮罩、面板骨架共 11 条
- 迁移「没碰过分类就回传落盘原值」对照用例并保留两条(标签面板侧),chip 用例搬到新面板文件
- 集成用例改走新入口:选中即落盘并自动关窗,另补 Esc/点外部不串台、只改标签后 manifest category 逐字不变两条宿主级用例
- appSurface 工具条清单补上「素材类型」
2026-09-14 17:07:15 +08:00
56 changed files with 10323 additions and 616 deletions
@@ -113,6 +113,11 @@ const allowedUncalledTauriCommands = [
'chat_with_game_creator_agent',
'check_ui_editor_font_glyph_coverage',
'create_ui_design_resource',
// 图片类生成的同步变体:GUI 已改为 `start_local_project_asset_generation` + 项目内任务账本
// (提交即返回、后台生成)。这条命令**没有生产调用方**,只有 Rust 集成测试
// `src/tests/project.rs`)与 `commands.rs` 单测在调;待后续批次删除,或改为转调
// `start_local_project_asset_generation`。
'generate_local_project_asset',
'open_game_creator_launcher_window',
'open_game_creator_workspace_window',
'read_direct_project_conversation',
@@ -9,6 +9,10 @@ import {
const agcDevHost = '127.0.0.1';
const legacyAgcDevPort = 3080;
const agcVitePortEnvKey = 'GENARRATIVE_AGC_VITE_PORT';
const agcAdminWebHost = '127.0.0.1';
const legacyAgcAdminWebPort = 3102;
// 与 scripts/dev.mjs 的后台 Web 端口配置保持同一环境变量名。
const agcAdminWebPortEnvKey = 'ADMIN_WEB_PORT';
function readConfiguredAgcDevPort(env = process.env) {
const rawPort = String(env[agcVitePortEnvKey] ?? '').trim();
@@ -99,13 +103,100 @@ function withAgcDevEndpointEnv(endpoint, env = process.env) {
};
}
function readConfiguredAgcAdminWebPort(env = process.env) {
const rawPort = String(env[agcAdminWebPortEnvKey] ?? '').trim();
if (!rawPort) {
return null;
}
const port = normalizePort(rawPort, -1);
if (port < 1024) {
throw new Error(`${agcAdminWebPortEnvKey} 必须是 1024-65535 的有效端口`);
}
return port;
}
function createAgcAdminWebEndpoint(port, portRange = null) {
const origin = `http://${agcAdminWebHost}:${port}`;
return {
host: agcAdminWebHost,
port,
origin,
basePath: '/admin/',
url: `${origin}/admin/`,
portRange,
};
}
// AGC 开发态的后台 Web 与 `npm run dev` 的后台 Vite 共用同一套优先端口约定:
// Linux 取当前用户端口段的 `start + 3` 槽位,非 Linux 保留 `3102` 兼容首选并允许统一漂移。
async function resolveAgcAdminWebEndpoint({
env = process.env,
platform = process.platform,
strictConfigured = false,
reservedPorts = [],
reservePortRange = reserveLinuxDevPortRange,
findPort = findAvailablePort,
} = {}) {
const configuredPort = readConfiguredAgcAdminWebPort(env);
let portRange = null;
let preferredPort = configuredPort ?? legacyAgcAdminWebPort;
if (platform === 'linux') {
const allocation = await reservePortRange({ env });
if (!allocation?.range) {
throw new Error('无法取得当前 Linux 用户的 dev 端口段');
}
portRange = allocation.range;
const mappedAdminWebPort = mapDevPortsToPortRange(portRange)?.adminWebPort;
if (!Number.isInteger(mappedAdminWebPort)) {
throw new Error(
`当前 Linux dev 端口段 ${portRange.label} 缺少后台 Web 槽位;请先迁移为至少 6 个端口且不与其它用户重叠的端口段`,
);
}
preferredPort = configuredPort ?? mappedAdminWebPort;
}
const reservedPortSet = new Set(
reservedPorts.filter((value) => Number.isInteger(value) && value > 0),
);
const port = await findPort({
host: agcAdminWebHost,
preferredPort,
portRange,
reservedPorts: reservedPortSet,
strict: strictConfigured && configuredPort != null,
});
console.log(
formatPortDecision({
name: 'ai-game-creator-shell-admin-web',
host: agcAdminWebHost,
preferredPort,
resolvedPort: port,
}),
);
if (portRange) {
console.log(
`[ai-game-creator-shell] admin-web port-range: ${portRange.label}`,
);
}
return createAgcAdminWebEndpoint(port, portRange);
}
export {
agcAdminWebHost,
agcAdminWebPortEnvKey,
agcDevHost,
agcVitePortEnvKey,
createAgcAdminWebEndpoint,
createAgcDevEndpoint,
legacyAgcAdminWebPort,
legacyAgcDevPort,
readAgcDevEndpoint,
readConfiguredAgcAdminWebPort,
readConfiguredAgcDevPort,
resolveAgcAdminWebEndpoint,
resolveAgcDevEndpoint,
withAgcDevEndpointEnv,
};
@@ -14,12 +14,14 @@ import {
import {
agcVitePortEnvKey,
readAgcDevEndpoint,
resolveAgcAdminWebEndpoint,
resolveAgcDevEndpoint,
withAgcDevEndpointEnv,
} from './dev-port.mjs';
const appRoot = fileURLToPath(new URL('..', import.meta.url));
const repoRoot = resolve(appRoot, '../..');
const adminWebDir = resolve(repoRoot, 'apps/admin-web');
const devStackStatePath = resolve(repoRoot, '.app/dev-stack.json');
const apiServerExePath = resolve(
repoRoot,
@@ -32,6 +34,8 @@ const backendSpacetimeDataDir = resolve(
repoRoot,
'server-rs/.spacetimedb/ai-game-creator/data',
);
// 后台 Web 默认跟随 AGC 一起起来,便于联调后台页面;`AGC_DEV_ADMIN_WEB=0` 可关闭。
const agcDevAdminWebEnvKey = 'AGC_DEV_ADMIN_WEB';
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const childLifecycles = new WeakMap();
@@ -200,36 +204,122 @@ function urlPort(url) {
}
}
// 读取端口当前真正的监听进程身份。返回 null 表示探测本身不可用(例如缺少
// Get-NetTCPConnection),此时调用方必须退化为旧行为,不能让本地启动直接失败。
// 端口归属探测脚本。历史实现用 `Get-NetTCPConnection` 取监听进程,而它底层走
// WMI:实测单端口单次 11.2 秒、再叠加每个 PID 的 `Get-CimInstance` 3.3 秒,
// 一轮探测约 43 秒,直接把"配套后端就绪"等待拖到分钟级。改用原生
// `netstat -ano`(约 30 毫秒)取端口 -> PID,再用 .NET `Process` 读进程名和
// 可执行文件路径(毫秒级);只有核对 SpacetimeDB `--data-dir` 归属时才按 PID
// 取命令行,并允许调用方把已知命令行传进来复用。
const windowsPortOwnerProbeCommand = [
'$ErrorActionPreference = "SilentlyContinue"',
'$queriedPorts = @()',
'foreach ($raw in ($env:GENARRATIVE_QUERY_PORTS -split ",")) {',
' if ($raw -match "^\\d+$") { $queriedPorts += [int]$raw }',
'}',
'$knownCommandLines = @{}',
'if ($env:GENARRATIVE_KNOWN_COMMAND_LINES) {',
' try {',
' foreach ($property in (ConvertFrom-Json $env:GENARRATIVE_KNOWN_COMMAND_LINES).PSObject.Properties) {',
' $knownCommandLines[[int]$property.Name] = [string]$property.Value',
' }',
' } catch { }',
'}',
'$listenerPidByPort = @{}',
'foreach ($line in (netstat -ano -p tcp)) {',
' $fields = @($line -split "\\s+" | Where-Object { $_ })',
' if ($fields.Count -lt 4) { continue }',
' if ($fields[0] -ne "TCP") { continue }',
' # A listening socket always has foreign address 0.0.0.0:0 / [::]:0, which',
' # is locale-independent unlike the localized netstat State column.',
' if ($fields[2] -notmatch ":0$") { continue }',
' $localPort = [int]($fields[1].Split(":")[-1])',
' if ($queriedPorts -notcontains $localPort) { continue }',
' # The PID is the last column; do not hardcode its index.',
' if ($fields[-1] -notmatch "^\\d+$") { continue }',
' $listenerPidByPort[$localPort] = [int]$fields[-1]',
'}',
'$result = @()',
'foreach ($port in ($listenerPidByPort.Keys | Sort-Object)) {',
' $processId = $listenerPidByPort[$port]',
' $name = $null',
' $executablePath = $null',
' $commandLine = $null',
' try {',
' $process = [System.Diagnostics.Process]::GetProcessById($processId)',
' $name = $process.ProcessName + ".exe"',
' try { $executablePath = $process.MainModule.FileName } catch { }',
' } catch { }',
' if ($knownCommandLines.ContainsKey($processId)) {',
' $commandLine = $knownCommandLines[$processId]',
' } elseif (($name -like "spacetime*") -or (-not $executablePath)) {',
' try { $commandLine = (Get-CimInstance Win32_Process -Filter ("ProcessId=" + $processId)).CommandLine } catch { }',
' }',
' $result += [pscustomobject]@{ port = [int]$port; processId = $processId; name = $name; executablePath = $executablePath; commandLine = $commandLine }',
'}',
'ConvertTo-Json -InputObject @($result) -Compress',
].join('\n');
// 进程命令行在进程生命周期内不变,但 PID 会被系统复用;按 PID 记 TTL 缓存,
// 让"等配套后端就绪"的轮询只在首个周期付出 WMI 成本。TTL 取 5 分钟:本轮实测
// 这台机器上首次 WMI 调用约 18 秒(热调用 3.3 秒),而 PID 在 5 分钟内被复用
// 成另一个运行本工作树 data dir 的 SpacetimeDB 才能造成误判,概率可忽略。
// 默认实现才缓存,注入实现(测试)与显式 env 始终重新读取。
const WINDOWS_COMMAND_LINE_CACHE_TTL_MS = 300_000;
const windowsPortOwnerCommandLineCache = new Map();
function resolveCommandLineCache({ spawnImpl, env }) {
return spawnImpl === spawnSync && env === process.env
? windowsPortOwnerCommandLineCache
: new Map();
}
// 读取端口当前真正的监听进程身份。返回 null 表示探测本身不可用(例如系统缺少
// netstat),此时调用方必须退化为旧行为,不能让本地启动直接失败。
function readWindowsPortOwnerIdentities(
ports,
{ spawnImpl = spawnSync, env = process.env } = {},
{
spawnImpl = spawnSync,
env = process.env,
now = Date.now,
commandLineTtlMs = WINDOWS_COMMAND_LINE_CACHE_TTL_MS,
commandLineCache = resolveCommandLineCache({ spawnImpl, env }),
} = {},
) {
const uniquePorts = [...new Set(ports.filter((port) => port > 0))];
if (uniquePorts.length === 0) {
return null;
}
const command = [
'$ErrorActionPreference = "SilentlyContinue"',
'$ports = ($env:GENARRATIVE_QUERY_PORTS -split ",") | Where-Object { $_ }',
'$result = @()',
'foreach ($port in $ports) {',
' $connection = Get-NetTCPConnection -State Listen -LocalPort ([int]$port) -ErrorAction SilentlyContinue | Select-Object -First 1',
' if (-not $connection) { continue }',
' $owner = Get-CimInstance Win32_Process -Filter ("ProcessId=" + $connection.OwningProcess) -ErrorAction SilentlyContinue',
' $result += [pscustomobject]@{ port = [int]$port; processId = [int]$connection.OwningProcess; name = $owner.Name; executablePath = $owner.ExecutablePath; commandLine = $owner.CommandLine }',
'}',
'ConvertTo-Json -InputObject @($result) -Compress',
].join('\n');
const knownCommandLines = {};
for (const [processId, record] of [...commandLineCache]) {
if (record && now() - record.at < commandLineTtlMs) {
knownCommandLines[processId] = record.commandLine;
} else {
commandLineCache.delete(processId);
}
}
const childEnv = {
...env,
GENARRATIVE_QUERY_PORTS: uniquePorts.join(','),
};
if (Object.keys(knownCommandLines).length > 0) {
childEnv.GENARRATIVE_KNOWN_COMMAND_LINES =
JSON.stringify(knownCommandLines);
}
const result = spawnImpl(
'powershell.exe',
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', command],
[
'-NoProfile',
'-ExecutionPolicy',
'Bypass',
'-Command',
windowsPortOwnerProbeCommand,
],
{
encoding: 'utf8',
env: { ...env, GENARRATIVE_QUERY_PORTS: uniquePorts.join(',') },
env: childEnv,
maxBuffer: 8 * 1024 * 1024,
},
);
@@ -240,9 +330,22 @@ function readWindowsPortOwnerIdentities(
const owners = new Map();
for (const entry of parseWindowsProcessSnapshot(result.stdout)) {
const port = Number(entry?.port);
if (Number.isInteger(port) && port > 0) {
owners.set(port, entry);
if (!Number.isInteger(port) || port <= 0) {
continue;
}
const processId = Number(entry?.processId);
if (
Number.isInteger(processId) &&
processId > 0 &&
typeof entry?.commandLine === 'string' &&
entry.commandLine
) {
commandLineCache.set(processId, {
commandLine: entry.commandLine,
at: now(),
});
}
owners.set(port, entry);
}
return owners;
}
@@ -879,10 +982,102 @@ async function startVite(apiTarget, endpoint = readAgcDevEndpoint()) {
);
}
function readAdminWebEnabled(env = process.env) {
return String(env[agcDevAdminWebEnvKey] ?? '').trim() !== '0';
}
// 后台 Web 与 AGC Vite 一样直接由本启动器持有,不经过 `dev.mjs admin-web`
// 后者会整体重写 `.app/dev-stack.json`,把本次配套后端的状态覆盖掉。
function startAdminWeb(
apiUrl,
endpoint,
{ env = process.env, spawnImpl = spawnChild } = {},
) {
return spawnImpl(
npm,
[
'--prefix',
'../..',
'exec',
'vite',
'--',
'--host',
endpoint.host,
'--port',
String(endpoint.port),
'--strictPort',
],
{
cwd: adminWebDir,
env: {
...env,
ADMIN_API_TARGET: apiUrl,
GENARRATIVE_API_TARGET: apiUrl,
GENARRATIVE_API_PORT: String(urlPort(apiUrl) || 8082),
ADMIN_WEB_BASE: endpoint.basePath,
},
},
);
}
function formatStartupSummary({
frontendUrl = '',
apiUrl = '',
adminWebUrl = '',
spacetimeUrl = '',
bgfilterWorkerUrl = '',
} = {}) {
const segments = [
['前端', frontendUrl],
['后端', apiUrl],
['后台', adminWebUrl],
['数据库', spacetimeUrl],
['bgfilter-worker', bgfilterWorkerUrl],
]
.filter(([, value]) => Boolean(value))
.map(([label, value]) => `${label} ${value}`);
return `[ai-game-creator-shell] 启动汇总: ${segments.join(' | ')}`;
}
// 后台 Web 是可选联调服务:端口解析或启动失败只告警,不能阻断 AGC 客户端与配套后端。
async function ensureAdminWeb({
apiUrl,
reservedPorts = [],
env = process.env,
enabled = readAdminWebEnabled(env),
resolveEndpoint = resolveAgcAdminWebEndpoint,
spawnAdminWeb = startAdminWeb,
waitForExit = waitForChildTermination,
warn = (message) => console.warn(message),
} = {}) {
if (!enabled) {
return { endpoint: null, child: null };
}
try {
const endpoint = await resolveEndpoint({ env, reservedPorts });
const child = spawnAdminWeb(apiUrl, endpoint, { env });
waitForExit(child).then((failure) => {
warn(
`[ai-game-creator-shell] 后台 Web 已退出(${formatChildFailure(failure)}),AGC 继续运行。`,
);
});
return { endpoint, child };
} catch (error) {
warn(
`[ai-game-creator-shell] 后台 Web 未能启动(${
error instanceof Error ? error.message : String(error)
}),AGC 继续运行。`,
);
return { endpoint: null, child: null };
}
}
async function main() {
let backendChild = null;
let startedBackend = false;
let viteChild = null;
let adminWebChild = null;
let shutdownSignal = '';
const signalHandlers = new Map();
@@ -905,6 +1100,7 @@ async function main() {
const handler = () => {
shutdownSignal = signal;
stopChild(viteChild, signal);
stopChild(adminWebChild, signal);
stopChild(backendChild, signal);
// 立刻清扫,避免外层 taskkill /F 抢在 finally 之前把本进程杀掉。
sweepStartedBackend();
@@ -937,6 +1133,25 @@ async function main() {
throw new Error(`启动期收到 ${shutdownSignal},已停止前端服务`);
}
const adminWeb = await ensureAdminWeb({
apiUrl: backend.targets.apiUrl,
// AGC Vite 端口尚未监听,必须显式保留,避免被后台 Web 抢先占用。
reservedPorts: [endpoint.port],
});
adminWebChild = adminWeb.child;
if (shutdownSignal) {
throw new Error(`启动期收到 ${shutdownSignal},已停止后台 Web`);
}
console.log(
formatStartupSummary({
frontendUrl: endpoint.url,
apiUrl: backend.targets.apiUrl,
adminWebUrl: adminWeb.endpoint?.url ?? '',
spacetimeUrl: backend.targets.spacetimeUrl,
bgfilterWorkerUrl: backend.targets.bgfilterWorkerUrl,
}),
);
const children = [backendChild, viteChild].filter(Boolean);
if (children.length === 0) {
return 0;
@@ -946,10 +1161,12 @@ async function main() {
children.map((child) => waitForChildTermination(child)),
);
stopChild(viteChild);
stopChild(adminWebChild);
stopChild(backendChild);
return failure.type === 'error' || failure.signal ? 1 : (failure.code ?? 0);
} catch (error) {
stopChild(viteChild);
stopChild(adminWebChild);
stopChild(backendChild);
console.error(
`[ai-game-creator-shell] ${error instanceof Error ? error.message : String(error)}`,
@@ -958,6 +1175,7 @@ async function main() {
} finally {
await Promise.all([
terminateChildTree(viteChild),
terminateChildTree(adminWebChild),
terminateChildTree(backendChild),
]);
sweepStartedBackend();
@@ -975,9 +1193,12 @@ function isDirectModuleExecution() {
}
export {
agcDevAdminWebEnvKey,
ensureAdminWeb,
ensureBackend,
formatChildFailure,
formatOwnerLabel,
formatStartupSummary,
isAiGameCreatorServer,
isBackendReady,
isDirectModuleExecution,
@@ -985,6 +1206,7 @@ export {
isWorktreeApiServerOwner,
isWorktreeSpacetimeOwner,
preflightExistingVite,
readAdminWebEnabled,
readBackendServiceFailure,
readChildFailure,
readExistingViteServer,
@@ -993,6 +1215,7 @@ export {
resolveBackendTargetsFromState,
runWindowsTaskkill,
spawnChild,
startAdminWeb,
stopChild,
terminateChildTree,
verifyAgcBackendOwnership,
File diff suppressed because it is too large Load Diff
@@ -1074,6 +1074,102 @@ pub(in crate::agent) fn remove_platform_art_generation_runtime_state_at(
}
}
/// 一次性兼容:升级前 standalone 槽身份只由 `{outputPath, requireSlices}` 派生,
/// 同一项目所有图片类生成共用一个槽;升级后槽身份按精确动作派生,路径随之变化。
///
/// 若旧槽路径上的账本仍然属于本次精确动作(`agentId` 与 `actionFingerprint` 都与
/// 当前上下文一致),就在项目写锁内把它迁移到新身份路径:保留原 `idempotencyKey`
/// 与 `operationId`,避免同一精确动作在升级后二次 POST 计费。旧账本属于其他动作时
/// 原样保留(不迁移、不删除、不阻塞),由对应动作自己的请求迁移。
///
/// 返回 `Ok(false)` 表示没有需要迁移的旧账本。任何身份无法安全解释的情形都失败关闭。
pub(super) fn adopt_legacy_standalone_platform_art_generation_runtime_state_at(
root: &Path,
context: &PlatformArtGenerationRuntimeContext,
legacy_run_id: &str,
) -> Result<bool, String> {
if !is_standalone_platform_art_generation_runtime_context(context)
|| legacy_run_id == context.run_id
|| !is_lowercase_sha256(legacy_run_id.strip_prefix("slot-").unwrap_or_default())
{
return Ok(false);
}
// 与账本创建互斥:迁移必须在同一把项目写锁内完成,否则两个调用可能同时把同一份
// 旧账本迁移到新路径,或与新建账本互相覆盖。
let _claim_lock = acquire_game_creator_agent_runtime_project_write_lock_with_wait(
root,
"canvas.asset_generate.runtime.claim",
)?;
if game_creator_agent_runtime_external_generation_exists(
root,
&context.agent_id,
&context.run_id,
) {
// 新身份账本已经存在:旧账本不属于本次动作的权威状态,保持两边各自的身份。
return Ok(false);
}
let legacy_relative_path =
platform_art_generation_runtime_relative_path(&context.agent_id, legacy_run_id);
let Some(legacy_state) =
read_agent_runtime_json_sidecar_with_max_bytes::<PlatformArtGenerationRuntimeState>(
root,
&legacy_relative_path,
"External Editor 生成账本",
PLATFORM_ART_GENERATION_RUNTIME_MAX_BYTES,
)?
else {
return Ok(false);
};
if legacy_state.agent_id != context.agent_id
|| legacy_state.run_id != legacy_run_id
|| legacy_state.action_fingerprint != context.action_fingerprint
{
// 旧槽里是另一个精确动作的账本:它仍归那个动作所有,本次调用不得消费、改写或删除它。
return Ok(false);
}
let legacy_identity = format!("{}:{legacy_run_id}", context.agent_id);
let legacy_context = PlatformArtGenerationRuntimeContext {
task_id: legacy_identity.clone(),
session_id: legacy_identity.clone(),
run_id: legacy_run_id.to_string(),
action_id: legacy_identity,
..context.clone()
};
let Some(mut migrated) = read_platform_art_generation_runtime_state(root, &legacy_context)?
else {
return Ok(false);
};
migrated.run_id = context.run_id.clone();
migrated.task_id = context.task_id.clone();
migrated.session_id = context.session_id.clone();
migrated.action_id = context.action_id.clone();
migrated.updated_at = unix_timestamp();
write_platform_art_generation_runtime_state(root, &migrated)?;
remove_platform_art_generation_runtime_state_at(root, &context.agent_id, legacy_run_id)?;
Ok(true)
}
#[cfg(test)]
pub(super) fn platform_art_generation_runtime_operation_id_for_test(
state: &PlatformArtGenerationRuntimeState,
) -> Option<&str> {
state.operation_id.as_deref()
}
#[cfg(test)]
pub(super) fn platform_art_generation_runtime_run_id_for_test(
state: &PlatformArtGenerationRuntimeState,
) -> &str {
&state.run_id
}
#[cfg(test)]
pub(super) fn platform_art_generation_runtime_action_fingerprint_for_test(
state: &PlatformArtGenerationRuntimeState,
) -> &str {
&state.action_fingerprint
}
#[cfg(test)]
pub(crate) fn write_platform_art_generation_runtime_accepted_for_test(
root: &Path,
File diff suppressed because it is too large Load Diff
@@ -27,6 +27,7 @@ fn user_selected_path_grants() -> &'static Mutex<HashMap<String, UserSelectedPat
#[cfg(windows)]
fn normalize_user_selected_path_key(path: &Path) -> Option<String> {
let path = normalize_windows_policy_path(path);
if !path.is_absolute()
|| path
.components()
@@ -42,6 +43,15 @@ fn normalize_user_selected_path_key(path: &Path) -> Option<String> {
)
}
#[cfg(windows)]
fn normalize_windows_policy_path(path: &Path) -> PathBuf {
let value = path.to_string_lossy();
if let Some(rest) = value.strip_prefix(r"\\?\UNC\") {
return PathBuf::from(format!(r"\\{rest}"));
}
PathBuf::from(value.strip_prefix(r"\\?\").unwrap_or(&value))
}
#[cfg(windows)]
pub(crate) fn register_game_creator_user_selected_path(path: &Path, is_directory: bool) {
let Some(key) = normalize_user_selected_path_key(path) else {
@@ -838,6 +848,7 @@ pub(crate) fn validate_game_creator_private_path_ancestors(
/// separate, explicit user-selected scope below covers native picker/project
/// root results, including projects stored outside the current profile.
fn game_creator_private_path_allows_auto_elevation(path: &Path) -> bool {
let path = normalize_windows_policy_path(path);
if !path.is_absolute()
|| path
.components()
@@ -846,7 +857,10 @@ fn game_creator_private_path_allows_auto_elevation(path: &Path) -> bool {
return false;
}
let starts_with_path = |root: &Path| path == root || path.starts_with(root);
let starts_with_path = |root: &Path| {
let root = normalize_windows_policy_path(root);
path == root || path.starts_with(root)
};
if game_creator_runtime_config_dir()
.as_deref()
.is_some_and(starts_with_path)
@@ -1056,6 +1070,7 @@ pub(crate) fn parse_windows_acl_repair_scope(value: &str) -> Result<WindowsAclRe
#[cfg(windows)]
fn game_creator_runtime_config_repair_scope(path: &Path) -> WindowsAclRepairScope {
let path = normalize_windows_policy_path(path);
let is_builtin_root = |root: PathBuf| path == root || path.starts_with(root);
if let Some(home) = std::env::var_os("USERPROFILE")
.or_else(|| std::env::var_os("HOME"))
@@ -4506,6 +4521,23 @@ mod private_path_elevation_policy_tests {
);
}
#[cfg(windows)]
#[test]
fn verbatim_packaged_appdata_path_keeps_managed_repair_scope() {
let root = std::env::var_os("LOCALAPPDATA")
.or_else(|| std::env::var_os("APPDATA"))
.map(PathBuf::from)
.expect("local appdata");
let packaged = root.join("world.genarrative.ai-game-creator");
let verbatim = PathBuf::from(format!(r"\\?\{}", packaged.display()));
assert!(game_creator_private_path_allows_auto_elevation(&verbatim));
assert_eq!(
game_creator_runtime_config_repair_scope(&verbatim),
WindowsAclRepairScope::Managed
);
}
#[cfg(windows)]
#[test]
fn picker_grant_is_required_and_directory_grant_covers_descendants() {
@@ -26,6 +26,12 @@ pub(crate) struct LocalProjectImagePreview {
pub(crate) byte_len: u64,
pub(crate) pixel_width: u32,
pub(crate) pixel_height: u32,
/// 这张图是否**真的**带 alpha 通道,判据见 [`detect_raster_image_has_alpha`]。
///
/// 资源卡只按它决定要不要铺棋盘格底:`data-preview-kind` 只说明「走图片预览分支」,
/// 与这张图有没有透明像素无关 —— 无条件铺底会让「AI 把棋盘格画进像素里」的不透明图
/// 与卡面棋盘格叠成两套,验收时无法区分「真透明底」与「假棋盘格」。
pub(crate) has_alpha: bool,
pub(crate) data_url: String,
}
@@ -102,12 +108,17 @@ pub(crate) fn load_local_project_image_preview_with_cancellation(
false,
)?;
cancellation.check()?;
// 头部级 alpha 判据:只读签名与头部标志(PNG 还会按 chunk 头跳过数据体找 `tRNS`),
// 不做熵解码、不做逐像素扫描,成本不随像素数增长,因此大图与「AI 把棋盘格画进图里」
// 的不透明图都不会因此变慢。
let has_alpha = detect_raster_image_has_alpha(&image.bytes, image.media_type);
Ok(LocalProjectImagePreview {
path: image.relative_path.clone(),
media_type: image.media_type.to_string(),
byte_len: image.byte_len,
pixel_width: image.pixel_width,
pixel_height: image.pixel_height,
has_alpha,
data_url: image.data_url_with_cancellation(cancellation)?,
})
}
@@ -420,6 +431,84 @@ fn detect_raster_image_dimensions(bytes: &[u8], media_type: &str) -> Option<(u32
}
}
/// 头部级 alpha 判据:这张图**有没有 alpha 通道 / 透明像素**,只看签名与头部标志
/// PNG 还会按 chunk 头跳过数据体找 `tRNS`)。
///
/// 为什么必须是头部级而不是像素级:资源卡预览按 8 MiB / 8192 边长 / 3270 万像素上限读取,
/// 逐像素扫描意味着对每张卡都做一次全量 RGBA 解码(真机单栏 51 张、单张均值 591 KB),
/// 成本与「卡面装饰底」的收益完全不成比例;而 alpha 是否存在在容器头部就是确定信息。
///
/// 判据(保守方向一致:判不出就当作不透明,宁可不铺棋盘格):
/// - PNG:颜色类型 4(灰度 + alpha/ 6(真彩 + alpha);0 / 2 / 3 本身没有 alpha 通道,
/// 但可以用 `tRNS` 声明透明色,因此还要在第一个 `IDAT` 之前找一次 `tRNS`
/// - WebP:扩展格式 `VP8X` 的 flags 第 4 位、无损 `VP8L` 位流头的 `alpha_is_used` 位;
/// 简单有损 `VP8 ` 不带 alpha 通道(带 alpha 的有损 WebP 一定走 `VP8X` + `ALPH`);
/// - JPEG:没有 alpha 通道,恒不透明(也绝不为了判 alpha 去扫它的段)。
fn detect_raster_image_has_alpha(bytes: &[u8], media_type: &str) -> bool {
match media_type {
"image/png" => detect_png_has_alpha(bytes),
"image/webp" => detect_webp_has_alpha(bytes),
_ => false,
}
}
fn detect_png_has_alpha(bytes: &[u8]) -> bool {
// 签名 8 字节 + IHDR 长度 4 + "IHDR" 4 + 宽 4 + 高 4 + 位深 1 + 颜色类型 1 = 26。
if bytes.len() < 26 || &bytes[12..16] != b"IHDR" {
return false;
}
if matches!(bytes[25], 4 | 6) {
return true;
}
png_has_transparency_chunk(bytes)
}
/// 按 chunk 头前进并查找 `tRNS`:只读 8 字节 chunk 头并按长度跳过数据体,不做 zlib 解压。
fn png_has_transparency_chunk(bytes: &[u8]) -> bool {
let mut offset = 8usize;
loop {
let Some(header_end) = offset.checked_add(8) else {
return false;
};
if header_end > bytes.len() {
return false;
}
let chunk_type = &bytes[offset + 4..header_end];
// `tRNS` 必须出现在第一个 `IDAT` 之前;碰到 `IDAT` / `IEND` 就没有再往下扫的意义。
if chunk_type == b"tRNS" {
return true;
}
if chunk_type == b"IDAT" || chunk_type == b"IEND" {
return false;
}
let chunk_len =
u32::from_be_bytes(bytes[offset..offset + 4].try_into().unwrap_or([0_u8; 4])) as usize;
let Some(next) = header_end
.checked_add(chunk_len)
.and_then(|value| value.checked_add(4))
else {
return false;
};
if next <= offset || next > bytes.len() {
return false;
}
offset = next;
}
}
fn detect_webp_has_alpha(bytes: &[u8]) -> bool {
if bytes.len() < 16 || &bytes[..4] != b"RIFF" || &bytes[8..12] != b"WEBP" {
return false;
}
match &bytes[12..16] {
// `VP8X` 的 flags 第 4 位(0x10)就是 alpha 标志(第 20 字节)。
b"VP8X" => bytes.get(20).is_some_and(|flags| flags & 0x10 != 0),
// `VP8L` 位流头第 28 位是 `alpha_is_used`,落在第 25 个字节(下标 24)的 0x10 位。
b"VP8L" => bytes.len() >= 25 && bytes[24] & 0x10 != 0,
_ => false,
}
}
#[derive(Clone, Copy)]
enum TiffByteOrder {
LittleEndian,
@@ -745,6 +834,74 @@ mod tests {
.expect("valid 1x1 png")
}
/// PNG 的「签名 + IHDR」头。判据只读这一段的位深 / 颜色类型,因此后续 chunk 由用例自行拼。
fn png_header(color_type: u8) -> Vec<u8> {
png_header_with_size(color_type, 1, 1)
}
fn png_header_with_size(color_type: u8, width: u32, height: u32) -> Vec<u8> {
let mut bytes = b"\x89PNG\r\n\x1a\n".to_vec();
let mut ihdr = Vec::new();
ihdr.extend_from_slice(&width.to_be_bytes());
ihdr.extend_from_slice(&height.to_be_bytes());
ihdr.push(8);
ihdr.push(color_type);
ihdr.extend_from_slice(&[0, 0, 0]);
push_png_chunk(&mut bytes, b"IHDR", &ihdr);
bytes
}
/// 追加一个结构合法(长度、类型、CRC 位置正确)但数据体可以是任意字节的 PNG chunk。
/// alpha 判据不消费 CRC,因此这里填零;正因数据体不必是合法 deflate 流,它同时能证明
/// 判据没有解码像素。
fn push_png_chunk(bytes: &mut Vec<u8>, kind: &[u8; 4], data: &[u8]) {
bytes.extend_from_slice(
&u32::try_from(data.len())
.expect("chunk length")
.to_be_bytes(),
);
bytes.extend_from_slice(kind);
bytes.extend_from_slice(data);
bytes.extend_from_slice(&[0, 0, 0, 0]);
}
/// 扩展格式 WebP`VP8X`):`flags` 第 4 位(0x10)是 alpha 标志。
fn webp_vp8x(flags: u8) -> Vec<u8> {
let mut bytes = b"RIFF".to_vec();
bytes.extend_from_slice(&0_u32.to_le_bytes());
bytes.extend_from_slice(b"WEBP");
bytes.extend_from_slice(b"VP8X");
bytes.extend_from_slice(&10_u32.to_le_bytes());
bytes.push(flags);
bytes.extend_from_slice(&[0, 0, 0]);
bytes.extend_from_slice(&[0, 0, 0]);
bytes.extend_from_slice(&[0, 0, 0]);
bytes
}
/// 无损 WebP`VP8L`):位流头第 28 位是 `alpha_is_used`,落在下标 24 的 0x10 位。
fn webp_vp8l(has_alpha: bool) -> Vec<u8> {
let mut bytes = b"RIFF".to_vec();
bytes.extend_from_slice(&0_u32.to_le_bytes());
bytes.extend_from_slice(b"WEBP");
bytes.extend_from_slice(b"VP8L");
bytes.extend_from_slice(&5_u32.to_le_bytes());
bytes.push(0x2f);
bytes.extend_from_slice(&[0, 0, 0, if has_alpha { 0x10 } else { 0 }]);
bytes
}
/// 简单有损 WebP`VP8 `):容器上没有 alpha 通道;带 alpha 的有损 WebP 一定走
/// `VP8X` 扩展格式(+ `ALPH` chunk)。
fn webp_vp8_simple() -> Vec<u8> {
let mut bytes = b"RIFF".to_vec();
bytes.extend_from_slice(&0_u32.to_le_bytes());
bytes.extend_from_slice(b"WEBP");
bytes.extend_from_slice(b"VP8 ");
bytes.extend_from_slice(&0_u32.to_le_bytes());
bytes
}
fn jpeg_bytes(width: u16, height: u16, app1_payload: Option<&[u8]>) -> Vec<u8> {
let mut bytes = vec![0xff, 0xd8];
if let Some(payload) = app1_payload {
@@ -840,6 +997,138 @@ mod tests {
assert_eq!(preview.media_type, "image/png");
assert_eq!(preview.byte_len, png_bytes().len() as u64);
assert!(preview.data_url.starts_with("data:image/png;base64,"));
// 这份 fixture 是 PNG colorType 4(灰度 + alpha),因此预览必须报「有 alpha」——
// 资源卡据此才铺棋盘格底。
assert!(preview.has_alpha);
}
#[test]
fn png_alpha_follows_color_type_and_transparency_chunk() {
let color_type_alpha = |color_type: u8| {
let mut bytes = png_header(color_type);
push_png_chunk(&mut bytes, b"IDAT", &[0, 0, 0]);
push_png_chunk(&mut bytes, b"IEND", &[]);
detect_raster_image_has_alpha(&bytes, "image/png")
};
// 颜色类型 4(灰度 + alpha)与 6(真彩 + alpha)才带 alpha 通道。
assert!(color_type_alpha(4), "colorType 4 应判为有 alpha");
assert!(color_type_alpha(6), "PNG-32colorType 6)应判为有 alpha");
// 0 / 2 / 3 本身没有 alpha 通道:这是「AI 把棋盘格画进像素里」那张不透明 PNG 的形状。
assert!(!color_type_alpha(0), "colorType 0 不应判为有 alpha");
assert!(
!color_type_alpha(2),
"PNG-24colorType 2)不应判为有 alpha"
);
assert!(
!color_type_alpha(3),
"colorType 3 无 tRNS 时不应判为有 alpha"
);
// 未定义的颜色类型失败关闭为「不透明」,不能把坏文件当成透明。
assert!(!color_type_alpha(7), "未定义 colorType 不应判为有 alpha");
// 灰度 / 真彩 / 调色板可以靠 tRNS 声明透明色,那也是真透明 PNG,必须铺棋盘格。
for color_type in [0_u8, 2, 3] {
let mut bytes = png_header(color_type);
push_png_chunk(&mut bytes, b"tRNS", &[0]);
push_png_chunk(&mut bytes, b"IDAT", &[0, 0, 0]);
push_png_chunk(&mut bytes, b"IEND", &[]);
assert!(
detect_raster_image_has_alpha(&bytes, "image/png"),
"colorType {color_type} + tRNS 也是真透明 PNG"
);
}
// tRNS 规范上必须在 IDAT 之前:出现在之后不再继续扫 chunk(成本有界)。
let mut late_trns = png_header(3);
push_png_chunk(&mut late_trns, b"IDAT", &[0, 0, 0]);
push_png_chunk(&mut late_trns, b"tRNS", &[0]);
push_png_chunk(&mut late_trns, b"IEND", &[]);
assert!(!detect_raster_image_has_alpha(&late_trns, "image/png"));
}
#[test]
fn jpeg_and_webp_alpha_follow_container_flags() {
// JPEG 没有 alpha 通道:恒不透明(也绝不为了判 alpha 去解码扫描段)。
assert!(!detect_raster_image_has_alpha(
&jpeg_bytes(40, 20, None),
"image/jpeg"
));
// 扩展格式 VP8X 的 flags 第 4 位就是 alpha 标志。
assert!(detect_raster_image_has_alpha(
&webp_vp8x(0x10),
"image/webp"
));
assert!(!detect_raster_image_has_alpha(
&webp_vp8x(0x00),
"image/webp"
));
// 只有 ICC0x20/ EXIF0x08)等其它标志时不是 alpha。
assert!(!detect_raster_image_has_alpha(
&webp_vp8x(0x28),
"image/webp"
));
// 无损 VP8L 的 alpha_is_used 位。
assert!(detect_raster_image_has_alpha(
&webp_vp8l(true),
"image/webp"
));
assert!(!detect_raster_image_has_alpha(
&webp_vp8l(false),
"image/webp"
));
// 简单有损格式不带 alpha 通道。
assert!(!detect_raster_image_has_alpha(
&webp_vp8_simple(),
"image/webp"
));
// 头部被截断时失败关闭为「不透明」,且不得 panic。
let truncated_webp = webp_vp8x(0x10);
assert!(!detect_raster_image_has_alpha(
&truncated_webp[..18],
"image/webp"
));
let truncated_png = png_header(6);
assert!(!detect_raster_image_has_alpha(
&truncated_png[..20],
"image/png"
));
}
#[test]
fn alpha_judgement_never_decodes_pixels() {
// 4096×4096 的 PNG-32:真按像素解码要 64 MiB 缓冲,而下面的 IDAT 数据体不是合法
// deflate 流(全零),任何真正的解码器都会失败。判据只看头部,所以这里必须成功,
// 并且仍然判 has_alpha=true —— 这就是「不做全量解码」的可执行证据。
let root = tempfile::tempdir().expect("temp root");
fs::create_dir_all(root.path().join("assets/ui")).expect("asset dir");
let mut bytes = png_header_with_size(6, 4_096, 4_096);
push_png_chunk(&mut bytes, b"IDAT", &[0x00, 0x00, 0x00, 0x00]);
push_png_chunk(&mut bytes, b"IEND", &[]);
fs::write(root.path().join("assets/ui/large.png"), &bytes).expect("large image");
let preview = load_local_project_image_preview(root.path(), "assets/ui/large.png")
.expect("header-only preview");
assert_eq!(preview.pixel_width, 4_096);
assert_eq!(preview.byte_len, bytes.len() as u64);
assert!(preview.has_alpha);
}
#[test]
fn image_preview_serializes_alpha_flag_for_the_shell() {
let root = tempfile::tempdir().expect("temp root");
fs::create_dir_all(root.path().join("assets/ui")).expect("asset dir");
fs::write(root.path().join("assets/ui/prototype.png"), png_bytes()).expect("image");
let preview = load_local_project_image_preview(root.path(), "assets/ui/prototype.png")
.expect("load project preview");
// 前端按 camelCase 读 `hasAlpha``ProjectResourceCardPreviewTransportPayload`);
// 字段名或大小写改了会让资源卡永远退回纯色底,所以这里钉住 IPC 契约。
let serialized = serde_json::to_value(&preview).expect("serialize preview");
assert_eq!(serialized["hasAlpha"], serde_json::json!(true));
}
#[test]
@@ -244,6 +244,7 @@ macro_rules! app_log {
// 用 #[cfg] 编译期门控:仅开发(debug)且非测试构建编入;生产 release 与 cargo test 下整体剔除。
mod agent;
mod agent_native_tools;
mod asset_generation_tasks;
mod assets;
mod browser;
mod builtin_plugins;
@@ -289,6 +290,7 @@ mod windows;
use agent::*;
use agent_native_tools::*;
use asset_generation_tasks::*;
use assets::*;
use browser::*;
use cli::*;
@@ -2736,6 +2738,8 @@ fn main() {
ensure_ui_design_resource_for_prototype,
generate_platform_art_asset,
generate_local_project_asset,
start_local_project_asset_generation,
list_local_project_asset_generations,
open_canvas_project,
get_game_creation_agent_capabilities,
get_limited_local_commands,
@@ -265,11 +265,11 @@ pub fn inspect_separation_recovery(
}
pub fn finalize_separation(root: &Path, asset_id: &str) -> Result<(), String> {
remove_separation_state(root, asset_id)
remove_separation_recovery_files(root, asset_id)
}
pub fn discard_separation_recovery(root: &Path, asset_id: &str) -> Result<(), String> {
remove_separation_state(root, asset_id)
remove_separation_recovery_files(root, asset_id)
}
fn remove_separation_state(root: &Path, asset_id: &str) -> Result<(), String> {
@@ -281,6 +281,33 @@ fn remove_separation_state(root: &Path, asset_id: &str) -> Result<(), String> {
}
}
fn remove_separation_recovery_files(root: &Path, asset_id: &str) -> Result<(), String> {
let sidecar = separation_sidecar_dir(root, asset_id)?;
remove_separation_state(root, asset_id)?;
let entries = match fs::read_dir(&sidecar) {
Ok(entries) => entries,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(()),
Err(error) => return Err(format!("读取 separation 临时文件失败:{error}")),
};
for entry in entries {
let entry = entry.map_err(|error| format!("读取 separation 临时文件失败:{error}"))?;
let name = entry.file_name();
let name = name.to_string_lossy();
if name.starts_with("processed-") || name.starts_with("binding-") {
let path = entry.path();
if entry
.file_type()
.map_err(|error| format!("检查 separation 临时文件失败:{error}"))?
.is_file()
{
fs::remove_file(&path)
.map_err(|error| format!("删除 separation 临时文件失败:{error}"))?;
}
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -0,0 +1,130 @@
/*
* 「设置素材类型」面板的弹窗骨架、纵向单选列表与信息浮层的类型入口。
*
* 单独一个文件而不是塞进 styles.css:与「编辑素材标签」面板当初同样的理由 ——
* 这份样式只服务本次的素材类型入口,与工作台其它区块没有共享选择器,独立文件让改动
* 边界更清楚,也不会与同一时段其它 Agent 在 styles.css 里的编辑互相踩。
*
* 骨架沿用「编辑素材标签」那套三段式契约(`auto / minmax(0, 1fr)`):标题常驻、
* 中间一行可压缩、`max-height` 兜住上界。类型面板没有底部按钮,所以只有两行。
*/
.game-resource-type-dialog {
width: min(480px, 100%);
max-height: min(720px, calc(100dvh - 40px));
grid-template-rows: auto minmax(0, 1fr);
}
/*
* body 分三段:提示 / 选项列表 / 错误提示。
*
* `min-height: 0` 是网格项能被 `1fr` 压缩的前提;**滚动不在这里**——滚动权交给选项列表
* (见下),否则往下滚时素材名和错误提示会跟着跑掉,用户看不到"改的是哪件素材、为什么失败"。
*/
.game-resource-type-body {
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
gap: 10px;
min-height: 0;
}
/*
* 类型选项之上的一句短提示。只说这一屏要选什么,不写规则说明或开发解释。
*/
.game-resource-type-hint {
margin: 0;
color: var(--platform-text-base);
font-size: 12px;
}
/*
* 纵向单选列表(`role="radiogroup"`):**一行一个选项**。
*
* 之前 6 项横排在一条里(`PlatformSegmentedTabs` 的 3~6 列网格),窄屏上互相叠字读不出来。
* 单列网格 + 按行流向是"每项一行、互不重叠"的充分条件:只声明一列,6 个子元素必然上下排 6 行,
* 不存在两项挤一行的可能。选项多时列表自己滚(`max-height` + `overflow-y: auto`),
* 面板不会被撑高。移动端优先:360px 宽的窄屏同样是这一套声明(没有按宽度改列数的媒体查询)。
*/
.game-resource-type-options {
display: grid;
grid-template-columns: minmax(0, 1fr);
grid-auto-flow: row;
align-content: start;
gap: 6px;
min-height: 0;
max-height: min(320px, 40dvh);
overflow-y: auto;
overscroll-behavior: contain;
scrollbar-gutter: stable;
}
/*
* 单个选项行:复用共享的 `PlatformNavigableListItem` 骨架(w-full / flex / text-left /
* 圆角 / 悬停 / 焦点环都由它给),这里只补"整行可点 + 明确选中态"的表现。
*
* `width/min-width` 显式写出来,不依赖共享件里的 Tailwind `w-full`:这一行是不是满宽
* 决定了"一项一行"能不能成立,不能挂在另一份文件的工具类上。
* `min-height: 44px` 是移动端点击热区下限;`overflow-wrap` 让长选项名在窄屏换行而不是溢出。
*/
.game-resource-type-option {
width: 100%;
min-width: 0;
min-height: 44px;
padding: 8px 12px;
border: 1px solid var(--platform-subpanel-border);
background: rgb(255 255 255 / 62%);
color: var(--platform-text-base);
font-size: 13px;
font-weight: 600;
overflow-wrap: anywhere;
}
.game-resource-type-option:hover:not(:disabled) {
border-color: var(--platform-surface-hover-border);
}
/*
* 选中态完全由 `aria-checked="true"` 驱动:视觉与读屏读的是同一个属性,不会各说一套。
*
* 选择器显式提权到 (0,3,0) 以上:共享列表行自带的 `.platform-navigable-list-item:hover:not(:disabled)`
* 也是 (0,3,0),只写 `.game-resource-type-option[aria-checked='true']`(0,2,0))会在悬停时
* 被它的底色顶掉;带 `:hover:not(:disabled)` 的那条 (0,5,0) 保证选中行悬停时也不变色。
*/
.game-resource-type-options .game-resource-type-option[aria-checked='true'],
.game-resource-type-options
.game-resource-type-option[aria-checked='true']:hover:not(:disabled) {
border-color: var(--platform-warm-border);
background: var(--platform-warm-bg);
color: var(--platform-text-strong);
}
.game-resource-type-error {
margin: 0;
color: #b3261e;
font-size: 11px;
}
/*
* 第二入口:信息浮层「分类」行右侧的入口按钮。
*
* 放在 `dd` **外面**:信息字段的读取口径(`dt` / `dd` 文本逐行比对)在两处共用,
* 把按钮塞进 `dd` 会让分类值变成「角色与对象设置」这类拼接文案。
*/
.game-resource-info-field-action {
align-self: start;
margin-left: auto;
padding: 0 6px;
border: 1px solid var(--platform-subpanel-border);
border-radius: 8px;
background: transparent;
color: var(--platform-text-base);
font-size: 11px;
line-height: 20px;
cursor: pointer;
}
.game-resource-info-field-action:hover,
.game-resource-info-field-action:focus-visible {
border-color: var(--platform-surface-hover-border);
background: var(--platform-warm-bg);
color: var(--platform-text-strong);
}
@@ -22,24 +22,47 @@ export type ResourceCanvasAssetGenerationSubmitInput = {
imageSize: string;
};
export type ResourceCanvasAssetGenerationPanelViewProps = {
action: ResourceCanvasAssetToolAction;
onSubmit: (input: ResourceCanvasAssetGenerationSubmitInput) => Promise<void>;
onClose: () => void;
/** 提交面板的草稿:点击即关闭之后,只有「即时失败」重开时才需要把这份草稿带回来。 */
export type ResourceCanvasAssetGenerationPanelDraft = {
prompt: string;
assetName: string;
aspectRatio: string;
imageSize: string;
};
function assetGenerationErrorMessage(error: unknown) {
if (typeof error === 'string' && error.trim()) return error;
if (error instanceof Error && error.message) return error.message;
return '生成素材失败';
}
export type ResourceCanvasAssetGenerationPanelViewProps = {
action: ResourceCanvasAssetToolAction;
/**
* 上一次「点击瞬间就失败」带回来的草稿。
*
* 面板点击即关闭,草稿只活在组件里;重开时由宿主把它传回来,用户改完就能重试。
*/
draft?: ResourceCanvasAssetGenerationPanelDraft;
/** 上一次即时失败的原因;重开时直接以 `role="alert"` 呈现。 */
error?: string | null;
/**
* 提交回调:**同步返回**,面板不等它的结果。
*
* 受理失败要不要把面板带回来由宿主决定(只有「从未被后端受理」的即时失败才重开),
* 面板自己不持有任何在途状态。
*/
onSubmit: (input: ResourceCanvasAssetGenerationSubmitInput) => void;
onClose: () => void;
};
/**
* 栏目画布底部工具栏的图片类生成浮层(生成图片 / 生成规范 / 生成角色形象 / 生成图标素材 /
* 生成 UI 设计图共用)。
*
* 形态是独立弹层(`ThemedModal`,与既有「生成素材」面板同一套宿主 chrome),不在任何现有
* 面板下面追加内容;提交链路与结果定位由宿主 `index.tsx` 负责,面板只持有草稿与失败状态
* 面板下面追加内容;提交链路与结果定位由宿主 `index.tsx` 负责。
*
* **点击「生成」即关闭面板**:不等 IPC、不等排队、不等生成结束,用户立刻回到画布。所以面板里
* 不存在「排队中。」「正在生成。」「提交中…」这类阶段文案——阶段文案的唯一去处是画布上的
* 「生成任务」侧栏与工具栏提示条。关闭**不等于**取消:任务照常在后台跑完并把结果写回项目。
*
* 只有「点击瞬间就失败」(校验 / 权限拒绝 / IPC 立即报错,即后端从未受理)时,宿主才会带着
* `draft` 与 `error` 把面板重新打开,用户可以直接改后重试。
*
* 比例 / 尺寸选项来自网页端美术画布的纯模型(`ImageCanvasGenerationModel.ts`)经本地 IPC
* 白名单收窄后的子集:网页端面板会渲染 `4:3`,而本地通道明确拒绝它,照搬就是一个点了必
@@ -48,57 +71,52 @@ function assetGenerationErrorMessage(error: unknown) {
*/
export function ResourceCanvasAssetGenerationPanelView({
action,
draft,
error: initialError,
onSubmit,
onClose,
}: ResourceCanvasAssetGenerationPanelViewProps) {
const [prompt, setPrompt] = useState('');
const [assetName, setAssetName] = useState(action.assetName);
const [aspectRatio, setAspectRatio] = useState(action.aspectRatio);
const [imageSize, setImageSize] = useState(action.imageSize);
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
const [prompt, setPrompt] = useState(draft?.prompt ?? '');
const [assetName, setAssetName] = useState(
draft?.assetName ?? action.assetName,
);
const [aspectRatio, setAspectRatio] = useState(
draft?.aspectRatio ?? action.aspectRatio,
);
const [imageSize, setImageSize] = useState(
draft?.imageSize ?? action.imageSize,
);
const [error, setError] = useState<string | null>(initialError ?? null);
// 提示词上限复用资源编辑模型的同一份口径:图片类入口默认 32000,与 Rust
// `LOCAL_PROJECT_ASSET_MAX_PROMPT_CHARS` 一致,不在面板里另抄常量。
const promptMaxLength = resourceEditPromptMaxLength('image-reference');
const canSubmit =
!submitting && prompt.trim().length > 0 && assetName.trim().length > 0;
const canSubmit = prompt.trim().length > 0 && assetName.trim().length > 0;
async function submit(event: FormEvent<HTMLFormElement>) {
function submit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const normalizedPrompt = prompt.trim();
const normalizedAssetName = assetName.trim();
if (!normalizedPrompt || !normalizedAssetName || submitting) {
if (!normalizedPrompt || !normalizedAssetName) {
return;
}
setSubmitting(true);
setError(null);
try {
await onSubmit({
kind: action.assetKind,
prompt: normalizedPrompt,
assetName: normalizedAssetName,
aspectRatio,
imageSize,
});
} catch (submitError) {
// 成功路径由宿主卸载面板;失败保留草稿,用户可直接用同一份输入重试。
setError(assetGenerationErrorMessage(submitError));
} finally {
setSubmitting(false);
}
// 点击即关闭:不等 IPC、不等排队、不等生成结束。失败要不要把面板带回来由宿主决定
// (只有「从未被后端受理」的即时失败才重开并带回草稿),面板不持有在途状态。
onSubmit({
kind: action.assetKind,
prompt: normalizedPrompt,
assetName: normalizedAssetName,
aspectRatio,
imageSize,
});
onClose();
}
return (
<ThemedModal
open
ariaLabel={action.label}
closeOnBackdrop={!submitting}
closeOnEscape={!submitting}
onClose={() => {
if (!submitting) {
onClose();
}
}}
onClose={onClose}
panelClassName="game-approval-dialog game-resource-generation-dialog"
>
<header>
@@ -108,7 +126,6 @@ export function ResourceCanvasAssetGenerationPanelView({
<button
type="button"
aria-label={`关闭${action.label}`}
disabled={submitting}
onClick={onClose}
>
<X size={16} aria-hidden="true" />
@@ -120,7 +137,6 @@ export function ResourceCanvasAssetGenerationPanelView({
<PlatformTextField
aria-label="素材名称"
maxLength={120}
disabled={submitting}
value={assetName}
onChange={(event) => setAssetName(event.currentTarget.value)}
/>
@@ -132,7 +148,6 @@ export function ResourceCanvasAssetGenerationPanelView({
aria-label="生成提示词"
rows={6}
autoFocus
disabled={submitting}
maxLength={promptMaxLength}
placeholder={action.promptPlaceholder}
value={prompt}
@@ -152,7 +167,6 @@ export function ResourceCanvasAssetGenerationPanelView({
columns="threeToSix"
gap="sm"
size="compact"
disabled={submitting}
onChange={setAspectRatio}
/>
<PlatformSegmentedTabs
@@ -166,7 +180,6 @@ export function ResourceCanvasAssetGenerationPanelView({
columns="three"
gap="sm"
size="compact"
disabled={submitting}
onChange={setImageSize}
/>
</div>
@@ -182,7 +195,6 @@ export function ResourceCanvasAssetGenerationPanelView({
subject={`素材生成提示词(${action.label}`}
editKind="image-reference"
prompt={prompt}
disabled={submitting}
applyPrompt={setPrompt}
/>
{error ? (
@@ -194,14 +206,13 @@ export function ResourceCanvasAssetGenerationPanelView({
<PlatformActionButton
type="button"
tone="secondary"
disabled={submitting}
onClick={onClose}
>
</PlatformActionButton>
<PlatformActionButton type="submit" disabled={!canSubmit}>
<Sparkles size={15} aria-hidden="true" />
{submitting ? '生成中…' : action.label}
{action.label}
</PlatformActionButton>
</div>
</form>
@@ -0,0 +1,293 @@
import './resourceCanvasAssetGenerationTasksSidebar.css';
import { ListChecks, X } from 'lucide-react';
import { useEffect, useMemo, useRef, useState } from 'react';
import {
RESOURCE_CANVAS_ASSET_GENERATION_STATUS_LABELS,
resourceCanvasAssetGenerationElapsedLabel,
type ResourceCanvasAssetGenerationTask,
resourceCanvasAssetGenerationTaskElapsedMillis,
resourceCanvasAssetGenerationTaskIsTerminal,
resourceCanvasAssetGenerationTaskTone,
sortResourceCanvasAssetGenerationTasks,
} from './resourceCanvasAssetGenerationTaskModel';
/** 「已完成」分栏的展示上限:触顶后只提示还有多少条,不无限拉长侧栏。 */
export const RESOURCE_CANVAS_ASSET_GENERATION_DONE_SECTION_LIMIT = 20;
/**
* 收起动画时长,必须与 `resourceCanvasAssetGenerationTasksSidebar.css` 里的
* `game-resource-generation-tasks-leave` 一致:收起时侧栏要先播完这一段再卸载。
*/
export const RESOURCE_CANVAS_ASSET_GENERATION_TASKS_LEAVE_MILLIS = 160;
export type ResourceCanvasAssetGenerationTasksPanelViewProps = {
tasks: readonly ResourceCanvasAssetGenerationTask[];
/** 侧栏是否展开;折叠时只留贴边把手。 */
open: boolean;
onToggleOpen: () => void;
/** 定位到该任务产出的素材卡(宿主复用既有 `pendingResourceFocusRef` 聚焦链)。 */
onFocusTask: (task: ResourceCanvasAssetGenerationTask) => void;
};
function taskRow(
task: ResourceCanvasAssetGenerationTask,
nowMillis: number,
onFocusTask: (task: ResourceCanvasAssetGenerationTask) => void,
) {
const focusable = task.status === 'completed' && Boolean(task.assetId);
return (
<li
key={task.taskId}
className="game-resource-generation-task-card"
data-task-status={task.status}
>
<div className="game-resource-generation-task-card-title-row">
<strong className="game-resource-generation-task-card-name">
{task.assetName}
</strong>
<span className="game-resource-generation-task-card-action">
{task.actionLabel}
</span>
</div>
<div className="game-resource-generation-task-card-meta">
<span
className="game-resource-generation-task-badge"
data-tone={resourceCanvasAssetGenerationTaskTone(task.status)}
>
{RESOURCE_CANVAS_ASSET_GENERATION_STATUS_LABELS[task.status]}
</span>
<span className="game-resource-generation-task-card-phase">
{task.phaseDetail}
</span>
<span className="game-resource-generation-task-card-elapsed">
{`已耗时 ${resourceCanvasAssetGenerationElapsedLabel(
resourceCanvasAssetGenerationTaskElapsedMillis(task, nowMillis),
)}`}
</span>
</div>
{task.error ? (
<p className="game-resource-generation-task-card-error" role="alert">
{task.error}
</p>
) : null}
{focusable ? (
<button
type="button"
className="game-resource-generation-task-locate"
aria-label={`定位素材 ${task.assetName}`}
onClick={() => onFocusTask(task)}
>
</button>
) : null}
</li>
);
}
/**
* 画布上的「生成任务」侧栏(常驻、可折叠、非模态)。
*
* 形态对齐网页端美术画布的任务侧栏:贴边的独立 `<aside>`,展开时是一列任务(画布照常可交互),
* 折叠时只留一个可点的贴边把手(带在途数量角标)。它**不是**模态浮层:不铺全屏遮罩、不做焦点
* 陷阱、不进 `isResourceCanvasFloatingPanelOpen` / `resourceCanvasHostGenerationPanelOpen` 的
* 遮挡判据;折叠也不影响任务推进——任务活在账本与本地队列里,与这个视图的生命周期无关。
*
* 位置取舍:AGC 栏目画布的右侧是「智能创作」对话面板、底部是栏目工具栏、顶部是栏目标题栏,所以
* 侧栏挂在**左侧、标题栏之下、工具栏之上**,并且是**覆盖式**而不是把画布挤窄(画布的视口数学与
* 资源卡排布都不被 reflow 动到,收起即完全让出画布)。宽度 300px 落在 280–340px 区间内。
*
* 分栏、条数、封顶、折叠语义都在这里;颜色与排版在同目录的 CSS 文件里,取值全部走
* `--platform-*` 设计 token。
*/
export function ResourceCanvasAssetGenerationTasksPanelView({
tasks,
open,
onToggleOpen,
onFocusTask,
}: ResourceCanvasAssetGenerationTasksPanelViewProps) {
const [nowMillis, setNowMillis] = useState(() => Date.now());
/**
* 收起动画期:`open` 已经变 false,但侧栏还要留在 DOM 里把 `…-leave` 播完
* `entering` 是刚打开时给根节点挂进场动画的那一档)。
*/
const [phase, setPhase] = useState<'idle' | 'entering' | 'leaving'>(
open ? 'entering' : 'idle',
);
const inFlightCount = tasks.filter(
(task) => !resourceCanvasAssetGenerationTaskIsTerminal(task),
).length;
const hasLiveTask = inFlightCount > 0;
const ordered = useMemo(
() => sortResourceCanvasAssetGenerationTasks(tasks),
[tasks],
);
const active = ordered.filter(
(task) => !resourceCanvasAssetGenerationTaskIsTerminal(task),
);
const done = ordered.filter((task) =>
resourceCanvasAssetGenerationTaskIsTerminal(task),
);
const visibleDone = done.slice(
0,
RESOURCE_CANVAS_ASSET_GENERATION_DONE_SECTION_LIMIT,
);
/**
* 收起动画期间必须沿用最后一份列表:宿主会在同一帧里收起侧栏并把「在途」收口成
* 已完成,直接吃新 props 会让退出动画里的内容跳一下。
*/
const lastRenderedRef = useRef({
inFlightCount,
ordered,
active,
visibleDone,
done,
});
if (open) {
lastRenderedRef.current = {
inFlightCount,
ordered,
active,
visibleDone,
done,
};
}
const rendered = open
? { inFlightCount, ordered, active, visibleDone, done }
: lastRenderedRef.current;
// 已耗时是前端计时(后端只给时间戳):只在还有未终态任务时走秒表,全部收口后停掉。
useEffect(() => {
if (!hasLiveTask) {
return undefined;
}
const timer = setInterval(() => setNowMillis(Date.now()), 1_000);
return () => clearInterval(timer);
}, [hasLiveTask]);
/**
* open → 进场,close → 先留一帧播 `…-leave` 再卸载。
*
* 减少动效偏好下这一段动画在 CSS 里被关掉,所以那次收起要**立即**卸载,不能白等 160ms。
*/
useEffect(() => {
if (open) {
setPhase('entering');
return undefined;
}
setPhase((current) => (current === 'idle' ? 'idle' : 'leaving'));
const reducedMotion =
typeof window.matchMedia === 'function' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const timer = window.setTimeout(
() => setPhase('idle'),
reducedMotion ? 0 : RESOURCE_CANVAS_ASSET_GENERATION_TASKS_LEAVE_MILLIS,
);
return () => window.clearTimeout(timer);
}, [open]);
// 折叠态不再在画布左侧留贴边把手:开合口只剩工具条上那一枚「生成任务」按钮
// (带在途计数),收起时侧栏完全让出画布(播完收起动画之后)。
if (!open && phase === 'idle') {
return null;
}
return (
<aside
className={`platform-theme platform-theme--light game-resource-generation-tasks-sidebar${
open ? '' : ' is-leaving'
}`}
role="region"
aria-label="生成任务"
data-resource-generation-task-count={rendered.inFlightCount}
>
<header className="game-resource-generation-tasks-sidebar-header">
<h2 className="game-resource-generation-tasks-sidebar-title">
<ListChecks size={15} aria-hidden="true" />
<span
className="game-resource-generation-tasks-sidebar-count"
aria-label={`在途生成任务 ${rendered.inFlightCount}`}
>
{rendered.inFlightCount}
</span>
</h2>
<button
type="button"
className="game-resource-generation-tasks-sidebar-icon-button"
aria-label="关闭生成任务"
onClick={onToggleOpen}
>
<X size={16} aria-hidden="true" />
</button>
</header>
<div
className="game-resource-generation-tasks-scroll"
data-resource-generation-task-scroll=""
>
{rendered.ordered.length === 0 ? (
<p className="game-resource-generation-tasks-empty" role="status">
</p>
) : (
<>
<section
className="game-resource-generation-tasks-section"
aria-label="排队与生成中"
>
<h3 className="game-resource-generation-tasks-section-title">
<span>/</span>
<span className="game-resource-generation-tasks-section-title-count">
{rendered.active.length}
</span>
</h3>
{rendered.active.length === 0 ? (
<p className="game-resource-generation-tasks-empty">
</p>
) : (
<ul className="game-resource-generation-tasks-list">
{rendered.active.map((task) =>
taskRow(task, nowMillis, onFocusTask),
)}
</ul>
)}
</section>
<section
className="game-resource-generation-tasks-section"
aria-label="已完成"
>
<h3 className="game-resource-generation-tasks-section-title">
<span></span>
<span className="game-resource-generation-tasks-section-title-count">
{rendered.done.length}
</span>
</h3>
{rendered.done.length === 0 ? (
<p className="game-resource-generation-tasks-empty">
</p>
) : (
<>
<ul className="game-resource-generation-tasks-list">
{rendered.visibleDone.map((task) =>
taskRow(task, nowMillis, onFocusTask),
)}
</ul>
{rendered.done.length > rendered.visibleDone.length ? (
<p className="game-resource-generation-tasks-empty">
{`仅显示最近 ${RESOURCE_CANVAS_ASSET_GENERATION_DONE_SECTION_LIMIT} 条,另有 ${
rendered.done.length - rendered.visibleDone.length
} 条较早记录`}
</p>
) : null}
</>
)}
</section>
</>
)}
</div>
</aside>
);
}
@@ -58,6 +58,10 @@ function resourceGenerationErrorMessage(error: unknown) {
* 形态是独立弹层(`ThemedModal`,与资源面板 / 分类面板同一套宿主 chrome),
* 不在任何现有面板下面追加内容;提交链路与结果定位由宿主 `index.tsx` 负责,
* 面板只持有草稿、类型选择与失败重试状态。
*
* 提交期间**不锁关闭**:× / 遮罩 / Esc / 「后台运行并关闭」四条路径都通。关闭只是把这一份
* view 卸下来,宿主那条请求继续跑(它是宿主的 `await onSubmit(...)`,不挂在面板生命周期上),
* 所以关闭**不等于**取消;失败时面板仍保留草稿与同一份请求身份可重试。
*/
export function ResourceCanvasGenerationPanelView({
kinds = RESOURCE_CANVAS_GENERATION_OPTIONS.map((option) => option.kind),
@@ -115,8 +119,8 @@ export function ResourceCanvasGenerationPanelView({
} catch (submitError) {
setError(resourceGenerationErrorMessage(submitError));
} finally {
// 成功路径也要收回在飞标记:宿主现在还靠卸载面板兜底,但组件本身不该
// 在 `onSubmit` 正常 resolve 后永久停在「生成中…」并把关闭路径全部锁住
// 成功路径也要收回在飞标记:宿主随后会卸载面板,但组件本身不该在 `onSubmit` 正常
// resolve 后永久停在「生成中…」;失败时收回标记才能让用户用同一份输入重试
setSubmitting(false);
}
}
@@ -125,13 +129,7 @@ export function ResourceCanvasGenerationPanelView({
<ThemedModal
open
ariaLabel={panelTitle}
closeOnBackdrop={!submitting}
closeOnEscape={!submitting}
onClose={() => {
if (!submitting) {
onClose();
}
}}
onClose={onClose}
panelClassName="game-approval-dialog game-resource-generation-dialog"
>
<header>
@@ -141,7 +139,6 @@ export function ResourceCanvasGenerationPanelView({
<button
type="button"
aria-label={`关闭${panelTitle}`}
disabled={submitting}
onClick={onClose}
>
<X size={16} aria-hidden="true" />
@@ -203,10 +200,9 @@ export function ResourceCanvasGenerationPanelView({
<PlatformActionButton
type="button"
tone="secondary"
disabled={submitting}
onClick={onClose}
>
{submitting ? '后台运行并关闭' : '取消'}
</PlatformActionButton>
{error ? (
<PlatformActionButton type="submit" disabled={submitting}>
@@ -0,0 +1,315 @@
import {
applyLocalProjectAssetGenerationRecords,
type LocalProjectAssetGenerationTaskRecord,
mergeLocalProjectAssetGenerationRecord,
nextResourceCanvasAssetGenerationDispatch,
type ResourceCanvasAssetGenerationTask,
} from './resourceCanvasAssetGenerationTaskModel';
export const RESOURCE_CANVAS_ASSET_GENERATION_POLL_INTERVAL_MILLIS = 2_000;
/**
* 账本里连续多少次找不到这条任务就放弃等待。
*
* 非终态记录一直存在时不能设上限(图片类生成最长 35 分钟),但记录**消失**是完全另一回事
* (账本被删、项目被换掉),继续轮询只会永远转下去。
*/
export const RESOURCE_CANVAS_ASSET_GENERATION_MISSING_RECORD_POLL_LIMIT = 15;
/** 账本读回的形状不合法(`undefined` / 非数组)时的原因文案。 */
export const RESOURCE_CANVAS_ASSET_GENERATION_MALFORMED_READ_ERROR =
'生成任务状态返回值不是数组';
/**
* 一次提交的终局。
*
* `record` 是后端账本里那条终态记录;任务连后端都没进去(IPC 抛错、后端拒绝入参)时为
* `null`,此时 `error` 带着原因。
*/
export type ResourceCanvasAssetGenerationSettlement = {
taskId: string;
/**
* 该任务所属项目。
*
* 宿主必须按它判断「这条终局还属不属于当前打开的项目」:任务可以跨项目切换收尾,拿当前项目
* 的路径去刷新另一个项目的清单是错的。
*/
projectId: string;
status: 'completed' | 'failed';
record: LocalProjectAssetGenerationTaskRecord | null;
error: string | null;
};
export type ResourceCanvasAssetGenerationQueueDeps = {
invoke(command: string, args: Record<string, unknown>): Promise<unknown>;
/**
* 当前项目路径。
*
* 队列实例要跨渲染保持同一份(`draining` 是它的内部状态),所以路径不能靠闭包捕获,
* 只能在派发那一刻从宿主当前值读。
*/
projectPath(): string;
/** 提交前的平台会话刷新(与既有生成入口同一条前置动作)。 */
refreshPlatformSession?: <T>(operation: () => Promise<T>) => Promise<T>;
listTasks(): readonly ResourceCanvasAssetGenerationTask[];
replaceTask(task: ResourceCanvasAssetGenerationTask): void;
onSettled(
settlement: ResourceCanvasAssetGenerationSettlement,
): void | Promise<void>;
pollIntervalMillis?: number;
wait?: (millis: number) => Promise<void>;
nowMillis?: () => number;
};
export type ResourceCanvasAssetGenerationQueue = {
/**
* 入队并推进。
*
* resolve = 该任务已终态(成功);reject = 失败(含后端拒绝入参)。面板据此保留草稿可重试。
* 排在别的在途任务后面的提交会先在本地队列里等,**不发 IPC**——这是本批的**提交节流**:
* AGC 本地 durable 输出槽已按精确动作指纹分槽,不同 prompt / 素材名可以同时在途,所以排队
* 不再是「远端会拒绝并发」的被迫行为;真并行派发需要并发收口设计(配对读 + manifest CAS +
* 聚焦意图互不覆盖),留待下一批。
*/
submit(task: ResourceCanvasAssetGenerationTask): Promise<void>;
/** 推进已有队列(宿主挂载 / 重开项目恢复任务时调一次)。 */
drain(): void;
};
function errorMessage(error: unknown) {
if (typeof error === 'string' && error.trim()) return error;
if (error instanceof Error && error.message) return error.message;
return '生成素材失败';
}
function isTerminalStatus(status: string) {
return status === 'completed' || status === 'failed';
}
type SettlementWaiter = {
resolve: () => void;
reject: (error: Error) => void;
};
/**
* 本地排队 + 后端任务账本的驱动器。
*
* 顺序上只有一条规则:**下一条必须等上一条终态**(本批的提交节流,见 `submit`);上一条结束
* (成功或失败)后由同一个循环自动补发。派发之后不再由前端猜进度:状态与阶段文案一律来自
* `list_local_project_asset_generations` 返回的后端记录。
*/
export function createResourceCanvasAssetGenerationQueue(
deps: ResourceCanvasAssetGenerationQueueDeps,
): ResourceCanvasAssetGenerationQueue {
const pollIntervalMillis =
deps.pollIntervalMillis ??
RESOURCE_CANVAS_ASSET_GENERATION_POLL_INTERVAL_MILLIS;
const wait =
deps.wait ??
((millis: number) =>
new Promise<void>((resolve) => {
setTimeout(resolve, millis);
}));
const nowMillis = deps.nowMillis ?? (() => Date.now());
const waiters = new Map<string, SettlementWaiter[]>();
let draining = false;
function settleWaiters(settlement: ResourceCanvasAssetGenerationSettlement) {
const pending = waiters.get(settlement.taskId);
if (!pending) {
return;
}
waiters.delete(settlement.taskId);
for (const waiter of pending) {
if (settlement.status === 'completed') {
waiter.resolve();
} else {
waiter.reject(new Error(settlement.error ?? '生成素材失败'));
}
}
}
function replaceFromRecord(
task: ResourceCanvasAssetGenerationTask,
record: LocalProjectAssetGenerationTaskRecord,
) {
deps.replaceTask(mergeLocalProjectAssetGenerationRecord(task, record));
}
async function dispatch(
task: ResourceCanvasAssetGenerationTask,
): Promise<ResourceCanvasAssetGenerationSettlement> {
const projectPath = deps.projectPath();
// 命令名写成字面量:`scripts/check-config.mjs` 的 invoke 门禁按字符串字面量登记调用方,
// 抽成常量会让这两条 IPC 被判成「没有前端调用方」。
const start = async () =>
(await deps.invoke('start_local_project_asset_generation', {
projectPath,
projectId: task.projectId,
taskId: task.taskId,
kind: task.assetKind,
prompt: task.prompt,
aspectRatio: task.aspectRatio,
imageSize: task.imageSize,
assetName: task.assetName,
outputPath: task.outputPath,
})) as LocalProjectAssetGenerationTaskRecord;
let started: LocalProjectAssetGenerationTaskRecord;
try {
started = await (deps.refreshPlatformSession
? deps.refreshPlatformSession(start)
: start());
} catch (error) {
return {
taskId: task.taskId,
projectId: task.projectId,
status: 'failed',
record: null,
error: errorMessage(error),
};
}
replaceFromRecord(task, started);
let missingRecordPolls = 0;
let readFailed = false;
let lastReadError = RESOURCE_CANVAS_ASSET_GENERATION_MALFORMED_READ_ERROR;
for (;;) {
let records: LocalProjectAssetGenerationTaskRecord[];
try {
records = (await deps.invoke('list_local_project_asset_generations', {
projectPath,
})) as LocalProjectAssetGenerationTaskRecord[];
} catch (error) {
// IPC 拒绝(未注册 / 权限拒绝 / 账本读坏):按「本轮读不到」处理,绝不把拒绝往上抛——
// 派发循环是 `void (async …)()`,抛出去就是未处理的 Promise 拒绝。
records = [];
readFailed = true;
lastReadError = errorMessage(error);
}
if (!Array.isArray(records)) {
records = [];
readFailed = true;
lastReadError = RESOURCE_CANVAS_ASSET_GENERATION_MALFORMED_READ_ERROR;
}
const record = records.find((item) => item.taskId === task.taskId);
if (record) {
missingRecordPolls = 0;
readFailed = false;
replaceFromRecord(task, record);
if (isTerminalStatus(record.status)) {
return {
taskId: task.taskId,
projectId: task.projectId,
status: record.status === 'completed' ? 'completed' : 'failed',
record,
error: record.error,
};
}
} else {
missingRecordPolls += 1;
if (
missingRecordPolls >=
RESOURCE_CANVAS_ASSET_GENERATION_MISSING_RECORD_POLL_LIMIT
) {
// 「读不到通道」与「读到数组但没有这条」是两件事,文案必须能区分:前者是账本不可用,
// 后者是记录被账本上限淘汰或项目被换掉。
return {
taskId: task.taskId,
projectId: task.projectId,
status: 'failed',
record: null,
error: readFailed
? `生成任务状态读取失败,已停止等待:${lastReadError}`
: '生成任务账本里已找不到这条任务,已停止等待',
};
}
}
await wait(pollIntervalMillis);
}
}
function markSettled(settlement: ResourceCanvasAssetGenerationSettlement) {
const settled = deps
.listTasks()
.find((task) => task.taskId === settlement.taskId);
if (!settled || isTerminalStatus(settled.status)) {
return;
}
// 连后端都没进去的任务(record === null)也必须收口为终态:留在「已派发但未终态」
// 会让本地队列认为还有在途任务,后面的排队任务永远补发不出去。
deps.replaceTask({
...settled,
status: settlement.status,
phaseDetail:
settlement.record?.phaseDetail ??
`生成失败:${settlement.error ?? '未知原因'}`,
error: settlement.error,
finishedAtMillis: settlement.record?.finishedAtMillis ?? nowMillis(),
});
}
function drain(): void {
if (draining) {
return;
}
draining = true;
void (async () => {
try {
for (;;) {
const next = nextResourceCanvasAssetGenerationDispatch(
deps.listTasks(),
);
if (!next) {
return;
}
deps.replaceTask({ ...next, dispatched: true });
let settlement: ResourceCanvasAssetGenerationSettlement;
try {
settlement = await dispatch(next);
} catch (error) {
// `dispatch` 已经把可预期的失败(提交失败 / 账本读失败 / 记录丢失)收口成
// settlement;这里是最后一道兜底:任何意外抛出都不能变成未处理的 Promise 拒绝,
// 也不能让这条任务永远停在「已派发但未终态」把后面的排队任务卡死。
settlement = {
taskId: next.taskId,
projectId: next.projectId,
status: 'failed',
record: null,
error: errorMessage(error),
};
}
markSettled(settlement);
settleWaiters(settlement);
try {
await deps.onSettled(settlement);
} catch {
// 宿主收尾(配对读清单 / 提示条)失败不改变任务终局,也不能打断队列:
// 任务本身的状态已经写进列表并通知了等待者。
}
}
} finally {
draining = false;
}
})();
}
return {
submit(task) {
deps.replaceTask(task);
const promise = new Promise<void>((resolve, reject) => {
const pending = waiters.get(task.taskId) ?? [];
waiters.set(task.taskId, [...pending, { resolve, reject }]);
});
drain();
return promise;
},
drain,
};
}
/** 用后端记录刷新整个任务列表(重开项目后恢复历史任务时用)。 */
export function mergeResourceCanvasAssetGenerationTasksWithRecords(
tasks: readonly ResourceCanvasAssetGenerationTask[],
records: readonly LocalProjectAssetGenerationTaskRecord[],
): ResourceCanvasAssetGenerationTask[] {
return applyLocalProjectAssetGenerationRecords(tasks, records);
}
@@ -0,0 +1,328 @@
import {
resolveResourceCanvasBottomTools,
type ResourceCanvasAssetToolAction,
resourceCanvasBottomToolActions,
} from './resourceCanvasBottomToolbarModel';
/** 一条生成任务在宿主里的状态。`queued` 包含「本地排队」和「后端排队」两种来源。 */
export type ResourceCanvasAssetGenerationTaskStatus =
| 'queued'
| 'running'
| 'completed'
| 'failed';
/**
* Rust 账本里的一条记录(`list_local_project_asset_generations` 的元素)。
*
* `phaseDetail` **由后端拥有**:前端只渲染这个字符串,不自己拼阶段或造百分比进度。
*/
export type LocalProjectAssetGenerationTaskRecord = {
taskId: string;
projectId: string;
kind: string;
assetName: string;
status: string;
phaseDetail: string;
createdAtMillis: number;
startedAtMillis: number | null;
finishedAtMillis: number | null;
assetId: string | null;
error: string | null;
};
/** 宿主「生成任务」列表里的一条:本地排队信息 + 后端账本记录。 */
export type ResourceCanvasAssetGenerationTask = {
/** 本地任务 id,同时作为提交给后端的 taskId(重开项目后靠它对上账本记录)。 */
taskId: string;
actionId: string;
actionLabel: string;
assetKind: string;
assetName: string;
prompt: string;
aspectRatio: string;
imageSize: string;
outputPath: string | null;
projectId: string;
/** 是否已经把这次提交交给后端。未派发的任务只活在本地队列里。 */
dispatched: boolean;
status: ResourceCanvasAssetGenerationTaskStatus;
phaseDetail: string;
createdAtMillis: number;
startedAtMillis: number | null;
finishedAtMillis: number | null;
assetId: string | null;
error: string | null;
/** 从账本恢复出来的历史任务(本地没有对应的草稿)。 */
restored: boolean;
};
export const RESOURCE_CANVAS_ASSET_GENERATION_STATUS_LABELS: Record<
ResourceCanvasAssetGenerationTaskStatus,
string
> = {
queued: '排队中',
running: '生成中',
completed: '已完成',
failed: '失败',
};
/**
* 状态 → 视觉 tone(中性 / 品牌 / 成功 / 危险)。
*
* 放在模型层而不是组件层有两个原因:① 它是纯映射,组件不该自己发明颜色语义;
* ② 组件文件只导出组件与常量(`react-refresh/only-export-components`),导出函数会破坏热更新边界。
* 具体样式在 `resourceCanvasAssetGenerationTasksSidebar.css` 里按 `[data-tone=…]` 落地,映射由测试钉住。
*/
export type ResourceCanvasAssetGenerationTaskTone =
| 'queued'
| 'running'
| 'completed'
| 'failed';
export function resourceCanvasAssetGenerationTaskTone(
status: ResourceCanvasAssetGenerationTaskStatus,
): ResourceCanvasAssetGenerationTaskTone {
return status;
}
/**
* 本地排队的阶段文案。
*
* 只有**还没交给后端**的那条任务会用到它:单值槽换成任务列表后,第二条提交在前一条终态
* 之前不发 IPC(见 `nextResourceCanvasAssetGenerationDispatch`),所以它在后端账本里不
* 存在,没有后端阶段可渲染。一旦派发,阶段文案一律改由后端 `phaseDetail` 提供。
*/
export const RESOURCE_CANVAS_ASSET_GENERATION_LOCAL_QUEUE_PHASE = '排队中。';
const RESOURCE_CANVAS_ASSET_GENERATION_CATEGORIES = [
'ui-interaction',
'character',
'scene',
] as const;
/**
* 图片类生成 kind → 入口文案。
*
* 从工具栏模型派生而不是另抄一张表:kind 白名单只有一份(`resourceCanvasBottomToolbarModel`),
* 抄第二份就会在加 kind 时漂移。同一 kind 出现在多个入口时取首次出现的那个。
*/
export function resourceCanvasAssetGenerationKindLabel(
kind: string,
): string | null {
for (const category of RESOURCE_CANVAS_ASSET_GENERATION_CATEGORIES) {
for (const tool of resolveResourceCanvasBottomTools(category)) {
for (const action of resourceCanvasBottomToolActions(tool)) {
if (action.route === 'asset' && action.assetKind === kind) {
return action.label;
}
}
}
}
return null;
}
export function resolveResourceCanvasAssetGenerationTaskStatus(
status: string,
): ResourceCanvasAssetGenerationTaskStatus {
switch (status) {
case 'queued':
case 'running':
case 'completed':
return status;
default:
return 'failed';
}
}
export function resourceCanvasAssetGenerationTaskIsTerminal(
task: Pick<ResourceCanvasAssetGenerationTask, 'status'>,
): boolean {
return task.status === 'completed' || task.status === 'failed';
}
/** 新提交的任务:先本地排队,派发之前不进后端账本。 */
export function createResourceCanvasAssetGenerationTask(input: {
taskId: string;
action: ResourceCanvasAssetToolAction;
prompt: string;
assetName: string;
aspectRatio: string;
imageSize: string;
outputPath: string | null;
projectId: string;
nowMillis: number;
}): ResourceCanvasAssetGenerationTask {
return {
taskId: input.taskId,
actionId: input.action.id,
actionLabel: input.action.label,
assetKind: input.action.assetKind,
assetName: input.assetName,
prompt: input.prompt,
aspectRatio: input.aspectRatio,
imageSize: input.imageSize,
outputPath: input.outputPath,
projectId: input.projectId,
dispatched: false,
status: 'queued',
phaseDetail: RESOURCE_CANVAS_ASSET_GENERATION_LOCAL_QUEUE_PHASE,
createdAtMillis: input.nowMillis,
startedAtMillis: null,
finishedAtMillis: null,
assetId: null,
error: null,
restored: false,
};
}
const RESOURCE_CANVAS_ASSET_GENERATION_TASK_LIMIT = 50;
/** 账本记录 → 任务列表里的一条(重开项目后恢复显示)。 */
export function restoreResourceCanvasAssetGenerationTask(
record: LocalProjectAssetGenerationTaskRecord,
): ResourceCanvasAssetGenerationTask {
return {
taskId: record.taskId,
actionId: `restored:${record.kind}`,
actionLabel:
resourceCanvasAssetGenerationKindLabel(record.kind) ?? record.assetName,
assetKind: record.kind,
assetName: record.assetName,
prompt: '',
aspectRatio: '',
imageSize: '',
outputPath: null,
projectId: record.projectId,
dispatched: true,
status: resolveResourceCanvasAssetGenerationTaskStatus(record.status),
phaseDetail: record.phaseDetail,
createdAtMillis: record.createdAtMillis,
startedAtMillis: record.startedAtMillis,
finishedAtMillis: record.finishedAtMillis,
assetId: record.assetId,
error: record.error,
restored: true,
};
}
/**
* 本地任务 + 后端记录 → 下一版任务列表。
*
* 两个方向都要覆盖:本地任务用后端记录刷新状态与阶段;后端有、本地没有的记录(重开项目、
* 或本地列表被清空)恢复成一条历史任务。后端不再返回的本地任务保持原样——记录被账本上限
* 淘汰不该让前端把一条已完成任务抹掉。
*
* `records` **在函数入口归一化**:宿主从 IPC 拿到的不一定是数组(旧壳没有这条命令、权限拒绝、
* 账本文件读坏、命令未注册都可能给出 `undefined` 或别的形状)。非数组一律按「没有后端记录」
* 处理——抛出去会变成 effect 里的未处理 Promise 拒绝,把「任务列表暂不可用」升级成整块视图出错。
* 数组里的垃圾条目(`null` / 数字 / 缺 `taskId`)同样逐条丢弃,不让一条坏记录带崩整次恢复。
*/
export function applyLocalProjectAssetGenerationRecords(
tasks: readonly ResourceCanvasAssetGenerationTask[],
records: readonly LocalProjectAssetGenerationTaskRecord[] | null | undefined,
): ResourceCanvasAssetGenerationTask[] {
const safeRecords = Array.isArray(records)
? records.filter(
(record): record is LocalProjectAssetGenerationTaskRecord =>
typeof record === 'object' &&
record !== null &&
typeof (record as LocalProjectAssetGenerationTaskRecord).taskId ===
'string' &&
(record as LocalProjectAssetGenerationTaskRecord).taskId.trim()
.length > 0,
)
: [];
const recordsByTaskId = new Map(
safeRecords.map((record) => [record.taskId, record]),
);
const merged = tasks.map((task) => {
const record = recordsByTaskId.get(task.taskId);
return record ? mergeLocalProjectAssetGenerationRecord(task, record) : task;
});
const knownTaskIds = new Set(tasks.map((task) => task.taskId));
const restored = safeRecords
.filter((record) => !knownTaskIds.has(record.taskId))
.map(restoreResourceCanvasAssetGenerationTask);
if (restored.length === 0) {
return merged;
}
return [...merged, ...restored].slice(
-RESOURCE_CANVAS_ASSET_GENERATION_TASK_LIMIT,
);
}
/** 用后端记录刷新一条本地任务:状态、阶段、时间戳、资源 id 与失败原因都以后端为准。 */
export function mergeLocalProjectAssetGenerationRecord(
task: ResourceCanvasAssetGenerationTask,
record: LocalProjectAssetGenerationTaskRecord,
): ResourceCanvasAssetGenerationTask {
return {
...task,
dispatched: true,
status: resolveResourceCanvasAssetGenerationTaskStatus(record.status),
phaseDetail: record.phaseDetail,
startedAtMillis: record.startedAtMillis ?? task.startedAtMillis,
finishedAtMillis: record.finishedAtMillis ?? task.finishedAtMillis,
assetId: record.assetId ?? task.assetId,
error: record.error ?? task.error,
};
}
/**
* 本地排队的派发判据:**同一时刻只派发一条任务**(本批的提交节流)。
*
* AGC 本地 durable 输出槽已按**精确动作指纹**分槽,不同 prompt / 素材名可以同时在途,所以这条
* 判据**不再是「远端会拒绝并发」的被迫排队**;本批前端仍按「同一时刻只派发一条」排队,作为提交
* 节流。真并行派发需要并发收口设计(配对读 + manifest CAS + 聚焦意图互不覆盖),留待下一批。
*
* 「在途」的判据是 `dispatched && 未终态`,而不是 `status === 'running'`:已派发但后端记录还
* 没读回来的那一段(状态仍是 `queued`)同样算在途,漏掉这一档就会提前放出第二条。
*/
export function nextResourceCanvasAssetGenerationDispatch(
tasks: readonly ResourceCanvasAssetGenerationTask[],
): ResourceCanvasAssetGenerationTask | null {
const inFlight = tasks.some(
(task) =>
task.dispatched && !resourceCanvasAssetGenerationTaskIsTerminal(task),
);
if (inFlight) {
return null;
}
return (
tasks.find((task) => !task.dispatched && task.status === 'queued') ?? null
);
}
/** 面板展示顺序:新提交的在上。 */
export function sortResourceCanvasAssetGenerationTasks(
tasks: readonly ResourceCanvasAssetGenerationTask[],
): ResourceCanvasAssetGenerationTask[] {
return [...tasks].sort(
(left, right) =>
right.createdAtMillis - left.createdAtMillis ||
left.taskId.localeCompare(right.taskId),
);
}
/** 已耗时文案:排队中按创建时间算,已结束按结束时间算。 */
export function resourceCanvasAssetGenerationElapsedLabel(
elapsedMillis: number,
): string {
const totalSeconds = Math.max(0, Math.floor(elapsedMillis / 1000));
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return minutes > 0 ? `${minutes}${seconds}` : `${seconds}`;
}
export function resourceCanvasAssetGenerationTaskElapsedMillis(
task: Pick<
ResourceCanvasAssetGenerationTask,
'createdAtMillis' | 'finishedAtMillis'
>,
nowMillis: number,
): number {
return Math.max(
0,
(task.finishedAtMillis ?? nowMillis) - task.createdAtMillis,
);
}
@@ -0,0 +1,377 @@
/* 「生成任务」侧栏的样式。
*
* 分层与网页端美术画布的任务侧栏(`ImageCanvasTaskSidebarView.tsx` + `src/index.css:6084+`)一一对应:
* 容器 → 头部(标题 + 在途计数)→ 分栏标题(各带条数)→ 条目卡片(状态徽标 / 阶段 / 耗时 / 定位)。
* 差别只有一处:**颜色全部换成 AGC 的平台设计 token`--platform-*`**,不再照抄网页端的固定色值,
* 这样亮/暗主题都跟着 `platform-theme` 走,也不引入第二套色板。
*
* 行为(分栏、条数、已完成封顶、折叠不清列表、提交后自动展开)都不在这里,样式只负责表现。
*/
.game-resource-generation-tasks-sidebar {
position: fixed;
top: 4rem;
bottom: 6rem;
left: 0.75rem;
z-index: 40;
display: flex;
width: min(300px, 80vw);
flex-direction: column;
overflow: hidden;
border: 1px solid var(--platform-subpanel-border);
border-radius: 0.75rem;
background: var(--platform-subpanel-fill);
color: var(--platform-text-strong);
box-shadow: var(--platform-panel-shadow);
backdrop-filter: blur(10px);
animation: game-resource-generation-tasks-enter 160ms ease-out;
}
/* 提交后面板会重新挂载,动画只负责「进场」这一下;不做宽度 reflow,避免画布抖动。 */
@keyframes game-resource-generation-tasks-enter {
from {
opacity: 0;
transform: translateX(-0.5rem);
}
to {
opacity: 1;
transform: translateX(0);
}
}
/* 收起:与进场同向反向播一遍,播完由组件卸载(时长见组件里的 `…_LEAVE_MILLIS`,两处必须一致)。 */
.game-resource-generation-tasks-sidebar.is-leaving {
animation: game-resource-generation-tasks-leave 160ms ease-in forwards;
pointer-events: none;
}
@keyframes game-resource-generation-tasks-leave {
from {
opacity: 1;
transform: translateX(0);
}
to {
opacity: 0;
transform: translateX(-0.5rem);
}
}
.game-resource-generation-tasks-sidebar-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
border-bottom: 1px solid var(--platform-line-soft);
padding: 0.68rem 0.78rem;
}
.game-resource-generation-tasks-sidebar-title {
display: inline-flex;
align-items: center;
gap: 0.35rem;
font-size: 0.8rem;
font-weight: 850;
}
.game-resource-generation-tasks-sidebar-count {
display: inline-flex;
min-width: 1.35rem;
height: 1.35rem;
align-items: center;
justify-content: center;
border: 1px solid var(--platform-neutral-border);
border-radius: 999px;
background: var(--platform-neutral-bg);
color: var(--platform-neutral-text);
font-size: 0.72rem;
font-variant-numeric: tabular-nums;
font-weight: 850;
}
.game-resource-generation-tasks-sidebar-icon-button {
display: grid;
width: 1.75rem;
height: 1.75rem;
place-items: center;
border: 1px solid transparent;
border-radius: 999px;
background: transparent;
color: var(--platform-button-ghost-text);
transition:
background 120ms ease,
color 120ms ease,
border-color 120ms ease;
}
.game-resource-generation-tasks-sidebar-icon-button:hover {
border-color: var(--platform-subpanel-border);
background: var(--platform-nav-item-hover-fill);
color: var(--platform-text-strong);
}
.game-resource-generation-tasks-sidebar-icon-button:focus-visible,
.game-resource-generation-task-locate:focus-visible {
outline: 2px solid var(--platform-accent);
outline-offset: 2px;
box-shadow: 0 0 0 3px var(--platform-input-focus-ring);
}
.game-resource-generation-tasks-scroll {
min-height: 0;
flex: 1 1 auto;
overflow-y: auto;
overscroll-behavior: contain;
padding: 0.5rem 0.6rem;
scrollbar-color: var(--platform-line-soft) transparent;
scrollbar-width: thin;
}
.game-resource-generation-tasks-scroll::-webkit-scrollbar {
width: 6px;
}
.game-resource-generation-tasks-scroll::-webkit-scrollbar-thumb {
border-radius: 999px;
background: var(--platform-line-soft);
}
.game-resource-generation-tasks-scroll::-webkit-scrollbar-track {
background: transparent;
}
.game-resource-generation-tasks-empty {
padding: 1rem 0.5rem;
color: var(--platform-text-muted);
font-size: 0.74rem;
font-weight: 750;
text-align: center;
}
.game-resource-generation-tasks-section
+ .game-resource-generation-tasks-section {
margin-top: 0.65rem;
border-top: 1px solid var(--platform-line-soft);
padding-top: 0.6rem;
}
.game-resource-generation-tasks-section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
color: var(--platform-text-muted);
font-size: 0.72rem;
font-weight: 850;
letter-spacing: 0.02em;
}
.game-resource-generation-tasks-section-title-count {
display: inline-flex;
min-width: 1.05rem;
height: 1.05rem;
align-items: center;
justify-content: center;
border-radius: 999px;
background: var(--platform-neutral-bg);
color: var(--platform-neutral-text);
font-size: 0.68rem;
font-variant-numeric: tabular-nums;
}
.game-resource-generation-tasks-list {
display: grid;
gap: 0.38rem;
margin-top: 0.4rem;
}
.game-resource-generation-task-card {
display: grid;
gap: 0.3rem;
width: 100%;
border: 1px solid var(--platform-subpanel-border);
border-radius: 0.5rem;
background: var(--platform-panel-fill);
padding: 0.5rem 0.55rem;
transition:
border-color 120ms ease,
box-shadow 120ms ease,
transform 120ms ease;
}
.game-resource-generation-task-card:hover {
border-color: var(
--platform-surface-hover-border,
var(--platform-subpanel-border)
);
box-shadow: var(--platform-desktop-hover-shadow);
transform: translateY(-1px);
}
.game-resource-generation-task-card-title-row {
display: grid;
min-width: 0;
grid-template-columns: minmax(0, 1fr) auto;
align-items: start;
gap: 0.45rem;
}
.game-resource-generation-task-card-name {
overflow: hidden;
color: var(--platform-text-strong);
font-size: 0.78rem;
font-weight: 850;
text-overflow: ellipsis;
white-space: nowrap;
}
.game-resource-generation-task-card-action {
overflow: hidden;
color: var(--platform-text-muted);
font-size: 0.68rem;
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
.game-resource-generation-task-card-meta {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 0.4rem;
}
.game-resource-generation-task-badge {
display: inline-flex;
align-items: center;
gap: 0.3rem;
border: 1px solid var(--platform-neutral-border);
border-radius: 999px;
background: var(--platform-neutral-bg);
color: var(--platform-neutral-text);
padding: 0.1rem 0.45rem;
font-size: 0.68rem;
font-weight: 800;
white-space: nowrap;
}
.game-resource-generation-task-badge::before {
content: '';
width: 0.375rem;
height: 0.375rem;
border-radius: 999px;
background: currentcolor;
}
/* 四种状态的 tone 映射:中性 / 品牌 / 成功 / 危险,全部走平台 token,不硬编码颜色。 */
.game-resource-generation-task-badge[data-tone='queued'] {
border-color: var(--platform-neutral-border);
background: var(--platform-neutral-bg);
color: var(--platform-neutral-text);
}
.game-resource-generation-task-badge[data-tone='running'] {
border-color: var(--platform-accent);
background: transparent;
color: var(--platform-accent);
}
.game-resource-generation-task-badge[data-tone='completed'] {
border-color: var(--platform-success-border);
background: var(--platform-success-bg);
color: var(--platform-success-text);
}
.game-resource-generation-task-badge[data-tone='failed'] {
border-color: var(--platform-button-danger-border);
background: var(--platform-button-danger-fill);
color: var(--platform-button-danger-text);
}
/* 生成中只给「有在动」的呼吸感,不做百分比 —— 后端没有可播报的百分比。 */
.game-resource-generation-task-badge[data-tone='running']::before {
animation: game-resource-generation-task-pulse 1.2s ease-in-out infinite;
}
@keyframes game-resource-generation-task-pulse {
50% {
opacity: 0.25;
}
}
.game-resource-generation-task-card-phase {
overflow: hidden;
color: var(--platform-text-muted);
font-size: 0.7rem;
line-height: 1.35;
text-overflow: ellipsis;
white-space: nowrap;
}
.game-resource-generation-task-card-elapsed {
color: var(--platform-text-muted);
font-size: 0.68rem;
font-variant-numeric: tabular-nums;
font-weight: 750;
text-align: right;
white-space: nowrap;
}
.game-resource-generation-task-card-error {
color: var(--platform-button-danger-text);
font-size: 0.7rem;
line-height: 1.35;
overflow-wrap: anywhere;
white-space: normal;
}
.game-resource-generation-task-locate {
justify-self: start;
border: 0;
background: transparent;
color: var(--platform-accent);
font-size: 0.7rem;
font-weight: 800;
padding: 0;
text-decoration: underline;
text-underline-offset: 0.16rem;
transition: color 120ms ease;
}
.game-resource-generation-task-locate:hover {
color: var(--platform-text-strong);
}
/* 窄屏(含 360px):侧栏占满可用宽度,不挡画布操作。 */
@media (max-width: 480px) {
.game-resource-generation-tasks-sidebar {
top: 3.5rem;
right: 0.5rem;
bottom: 5.5rem;
left: 0.5rem;
width: auto;
}
}
/* 降低动效偏好:进场 / 收起动画、悬停位移与呼吸全部关掉。 */
@media (prefers-reduced-motion: reduce) {
.game-resource-generation-tasks-sidebar,
.game-resource-generation-tasks-sidebar.is-leaving {
animation: none;
}
.game-resource-generation-task-card,
.game-resource-generation-tasks-sidebar-icon-button,
.game-resource-generation-task-badge::before,
.game-resource-generation-task-locate {
transition: none;
animation: none;
}
.game-resource-generation-task-card:hover {
transform: none;
}
}
@@ -21,7 +21,7 @@ import type { ResourceCanvasGenerationKind } from './resourceCanvasGenerationMod
*/
/**
* `generate_local_project_asset` 放行的无源生成类型。
* `start_local_project_asset_generation` 放行的无源生成类型。
*
* 与 Rust `PLATFORM_ART_ASSET_GENERATION_KINDS` 一一对应(`publication-material` 属宣发
* 素材,本轮不做,因此不在这里)。`spec` / `icon-spec` 都会在 Rust 侧收口到 `icon-spec`
@@ -72,7 +72,7 @@ type ResourceCanvasBottomToolActionBase = {
imageSize: string;
};
/** 图片类生成入口:走 `generate_local_project_asset`。 */
/** 图片类生成入口:走 `start_local_project_asset_generation`(提交即返回、后台生成)。 */
export type ResourceCanvasAssetToolAction =
ResourceCanvasBottomToolActionBase & {
route: 'asset';
@@ -19,6 +19,14 @@ export type ResourceInfoFieldRow = {
const EMPTY_TAGS_TEXT = '暂无标签';
/**
* 「分类」字段的行标识。
*
* 画布上的信息浮层用这一行接出素材类型设置入口(运行页签的「信息展示」不带入口,
* 同一份字段清单在两处渲染);把字面量放在这里,模型与入口两侧不会各写一个。
*/
export const RESOURCE_INFO_CATEGORY_FIELD_LABEL = '分类';
/**
* 栏目文案与资源筛选同源;`version` 不是跨端资源分类,和画布栏目一样单独给文案。
*/
@@ -43,7 +51,10 @@ export function resolveResourceInfoFieldRows(
{ label: '名称', value: resource.label },
{ label: '路径', value: resource.path },
{ label: '类型', value: resource.mediaType },
{ label: '分类', value: resourceCategoryLabel(resource.category) },
{
label: RESOURCE_INFO_CATEGORY_FIELD_LABEL,
value: resourceCategoryLabel(resource.category),
},
{
label: '标签',
value: tags.length > 0 ? tags.join('、') : EMPTY_TAGS_TEXT,
+34 -13
View File
@@ -5521,6 +5521,15 @@ iframe.preview-frame {
background: transparent;
}
/* 左侧控件组:「资源管理 / 运行」分段 + 紧贴其后的「播放」。
* 整组在工具条里左对齐,取代播放按钮原先的居中悬浮(absolute + translateX(-50%))。 */
.game-workbench-view-tabs {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 7px;
}
.game-workbench-tabs,
.game-workbench-view-actions {
display: flex;
@@ -5557,7 +5566,9 @@ iframe.preview-frame {
border-color: transparent;
}
/* 左侧控件组里的按钮(目前只有「播放」)与分段控件、右侧动作区共用同一套基础外观。 */
.game-workbench-tabs button,
.game-workbench-view-tabs button,
.game-workbench-view-actions button {
display: inline-flex;
align-items: center;
@@ -5576,6 +5587,7 @@ iframe.preview-frame {
}
.game-workbench-tabs button:focus-visible,
.game-workbench-view-tabs button:focus-visible,
.game-workbench-view-actions button:focus-visible,
.game-workbench-approval-trigger:focus-visible,
.game-agent-dock-more:focus-visible {
@@ -5607,16 +5619,16 @@ iframe.preview-frame {
color: var(--platform-button-secondary-text);
}
.game-workbench-view-actions .game-workbench-play-button {
position: absolute;
left: 50%;
/* 「播放」与「资源管理 / 运行」同组,外观仍按主按钮走;禁用时退回次级按钮。 */
.game-workbench-view-tabs .game-workbench-play-button {
position: static;
border-color: var(--platform-button-primary-border);
background: var(--platform-button-primary-fill);
color: var(--platform-button-primary-text);
transform: translateX(-50%);
transform: none;
}
.game-workbench-view-actions .game-workbench-play-button:disabled {
.game-workbench-view-tabs .game-workbench-play-button:disabled {
border-color: var(--platform-surface-border);
background: var(--platform-button-secondary-fill);
color: var(--platform-text-muted);
@@ -7023,10 +7035,24 @@ iframe.preview-frame {
place-items: center;
}
.game-resource-card[data-preview-kind='raster-image']
/*
* 棋盘格底只铺给**这张图真的有 alpha 通道**的卡(`data-preview-has-alpha='true'`
* 判据来自原生侧头部解析,见 `src-tauri/src/image_inspect.rs`),不再按「预览分支是图片」
* 无条件铺。
*
* 原因:AI 生成的「透明底」PNG 常常把棋盘格**画进像素里**。无条件铺底时,卡面棋盘格与图内
* 棋盘格叠在一起,验收无法区分「真透明底」与「假棋盘格」;改为按真实 alpha 判定后两者可分。
*
* 没有该属性时(JPEG 恒不透明;media-image / video 目前没有头部 alpha 判据)退回
* `.game-resource-card-visual` 的既有纯色底(见上一条规则),不引入第二套底色,
* 因此不会出现「半透明叠色」之类的问题。
*/
.game-resource-card[data-preview-kind='raster-image'][data-preview-has-alpha='true']
.game-resource-card-visual,
.game-resource-card[data-preview-kind='media-image'] .game-resource-card-visual,
.game-resource-card[data-preview-kind='video'] .game-resource-card-visual {
.game-resource-card[data-preview-kind='media-image'][data-preview-has-alpha='true']
.game-resource-card-visual,
.game-resource-card[data-preview-kind='video'][data-preview-has-alpha='true']
.game-resource-card-visual {
background: linear-gradient(45deg, #f1ebe7 25%, transparent 25%),
linear-gradient(-45deg, #f1ebe7 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #f1ebe7 75%),
@@ -9115,11 +9141,6 @@ iframe.preview-frame {
.game-workbench-view-actions {
justify-content: flex-end;
}
.game-workbench-view-actions .game-workbench-play-button {
position: static;
transform: none;
}
}
@media (max-width: 760px) {
@@ -5,38 +5,22 @@ import { useState } from 'react';
import { PlatformActionButton } from '../../../../../packages/shared/src/components/PlatformActionButton';
import { PlatformPillBadge } from '../../../../../packages/shared/src/components/PlatformPillBadge';
import { PlatformSegmentedTabs } from '../../../../../packages/shared/src/components/PlatformSegmentedTabs';
import { PlatformTextField } from '../../../../../packages/shared/src/components/PlatformTextField';
import {
GAME_CREATION_APP_ASSET_CATEGORIES,
type GameCreationAppAssetCategory,
gameCreationAppAssetCategory,
type GameCreationAppAssetManifestEntry,
gameCreationAppAssetPersistedCategory,
gameCreationAppAssetTags,
normalizeGameCreationAppAssetTags,
} from '../../../../../packages/shared/src/contracts/gameCreationApp';
import { ThemedModal } from '../../components/modal/ThemedModal';
import { resourceReferenceCategoryLabel } from '../../features/project-workspace/resourceReferences';
import { projectAssetCommandErrorMessage } from './projectAssetCommandErrorMessage';
import { resourceAssetDisplayName } from './resourceAssetDisplayName';
type UpdateLocalProjectResourceClassificationResult = {
asset: GameCreationAppAssetManifestEntry;
committedProjectRevision: number;
};
/**
* 素材类型(功能分类)选项 = 合法分类枚举 × 既有中文展示名。
*
* 展示名只从 `resourceReferenceCategoryLabel`(筛选与栏目的同一份口径)取,
* 不在业务页另写一张译名表 —— 面板说「角色与对象」而栏目说别的,用户会以为是两个东西。
*/
const RESOURCE_CLASSIFICATION_CATEGORY_OPTIONS =
GAME_CREATION_APP_ASSET_CATEGORIES.map((category) => ({
id: category,
label: resourceReferenceCategoryLabel(category),
}));
/**
* 标签草稿沿用写入路径的归一化边界,只按中英文逗号、顿号与换行切分。
* 与输入框旧的"整段逗号分隔文本"口径完全一致,改动只是把结果换成逐个可删的 pill。
@@ -57,16 +41,6 @@ function mergeResourceClassificationTagDraft(
return next;
}
/**
* 素材名取 `localPath` 的 basenamemanifest 资产没有独立的显示名字段,
* 与资源卡、`@` 面板的显示口径一致。
*/
function resourceAssetDisplayName(localPath: string) {
const normalized = localPath.replaceAll('\\', '/');
const segments = normalized.split('/');
return segments[segments.length - 1] || localPath;
}
function resourceClassificationErrorMessage(error: unknown) {
// 项目身份 / 版本 CAS 拒绝翻成用户可读中文,其余原样透出;
// 与重命名、删除共用同一份映射。
@@ -89,26 +63,17 @@ export function ResourceClassificationPanel({
onSaved,
}: ResourceClassificationPanelProps) {
/**
* 素材类型(功能分类)从本面板设置,与标签同一次保存、同一条写入路径
* 本面板只编辑标签:素材类型(功能分类)在「设置素材类型」面板里单独设置
*
* **选择器读的是「显示口径** `gameCreationAppAssetCategory`:它与资源画布栏目
* `projectResourceAssetCategory` / `projectResourceCanvasCategory`)同一份读数,
* 所以用户看到的选中项恰好就是他看到的那一栏,不存在「面板说 A、卡片在 B 栏」。
*
* **写回不能用这个读数**:显示口径含读时自愈 —— 落盘 `unclassified` 而 `kind` 能派生出
* 明确分类时,读出来的是派生值。回传它就等于用户只改标签也被静默改了分类
* **写回必须用落盘口径** `gameCreationAppAssetPersistedCategory`,不能用读显示口径
* `gameCreationAppAssetCategory`:显示口径含读时自愈 —— 落盘 `unclassified` 而 `kind`
* 能派生出明确分类时,读出来的是派生值。回传它就等于用户只改标签也被静默改了分类
* (真机上同一条 `kind:"ui"` 资产同时出现过 `unclassified` 与 `ui-interaction` 两种落盘值)。
*
* 因此用 `categoryChoice` 表达「用户是否主动选过」
* - `null`(没碰过分类控件)→ 回传 `gameCreationAppAssetPersistedCategory` 落盘原值
* - 用户选过 → 回传用户选的那个值
* 这条分叉是本次改动的核心不变量,两个方向都由
* `tests/resourceClassificationPanel.test.tsx` 的对照用例钉住。
* 拆出类型面板后这条不变量不再依赖"用户是否碰过控件",而是结构性的
* 本面板没有类型控件,`category` 恒为落盘原值
* `tests/resourceClassificationPanel.test.tsx` 两个方向各有用例钉住它
*/
const [categoryChoice, setCategoryChoice] =
useState<GameCreationAppAssetCategory | null>(null);
const displayedCategory =
categoryChoice ?? gameCreationAppAssetCategory(asset);
const [tags, setTags] = useState<string[]>(() =>
gameCreationAppAssetTags(asset),
);
@@ -159,9 +124,8 @@ export function ResourceClassificationPanel({
expectedProjectId: projectId,
expectedProjectRevision: status.revision,
assetId: asset.id,
// 用户没主动选类型就原样回传落盘值(不含读时自愈),选了就写用户选的那个
category:
categoryChoice ?? gameCreationAppAssetPersistedCategory(asset),
// 分类不由本面板编辑:恒回传落盘值(不含读时自愈)。
category: gameCreationAppAssetPersistedCategory(asset),
tags: normalizeGameCreationAppAssetTags(tagsToSave),
},
},
@@ -214,20 +178,10 @@ export function ResourceClassificationPanel({
</header>
<div className="game-resource-classification-body">
{/*
素材类型选择器:选中的那一项就是这张卡当前所在的画布栏目。
点任意一项即视为用户主动改类型(即便点的是当前已选中的那一项),
与「没碰过就回传落盘原值」的分叉保持同一条判据,不做隐式 no-op
本面板没有素材类型控件:类型是「设置素材类型」面板的编辑对象,入口在资源卡选中
工具条上。曾长在这里的类型 chip 只改本地 state、不落盘,保存又只能借道标签的
「添加」,导致"改了类型没生效"
*/}
<PlatformSegmentedTabs
items={RESOURCE_CLASSIFICATION_CATEGORY_OPTIONS}
activeId={displayedCategory}
onChange={setCategoryChoice}
layout="scroll"
gap="sm"
frame="bare"
surface="transparent"
size="compact"
/>
{tags.length > 0 ? (
<ul className="game-resource-tag-list" aria-label="已有标签">
{tags.map((tag) => (
@@ -3,6 +3,7 @@ import { Info, X } from 'lucide-react';
import {
resolveResourceInfoFieldRows,
resolveResourceInfoPanelStyle,
RESOURCE_INFO_CATEGORY_FIELD_LABEL,
type ResourceInfoPanelAnchor,
} from '../../features/resource-canvas/resourceCanvasInfoModel';
import type { ProjectResource } from './resourceProjectionModel';
@@ -10,11 +11,17 @@ import type { ProjectResource } from './resourceProjectionModel';
/**
* 只读资源信息字段。运行页签的「信息展示」与画布上的信息浮层共用这一份,
* 字段清单只在 `resolveResourceInfoFieldRows` 里定义,两处不会各说一套。
*
* `onEditCategory` 是「分类」行的可选入口(只有画布浮层传):分类值本身仍然只读展示,
* 入口按钮渲染在 `dd` **外面** —— 字段值的读取口径是 `dt` / `dd` 的文本,
* 把按钮塞进 `dd` 会让分类值变成「角色与对象设置」这类拼接文案。
*/
export function ResourceInfoFieldsView({
resource,
onEditCategory,
}: {
resource: ProjectResource;
onEditCategory?: () => void;
}) {
return (
<dl className="game-resource-info-fields">
@@ -22,6 +29,18 @@ export function ResourceInfoFieldsView({
<div key={row.label}>
<dt>{row.label}</dt>
<dd>{row.value}</dd>
{onEditCategory &&
row.label === RESOURCE_INFO_CATEGORY_FIELD_LABEL ? (
<button
type="button"
className="game-resource-info-field-action"
aria-label="设置素材类型"
title="设置素材类型"
onClick={onEditCategory}
>
</button>
) : null}
</div>
))}
</dl>
@@ -30,6 +49,10 @@ export function ResourceInfoFieldsView({
export type ResourceInfoPanelViewProps = ResourceInfoPanelAnchor & {
resource: ProjectResource;
/**
* 「分类」行的类型设置入口;不传就没有入口(资源不是 manifest 资产时宿主不传)。
*/
onEditCategory?: () => void;
onClose: () => void;
};
@@ -44,6 +67,7 @@ export function ResourceInfoPanelView({
sourceLayer,
viewport,
canvasSize,
onEditCategory,
onClose,
}: ResourceInfoPanelViewProps) {
const style = resolveResourceInfoPanelStyle({
@@ -75,7 +99,10 @@ export function ResourceInfoPanelView({
<X size={14} aria-hidden="true" />
</button>
</header>
<ResourceInfoFieldsView resource={resource} />
<ResourceInfoFieldsView
resource={resource}
onEditCategory={onEditCategory}
/>
</section>
);
}
@@ -0,0 +1,238 @@
import '../../features/project-workspace/resourceTypePanel.css';
import { Check } from 'lucide-react';
import {
type KeyboardEvent as ReactKeyboardEvent,
useRef,
useState,
} from 'react';
import { PlatformNavigableListItem } from '../../../../../packages/shared/src/components/PlatformNavigableListItem';
import {
GAME_CREATION_APP_ASSET_CATEGORIES,
type GameCreationAppAssetCategory,
gameCreationAppAssetCategory,
type GameCreationAppAssetManifestEntry,
gameCreationAppAssetTags,
} from '../../../../../packages/shared/src/contracts/gameCreationApp';
import { ThemedModal } from '../../components/modal/ThemedModal';
import { resourceReferenceCategoryLabel } from '../../features/project-workspace/resourceReferences';
import { projectAssetCommandErrorMessage } from './projectAssetCommandErrorMessage';
import { resourceAssetDisplayName } from './resourceAssetDisplayName';
type UpdateLocalProjectResourceClassificationResult = {
asset: GameCreationAppAssetManifestEntry;
committedProjectRevision: number;
};
/**
* 素材类型(功能分类)选项 = 合法分类枚举 × 既有中文展示名。
*
* 展示名只从 `resourceReferenceCategoryLabel`(筛选与栏目的同一份口径)取,
* 不在业务页另写一张译名表 —— 面板说「角色与对象」而栏目说别的,用户会以为是两个东西。
*/
const RESOURCE_TYPE_CATEGORY_OPTIONS = GAME_CREATION_APP_ASSET_CATEGORIES.map(
(category) => ({
id: category,
label: resourceReferenceCategoryLabel(category),
}),
);
function resourceTypeErrorMessage(error: unknown) {
// 项目身份 / 版本 CAS 拒绝翻成用户可读中文,其余原样透出;
// 与重命名、删除、标签共用同一份映射。
return projectAssetCommandErrorMessage(error, '设置素材类型失败');
}
type ResourceTypePanelProps = {
projectPath: string;
projectId: string;
asset: GameCreationAppAssetManifestEntry;
onClose: () => void;
onSaved: (result: UpdateLocalProjectResourceClassificationResult) => void;
};
/**
* 「设置素材类型」面板:素材类型(功能分类)的独立入口,与「编辑素材标签」彻底分家。
*
* 拆开的理由是原设计的动作语义错位 —— 类型 chip 曾长在标签弹窗里,点它只改本地 state,
* 而全弹窗唯一的保存入口是标签的「添加」。于是「改类型」必须借道一个语义上是"加标签"的
* 按钮,只选类型就直接关窗(点遮罩 / Esc / ×)则改动静默丢失。
*
* 本面板把动作压成一步:**选中即落盘**,不再有也只不需要任何标签动作。
*
* 三个口径要点:
* 1. **显示**用读显示口径 `gameCreationAppAssetCategory`:它与画布栏目、资源卡角标同一份
* 读数,用户看到的选中项恰好就是他看到的那一栏。
* 2. **写回**用用户当次点的那个值,且只写这一个字段;`tags` 逐字回传
* `gameCreationAppAssetTags(asset)`(落盘原值),不使用任何读时自愈口径
* —— 改类型不许顺手改标签,也不许把自愈出来的值写回去。
* 3. **没碰过就不写**:面板本身不产生"打开即写"或"关闭时补写",没有用户动作就没有写入。
* 另一半对照(用户主动选了就必须写)由 `tests/resourceTypePanel.test.tsx` 钉住。
*/
export function ResourceTypePanel({
projectPath,
projectId,
asset,
onClose,
onSaved,
}: ResourceTypePanelProps) {
/**
* 保存在飞时先把用户点的那一项显出来(否则 await 期间面板像没反应)。
* 写入失败就退回显示口径,不留一个"看起来成功"的选中态。
*/
const [pendingCategory, setPendingCategory] =
useState<GameCreationAppAssetCategory | null>(null);
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
const activeCategory = pendingCategory ?? gameCreationAppAssetCategory(asset);
const optionsRef = useRef<HTMLDivElement | null>(null);
/**
* 单选组的键盘口径:Tab 进组只停一次(roving tabindex,见下面的 `tabIndex`);
* 方向键在选项之间移动**焦点**Enter/Space`<button>` 的原生行为)才落盘。
*
* 方向键刻意不顺手选中:这里的"选中"是一次 CAS 写盘动作,"浏览选项"不该变成连环写盘。
* 读屏仍能逐项读到"选项名 + 已选中/未选中"`aria-checked`),所以浏览时不丢上下文。
* 走到头不越界(不回卷):单选组里回卷会让焦点从最后一项跳回第一项,方向感丢失。
*/
function handleOptionKeyDown(
event: ReactKeyboardEvent<HTMLButtonElement>,
index: number,
) {
const step =
event.key === 'ArrowDown' || event.key === 'ArrowRight'
? 1
: event.key === 'ArrowUp' || event.key === 'ArrowLeft'
? -1
: 0;
if (step === 0) return;
event.preventDefault();
// 不在子组件上挂 ref(共享列表行不透传 ref),按住处从自己的容器里数。
const options =
optionsRef.current?.querySelectorAll<HTMLButtonElement>('[role="radio"]');
if (!options || options.length === 0) return;
const target =
options[Math.min(Math.max(index + step, 0), options.length - 1)];
target?.focus();
}
async function saveResourceType(
category: GameCreationAppAssetCategory,
): Promise<void> {
const invoke = window.__TAURI__?.core?.invoke;
if (!invoke) {
setError('设置素材类型需要在客户端内保存');
return;
}
setSaving(true);
setError(null);
try {
const status = await invoke<{ revision: number }>(
'get_local_game_project_revision',
{ projectPath },
);
if (!Number.isSafeInteger(status.revision) || status.revision < 0) {
throw new Error('项目 revision 无效');
}
const result =
await invoke<UpdateLocalProjectResourceClassificationResult>(
'update_local_project_resource_classification',
{
input: {
projectPath,
expectedProjectId: projectId,
expectedProjectRevision: status.revision,
assetId: asset.id,
// 用户点的就是落盘值:不套用读时自愈,也不和"是否碰过控件"分叉。
category,
// 类型面板不改标签:逐字回传落盘原值。
tags: gameCreationAppAssetTags(asset),
},
},
);
onSaved(result);
} catch (saveError) {
setPendingCategory(null);
setError(resourceTypeErrorMessage(saveError));
} finally {
setSaving(false);
}
}
return (
<ThemedModal
open
ariaLabel="设置素材类型"
onClose={onClose}
// 保存在飞时不许用 Escape / 点遮罩把面板关掉:关掉后迟到的 `onSaved`
// 会打到一个已经卸载的面板上。头部 × 同样按 `saving` 禁用。
closeOnBackdrop={!saving}
closeOnEscape={!saving}
panelClassName="game-approval-dialog game-resource-type-dialog"
>
<header>
<div>
<h2></h2>
<p>{resourceAssetDisplayName(asset.localPath)}</p>
</div>
<button
type="button"
aria-label="关闭设置素材类型"
disabled={saving}
onClick={onClose}
>
×
</button>
</header>
<div className="game-resource-type-body">
{/* 只说这一屏要选什么,不写规则说明或开发解释。 */}
<p className="game-resource-type-hint"></p>
{/*
纵向单选列表(`role="radiogroup"` + 每项 `role="radio"`):
一行一个选项,不再横排成一条 —— 6 项挤在一行时窄屏会互相叠字。
选中项就是这张卡当前所在的画布栏目;点任意一项即落盘(含点当前已选中的那一项:
用户显式确认归属,不做隐式 no-op)。视觉选中态由 `aria-checked="true"` 驱动,
与读屏读到的状态是同一个属性。
*/}
<div
ref={optionsRef}
role="radiogroup"
aria-label="素材类型"
className="game-resource-type-options"
>
{RESOURCE_TYPE_CATEGORY_OPTIONS.map((option, index) => {
const active = option.id === activeCategory;
return (
<PlatformNavigableListItem
key={option.id}
role="radio"
aria-checked={active}
// roving tabindex:只有选中项进入 Tab 序列,Tab 进组只停一次。
tabIndex={active ? 0 : -1}
disabled={saving}
className="game-resource-type-option"
trailing={
active ? <Check size={14} aria-hidden="true" /> : null
}
onClick={() => {
setPendingCategory(option.id);
void saveResourceType(option.id);
}}
onKeyDown={(event) => handleOptionKeyDown(event, index)}
>
{option.label}
</PlatformNavigableListItem>
);
})}
</div>
{error ? (
<p className="game-resource-type-error" role="alert">
{error}
</p>
) : null}
</div>
</ThemedModal>
);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,12 @@
/**
* 素材名取 `localPath` 的 basenamemanifest 资产没有独立的显示名字段,
* 与资源卡、`@` 面板的显示口径一致。
*
* 「编辑素材标签」与「设置素材类型」两块面板共用这一份 —— 副标题是同一个素材名,
* 两处各写一份 basename 实现迟早会出现一个带目录、一个不带。
*/
export function resourceAssetDisplayName(localPath: string) {
const normalized = localPath.replaceAll('\\', '/');
const segments = normalized.split('/');
return segments[segments.length - 1] || localPath;
}

Some files were not shown because too many files have changed in this diff Show More