From e4e9ee0ac85fb77240b2b3df86e09b2d42210bf0 Mon Sep 17 00:00:00 2001 From: d-robotics Date: Tue, 13 Oct 2026 16:14:06 +0530 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8E=AB=2010:=20claim=20demo=20fixture?= =?UTF-8?q?=20seed=20ticket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md b/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md index d56dd456..d80fa469 100644 --- a/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md +++ b/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md @@ -1,6 +1,6 @@ # 10 · 演示 fixture:播种脚本 + 场景清单人工验收 -Status: ready-for-agent +Status: claimed Type: task Blocked by: 05, 06, 07, 08 Spec: [spec.md](../spec.md) §4、§2 R3-3:a / R3-4:ok、§6 seam ④ From 5c713eda86dc806daf90257afb6890b03bb6d0ae Mon Sep 17 00:00:00 2001 From: d-robotics Date: Tue, 13 Oct 2026 16:40:57 +0530 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8E=AC=2010:=20one-command=20demo=20f?= =?UTF-8?q?ixture=20seed=20+=20scenario=20walkthrough=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/manuals/ise-demo-walkthrough.zh-CN.md | 213 +++++ scripts/local/seed-ise-demo.mjs | 931 +++++++++++++++++++++ 2 files changed, 1144 insertions(+) create mode 100644 docs/manuals/ise-demo-walkthrough.zh-CN.md create mode 100644 scripts/local/seed-ise-demo.mjs diff --git a/docs/manuals/ise-demo-walkthrough.zh-CN.md b/docs/manuals/ise-demo-walkthrough.zh-CN.md new file mode 100644 index 00000000..e556c0ac --- /dev/null +++ b/docs/manuals/ise-demo-walkthrough.zh-CN.md @@ -0,0 +1,213 @@ +# ISE 演示环境人工验收走查手册(原地切片结构编辑与质检同款返修视图) + +适用版本:inplace-slice-editing 全量合入后的集成分支(spec §4 场景 ①–⑩)。 +配套播种脚本:`scripts/local/seed-ise-demo.mjs`(一条命令从零重建演示环境,spec §6 seam ④)。 + +--- + +## 〇、准备演示环境(一次性) + +```bash +# 在本 worktree 根目录执行;需要 docker 快照库 27018 在跑、本机有 ffmpeg +node scripts/local/seed-ise-demo.mjs # 重建(幂等:先清后建) +node scripts/local/seed-ise-demo.mjs --clean # 用完整体清除演示数据与媒体 +``` + +脚本自动完成:合成 4 分钟双相机视频(场景字幕 S1–S8)→ 写入 `ise-demo-*` 隔离组织与账号 → +自起 3011 专用 API 走真实业务流(领取 → 8 切片首轮提交 → 质检打回 + 8 条意见)→ 停掉实例。 +产物:**任务已处于第 1 轮返修、定向归还原标注员**,可直接开始下面两个案例。 + +**账号**(仅本地合成账号,密码统一 `ise-demo-2026`): + +| 角色 | 手机号(登录标识) | +|---|---| +| 标注员(返修人) | `13800001010` | +| 质检员 | `13800001011` | +| 管理员 | `13800001012` | + +**启动本地复刻栈**(两个终端,都在本 worktree;5173 被共用栈占用时前端换空闲端口如 5174): + +```bash +source scripts/local/env-local-snapshot.sh && npm run dev:api # 终端 1:API 3001 +npx vite --port 5174 --strictPort # 终端 2:前端 +``` + +**采集剧本**(4 分钟 = 240 秒,8 片 × 30 秒;画面顶部有场景字幕): + +| 片 | 时间段 | 内容 | 首轮状态 | +|---|---|---|---| +| S1 | 0–30s | 货架补货(6 个动作无缝密集覆盖) | 保留 | +| S2 | 30–60s | 鲜食处理(3 个动作) | 保留 | +| S3 | 60–90s | 3 个无效动作(遮挡/起雾/走过) | 保留 | +| S4 | 90–120s | 蒸点备货(2 个动作) | 保留 | +| S5 | 120–150s | 遮挡走动区 | **首轮已舍弃** | +| S6 | 150–180s | 台面清洁(2 个动作) | 保留 | +| S7 | 180–210s | 收银结算(1 无效 + 2 有效动作) | 保留 | +| S8 | 210–240s | 闭店巡检(2 个动作) | 保留 | + +**第 1 轮 8 条意见**(整体 1 / 切片 2 / 动作 3 / 时间点 2,已冻结在退回基线): + +| # | 粒度 | 目标 | 意见 | 铺垫的场景 | +|---|---|---|---|---| +| 1 | 整体 | 任务 | 边界与动作起止不贴合,原地调整结构后重送 | ② | +| 2 | 切片 | S1 | 建议第 15 秒附近拆分 | ⑤拆分 | +| 3 | 切片 | S3 | 建议整片舍弃 | ⑤舍弃消红 | +| 4 | 动作 | S2 · act-07(33–40s) | 描述不符,改双手并补细节 | ⑤动作消红 | +| 5 | 动作 | S7 · act-17(183–190s) | 缩短至实际扫码区间 | ③拖边界穿过 | +| 6 | 动作 | S4 · act-13(93–101s) | 应改判无效 | ⑤改无效 | +| 7 | 时间点 | S2 @46.0s | 关东煮台面残留水渍 | ②字幕 | +| 8 | 时间点 | S8 @225.5s | 价签歪斜 | ⑨ QC 定位 | + +--- + +## 一、标注员案例(场景 ①–⑧) + +> 页面入口:浏览器打开 `http://127.0.0.1:5174` → 标注员登录 → +> `http://127.0.0.1:5174/plugins/annotation-qa/workflows/all/annotate` +> → 「我的任务」顶部红色「打回」徽标的 **ISE 演示** 任务 → 打开工作台。 + +### ① 接到返修任务,看到意见全景 + +1. 工作台加载后:视频可播(双目,左上/右下角有 LEFT/RIGHT CAM 字幕),统一帧范围 0–240s。 + **预期**:切分区 S1/S2/S3/S4/S7/S8 有红色时间块(含未处理意见),S5 灰(已舍弃); + 意见徽标(红=意见 N,灰=已处理 N)挂在对应动作块上;时间轴有两个红点(时间点意见 7/8)。 +2. 按 **J / K** 逐条跳意见(与质检同一肌肉记忆)。 + **预期**:每次跳转定位到意见目标(切片/动作/时间点),红色高亮随跳转移动,共 8 条循环。 +3. 播放视频穿过意见区间。 + **预期**:画面下方**意见字幕三排**随播放头切换显示当前时刻命中的意见内容。 + +### ② J/K 逐条跳 + 字幕三排(已含在 ① 的 2/3 步) + +**预期**:`J` 到下一条、`K` 到上一条;字幕只显示与当前播放头相关的意见,离开区间即消失。 + +### ③ 拖边界穿过动作 → 三选卡(截断 / 挪片 / 判无效,各演示一次) + +> 目标边界:**S6/S7 边界(180.0s)**。act-17 = 183–190s(有效)。 + +1. **演示「判无效」**:用鼠标拖动 S6/S7 边界手柄向右越过 185s(或进入切片编辑模式后 + `Shift+→` 粗步进),松手时边界扫过 act-17 内部。 + **预期**:视频画面上**浮出三选卡**(锚定在越界分界处),列出被穿过的动作 act-17。 + 点选 **3 判无效** → 卡关闭,act-17 变无效(无效徽标),边界生效落在 185s。 + *(此时意见 5 自动消红——目标动作已改动,见场景 ⑤。)* +2. **演示「截断」**:先把边界拖回 180s 附近复原(可 `Ctrl/⌘+Z` 撤销上一步,见 ⑦), + 再次拖到 185s 穿过 act-17 → 三选卡出现 → 点 **1 截断** → act-17 被切成两段 + (183–185 与 185–190,两段均为 pending/described 既有状态),边界生效。 +3. **演示「挪片」**:再次复原后拖到 185s → 三选卡 → 点 **2 挪片** → act-17 边界被修剪 + 使其完整落入一侧(起点吸附到 185s),边界生效。 +4. **演示「不选 = 不生效」**:复原后拖到 185s → 三选卡出现 → 按 **Esc**(或点关闭)。 + **预期**:**边界停在原地 180s**,动作原样未动(R2-Q1 拦)。 + +### ④ 贴边场景:无效自动跟随;有效弹两选卡(默认跟随) + +> 目标边界:仍是 **S6/S7 边界(180.0s)**。act-inv = 180–181s(无效,起点贴住边界)。 + +1. **无效贴边自动跟随**:拖边界向**左** 2s(180→178)松手。 + **预期**:**无弹卡**,act-inv 起点自动跟随伸缩到 178s(区间语义),边界生效。 +2. **有效贴边两选卡**:换目标 **S2/S3 边界(60.0s)**,act-09 = 52–60s(有效,终点贴住边界)。 + 拖边界向**右** 1s(60→61)松手。 + **预期**:浮出**两选卡**(跟随伸缩(默认)/ 保持原边界),高亮"跟随"为默认项。 + - 按 **Enter** 或点选跟随 → act-09 伸缩为 52–61s; + - 复原后重试并选 **保持原边界** → act-09 保持 52–60s(完整落入扩展后的 S2)。 +3. **模式外键位不变**:退出弹卡后按 `1`/`2`(慢速/常速)、`B`(片头复查)等照常工作。 + +### ⑤ 合并 / 拆分 / 舍弃 → 意见跟块消红 + +1. **拆分 S1**(意见 2 要求):定位到 S1 第 15s 附近(`←/→` 逐帧),按 **C**(或点悬停"+")切分。 + **预期**:S1 变两片;**意见 2 跟到包含意见足迹起点的新片**,且因承接片结构(起止/名称) + 已变化 → **意见 2 消红(灰)**;红块随拆分重新分配到剩余未处理意见。 +2. **舍弃 S3**(意见 3 要求):高亮 S3 后按 **G**(模式外)或在切片编辑模式内按 **G** + → 舍弃原因弹窗选字典原因「画面遮挡(演示)」确认。 + **预期**:S3 整片转灰;**意见 3 整条自动消红**(舍弃 = 最强响应);S3 内 3 个无效动作 + 全部自动转无效并保留证据;相邻 S2/S3、S3/S4 边界不动。 +3. **合并 S7 + S8**:点击两片间垃圾桶图标(或选中区间删除合并)。 + **预期**:两片合一;意见 5(act-17)与意见 8(时间点 @225.5s)**跟到合并后的新块**, + 意见栏仍可 J/K 定位;合并片结构已变 → 未处理的切片/时间点意见随之消红。 +4. **动作级消红**:打开 act-07(S2,33–40s)描述编辑,按意见 4 改为 + 「双手拿取饭团并核对保质期与价签」保存。 + **预期**:act-07 徽标红→灰(**意见 4 消红**:目标动作已改动)。 +5. **改判无效**:选中 act-13(S4,93–101s)按 **G**(annotate 相模式外 = 标无效)。 + **预期**:act-13 转无效;**意见 6 消红**。 + +### ⑥ E 进切片编辑模式:←/→ 挪边界、G 舍弃、Esc 退出 + +1. 按 **E** 进入模式。 + **预期**:出现模式指示(帮助弹层多出模式键表),当前高亮边界可编辑。 +2. **← / →** 逐帧挪高亮边界;**Shift + ← / →** 粗步进 0.5s;**↑ / ↓** 切换高亮到相邻边界。 + **预期**:每次挪动落点吸附统一帧边界(0.1s 网格);若挪动穿过动作 → 三选卡(同 ③)。 +3. **G** 舍弃当前高亮片(走既有舍弃原因弹窗,可撤销恢复)。 +4. **E** 或 **Esc** 退出模式。 + **预期**:全部键位复原(`←/→` 回到逐帧播放步进,`G` 回到标无效)。 +5. **模式外键位不串扰**:进出模式后 `E`(其他输入框聚焦时)不影响文字输入。 + +### ⑦ 结构编辑后撤销 / 重做仍正确 + +1. 连续做 2–3 个结构操作(挪边界、拆分、合并)。 +2. 按 **Ctrl/⌘ + Z** 逐步撤销。 + **预期**:每次撤销精确回退一个结构操作(切片集与动作集同时还原,包括三选卡的产物); + 意见跟块随结构回退重新计算(红块回到撤销前的分布)。 +3. 按 **Ctrl/⌘ + Shift + Z** 重做。 + **预期**:重做与撤销镜像一致。 +4. 舍弃片的撤销:对 ⑤-2 舍弃的 S3 按 `Ctrl/⌘+Z`。 + **预期**:S3 恢复保留,3 个无效动作还原,意见 3 回到未处理(红)。 + +### ⑧ 重新送检(附结构变更摘要) + +1. 处理完 8 条意见(或对误报意见点「不改了」留痕)。 +2. 点**送检**。 + **预期**:送检走既有确认流程;服务端从"退回基线 vs 提交工作区"计算**结构变更摘要** + (合并 X 次 / 拆分 Y 次 / 弃用 Z 片 / 边界挪动 N 处)随送检记录落库; + 本地演示中可在下一步质检页顶部看到该摘要(场景 ⑨ 的横幅)。 + +--- + +## 二、质检员案例(场景 ⑨–⑩) + +> 页面入口:标注员账号退出,质检员 `13800001011` 登录 → +> `http://127.0.0.1:5174/plugins/annotation-qa/workflows/all/quality` +> → 领取/打开 **ISE 演示** 任务 → 审查工作台。 + +### ⑨ 复审视图:J/K 跳意见、意见栏红/灰、字幕、红灰对照 + 结构对比面板 + +1. **顶部横幅**:审查工作台顶部显示 + 「第 1 轮返工送检 · 结构变更摘要:合并 X / 拆分 Y / 弃用 Z / 挪边 N」(无变化则显示"本轮结构无变化")。 +2. **意见栏(ReworkOpinionRail)**:侧栏按意见目标列出 8 条原意见,**红**=未解决、 + **灰**=已处理/跳过/历史轮;点选任一条定位到意见位置。 +3. **J / K** 在审查键表内逐条跳意见(与标注员同一肌肉记忆)。 + **预期**:跳转定位绑定 `seekSlice/seekAction/seekTime`(整体/切片/动作/时间点各自定位准确)。 +4. **意见字幕**:播放视频穿过意见区间时,下方字幕显示命中的意见内容(三排随播放头切换)。 +5. **红灰对照双栏视图(ReworkContrastView)**:左=退回基线、右=提交版本,按意见目标 + 对齐渲染切片/动作结构;未解决意见红显、已处理灰显。 + **预期**:标注员在 ③–⑤ 做的每处结构变化(拆分/舍弃/合并/挪边/改无效)在双栏中 + 逐项可对照,意见红灰与意见栏一致。 +6. **结构对比面板(ReworkComparisonPanel)**:展示具体结构差异明细, + **叠加意见级红/灰判定列**(R2-Q3:a+b:对照视图管"改了没",结构面板管"具体改什么")。 + +### ⑩ D7 逐条判定 → 确认提交 + +1. 在 **ReviewProblemPanel**(判定操作留在既有面板,意见栏只做导航与展示,R2-Q8:a) + 对每条原意见做 D7 核对:**已解决** / **仍有问题**(后者必须给出现场意见)。 +2. 全部判定完成后**提交正式决定**(通过 / 再退回)。 + **预期**:判定随决定冻结(提交后不可撤销,改判走再退回); + - 通过:任务进入后续流程; + - 再退回:生成第 2 轮退回基线,任务再次定向归还标注员(回到案例一,可循环演示)。 + +--- + +## 三、清理与重建 + +```bash +node scripts/local/seed-ise-demo.mjs --clean # 清除 ise-demo-* 数据 + 媒体 + 物化产物 +node scripts/local/seed-ise-demo.mjs # 随时整体重建(幂等) +``` + +也可保留 Mongo 数据只重置任务状态:`ISE_DEMO_SKIP_MEDIA=1 node scripts/local/seed-ise-demo.mjs` +(复用已生成的视频/PTS/IMU,仅重建任务与意见状态)。 + +## 四、已知边界(当前实现下不可演示/需注意的点) + +- **`v` 返工回看**、`Ctrl/⌘+↑/↓` 动作定位等为既有能力,非本 feature 新增,走查不覆盖。 +- 意见"跳过(不改了)"留痕后复审可见,但**消红判定仍以目标是否改动为准**; + 被跳过的意见在 QC 侧显示灰(已处理),场景 ⑩ 可对其实测"仍有问题"改判。 +- **整体意见(意见 1)消红条件**:本轮 7 条局部意见全部处理完(红=0)后自动消红 + (`computeReworkEmphasis` 派生规则);走查 ⑤ 做完前它保持红属预期。 +- 合成视频为 `testsrc2` 图形 + 点阵字幕,无真实人手;动作语义按字幕与走查剧本对照。 diff --git a/scripts/local/seed-ise-demo.mjs b/scripts/local/seed-ise-demo.mjs new file mode 100644 index 00000000..95fb6fd3 --- /dev/null +++ b/scripts/local/seed-ise-demo.mjs @@ -0,0 +1,931 @@ +#!/usr/bin/env node +// 🎫 ticket 10 — inplace-slice-editing 演示 fixture 一键播种(seam ④)。 +// +// 从零重建人工验收演示环境(R3-3:a / R3-4:ok,spec §4 场景 ①–⑩ 的数据基座): +// 1. 合成 ~4 分钟双相机采集(ffmpeg testsrc2 + 场景字幕;左右目画面可区分) +// + 严格递增的 PTS CSV(帧数与视频逐帧一致)+ accel/gyro 成对 IMU CSV, +// 写入本地 workspace 挂载根(safeMaterializationSourcePath 安全约束)。 +// 2. 直写快照库(27018 容器,本地复刻专用)ise-demo-* 前缀的隔离组织/ +// 账号/项目/模板/切片字典/批次/Run/任务,全部带 ise-demo- 前缀可整体清除。 +// 3. 自起专用 API 实例(默认 3011,不碰 3001/5173),走真实业务流: +// 标注员随机领取 → 提交 8 切片首轮工作区(真实 ffmpeg 切片物化)→ +// 质检员领取 → 保存 8 条意见(整体 1 / 切片 2 / 动作 3 / 时间点 2)→ +// 打回。产物 = 退回基线 + 定向归还原标注员的返修任务。 +// 4. 取证后停掉自起实例;不留任何后台进程。 +// +// 用法: +// node scripts/local/seed-ise-demo.mjs # 一键重建(幂等:先清后建) +// node scripts/local/seed-ise-demo.mjs --clean # 只清除演示数据与媒体 +// node scripts/local/seed-ise-demo.mjs --keep-api # 调试:结束后保留 3011 实例 +// +// 环境变量(全部可选): +// ISE_DEMO_API_PORT 自起 API 端口(默认 3011) +// ISE_DEMO_SKIP_MEDIA=1 复用已有媒体文件,仅重建任务状态 +// ISE_DEMO_MONGO_URI mongosh 连接串(默认 mongodb://127.0.0.1:27018/drobodata-fanyu) +// +// 凭据(仅本地合成账号,密码为固定合成值,不入库任何真实凭据): +// 标注员 13800001010 / 质检员 13800001011 / 管理员 13800001012,密码 ise-demo-2026 +// +// 红线遵循:只写本地容器与 workspace 目录;绝不触碰公司集群 / BOS / 3001 / 5173。 + +import { spawn, spawnSync } from "node:child_process"; +import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"; +import { basename, dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import zlib from "node:zlib"; + +const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url)); +const WORKTREE_ROOT = resolve(SCRIPT_DIR, "..", ".."); +const KEEP_API = process.argv.includes("--keep-api"); +const CLEAN_ONLY = process.argv.includes("--clean"); +const SKIP_MEDIA = process.env.ISE_DEMO_SKIP_MEDIA === "1"; +const API_PORT = Number(process.env.ISE_DEMO_API_PORT || 3011); +const MONGO_URI = process.env.ISE_DEMO_MONGO_URI || "mongodb://127.0.0.1:27018/drobodata-fanyu"; + +// 主仓根(local-data 为未跟踪目录,各 worktree 各有一份;workspace 挂载根 +// 与 env-local-snapshot.sh 的 WORKSPACE_MOUNT_PATH 指向主仓那份)。 +function mainRepoRoot() { + const gitDir = spawnSync("git", ["-C", WORKTREE_ROOT, "rev-parse", "--git-common-dir"], { encoding: "utf8" }); + if (gitDir.status === 0) { + const dir = gitDir.stdout.trim(); + return resolve(WORKTREE_ROOT, dir.endsWith("/.git") ? dirname(dir) : dir); + } + return resolve(WORKTREE_ROOT, "..", "..", "..", ".."); +} +const MAIN_ROOT = mainRepoRoot(); +const WORKSPACE = resolve(MAIN_ROOT, "local-data", "workspace"); + +const CAPTURE_DIR = "ISE_DEMO_CAPTURE_20261013"; +const MEDIA_DIR = resolve(WORKSPACE, CAPTURE_DIR); +const DEMO = { + org: "org-ise-demo", + supplier: "ise-demo-supplier", + project: "ise-demo-project", + workflow: "ise-demo-workflow", + template: "ise-demo-template", + batch: "ise-demo-batch", + run: "ise-demo-run", + task: "ise-demo-task", + item: "ise-demo-item", + annotator: "ise-demo-annotator", + qc: "ise-demo-qc", + admin: "ise-demo-admin", + nodeId: "ise-demo-human-gate", + captureId: "ise-demo-capture-0001", + password: "ise-demo-2026", + // bcrypt(ise-demo-2026, cost 10) — 本地合成账号专用,可随时旋转。 + passwordHash: "$2a$10$VpNetpCU/Rjz1QQBG3k5FOieaQ5BdenSDKtRh1kQ3n3sStf1P0wLa", +}; + +const FPS = 10; +const DURATION_S = 240; + +function log(step, message) { + console.log(`[seed-ise-demo ${step}] ${message}`); +} +function fail(step, message) { + console.error(`[seed-ise-demo ${step}] ✗ ${message}`); + process.exitCode = 1; + throw new Error(message); +} +function sh(cmd, args, opts = {}) { + const r = spawnSync(cmd, args, { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, ...opts }); + if (r.status !== 0) { + fail("sh", `${cmd} ${args.join(" ")} → exit ${r.status}\n${r.stderr || r.stdout}`); + } + return r.stdout.trim(); +} +const now = () => new Date().toISOString().replace(/\.\d+Z$/, "Z"); + +// --------------------------------------------------------------------------- +// 1. 媒体合成:双相机 MP4 + 逐帧 PTS + IMU +// --------------------------------------------------------------------------- + +// 与服务端 ffprobeDurationSeconds 同一口径(format=duration)。 +function ffprobeDuration(path) { + return Number(sh("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", path])); +} +function ffprobeFrames(path) { + return Number(sh("ffprobe", ["-v", "error", "-select_streams", "v:0", "-count_packets", "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", path])); +} + +const SCENES = [ + { from: 0, to: 30, text: "S1 SHELF RESTOCK" }, + { from: 30, to: 60, text: "S2 FRESH FOOD" }, + { from: 60, to: 90, text: "S3 INVALID x3" }, + { from: 90, to: 120, text: "S4 BUN PREP" }, + { from: 120, to: 150, text: "S5 DISCARD RANGE" }, + { from: 150, to: 180, text: "S6 CLEANING" }, + { from: 180, to: 210, text: "S7 CHECKOUT" }, + { from: 210, to: 240, text: "S8 CLOSING" }, +]; + +// —— 本机 ffmpeg 无 drawtext:用内置 5x7 点阵字体渲染标签 PNG(零依赖)。—— +const FONT57 = { + A: [0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11], B: [0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e], + C: [0x0e, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0e], D: [0x1c, 0x12, 0x11, 0x11, 0x11, 0x12, 0x1c], + E: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f], F: [0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10], + G: [0x0e, 0x11, 0x10, 0x17, 0x11, 0x11, 0x0f], H: [0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11], + I: [0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e], J: [0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c], + K: [0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11], L: [0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f], + M: [0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11], N: [0x11, 0x19, 0x15, 0x13, 0x11, 0x11, 0x11], + O: [0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e], P: [0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10], + Q: [0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d], R: [0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11], + S: [0x0f, 0x10, 0x10, 0x0e, 0x01, 0x01, 0x1e], T: [0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04], + U: [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e], V: [0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04], + W: [0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11], X: [0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11], + Y: [0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04], Z: [0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f], + "0": [0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e], "1": [0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e], + "2": [0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f], "3": [0x1f, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0e], + "4": [0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02], "5": [0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e], + "6": [0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e], "7": [0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08], + "8": [0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e], "9": [0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c], + " ": [0, 0, 0, 0, 0, 0, 0], "(": [0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02], + ")": [0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08], "-": [0, 0, 0, 0x1f, 0, 0, 0], + "/": [0x01, 0x01, 0x02, 0x04, 0x08, 0x10, 0x10], ".": [0, 0, 0, 0, 0, 0x0c, 0x0c], +}; + +const CRC_TABLE = (() => { + const table = new Int32Array(256); + for (let n = 0; n < 256; n += 1) { + let c = n; + for (let k = 0; k < 8; k += 1) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; + table[n] = c; + } + return table; +})(); +function crc32(buf) { + let c = ~0; + for (const b of buf) c = CRC_TABLE[(c ^ b) & 0xff] ^ (c >>> 8); + return ~c >>> 0; +} +function pngChunk(type, data) { + const length = Buffer.alloc(4); + length.writeUInt32BE(data.length); + const body = Buffer.concat([Buffer.from(type, "ascii"), data]); + const crc = Buffer.alloc(4); + crc.writeUInt32BE(crc32(body)); + return Buffer.concat([length, body, crc]); +} +function encodePNG(width, height, rgba) { + const ihdr = Buffer.alloc(13); + ihdr.writeUInt32BE(width, 0); + ihdr.writeUInt32BE(height, 4); + ihdr[8] = 8; ihdr[9] = 6; // 8-bit RGBA + const raw = Buffer.alloc(height * (width * 4 + 1)); + for (let y = 0; y < height; y += 1) { + raw[y * (width * 4 + 1)] = 0; + rgba.copy(raw, y * (width * 4 + 1) + 1, y * width * 4, (y + 1) * width * 4); + } + return Buffer.concat([ + Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), + pngChunk("IHDR", ihdr), + pngChunk("IDAT", zlib.deflateSync(raw, { level: 9 })), + pngChunk("IEND", Buffer.alloc(0)), + ]); +} +function labelPNG(text, { scale = 4, fg = [255, 255, 255, 255], bg = [0, 0, 0, 140], pad = 10 } = {}) { + const advance = 6 * scale; + const glyphs = [...text.toUpperCase()].map((ch) => FONT57[ch] || FONT57["?"]); + const width = pad * 2 + advance * glyphs.length - scale; + const height = pad * 2 + 7 * scale; + const rgba = Buffer.alloc(width * height * 4); + for (let i = 0; i < width * height; i += 1) { + rgba[i * 4] = bg[0]; rgba[i * 4 + 1] = bg[1]; rgba[i * 4 + 2] = bg[2]; rgba[i * 4 + 3] = bg[3]; + } + glyphs.forEach((rows, gi) => { + rows.forEach((bits, ry) => { + for (let rx = 0; rx < 5; rx += 1) { + if (!((bits >> (4 - rx)) & 1)) continue; + for (let sy = 0; sy < scale; sy += 1) { + for (let sx = 0; sx < scale; sx += 1) { + const x = pad + gi * advance + rx * scale + sx; + const y = pad + ry * scale + sy; + const o = (y * width + x) * 4; + rgba[o] = fg[0]; rgba[o + 1] = fg[1]; rgba[o + 2] = fg[2]; rgba[o + 3] = fg[3]; + } + } + } + }); + }); + return { png: encodePNG(width, height, rgba), width, height }; +} + +function generateMedia() { + mkdirSync(MEDIA_DIR, { recursive: true }); + const left = resolve(MEDIA_DIR, "ISE_DEMO_camera_left.mp4"); + const right = resolve(MEDIA_DIR, "ISE_DEMO_camera_right.mp4"); + const leftPts = resolve(MEDIA_DIR, "ISE_DEMO_camera_left_pts.csv"); + const rightPts = resolve(MEDIA_DIR, "ISE_DEMO_camera_right_pts.csv"); + const imu = resolve(MEDIA_DIR, "ISE_DEMO_imu.csv"); + const mediaReady = + SKIP_MEDIA && + [left, right, leftPts, rightPts, imu].every((p) => existsSync(p) && statSync(p).size > 1024); + if (mediaReady) { + log("media", `复用已有媒体: ${MEDIA_DIR}`); + } else { + log("media", `ffmpeg 合成 ${DURATION_S}s 双相机视频 → ${MEDIA_DIR}`); + // 标签 PNG:8 个场景标签(顶部居中,左右目共用)+ 相机标签(左下常驻)。 + const labelsDir = resolve(MEDIA_DIR, "labels"); + mkdirSync(labelsDir, { recursive: true }); + let labelIndex = 0; + const writeLabel = (png) => { + labelIndex += 1; + const file = resolve(labelsDir, `label-${labelIndex}.png`); + writeFileSync(file, png.png); + return { index: labelIndex, width: png.width, height: png.height }; + }; + const sceneLabels = SCENES.map((scene) => ({ + ...writeLabel(labelPNG(scene.text, { scale: 4 })), + x: "(W-w)/2", y: 26, enable: `between(t,${scene.from},${scene.to})`, + })); + const encode = (out, camera) => { + const camLabel = { + ...writeLabel(labelPNG(camera === "left" ? "LEFT CAM" : "RIGHT CAM MIRROR", { scale: 3, fg: camera === "left" ? [255, 235, 100, 255] : [120, 235, 255, 255] })), + x: 16, y: "H-h-14", enable: null, + }; + const overlays = [...sceneLabels, camLabel]; + const inputs = []; + for (let i = 1; i <= labelIndex; i += 1) inputs.push("-i", resolve(labelsDir, `label-${i}.png`)); + const chain = [camera === "right" ? "[0:v]hflip,hue=h=25[base]" : "[0:v]null[base]"]; + overlays.forEach((o, i) => { + const src = i === 0 ? "base" : `m${i - 1}`; + const dst = i === overlays.length - 1 ? "vout" : `m${i}`; + const opts = o.enable ? `:enable='${o.enable}'` : ""; + chain.push(`[${src}][${o.index}:v]overlay=x=${o.x}:y=${o.y}${opts}[${dst}]`); + }); + sh("ffmpeg", [ + "-y", "-loglevel", "error", + "-f", "lavfi", "-i", `testsrc2=size=640x360:rate=${FPS}:duration=${DURATION_S}`, + ...inputs, + "-filter_complex", chain.join(";"), + "-map", "[vout]", + "-c:v", "libx264", "-preset", "ultrafast", "-crf", "28", "-pix_fmt", "yuv420p", + "-movflags", "+faststart", out, + ]); + }; + encode(left, "left"); + encode(right, "right"); + } + const frames = ffprobeFrames(left); + const framesRight = ffprobeFrames(right); + if (frames !== framesRight) { + fail("media", `左右目帧数不一致: left=${frames} right=${framesRight}`); + } + const duration = ffprobeDuration(left); + log("media", `帧数=${frames} 时长=${duration.toFixed(6)}s`); + + // PTS:左右目同源同时钟(合成双目同步采集),origin 固定常量(幂等); + // 严格递增、逐帧一行,行数与视频帧数严格相等(物化硬校验)。 + // 同步 origin 使 commonStart=origin → 统一边界网格从第 0 帧铺到最后一帧, + // 切片区间与任务 [clipStart, clipEnd] 严格重合(完整覆盖校验 1ms 容差)。 + const leftOrigin = 1_760_000_000_000_000n; + const step = BigInt(Math.round(1e6 / FPS)); + const rightOrigin = leftOrigin; + const ptsCsv = (origin) => { + const rows = ["timestamp_us"]; + for (let i = 0; i < frames; i += 1) rows.push(String(origin + step * BigInt(i))); + return rows.join("\n") + "\n"; + }; + if (!mediaReady) { + writeFileSync(leftPts, ptsCsv(leftOrigin)); + writeFileSync(rightPts, ptsCsv(rightOrigin)); + // IMU:50Hz accel/gyro 成对,覆盖范围向两端各外扩 1s(公共范围裁剪用)。 + const imuHz = 50; + const imuStart = leftOrigin - 1_000_000n; + const imuEnd = leftOrigin + BigInt(DURATION_S) * 1_000_000n + 1_000_000n; + const imuStep = BigInt(Math.round(1e6 / imuHz)); + const rows = ["timestamp_us,x,y,z,type"]; + for (let t = imuStart; t <= imuEnd; t += imuStep) { + const sec = Number(t - imuStart) / 1e6; + const ax = (0.12 * Math.sin(sec / 7)).toFixed(6); + const ay = (0.98 + 0.03 * Math.cos(sec / 11)).toFixed(6); + const az = (0.05 * Math.sin(sec / 3)).toFixed(6); + const gx = (0.4 * Math.sin(sec / 5)).toFixed(6); + const gy = (0.2 * Math.cos(sec / 9)).toFixed(6); + const gz = (0.1 * Math.sin(sec / 4)).toFixed(6); + rows.push(`${t},${ax},${ay},${az},accel`); + rows.push(`${t},${gx},${gy},${gz},gyro`); + } + writeFileSync(imu, rows.join("\n") + "\n"); + } + return { left, right, leftPts, rightPts, imu, frames, duration }; +} + +// 帧号 → 秒:与服务端 grid.Seconds 完全同式(l*mediaDuration/len(left)), +// 保证 resolve() 的 1e-6 对齐容差内零误差。 +function frameSecondsBuilder(frames, duration) { + return (frame) => (frame * duration) / frames; +} + +// --------------------------------------------------------------------------- +// 2. 任务剧本:8 切片 + 动作 + 第 1 轮 8 条意见(spec §4 场景的数据基座) +// --------------------------------------------------------------------------- + +function buildScriptData(sec, frames) { + // 边界帧号:网格首边界 = 第 0 帧(同步 origin),末边界 = 全部帧数; + // 与任务 [clipStart=0, clipEnd=duration] 严格重合(完整覆盖校验)。 + const B = [0, 300, 600, 900, 1200, 1500, 1800, 2100, frames]; + const sliceNames = ["货架补货", "鲜食处理", "无效动作整理", "蒸点备货", "遮挡与走动", "台面清洁", "收银结算", "闭店巡检"]; + const slices = B.slice(0, -1).map((_, i) => ({ + id: `ise-demo-slice-${i + 1}`, + name: i === 4 ? "" : sliceNames[i], + start: sec(B[i]), + end: sec(B[i + 1]), + // S5 = 首轮已舍弃片(spec §4 场景 1“1 舍弃片”);舍弃片名称清空。 + deliveryDisposition: i === 4 ? "discard" : undefined, + discardReason: i === 4 ? "演示剧本:画面长时间遮挡,首轮即判定不交付" : undefined, + annotationStatus: i === 4 ? "pending" : "labeled", + sourceIds: [`ise-demo-slice-${i + 1}-src`], + })); + + const A = (id, startF, endF, status, label, description, handedness) => ({ + id, + labelId: "", + label: "", + status, + isInvalid: status === "invalid" || undefined, + description, + handedness: handedness || "", + start: sec(startF), + end: sec(endF), + confidence: 1, + source: "manual", + }); + const actions = [ + // S1 密集连续段(全覆盖无缝):左右手/类别/描述齐备。 + A("ise-demo-act-01", 5, 50, "described", "08", "右手从推车拿起饮料整箱放入货架上层", "right"), + A("ise-demo-act-02", 50, 100, "described", "08", "左手整理货架前排商品并前移", "left"), + A("ise-demo-act-03", 100, 150, "described", "09", "双手将冷藏柜饮料逐排前移补齐", "both"), + A("ise-demo-act-04", 150, 200, "described", "08", "右手补货至货架第二层,左手扶稳货架", "right"), + A("ise-demo-act-05", 200, 250, "described", "11", "左手核对价签并更新过期标签", "left"), + A("ise-demo-act-06", 250, 300, "described", "08", "右手继续补货,左手收拢空纸箱", "both"), + // S2 常规段;act-07 终点贴住 S2/S3 边界(两选卡演示位)。 + A("ise-demo-act-07", 330, 400, "described", "01", "右手拿取饭团检查保质期", "right"), + A("ise-demo-act-08", 420, 500, "described", "02", "双手清理关东煮设备台面", "both"), + A("ise-demo-act-09", 520, 600, "described", "03", "右手将关东煮装入纸碗递给顾客", "right"), + // S3 三连无效动作(spec §4 场景 1“1 片含 3 个无效动作”)。 + A("ise-demo-act-10", 630, 680, "invalid", "", "顾客身影遮挡镜头,动作无法辨认"), + A("ise-demo-act-11", 720, 780, "invalid", "", "镜头起雾,画面模糊不可用"), + A("ise-demo-act-12", 830, 880, "invalid", "", "店员快速经过造成画面遮挡"), + // S4 常规段;act-13 带动作级意见(演示“改标无效”)。 + A("ise-demo-act-13", 930, 1010, "described", "04", "右手将蒸包放入蒸柜加热", "right"), + A("ise-demo-act-14", 1040, 1120, "described", "05", "双手整理蒸点陈列柜", "both"), + // S6 常规段。 + A("ise-demo-act-15", 1540, 1620, "described", "17", "右手用抹布擦拭收银台面", "right"), + A("ise-demo-act-16", 1700, 1780, "described", "18", "左手清洗并拧干清洁工具", "left"), + // S7:act-inv 起点贴住 S6/S7 边界(无效贴边自动跟随演示位); + // act-17 严格在片内(拖边界穿过 → 三选卡演示位)。 + A("ise-demo-act-inv", 1800, 1810, "invalid", "", "收银前画面短暂遮挡"), + A("ise-demo-act-17", 1830, 1900, "described", "14", "右手逐件扫描商品条码结算", "right"), + A("ise-demo-act-18", 1930, 2000, "described", "15", "双手装袋并递给顾客", "both"), + // S8 常规段。 + A("ise-demo-act-19", 2150, 2250, "described", "21", "双手核对货架价签并记录巡检结果", "both"), + A("ise-demo-act-20", 2300, 2380, "described", "22", "右手整理收银台周边设备", "right"), + ]; + return { slices, actions, sliceNames }; +} + +function buildOpinions(slices, actions, sec) { + const byAction = Object.fromEntries(actions.map((a) => [a.id, a])); + const bySlice = Object.fromEntries(slices.map((s) => [s.id, s])); + const P = (id, scope, extra, text) => ({ id: `ise-demo-op-${id}`, scope, text, ...extra }); + return [ + // 整体 1(spec §4 场景 2:J/K 逐条跳的锚点之一) + P("task", "task", { timeBasis: "task", atSeconds: 0 }, "整体:多段切片边界与动作起止不贴合,请结合以下逐条意见原地调整切片结构(可拆分/合并/舍弃/挪边界)后重新送检。"), + // 切片 2:S1 拆分建议(场景 5 拆分跟块)+ S3 舍弃建议(场景 5 舍弃整片消红 / 场景 6 G 舍弃) + P("slice-1", "slice", { sliceId: "ise-demo-slice-1", atSeconds: sec(150), timeBasis: "capture-seconds" }, "该片段动作密集且时长偏长(约 30 秒),建议在第 15 秒附近拆分为两片,便于复审逐段核对。"), + P("slice-3", "slice", { sliceId: "ise-demo-slice-3", atSeconds: sec(750), timeBasis: "capture-seconds" }, "该片段以无效动作为主(遮挡/画面模糊),建议整片舍弃;如需保留请重新划分有效区间。"), + // 动作 3:act-07 改描述;act-17 缩区间;act-13 改判无效 + P("act-07", "action", { sliceId: "ise-demo-slice-2", actionId: "ise-demo-act-07", atSeconds: byAction["ise-demo-act-07"].start, timeBasis: "capture-seconds" }, "动作描述与画面不符:实际为双手协同操作,请修正为双手并补充拿取对象细节。"), + P("act-17", "action", { sliceId: "ise-demo-slice-7", actionId: "ise-demo-act-17", atSeconds: byAction["ise-demo-act-17"].start, timeBasis: "capture-seconds" }, "该动作起止包含收银前的空闲等待,请缩短至实际扫码操作区间。"), + P("act-13", "action", { sliceId: "ise-demo-slice-4", actionId: "ise-demo-act-13", atSeconds: byAction["ise-demo-act-13"].start, timeBasis: "capture-seconds" }, "此动作画面后半段被蒸柜遮挡,应判定为无效,请改标无效。"), + // 时间点 2(spec §4 场景 2:字幕三排 + 时间点意见) + P("ts-1", "timestamp", { sliceId: "ise-demo-slice-2", atSeconds: sec(460), timeBasis: "capture-seconds" }, "此处关东煮台面有残留水渍,请核对是否需要补充清洁动作。"), + P("ts-2", "timestamp", { sliceId: "ise-demo-slice-8", atSeconds: sec(2255), timeBasis: "capture-seconds" }, "画面右侧价签歪斜,请确认是否需要记录价签维护动作。"), + ]; +} + +// --------------------------------------------------------------------------- +// 3. Mongo fixture 直写(mongosh,ise-demo-* 前缀整体可清) +// --------------------------------------------------------------------------- + +function mongoshEval(js, { allowFail = false } = {}) { + // REPL stdin 会带提示符噪音;落临时文件执行,输出即脚本自身 print。 + const tmp = resolve(process.env.TMPDIR || "/tmp", `ise-demo-seed-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.js`); + writeFileSync(tmp, js); + try { + const proc = spawnSync("mongosh", ["--quiet", MONGO_URI, tmp], { + encoding: "utf8", + maxBuffer: 64 * 1024 * 1024, + }); + if (proc.status !== 0 && !allowFail) { + fail("mongo", `mongosh exit ${proc.status}: ${proc.stderr}\n${proc.stdout}`); + } + return proc.stdout.trim(); + } finally { + rmSync(tmp, { force: true }); + } +} + +function cleanMongo() { + const js = ` +const ids = ${JSON.stringify([DEMO.org, DEMO.supplier, DEMO.project, DEMO.workflow, DEMO.template, DEMO.batch, DEMO.run, DEMO.task, DEMO.item, DEMO.annotator, DEMO.qc, DEMO.admin])}; +const item = ${JSON.stringify(DEMO.item)}, task = ${JSON.stringify(DEMO.task)}, org = ${JSON.stringify(DEMO.org)}, run = ${JSON.stringify(DEMO.run)}, project = ${JSON.stringify(DEMO.project)}; +const deleted = {}; +const d = (coll, filter) => { deleted[coll] = db.getCollection(coll).deleteMany(filter).deletedCount; }; +d("organizations", {id: org}); +d("suppliers", {id: ${JSON.stringify(DEMO.supplier)}}); +d("users", {organizationId: org}); +d("sessions", {userId: {$in: [${JSON.stringify(DEMO.annotator)}, ${JSON.stringify(DEMO.qc)}, ${JSON.stringify(DEMO.admin)}]}}); +d("projects", {id: project}); +d("workflows", {id: ${JSON.stringify(DEMO.workflow)}}); +d("annotationTemplates", {id: ${JSON.stringify(DEMO.template)}}); +d("annotationLabels", {organizationId: org}); +d("projectAnnotationLabels", {projectId: project}); +d("projectMembers", {projectId: project}); +d("humanBatches", {id: ${JSON.stringify(DEMO.batch)}}); +d("runs", {id: run}); +d("annotationTasks", {id: task}); +d("humanItems", {id: item}); +d("humanEvents", {organizationId: org}); +d("humanStageAttempts", {organizationId: org}); +d("humanRejects", {organizationId: org}); +d("humanClaimRequests", {organizationId: org}); +d("sliceRevisions", {taskId: task}); +d("annotationRevisions", {taskId: task}); +d("annotationReviews", {taskId: task}); +d("annotationWorklogEvents", {projectId: project}); +d("annotationWorkBuffers", {$or: [{organizationId: org}, {taskId: task}]}); +d("reviewDrafts", {organizationId: org}); +d("reviewSessions", {_id: {$regex: ":" + item + ":"}}); +d("reviewOperations", {organizationId: org}); +d("reworkBaselines", {organizationId: org}); +d("reworkHandlings", {organizationId: org}); +print(JSON.stringify(deleted)); +`; + const out = mongoshEval(js); + const counts = JSON.parse(out.split("\n").pop()); + const total = Object.values(counts).reduce((a, b) => a + b, 0); + log("clean", `已清除 ise-demo 数据 ${total} 条: ${JSON.stringify(counts)}`); +} + +const LABELS_22 = [ + ["01", "鲜食处理", "#E53935"], ["02", "关东煮备料和清洁", "#FB8C00"], ["03", "关东煮出餐", "#FDD835"], + ["04", "蒸点与糕点备货", "#43A047"], ["05", "蒸点陈列与出餐", "#00ACC1"], ["06", "热食加工与出餐", "#1E88E5"], + ["07", "即食商品陈列", "#5E35B1"], ["08", "常温商品补货", "#D81B60"], ["09", "冷藏饮料补货", "#8E24AA"], + ["10", "货架深度清洁", "#3949AB"], ["11", "价签与标识维护", "#039BE5"], ["12", "包装准备", "#00897B"], + ["13", "包装封装与材料整理", "#7CB342"], ["14", "收银扫码", "#C0CA33"], ["15", "顾客交付与内部协作", "#F4511E"], + ["16", "烟草、槟榔和小商品销售", "#6D4C41"], ["17", "表面清洁", "#757575"], ["18", "清洗清洁", "#546E7A"], + ["19", "清洁工具处理", "#00838F"], ["20", "垃圾和食品报废", "#2E7D32"], ["21", "门店巡检记录", "#C2185B"], + ["22", "工具、钥匙与设备管理", "#455A64"], +]; + +function writeFixtures(media, { slices, actions, sliceNames }) { + const t = now(); + const artifact = (id, name, path, type) => ({ + id, runId: DEMO.run, nodeId: DEMO.nodeId, name, type, size: "", path, + data: { collectionId: DEMO.captureId }, + }); + const artLeft = artifact("ise-demo-art-left", "ISE_DEMO_camera_left.mp4", media.left, "file"); + const artRight = artifact("ise-demo-art-right", "ISE_DEMO_camera_right.mp4", media.right, "file"); + const artLeftPts = artifact("ise-demo-art-left-pts", "ISE_DEMO_camera_left_pts.csv", media.leftPts, "file"); + const artRightPts = artifact("ise-demo-art-right-pts", "ISE_DEMO_camera_right_pts.csv", media.rightPts, "file"); + const artImu = artifact("ise-demo-art-imu", "ISE_DEMO_imu.csv", media.imu, "file"); + const binding = (port, artifacts) => ({ targetPortId: port, artifacts }); + + const labelIds = sliceNames.map((_, i) => `ise-demo-slice-label-${i + 1}`); + const discardReasonLabelId = "ise-demo-discard-reason-1"; + const sliceLabelDocs = sliceNames.map((name, i) => ({ + id: labelIds[i], organizationId: DEMO.org, kind: "slice", code: labelIds[i], name, + nameKey: `slice:${name.toLowerCase()}`, status: "active", version: 1, + createdByUserId: DEMO.admin, updatedByUserId: DEMO.admin, createdAt: t, updatedAt: t, + })); + sliceLabelDocs.push({ + id: discardReasonLabelId, organizationId: DEMO.org, kind: "discard_reason", code: discardReasonLabelId, + name: "画面遮挡(演示)", nameKey: "discard_reason:画面遮挡(演示)", status: "active", version: 1, + createdByUserId: DEMO.admin, updatedByUserId: DEMO.admin, createdAt: t, updatedAt: t, + }); + + const doc = { + organization: { id: DEMO.org, name: "泛宇演示组织(原地切片编辑)", slug: "ise-demo", status: "active", createdAt: t, updatedAt: t }, + supplier: { id: DEMO.supplier, organizationId: DEMO.org, name: "ISE 演示供应商", status: "active", createdAt: t, updatedAt: t }, + users: [ + { id: DEMO.annotator, organizationId: DEMO.org, name: "演示标注员", phone: "13800001010", email: "", role: "annotator", supplierId: DEMO.supplier, passwordHash: DEMO.passwordHash, status: "active", createdAt: t, updatedAt: t }, + { id: DEMO.qc, organizationId: DEMO.org, name: "演示质检员", phone: "13800001011", email: "", role: "quality_reviewer", supplierId: DEMO.supplier, passwordHash: DEMO.passwordHash, status: "active", createdAt: t, updatedAt: t }, + { id: DEMO.admin, organizationId: DEMO.org, name: "演示管理员", phone: "13800001012", email: "", role: "admin", supplierId: DEMO.supplier, passwordHash: DEMO.passwordHash, status: "active", createdAt: t, updatedAt: t }, + ], + project: { id: DEMO.project, organizationId: DEMO.org, name: "ISE 演示项目(原地切片编辑)", description: "ticket 10 人工验收演示:合成双相机采集 + 8 切片返修全流程", status: "active", createdAt: t, updatedAt: t }, + workflow: { id: DEMO.workflow, organizationId: DEMO.org, projectId: DEMO.project, name: "ISE 演示工作流", description: "演示专用", type: "annotation", definitionState: "published", definitionVersion: 1, definitionFamilyId: DEMO.workflow, nodes: [], createdAt: t, updatedAt: t }, + template: { + id: DEMO.template, organizationId: DEMO.org, projectId: DEMO.project, + name: "便利店22类行为标注模板(ISE 演示)", version: 6, status: "published", + labels: LABELS_22.map(([id, name, color]) => ({ id, name, color })), + humanStages: [ + { id: "annotation_combined", label: "真实切分与语义标注", kind: "annotation", requiredRole: "annotator", editorSchema: "temporal-semantic-annotation/v2" }, + { id: "quality_review", label: "切分与标注审核", kind: "review", requiredRole: "quality_reviewer", rejectTargets: ["annotation_combined"] }, + ], + createdAt: t, updatedAt: t, publishedAt: t, publishedByUserId: DEMO.admin, + }, + sliceLabels: sliceLabelDocs, + // 注意 bson 标签为全小写 s 结尾(discardReasonLabelIds / sliceLabelIds)。 + projectLabels: { id: `labels-${DEMO.project}`, organizationId: DEMO.org, projectId: DEMO.project, labelIds, sliceLabelIds: labelIds, discardReasonLabelIds: [discardReasonLabelId], updatedByUserId: DEMO.admin, updatedAt: t }, + members: [ + { id: "ise-demo-member-annotator", organizationId: DEMO.org, projectId: DEMO.project, userId: DEMO.annotator, supplierId: DEMO.supplier, roles: ["annotator"], createdAt: t, updatedAt: t }, + { id: "ise-demo-member-qc", organizationId: DEMO.org, projectId: DEMO.project, userId: DEMO.qc, supplierId: DEMO.supplier, roles: ["quality_reviewer"], createdAt: t, updatedAt: t }, + ], + batch: { + id: DEMO.batch, organizationId: DEMO.org, pluginId: "annotation-qa", projectId: DEMO.project, + workflowId: DEMO.workflow, runId: DEMO.run, gateNodeId: DEMO.nodeId, status: "active", + stages: [ + { id: "annotation_combined", label: "真实切分与语义标注", kind: "annotation", requiredRole: "annotator", editorSchema: "temporal-semantic-annotation/v2" }, + { id: "quality_review", label: "切分与标注审核", kind: "review", requiredRole: "quality_reviewer", rejectTargets: ["annotation_combined"] }, + ], + releasePolicy: "accepted_partition", partitionMaxItems: 32, partitionMaxWaitSeconds: 60, + maxReworkRounds: 5, itemCount: 1, requirePrePackageAcceptance: true, createdAt: t, updatedAt: t, + }, + run: { + id: DEMO.run, organizationId: DEMO.org, workflowId: DEMO.workflow, workflowName: "ISE 演示工作流", + projectId: DEMO.project, projectName: "ISE 演示项目(原地切片编辑)", trigger: "manual", + status: "running", currentNodeId: DEMO.nodeId, captureDirectories: [CAPTURE_DIR], + nodeExecutions: [{ + nodeId: DEMO.nodeId, nodeLabel: "ISE 演示人审闸口", status: "running", startedAt: t, logs: [], + inputBindings: [ + binding("fullLeftVideos", [artLeft]), + binding("leftTimestamps", [artLeftPts]), + binding("fullRightVideos", [artRight]), + binding("rightTimestamps", [artRightPts]), + binding("imu", [artImu]), + ], + artifacts: [artLeft, artLeftPts, artRight, artRightPts, artImu], + }], + createdAt: t, updatedAt: t, + }, + task: { + id: DEMO.task, organizationId: DEMO.org, projectId: DEMO.project, workflowId: DEMO.workflow, + runId: DEMO.run, nodeId: DEMO.nodeId, artifactId: artLeft.id, rightArtifactId: artRight.id, + sourceVideo: `/api/runs/${DEMO.run}/artifacts/${artLeft.id}/content`, + rightSourceVideo: `/api/runs/${DEMO.run}/artifacts/${artRight.id}/content`, + clipStart: 0, clipEnd: media.duration, templateId: DEMO.template, templateVersion: 6, + status: "pending_annotation", currentRevision: 0, createdAt: t, updatedAt: t, + }, + item: { + id: DEMO.item, organizationId: DEMO.org, pluginId: "annotation-qa", batchId: DEMO.batch, + projectId: DEMO.project, workflowId: DEMO.workflow, runId: DEMO.run, gateNodeId: DEMO.nodeId, + legacyTaskId: DEMO.task, subject: { + itemKey: `${CAPTURE_DIR}/ISE_DEMO_camera_left.mp4`, mediaType: "video/mp4", + artifactId: artLeft.id, payload: { rightArtifactId: artRight.id, captureDirectory: CAPTURE_DIR }, + }, + currentStageId: "annotation_combined", status: "ready", currentRevision: 0, reviewRound: 0, + maxReworkRounds: 5, version: 1, createdAt: t, updatedAt: t, + }, + }; + + const js = ` +const payload = ${JSON.stringify(doc)}; +const put = (coll, record) => db.getCollection(coll).replaceOne({id: record.id}, record, {upsert: true}); +put("organizations", payload.organization); +put("suppliers", payload.supplier); +for (const u of payload.users) put("users", u); +put("projects", payload.project); +db.projects.updateOne({id: payload.project.id}, {$unset: {workflowCount: "", workflowStatusCounts: ""}}); +put("workflows", payload.workflow); +db.workflows.updateOne({id: payload.workflow.id}, {$set: {status: "active"}}); +put("annotationTemplates", payload.template); +for (const l of payload.sliceLabels) put("annotationLabels", l); +db.projectAnnotationLabels.replaceOne({id: payload.projectLabels.id}, payload.projectLabels, {upsert: true}); +for (const m of payload.members) put("projectMembers", m); +put("humanBatches", payload.batch); +put("runs", payload.run); +put("annotationTasks", payload.task); +put("humanItems", payload.item); +print(JSON.stringify({ok: true, task: payload.task.id, item: payload.item.id})); +`; + const out = mongoshEval(js); + log("fixtures", `已写入 Mongo: ${out.split("\n").pop()}`); + return doc; +} + +// --------------------------------------------------------------------------- +// 4. 自起 API + 真实业务流(领取→提交→质检→打回) +// --------------------------------------------------------------------------- + +class ApiClient { + constructor(base) { + this.base = base; + this.cookies = new Map(); + } + cookieHeader() { + return [...this.cookies.entries()].map(([k, v]) => `${k}=${v}`).join("; "); + } + csrf() { + return this.cookies.get("droboticflow_csrf") || ""; + } + async call(method, path, body, extraHeaders = {}) { + const headers = { ...extraHeaders }; + if (this.cookies.size) headers.Cookie = this.cookieHeader(); + if (body !== undefined) headers["Content-Type"] = "application/json"; + if (this.csrf() && method !== "GET") headers["X-Droboticflow-CSRF-Token"] = this.csrf(); + const res = await fetch(this.base + path, { + method, headers, body: body === undefined ? undefined : JSON.stringify(body), redirect: "manual", + }); + for (const raw of res.headers.getSetCookie?.() || []) { + const [pair] = raw.split(";"); + const eq = pair.indexOf("="); + if (eq > 0) this.cookies.set(pair.slice(0, eq), pair.slice(eq + 1)); + } + const text = await res.text(); + let json = null; + try { json = JSON.parse(text); } catch { /* keep text */ } + if (process.env.ISE_DEMO_DEBUG) { + console.log(`[debug ${method} ${path}] status=${res.status} set-cookie=${(res.headers.getSetCookie?.() || []).length} cookie-sent=${headers.Cookie ? "yes" : "no"}`); + } + return { status: res.status, json, text }; + } + async login(phone, password) { + const r = await this.call("POST", "/api/auth/login", { phone, password }); + if (process.env.ISE_DEMO_DEBUG) { + log("login", `status=${r.status} cookies=${[...this.cookies.keys()].join(",") || "无"} body=${(r.text || "").slice(0, 120)}`); + } + if (r.status !== 200) fail("login", `登录失败 ${phone}: ${r.status} ${r.text}`); + return r.json; + } +} + +function startApi() { + log("api", `自起专用 API 实例 127.0.0.1:${API_PORT}(env-local-snapshot + PORT 覆盖)`); + const child = spawn( + "bash", + ["-c", `cd "${WORKTREE_ROOT}" && source scripts/local/env-local-snapshot.sh && export PORT=${API_PORT} && exec npm run dev:api`], + { detached: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, FORCE_COLOR: "0" } }, + ); + let bootLog = ""; + child.stdout.on("data", (d) => { bootLog += d; }); + child.stderr.on("data", (d) => { bootLog += d; }); + return { child, bootLog: () => bootLog }; +} + +async function waitForApi(base, bootLog, timeoutMs = 120000) { + const deadline = Date.now() + timeoutMs; + while (Date.now() < deadline) { + try { + const res = await fetch(`${base}/api/health`); + if (res.ok) { + log("api", "健康检查通过"); + return; + } + } catch { /* not up yet */ } + await new Promise((r) => setTimeout(r, 1000)); + } + fail("api", `API ${base} 启动超时。启动日志尾部:\n${bootLog().slice(-3000)}`); +} + +async function driveFlow({ slices, actions, opinions }) { + const base = `http://127.0.0.1:${API_PORT}`; + const annotator = new ApiClient(base); + const qc = new ApiClient(base); + + // —— 标注员:随机领取(真实约束:标注阶段必须项目内随机领取; + // 随机领取围栏同时禁止标注员直接读取未归属的标注阶段条目)—— + await annotator.login("13800001010", DEMO.password); + const requestId = `ise-demo-seed-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`.slice(0, 100); + const claim = await annotator.call("POST", "/api/plugins/annotation-qa/random-claims", { projectId: DEMO.project, requestId }); + if (claim.status !== 200 || !claim.json.item || claim.json.item.id !== DEMO.item) { + fail("flow", `随机领取失败: ${claim.status} ${claim.text}`); + } + let item = claim.json.item; + log("flow", `标注员已领取 ${item.id}(version=${item.version})`); + + // —— 媒体接线自检:统一帧范围(左右目都要能解析)—— + for (const camera of ["left", "right"]) { + const tl = await annotator.call("GET", `/api/plugins/annotation-qa/tasks/${DEMO.task}/frame-timeline?camera=${camera}&encoding=compact`); + if (tl.status !== 200 || !tl.json.frameCount) { + fail("flow", `frame-timeline(${camera}) 失败: ${tl.status} ${tl.text}`); + } + log("flow", `frame-timeline ${camera}: frameCount=${tl.json.frameCount} range=[${Number(tl.json.rangeStartSecond).toFixed(3)}, ${Number(tl.json.rangeEndSecond).toFixed(3)}]`); + } + + // —— 标注员:确认初始切片并舍弃 S5(真实路径:切片用途必须走舍弃/恢复端点, + // 舍弃原因来自项目字典;服务端补齐审计字段并清空舍弃片名称)—— + const dispositionBody = { + version: item.version, + sliceSegments: slices.map(({ deliveryDisposition, discardReason, sourceIds, ...rest }) => rest), + segments: actions, + sliceId: "ise-demo-slice-5", + disposition: "discard", + reason: "演示剧本:画面长时间遮挡,首轮即判定不交付", + reasonLabelId: "ise-demo-discard-reason-1", + reasonVersion: 1, + }; + const disposition = await annotator.call("POST", `/api/plugins/annotation-qa/tasks/${DEMO.task}/slice-dispositions`, dispositionBody); + if (disposition.status !== 200) { + fail("flow", `切片确认/舍弃失败: ${disposition.status} ${disposition.text}`); + } + const workspace = disposition.json.workspace; + item = disposition.json.item; + const canonicalSlices = workspace.sliceSegments; + log("flow", `初始切片已确认(S5 已舍弃,version=${item.version})`); + + // —— 标注员:保存草稿 + 提交首轮工作区(真实 ffmpeg 切片物化)—— + const draftPayload = { + version: item.version, + sliceSegments: canonicalSlices, + operations: [], + segments: actions, + statuses: Object.fromEntries(canonicalSlices.map((s) => [s.id, s.annotationStatus || (s.deliveryDisposition === "discard" ? "pending" : "labeled")])), + }; + const draft = await annotator.call("PUT", `/api/plugins/annotation-qa/tasks/${DEMO.task}/drafts`, draftPayload); + if (draft.status !== 200) fail("flow", `草稿保存失败: ${draft.status} ${draft.text}`); + log("flow", "首轮草稿已保存"); + + const submitPayload = { + version: item.version + 1, + sliceSegments: canonicalSlices, + segments: actions, + changeReason: "ise-demo 首轮送检(演示播种)", + }; + const submit = await annotator.call("POST", `/api/plugins/annotation-qa/tasks/${DEMO.task}/combined-submissions`, submitPayload); + if (submit.status !== 201 && submit.status !== 200) { + fail("flow", `首轮提交失败: ${submit.status} ${submit.text}`); + } + const submitted = submit.json.humanItem || submit.json.item; + if (submitted.currentStageId !== "quality_review" || submitted.status !== "ready") { + fail("flow", `提交后状态异常: ${JSON.stringify({ stage: submitted.currentStageId, status: submitted.status })}`); + } + log("flow", `首轮提交完成(revision=${submit.json.revision?.revision}),物化切片 ${submit.json.sliceRevision?.segments?.length} 片`); + + // —— 质检员:领取 + 审查会话 + 8 条意见 + 打回 —— + await qc.login("13800001011", DEMO.password); + let qcItem = (await qc.call("GET", `/api/human-items/${DEMO.item}`)).json.item; + const qcClaim = await qc.call("POST", `/api/human-items/${DEMO.item}/claim`, { version: qcItem.version }); + if (qcClaim.status !== 200) fail("flow", `质检领取失败: ${qcClaim.status} ${qcClaim.text}`); + qcItem = qcClaim.json.item; + + const page = "ise-demo-seed"; + const generation = 1; + const headers = { "X-Review-Page": page, "X-Review-Generation": String(generation) }; + const session = await qc.call("POST", `/api/human-items/${DEMO.item}/review-session`, { action: "acquire", pageId: page, generation }, headers); + if (session.status !== 200 || !session.json.writable) { + fail("flow", `审查会话获取失败: ${session.status} ${session.text}`); + } + const resultVersion = session.json.resultVersion; + + const currentDraft = (await qc.call("GET", `/api/human-items/${DEMO.item}/review-draft`, undefined, headers)).json.draft; + const opinionSave = await qc.call("PUT", `/api/human-items/${DEMO.item}/review-draft`, { + modelVersion: 2, + version: currentDraft.version, + resultVersion, + operationId: "ise-demo-seed-draft-1", + problems: opinions, + }, headers); + if (opinionSave.status !== 200 && opinionSave.status !== 202) { + fail("flow", `意见草稿保存失败: ${opinionSave.status} ${opinionSave.text}`); + } + // 操作收据可能异步落账:轮询至草稿版本稳定。 + let opinionDraft = null; + for (let i = 0; i < 30; i += 1) { + await new Promise((r) => setTimeout(r, 500)); + opinionDraft = (await qc.call("GET", `/api/human-items/${DEMO.item}/review-draft`, undefined, headers)).json.draft; + if (opinionDraft?.problems?.length === opinions.length) break; + } + if (opinionDraft?.problems?.length !== opinions.length) { + fail("flow", `意见未落账: ${opinionDraft?.problems?.length}/${opinions.length}`); + } + log("flow", `8 条意见已保存(draft version=${opinionDraft.version})`); + + const decision = await qc.call("POST", `/api/plugins/annotation-qa/tasks/${DEMO.task}/reviews`, { + stage: "quality", + decision: "rejected", + comment: "第 1 轮退回:请按 8 条意见原地调整切片结构与动作标注(含拆分/舍弃/合并/改无效),处理后重新送检。", + reasonCodes: ["manual_review_reject"], + problemSliceIds: ["ise-demo-slice-1", "ise-demo-slice-2", "ise-demo-slice-3", "ise-demo-slice-4", "ise-demo-slice-7", "ise-demo-slice-8"], + operationId: "ise-demo-seed-decision-1", + draftVersion: opinionDraft.version, + resultVersion: opinionDraft.resultVersion, + }, headers); + if (decision.status !== 201 && decision.status !== 200 && decision.status !== 202) { + fail("flow", `打回失败: ${decision.status} ${decision.text}`); + } + // 收据协议:等待正式决定落账。 + let finalItem = null; + for (let i = 0; i < 30; i += 1) { + await new Promise((r) => setTimeout(r, 500)); + finalItem = (await qc.call("GET", `/api/human-items/${DEMO.item}`)).json.item; + if (finalItem.status === "claimed" && finalItem.currentStageId === "annotation_combined" && finalItem.reviewRound === 1) break; + } + if (finalItem.reviewRound !== 1 || finalItem.currentStageId !== "annotation_combined") { + fail("flow", `打回后状态异常: ${JSON.stringify({ stage: finalItem.currentStageId, status: finalItem.status, round: finalItem.reviewRound, assigned: finalItem.assignedUserId })}`); + } + log("flow", `质检打回完成:reviewRound=1 归属=${finalItem.assignedUserId}(应为演示标注员,定向退回)`); + + // —— 终态校验:退回基线存在且 8 条意见齐备 —— + const baseline = (await annotator.call("GET", `/api/human-items/${DEMO.item}/rework-baseline`)).json.baseline; + if (!baseline || baseline.problems?.length !== 8) { + fail("flow", `退回基线异常: ${JSON.stringify(baseline && { round: baseline.round, problems: baseline.problems?.length })}`); + } + const scopeCount = (scope) => baseline.problems.filter((p) => p.scope === scope).length; + log("flow", `退回基线就绪:整体=${scopeCount("task")} 切片=${scopeCount("slice")} 动作=${scopeCount("action")} 时间点=${scopeCount("timestamp")}`); + return { finalItem, baseline }; +} + +// --------------------------------------------------------------------------- +// main +// --------------------------------------------------------------------------- + +function cleanMediaFiles() { + if (existsSync(MEDIA_DIR)) { + rmSync(MEDIA_DIR, { recursive: true, force: true }); + log("clean", `已删除演示媒体 ${MEDIA_DIR}`); + } +} + +function cleanMaterializations() { + // 物化产物目录(system/runs//human-materializations)。 + const materializations = resolve(WORKSPACE, "system", "runs", DEMO.run); + if (existsSync(materializations)) { + rmSync(materializations, { recursive: true, force: true }); + log("clean", `已删除物化产物 ${materializations}`); + } +} + +function cleanMedia() { + cleanMediaFiles(); + cleanMaterializations(); +} + +function printSummary() { + const rule = "═══════════════════════════════════════════════════════════════"; + const lines = [ + "", + rule, + " ISE 演示环境就绪(inplace-slice-editing 人工验收)", + rule, + ` 标注员(返修人): 手机号 13800001010 密码 ${DEMO.password}`, + " 质检员 : 手机号 13800001011 密码 " + DEMO.password, + " 管理员 : 手机号 13800001012 密码 " + DEMO.password, + ` 组织/项目 : ${DEMO.org} / ${DEMO.project}(全部数据带 ise-demo- 前缀)`, + ` 任务/条目 : ${DEMO.task} / ${DEMO.item}(已处于第 1 轮返修,8 条意见)`, + "", + " 启动本地复刻栈(本 worktree,两个终端):", + " source scripts/local/env-local-snapshot.sh && npm run dev:api # API 3001", + " npx vite --port 5174 # 前端(5173 被共用栈占用时用空闲端口)", + "", + " 浏览器打开 http://127.0.0.1:5174 → 标注员登录 → 我的任务", + " → 打开 ISE 演示任务 → 按走查文档逐场景验收:", + " docs/manuals/ise-demo-walkthrough.zh-CN.md", + "", + " 清除演示环境:", + " node scripts/local/seed-ise-demo.mjs --clean", + rule, + ]; + console.log(lines.join("\n")); +} + +async function main() { + console.log(`worktree=${WORKTREE_ROOT}\nmain-root=${MAIN_ROOT}\nworkspace=${WORKSPACE}`); + // 前置检查 + sh("ffmpeg", ["-version"]); + sh("ffprobe", ["-version"]); + mongoshEval("db.runCommand({ping: 1})"); + + if (CLEAN_ONLY) { + cleanMongo(); + cleanMedia(); + log("clean", "演示环境已完全清除(--clean)"); + return; + } + + log("step", "① 清除旧演示数据(幂等:先清后建)"); + cleanMongo(); + cleanMaterializations(); + if (!SKIP_MEDIA) cleanMediaFiles(); + + log("step", "② 合成双相机媒体"); + const media = generateMedia(); + const sec = frameSecondsBuilder(media.frames, media.duration); + + log("step", "③ 写入 fixture 图谱"); + const { slices, actions, sliceNames } = buildScriptData(sec, media.frames); + const opinions = buildOpinions(slices, actions, sec); + writeFixtures(media, { slices, actions, sliceNames }); + + log("step", "④ 自起 API 并驱动真实业务流"); + const api = startApi(); + try { + await waitForApi(`http://127.0.0.1:${API_PORT}`, api.bootLog); + await driveFlow({ slices, actions, opinions }); + } finally { + if (KEEP_API) { + log("api", `--keep-api:保留 127.0.0.1:${API_PORT} 实例(pid 组 ${api.child.pid}),调试完请手动停止`); + } else { + try { process.kill(-api.child.pid, "SIGTERM"); } catch { /* already gone */ } + log("api", "自起 API 实例已停止"); + } + } + printSummary(); +} + +main().catch((error) => { + console.error(`\n[seed-ise-demo] 播种失败: ${error?.message || error}`); + process.exit(process.exitCode || 1); +}); From 062d656bfe0ead283600f0ac5b824177d6327c70 Mon Sep 17 00:00:00 2001 From: d-robotics Date: Tue, 13 Oct 2026 16:43:10 +0530 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A7=B9=2010:=20complete=20demo=20clea?= =?UTF-8?q?nup=20coverage=20and=20align=20walkthrough=20with=20merged=20ke?= =?UTF-8?q?yboard=20guide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/manuals/ise-demo-walkthrough.zh-CN.md | 11 +++++++---- scripts/local/seed-ise-demo.mjs | 6 +++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/manuals/ise-demo-walkthrough.zh-CN.md b/docs/manuals/ise-demo-walkthrough.zh-CN.md index e556c0ac..f0c397b4 100644 --- a/docs/manuals/ise-demo-walkthrough.zh-CN.md +++ b/docs/manuals/ise-demo-walkthrough.zh-CN.md @@ -89,10 +89,11 @@ npx vite --port 5174 --strictPort # 终端 2: **预期**:视频画面上**浮出三选卡**(锚定在越界分界处),列出被穿过的动作 act-17。 点选 **3 判无效** → 卡关闭,act-17 变无效(无效徽标),边界生效落在 185s。 *(此时意见 5 自动消红——目标动作已改动,见场景 ⑤。)* -2. **演示「截断」**:先把边界拖回 180s 附近复原(可 `Ctrl/⌘+Z` 撤销上一步,见 ⑦), - 再次拖到 185s 穿过 act-17 → 三选卡出现 → 点 **1 截断** → act-17 被切成两段 +2. **演示「截断」**:先把边界拖回 180s 附近复原(退出切片编辑模式后按 `Ctrl/⌘+Z` + 撤销上一步最省事——**撤销键在模式内不响应**,见 ⑥/⑦), + 再次拖到 185s 穿过 act-17 → 三选卡出现 → 按 **1** 截断 → act-17 被切成两段 (183–185 与 185–190,两段均为 pending/described 既有状态),边界生效。 -3. **演示「挪片」**:再次复原后拖到 185s → 三选卡 → 点 **2 挪片** → act-17 边界被修剪 +3. **演示「挪片」**:再次复原后拖到 185s → 三选卡 → 按 **2** 挪片 → act-17 边界被修剪 使其完整落入一侧(起点吸附到 185s),边界生效。 4. **演示「不选 = 不生效」**:复原后拖到 185s → 三选卡出现 → 按 **Esc**(或点关闭)。 **预期**:**边界停在原地 180s**,动作原样未动(R2-Q1 拦)。 @@ -107,7 +108,7 @@ npx vite --port 5174 --strictPort # 终端 2: 拖边界向**右** 1s(60→61)松手。 **预期**:浮出**两选卡**(跟随伸缩(默认)/ 保持原边界),高亮"跟随"为默认项。 - 按 **Enter** 或点选跟随 → act-09 伸缩为 52–61s; - - 复原后重试并选 **保持原边界** → act-09 保持 52–60s(完整落入扩展后的 S2)。 + - 复原后重试并按 **2**(或点选保持原边界)→ act-09 保持 52–60s(完整落入扩展后的 S2)。 3. **模式外键位不变**:退出弹卡后按 `1`/`2`(慢速/常速)、`B`(片头复查)等照常工作。 ### ⑤ 合并 / 拆分 / 舍弃 → 意见跟块消红 @@ -141,6 +142,8 @@ npx vite --port 5174 --strictPort # 终端 2: ### ⑦ 结构编辑后撤销 / 重做仍正确 +> 撤销/重做是全局键:**先按 `E`/`Esc` 退出切片编辑模式**再操作(模式内不响应,见 ⑥)。 + 1. 连续做 2–3 个结构操作(挪边界、拆分、合并)。 2. 按 **Ctrl/⌘ + Z** 逐步撤销。 **预期**:每次撤销精确回退一个结构操作(切片集与动作集同时还原,包括三选卡的产物); diff --git a/scripts/local/seed-ise-demo.mjs b/scripts/local/seed-ise-demo.mjs index 95fb6fd3..8509f2d6 100644 --- a/scripts/local/seed-ise-demo.mjs +++ b/scripts/local/seed-ise-demo.mjs @@ -435,7 +435,11 @@ const item = ${JSON.stringify(DEMO.item)}, task = ${JSON.stringify(DEMO.task)}, const deleted = {}; const d = (coll, filter) => { deleted[coll] = db.getCollection(coll).deleteMany(filter).deletedCount; }; d("organizations", {id: org}); -d("suppliers", {id: ${JSON.stringify(DEMO.supplier)}}); +d("suppliers", {organizationId: org}); +d("supplierProjectAuthorizations", {organizationId: org}); +d("supplierProjectAuthorizationInit", {organizationId: org}); +d("acceptanceCompatibilitySnapshots", {organizationId: org}); +d("annotationTimelineIndexes", {organizationId: org}); d("users", {organizationId: org}); d("sessions", {userId: {$in: [${JSON.stringify(DEMO.annotator)}, ${JSON.stringify(DEMO.qc)}, ${JSON.stringify(DEMO.admin)}]}}); d("projects", {id: project}); From 7b4087eabbffb4be0ac3a0013ba6e0261f64ac7e Mon Sep 17 00:00:00 2001 From: d-robotics Date: Tue, 13 Oct 2026 16:43:38 +0530 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8E=AB=2010:=20resolve=20demo=20fixtu?= =?UTF-8?q?re=20seed=20ticket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issues/10-demo-fixture-seed.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md b/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md index d80fa469..a0922806 100644 --- a/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md +++ b/.scratch/inplace-slice-editing/issues/10-demo-fixture-seed.md @@ -1,6 +1,6 @@ # 10 · 演示 fixture:播种脚本 + 场景清单人工验收 -Status: claimed +Status: resolved Type: task Blocked by: 05, 06, 07, 08 Spec: [spec.md](../spec.md) §4、§2 R3-3:a / R3-4:ok、§6 seam ④ @@ -21,3 +21,13 @@ Spec: [spec.md](../spec.md) §4、§2 R3-3:a / R3-4:ok、§6 seam ④ ## Comments - 脚本入 `scripts/local/`(仓库现行脚本布局),凭据走本地未跟踪文件模式,不硬编码。 + +## Answer + +分支 `codex/ise-10`(worktree `local-data/worktrees/ise-10`,未 push)。提交:`e4e9ee0a` 领票 → `5c713eda` 播种脚本 + 走查文档 → `41c849eb` 合并集成分支 → `062d656b` 清理补全 + 走查对齐键盘指南 → 本提交 resolve。 + +1. **合成采集** ✅ — `scripts/local/seed-ise-demo.mjs` 用 ffmpeg `testsrc2` 合成 240.000s 双相机 MP4(2400 帧 @10fps,左右目画面可区分 + S1–S8 场景点阵字幕;本机 ffmpeg 无 drawtext,内置 5x7 点阵字体渲染标签 PNG + overlay,零依赖)+ 逐帧严格递增 PTS CSV(行数与视频帧数严格相等,左右目同步 origin)+ 50Hz accel/gyro 成对 IMU CSV,全部落在 workspace 挂载根下。切片/动作边界全部按服务端同式(frame×duration/frames)计算,`grid.resolve` 1e-6 对齐零误差。 +2. **一键播种** ✅ — `node scripts/local/seed-ise-demo.mjs`:隔离组织 `org-ise-demo`(全部 `ise-demo-*` 前缀)+ 3 合成账号(手机号 1380000101x,密码 `ise-demo-2026`,bcrypt 哈希内嵌)+ 项目/模板(22 类)/切片字典(8 名称 + 舍弃原因字典)/v5.8 三角色批次后,自起 3011 专用 API 走真实业务流:随机领取 → 切片确认(S5 走舍弃端点)→ 草稿 → 首轮提交(真实 ffmpeg 物化 8 片双目切片)→ 质检领取 → 审查会话 → 8 条意见(整体 1/切片 2/动作 3/时间点 2,ModelVersion 2 收据协议)→ 打回。终态:任务 rework、条目 claimed@annotation_combined、reviewRound=1、定向归还原标注员、退回基线冻结 8 意见。剧本含三选卡演示位(act-17@183–190s 拖 S6/S7 边界穿过)、两选卡演示位(act-09 终点贴 S2/S3 边界)、无效贴边自动跟随演示位(act-inv 起点贴 S6/S7 边界)。 +3. **走查文档** ✅ — `docs/manuals/ise-demo-walkthrough.zh-CN.md`:spec §4 场景 ①–⑩ 全部映射为可执行步骤(URL/账号/键位/预期逐条),含采集剧本表、8 条意见与场景的对应表、启动/清理说明、已知边界。 +4. **验证证据**:seed→landed(frame-timeline 左右 2400 帧/0–240s、8 片物化、基线 8 意见、任务出现在标注员"我的任务");幂等(连跑两次状态指纹 byte-identical,无重复记录);--clean 清除 27 个集合残留 0(含 API 启动自动派生的 supplier/authorization/timeline-index 快照);取毕即清,未留任何后台进程。tripwire:`npx tsc --noEmit` exit 0;`node --test tests/frontend/*.test.mjs` 730/716/14,失败名集合并集前后 byte-identical;无 Go 改动(`go build` 未跑,不适用);`git merge codex/inplace-slice-editing`(含 09 文档票)零冲突,合并后 tripwire 复跑全绿。 +5. **判断与遗留**:UI 交互按 spec §6 seam ④ 不写自动化,人工验收待用户按走查执行;走查 §四 记录两个实现侧注意点(整体意见消红条件;模式内撤销不响应)。