diff --git a/CHANGELOG.md b/CHANGELOG.md index dba498193f..7b335ab6d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,8 @@ Bots can be pinned as pixel Window Companions that play their replies, binding o - Bot settings can export and inspect one verified complete `.botharness-backup`, including retained custom/deleted Memory, current attachments, model templates and independent plans, and the canonical purge checkpoint; the installed local command restores only into a new stopped environment ([#886](https://github.com/BotHarness/DeepSeekBot/issues/886), [guide](docs/settings.md#complete-environment-backup-and-restore)). +- Window Companion bubbles follow the displayed pixel bust's head through tilt, stretch and movement, retain an origin connector when cards move to avoid overlap or viewport edges, and keep text upright; resize updates the clamped character and bubble origin together, while image and unsupported-rig fallbacks use their visible box top ([#1177](https://github.com/BotHarness/DeepSeekBot/issues/1177)). + - WeChat identity enablement and native typing can inherit independent global defaults or retain Bot-specific overrides; existing choices are preserved on upgrade, and unsupported group/Thread settings stay hidden ([#912](https://github.com/BotHarness/BotHarness/issues/912), [guide](docs/wechat-connection.md)). - Isolated AX launches expose bounded, allowlisted real Client startup/runtime evidence and explicit shell readiness for coding agents, retaining first failures across document retries ([#1184](https://github.com/BotHarness/DeepSeekBot/issues/1184), [guide](docs/dev/guides/client-startup-diagnostics.md)). diff --git a/CHANGELOG.zh.md b/CHANGELOG.zh.md index 4ac915e42c..1494d2cf81 100644 --- a/CHANGELOG.zh.md +++ b/CHANGELOG.zh.md @@ -53,6 +53,8 @@ Bot 可以作为像素窗口伙伴固定在窗口里播放回复;绑定一个 - Bot 设置可导出、检查一个完整且已验证的 `.botharness-backup`,包含自定义及已删除身份保留的 Memory、当前附件、模型模板与独立计划,以及真实清除检查点;安装包提供的本地命令仅恢复至新的停止环境([#886](https://github.com/BotHarness/DeepSeekBot/issues/886), [guide](docs/settings.md#complete-environment-backup-and-restore))。 +- 窗口伙伴气泡随像素半身的头部倾斜、拉伸与移动定位;卡片因避让或视口限位偏移时保留来源连线,文字保持直立;窗口缩小时人物与连线锚点同步限位,图片与不支持的形象使用可见盒子顶部锚点([#1177](https://github.com/BotHarness/DeepSeekBot/issues/1177))。 + - 微信身份启停与原生输入状态可分别继承全局默认值或保留 Bot 自定义;升级保留现有选择,界面不显示未支持的群聊/Thread 设置([#912](https://github.com/BotHarness/BotHarness/issues/912),[指南](docs/wechat-connection.md))。 - 隔离 AX 启动向 coding agent 提供有界、白名单化的真实 Client 启动/运行证据和明确 shell 就绪状态,跨文档重试保留首次失败([#1184](https://github.com/BotHarness/DeepSeekBot/issues/1184), [guide](docs/dev/guides/client-startup-diagnostics.md))。 diff --git a/docs/architecture/botharness-architecture.en.md b/docs/architecture/botharness-architecture.en.md index 481df7f3b7..df291108e6 100644 --- a/docs/architecture/botharness-architecture.en.md +++ b/docs/architecture/botharness-architecture.en.md @@ -623,6 +623,8 @@ If an EventSource enters the terminal CLOSED state after a temporary HTTP failur The Client's independent `CompanionMotion` owns bounded drag poses, velocity sampling, continuous gravity, damped lateral motion, a small floor rebound and settling. View owns the existing frame loop and eases character transforms; bubbles follow the same position. Resizing preserves the current motion and retargets bounds and the drag origin; pointer cancellation matches the active capture. Final landing persists only the normalized horizontal position. Reduced motion returns directly to the floor without pose effects. These are independently implemented presentation dynamics, informed by Coopanion's drag/air/landing interaction rather than imported source or artwork. +For companion consumers, Avatar exposes a disposable anchor reader. It captures the supported head's local top-center once per Avatar replacement, then reads only that local group's displayed screen matrix in the existing visible-frame loop, including outer rotation, scale and transition origin. Activity pixel covers use the same stable head-region point with the SVG root matrix. Images, unknown rigs and unavailable SVG geometry use the visible Avatar box top-center. There is no whole-SVG bounds scan per frame or Host pose RPC. `CompanionBubbles` keeps the original projected point while placing upright cards within viewport limits, above the toolbar and away from other companions; a pixel-style connector preserves the relationship after displacement. Reading keeps its placement continuity and existing grace period. Hidden/offscreen presentation stops sampling, and Avatar replacement/disposal clears the reader ([#1177](https://github.com/BotHarness/DeepSeekBot/issues/1177)). + The application-defined Window Companion owner lives for the Client Plugin lifetime, outside Bot-mode panels, and renders through the official `shell.overlay` Slot. Its preferences are local to the Client origin and the opaque hash of the native `profileContext.dir`; cards never persist. The authenticated Connection Fetch endpoint `/api/botharness/companion` supplies a Profile context and a future-only SSE baseline. A consumer registers and snapshots synchronously in one Host turn, then projects Registry appearance, the existing all-Bot Activity snapshot and owned committed Human–Bot DM output. The Channel store and Session ownership remain canonical; neither drafts nor historical queries enter this first feed. The application-defined `WindowCompanions` collection owns Profile selection and shared capacity, composing an independent playback owner and motion View per Bot. Sidebar menus and individual Bot header buttons update this collection independently of Channel pinning. Preferences migrate from single-selection v1 to v2 and persist only selections, sources/scope, positions, walking and capacity. Companions share one authenticated SSE; a native random transient consumer ID and same-path POST atomically replace subscriptions. Control handles expire with the stream and are neither identity nor durable authority. Monotonic selection revisions reject superseded baselines; selecting or removing another Bot does not reset a reading list. diff --git a/docs/architecture/botharness-architecture.md b/docs/architecture/botharness-architecture.md index 4457f6b99e..8eb78b5a1f 100644 --- a/docs/architecture/botharness-architecture.md +++ b/docs/architecture/botharness-architecture.md @@ -775,6 +775,8 @@ EventSource 在暂时 HTTP 失败后进入终态 CLOSED 时,集合 owner 用 Client 独立的 `CompanionMotion` 拥有有界拖拽姿态、速度采样、连续重力、横向阻尼、轻微地面回弹与落地收敛。View 继续拥有既有帧循环,对人物变换做缓动;气泡跟随同一位置。调整窗口保留当前运动并重新收敛边界、协调拖拽原点,指针取消只匹配活动捕获。最终落地只保存归一化横向位置;减少动效时直接回到底部并关闭姿态效果。这些呈现动力学独立实现,参考 Coopanion 的拖拽/空中/落地交互概念,不引入其源码或美术。 +Avatar 为伙伴消费者提供可释放的锚点读取器:每次形象替换只采集一次受支持头部的局部顶部中心,既有可见帧循环只读取该局部组当前显示的屏幕矩阵,包含外层旋转、缩放及过渡中的变换原点。像素 Activity 覆盖使用相同头部区域点与 SVG 根矩阵;图片、未知 rig 或不可用的 SVG 几何使用可见 Avatar 盒子顶部中心。不逐帧扫描整个 SVG 边界,也不向 Host 发送姿态 RPC。`CompanionBubbles` 保留原始投射点,让直立卡片受视口、工具栏与多伙伴避让约束,偏移后用像素式连线保持来源关系。阅读延续既有位置与离开宽限;隐藏/离屏停止采样,形象替换/销毁清除读取器([#1177](https://github.com/BotHarness/DeepSeekBot/issues/1177))。 + 应用定义的 Window Companion owner 跟随 Client Plugin 生命周期,位于 Bot 模式页面之外,通过官方 `shell.overlay` Slot 渲染。本地偏好按 Client origin 与原生 `profileContext.dir` 的不透明哈希隔离,消息卡片不落盘。受认证的 Connection Fetch `/api/botharness/companion` 提供 Profile 上下文及只处理未来消息的 SSE 基线;消费者在同一 Host turn 同步注册并读取快照,再投影 Registry 形象、现有全 Bot Activity 和拥有者已提交的 Human–Bot DM 输出。Channel store 与 Session ownership 保持权威;草稿和历史查询不进入首个 feed。 应用定义的 `WindowCompanions` 集合拥有 Profile 的钉选集合和共用容量,组合每个 Bot 独立的播放 owner 与运动 View。侧栏菜单与各 Bot 的 header 按钮均操作此集合,与 Channel 置顶无关。偏好从单选 v1 迁移到 v2;只持久化形象选择、来源/范围、位置、走动与容量。多个伙伴复用一条受认证 SSE,通过原生随机的临时 consumer ID 和同路径 POST 原子替换消费集合;控制句柄随流关闭释放,既不是身份也不是耐久权威。递增选择版本阻止迟到的基线初始化被替换的消费;增加或移除其他 Bot 不重置正在阅读的卡片。 diff --git a/docs/assets/pr/1177-companion-anchors/README.md b/docs/assets/pr/1177-companion-anchors/README.md new file mode 100644 index 0000000000..d967f2d80c --- /dev/null +++ b/docs/assets/pr/1177-companion-anchors/README.md @@ -0,0 +1,45 @@ +# Companion anchor resize qualification + +Real isolated DSH 0.2.0-rc.1, Chinese, dark theme, the same Ada and Grace QA PersonaBots and Profile. Official Chrome DevTools MCP captured actual pointer dragging, release, keyboard movement and a 1559 × 865 → 600 × 700 → 1559 × 865 resize. Videos are continuous, silent screen recordings, remuxed without re-encoding; screenshots are unchanged captures. No synthetic presentation or message was injected. + +- Before: `1ed6dcbd9caf4d179753c03ea930fb34fb8157c3`. +- After: `c946a74981944250376db5f8dc609a09c501072d`, including resize correction `f9fad41a` and integration of main `8940165f`. +- Main integration adds native onboarding content between captures. The center chat is therefore not a matched visual comparison; the same companion geometry and resize interaction are the subject of this check. + +| Settled narrow viewport before | Settled narrow viewport after | +| ------------------------------ | ----------------------------- | +| ![](resize-before-dark.png) | ![](resize-after-dark.png) | + +The settled screenshots do **not** show the transient defect. A QA-only observer independently compared the displayed head point with the connector origin every 50 ms. It observed one 588.694 px resize mismatch before correction. After correction, all 101 narrow-viewport samples were within 0.012 px; the maximum across all 1,200 samples was 0.710 px. Both recordings include rest, drag, fall and land; the after run contains 11 trusted pointer events and real focused-character arrow-key movement. Sampling cannot prove the absence of all unsampled transients and is not a performance measurement. + +[Before recording](resize-before.webm) · [After recording](resize-after.webm) + +Console inspection after the correction found no JavaScript errors; the existing form-field id/name browser issue remains. No historical companion message replayed after restart. Other fallback/tool-cover/reduced-motion and reading-stack scenarios retain their separately stated acceptance status in PR #1183; this check does not qualify them. + +## Focused reading and reduced-motion release + +At `c946a749` (evidence head `5c16fab9`), three new native Bot replies are verified against canonical Channel messages. The first focused-arrival screenshot shows two Ada cards beside Grace's independently sourced card. The later expanded-reading samples retain Ada's two upright cards; Grace's card has expired by then. Autonomous walking was paused through existing native buttons. As the third real card appears, normal public character focus enters reading before tool latency consumes its short lifetime; a subsequent actual MCP hover retains it. This is focused-reading evidence, not acceptance of mouse hover on a moving character. `focused-arrivals-dark.png` and `expanded-reading-dark.png` show those distinct moments. + +The actual Bot Settings menu then selects reduced motion; native drag/release leaves both companions settled at bottom865 in every observed post-release sample (`reduced-released-dark.png`). Message cards have expired by that later screenshot; it does not show reduced-motion message reading or the first release frame. All sampled connector origins match their displayed bust anchors, maximum0px in this stationary/settled workload; sampling every80ms is not performance measurement or a guarantee about unsampled motion. Sanitized details: `reading-reduced-qualification.json`. + +`reading-reduced.webm` is continuous silent official MCP output, container-remuxed only. Earlier failed attempts are retained privately and excluded: native hover could not stabilize a roaming character; a paused attempt lost its messages to TTL during capture latency. No fake reply/event, replay or card/store injection was used. Console contained no JavaScript error; the existing native form-field issue remained. Held/reversal, image/tool-cover and background scenarios remain separate. + +## Latest-main image fallback and real tool cover + +Runtime `d1dde91edc4fd01dab9cbaa12a43ed504be68434` integrates main `04da609342f31b613b4102aa716228f00cb3d171` with the formal pixel-avatar `0.6.0`. Both themes use Chinese and 1559 × 865. These are after-state qualification scenes, not new matched before/after comparisons. + +The native avatar editor saves Grace's own current seeded appearance. The owning avatar API then uses its identical PNG bytes without an Appearance, exercising actual image fallback. A newly generated canonical DM supplies the bubble; native drag/release is recorded. The owning reset restores the original absent avatar/appearance/seed fields, independently verified against the immutable original detail snapshot. + +Ada first sends a new canonical explanation, then calls actual `ask_user_question`. The owning Activity snapshot and pending question confirm the real tool cover. Light and dark captures retain the bubble above the tool symbol, using the head point sampled before the cover and projected through the displayed SVG root. The native question form is then answered, an actual Bot continuation is verified, and the original bust returns. Both QA requests created during setup/capture were completed; the Host status query after completion returns expired, while actual canonical Bot continuations independently prove the submitted selected labels. + +Across the five stationary/post-release phases, every 80ms geometry sample with a connector measures 0px origin error. Native movement is in the two continuous silent official MCP videos, remuxed only. This does not qualify held/reversing motion, first-release-frame timing, moving-hover/grace, background, reduced-motion reading or performance. Normal public character focus retains real cards before capture latency exhausts TTL; walking was paused with native buttons. No synthetic replies, SSE, cards or store mutations were injected. Console has no JavaScript errors. All owned test pages and the isolated browser were closed. `variants-qualification.json` records scope and limitations. + +| Image fallback: light | Image fallback: dark | +| ----------------------------- | ---------------------------- | +| ![](image-fallback-light.png) | ![](image-fallback-dark.png) | + +| Native tool cover: light | Native tool cover: dark | +| ------------------------- | ------------------------ | +| ![](tool-cover-light.png) | ![](tool-cover-dark.png) | + +[Image fallback recording](image-fallback.webm) · [Tool-cover recording](tool-cover.webm) diff --git a/docs/assets/pr/1177-companion-anchors/expanded-reading-dark.png b/docs/assets/pr/1177-companion-anchors/expanded-reading-dark.png new file mode 100644 index 0000000000..0a93471a51 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/expanded-reading-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/focused-arrivals-dark.png b/docs/assets/pr/1177-companion-anchors/focused-arrivals-dark.png new file mode 100644 index 0000000000..fe1e9f800c Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/focused-arrivals-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/image-fallback-dark.png b/docs/assets/pr/1177-companion-anchors/image-fallback-dark.png new file mode 100644 index 0000000000..31d8953885 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/image-fallback-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/image-fallback-light.png b/docs/assets/pr/1177-companion-anchors/image-fallback-light.png new file mode 100644 index 0000000000..272ae2f284 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/image-fallback-light.png differ diff --git a/docs/assets/pr/1177-companion-anchors/image-fallback.webm b/docs/assets/pr/1177-companion-anchors/image-fallback.webm new file mode 100644 index 0000000000..1b935601f5 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/image-fallback.webm differ diff --git a/docs/assets/pr/1177-companion-anchors/image-released-dark.png b/docs/assets/pr/1177-companion-anchors/image-released-dark.png new file mode 100644 index 0000000000..c52843e346 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/image-released-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/reading-reduced-qualification.json b/docs/assets/pr/1177-companion-anchors/reading-reduced-qualification.json new file mode 100644 index 0000000000..9962789d0d --- /dev/null +++ b/docs/assets/pr/1177-companion-anchors/reading-reduced-qualification.json @@ -0,0 +1,126 @@ +{ + "runtimeCode": "c946a749", + "evidenceHead": "5c16fab9", + "viewport": [1559, 865], + "theme": "dark", + "locale": "zh-CN", + "canonicalNativeReplies": [ + { + "name": "锚点验收 Grace", + "length": 82 + }, + { + "name": "锚点验收 Ada", + "length": 80 + }, + { + "name": "锚点验收 Ada", + "length": 80 + } + ], + "setup": "Autonomous walking paused by native buttons; when three real new cards appear, public character.focus() enters reading before tool/capture latency expires their TTL. No card/store mutation or message replay.", + "phases": [ + { + "label": "full-idle", + "samples": 18, + "motion": ["full"], + "bots": [ + { + "name": "锚点验收 Ada · 窗口伙伴", + "reading": "false", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + }, + { + "name": "锚点验收 Grace · 窗口伙伴", + "reading": "false", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + } + ] + }, + { + "label": "expanded-reading", + "samples": 36, + "motion": ["full"], + "bots": [ + { + "name": "锚点验收 Ada · 窗口伙伴", + "reading": "true", + "phase": "rest", + "cards": 2, + "bottom": 865, + "viewport": 865 + }, + { + "name": "锚点验收 Grace · 窗口伙伴", + "reading": "false", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + } + ] + }, + { + "label": "reduced-reading", + "samples": 18, + "motion": ["reduce"], + "bots": [ + { + "name": "锚点验收 Ada · 窗口伙伴", + "reading": "false", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + }, + { + "name": "锚点验收 Grace · 窗口伙伴", + "reading": "false", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + } + ] + }, + { + "label": "reduced-released", + "samples": 22, + "motion": ["reduce"], + "bots": [ + { + "name": "锚点验收 Ada · 窗口伙伴", + "reading": "true", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + }, + { + "name": "锚点验收 Grace · 窗口伙伴", + "reading": "false", + "phase": "rest", + "cards": 0, + "bottom": 865, + "viewport": 865 + } + ] + } + ], + "maxSampledAnchorError": 0, + "p95SampledAnchorError": 0, + "limits": [ + "80ms geometry sampling, not frame-time or proof about unsampled transients", + "Public focus setup before real hover; not moving-character mouse usability acceptance", + "Both earlier failed attempts preserved privately: moving target hover timeout, then cards expired during tool latency", + "Reduced-release samples qualify settled floor alignment, not timing of the first release frame", + "Continuous silent official MCP recording, remux only; no synthetic reply/SSE/card injection", + "Does not qualify held/reversing grab, image/tool-cover variants, background or performance" + ] +} diff --git a/docs/assets/pr/1177-companion-anchors/reading-reduced.webm b/docs/assets/pr/1177-companion-anchors/reading-reduced.webm new file mode 100644 index 0000000000..089bfaef3d Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/reading-reduced.webm differ diff --git a/docs/assets/pr/1177-companion-anchors/reduced-released-dark.png b/docs/assets/pr/1177-companion-anchors/reduced-released-dark.png new file mode 100644 index 0000000000..a4683608d8 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/reduced-released-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/resize-after-dark.png b/docs/assets/pr/1177-companion-anchors/resize-after-dark.png new file mode 100644 index 0000000000..4f470303d4 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/resize-after-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/resize-after.webm b/docs/assets/pr/1177-companion-anchors/resize-after.webm new file mode 100644 index 0000000000..c53d4e3b51 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/resize-after.webm differ diff --git a/docs/assets/pr/1177-companion-anchors/resize-before-dark.png b/docs/assets/pr/1177-companion-anchors/resize-before-dark.png new file mode 100644 index 0000000000..741ddef9c1 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/resize-before-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/resize-before.webm b/docs/assets/pr/1177-companion-anchors/resize-before.webm new file mode 100644 index 0000000000..67445280c8 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/resize-before.webm differ diff --git a/docs/assets/pr/1177-companion-anchors/tool-completed-dark.png b/docs/assets/pr/1177-companion-anchors/tool-completed-dark.png new file mode 100644 index 0000000000..c1fa3b9e85 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/tool-completed-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/tool-cover-dark.png b/docs/assets/pr/1177-companion-anchors/tool-cover-dark.png new file mode 100644 index 0000000000..649960c7a4 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/tool-cover-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/tool-cover-light.png b/docs/assets/pr/1177-companion-anchors/tool-cover-light.png new file mode 100644 index 0000000000..2b87fb9032 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/tool-cover-light.png differ diff --git a/docs/assets/pr/1177-companion-anchors/tool-cover.webm b/docs/assets/pr/1177-companion-anchors/tool-cover.webm new file mode 100644 index 0000000000..1d377bd242 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/tool-cover.webm differ diff --git a/docs/assets/pr/1177-companion-anchors/tool-released-dark.png b/docs/assets/pr/1177-companion-anchors/tool-released-dark.png new file mode 100644 index 0000000000..719c684297 Binary files /dev/null and b/docs/assets/pr/1177-companion-anchors/tool-released-dark.png differ diff --git a/docs/assets/pr/1177-companion-anchors/variants-qualification.json b/docs/assets/pr/1177-companion-anchors/variants-qualification.json new file mode 100644 index 0000000000..34f92df9c0 --- /dev/null +++ b/docs/assets/pr/1177-companion-anchors/variants-qualification.json @@ -0,0 +1,65 @@ +{ + "runtimeCode": "d1dde91edc4fd01dab9cbaa12a43ed504be68434", + "integratedMain": "04da609342f31b613b4102aa716228f00cb3d171", + "formalPixelAvatar": "0.6.0", + "viewport": [1559, 865], + "themes": ["light", "dark"], + "locale": "zh-CN", + "actualCanonicalReplies": 2, + "actualNativeQuestionContinuations": 2, + "scenes": [ + { + "label": "light-image-reading", + "samples": 25, + "maxSampledAnchorError": 0, + "samplesWithConnector": 25, + "coveredSamples": 0, + "lastPhase": "rest" + }, + { + "label": "native-image-release", + "samples": 25, + "maxSampledAnchorError": 0, + "samplesWithConnector": 25, + "coveredSamples": 0, + "lastPhase": "rest" + }, + { + "label": "light-native-tool-cover", + "samples": 25, + "maxSampledAnchorError": 0, + "samplesWithConnector": 25, + "coveredSamples": 25, + "lastPhase": "rest" + }, + { + "label": "dark-native-tool-cover", + "samples": 25, + "maxSampledAnchorError": 0, + "samplesWithConnector": 25, + "coveredSamples": 25, + "lastPhase": "rest" + }, + { + "label": "native-tool-release", + "samples": 25, + "maxSampledAnchorError": 0, + "samplesWithConnector": 25, + "coveredSamples": 25, + "lastPhase": "rest" + } + ], + "originalAvatarsRestored": true, + "ownedPagesClosed": [1, 2], + "consoleErrors": 0, + "limits": [ + "After-state qualification only; no matched original-main fallback/tool-cover baseline in this capture", + "Native editor saved QA Grace own seeded appearance to PNG; owning avatar API switched to the identical PNG; owning reset restored exact original absent avatar/appearance/seed fields", + "Native channel_send and ask_user_question, canonical request pending plus real native form submission and actual Bot continuation; no synthetic SSE, replies, cards or activity", + "Normal public character focus retains a newly arrived card while official-tool capture latency elapses; walking paused with native buttons", + "80ms geometry sampling covers stationary reading and observed post-release state; native drag is visible in continuous video but no claim about held/reversing grabs or unsampled first frames", + "Continuous silent official MCP screen recordings, remux only; not an audio or performance measurement", + "This branch independently retains its existing quiet-idle presentation; PR1180 quiet-idle/sound changes are not part of this capture", + "Background, automatic reconnect, moving-hover/grace and reduced-motion message reading remain separately unqualified" + ] +} diff --git a/packages/client/src/client/avatar-anchor.ts b/packages/client/src/client/avatar-anchor.ts new file mode 100644 index 0000000000..55b86d2f42 --- /dev/null +++ b/packages/client/src/client/avatar-anchor.ts @@ -0,0 +1,32 @@ +export interface AvatarAnchor { + read(): { x: number; y: number } | undefined; +} + +export function createAvatarAnchor(node: HTMLElement): AvatarAnchor { + const head = node.querySelector('.bh-illustrated-head'); + const svg = head?.ownerSVGElement; + let local: { x: number; y: number } | undefined; + try { + const box = head?.getBBox(); + if (box && box.width > 0 && box.height > 0) local = { x: box.x + box.width / 2, y: box.y }; + } catch {} + return { + read() { + if (!node.isConnected) return; + if (local && head?.isConnected && svg) { + try { + const target = svg.hasAttribute('data-pixel-cover') ? svg : head; + const matrix = target.getScreenCTM(); + if (matrix) { + const x = matrix.a * local.x + matrix.c * local.y + matrix.e; + const y = matrix.b * local.x + matrix.d * local.y + matrix.f; + if (Number.isFinite(x) && Number.isFinite(y)) return { x, y }; + } + } catch {} + } + const box = node.getBoundingClientRect(); + if (box.width > 0 && box.height > 0) return { x: box.left + box.width / 2, y: box.top }; + return; + }, + }; +} diff --git a/packages/client/src/client/avatar.tsx b/packages/client/src/client/avatar.tsx index a63a2d633f..ac6058dc67 100644 --- a/packages/client/src/client/avatar.tsx +++ b/packages/client/src/client/avatar.tsx @@ -20,6 +20,8 @@ import { pixelSymbolFor, } from '../../../core/src/bots/avatar-appearance.js'; import { IllustratedAvatar } from './illustrated-avatar.js'; +import { createAvatarAnchor, type AvatarAnchor } from './avatar-anchor.js'; +import { useMountedResource } from './mounted-resource.js'; export const PERSONA_BOT_ACTIVITY_STATES = [ 'idle', @@ -55,6 +57,7 @@ export interface PersonaBotAvatarProps { surface?: 'portrait' | 'companion' | undefined; still?: boolean | undefined; mouth?: PixelMouthState | undefined; + anchorRef?: ((anchor: AvatarAnchor | undefined) => void) | undefined; } export interface PersonaBotFacepileItem { @@ -349,6 +352,7 @@ export function PersonaBotAvatar({ surface = 'portrait', still = false, mouth = 'saved', + anchorRef, t = zhTranslate, }: PersonaBotAvatarProps): ReactElement { const resolvedEffect = @@ -363,9 +367,18 @@ export function PersonaBotAvatar({ const mediaKind = composed ? 'composed' : seeded ? 'seeded' : 'image'; const active = !still && (state === 'thinking' || state === 'working'); const classes = ['bh-persona-avatar', className].filter(Boolean).join(' '); + const anchorMount = useMountedResource( + (node) => { + if (!anchorRef || surface !== 'companion') return; + anchorRef(createAvatarAnchor(node)); + return () => anchorRef(undefined); + }, + [anchorRef, appearance, seededRecipe, src, size, state, surface], + ); return ( Math.max(8, Math.min(left, width - 328)); - const minimum = 8 - (y + 134); + const bottom = Math.max(y + 134, origin.y + 38); + const minimum = 8 - bottom; const collapsedOverflow = !reading && cards ? (cards - 1) * 8 : 0; - const maximum = height - 16 - (y + (cards ? 286 + collapsedOverflow : 158)); + const maximum = height - 16 - (bottom + (cards ? 152 + collapsedOverflow : 24)); const base = Math.max(minimum, Math.min(0, maximum)); const previous = this.boxes.get(botId); const box = (left: number, offset: number): BubbleBox => { const cardHeight = reading && cards - ? Math.min(cards * 112, Math.max(112, height - y - 174 - offset - 16)) + ? Math.min(cards * 112, Math.max(112, height - bottom - 40 - offset - 16)) : 112; return { left, offset, cardHeight, - anchorX: x, + anchorX: origin.x, + originX: origin.x, + originY: origin.y, right: Math.min(width - 8, left + 320), - bottom: y + 134 + offset, - top: y + (cards ? 174 + cardHeight + (reading ? 0 : (cards - 1) * 8) : 158) + offset, + bottom: bottom + offset, + top: bottom + (cards ? 40 + cardHeight + (reading ? 0 : (cards - 1) * 8) : 24) + offset, }; }; - let placed = box(boundedLeft(x - 108), base); + let placed = box(boundedLeft(origin.x - 160), base); if (reading && previous) { placed = box( - boundedLeft(previous.left + x - previous.anchorX), + boundedLeft(previous.left + origin.x - previous.anchorX), Math.max(minimum, Math.min(previous.offset, maximum)), ); } else { @@ -62,7 +68,7 @@ export class CompanionBubbles { const offsets = [ base, ...others.flatMap((other) => [ - other.top + 8 - (y + 134), + other.top + 8 - bottom, other.bottom - 8 - placed.top + base, ]), ].filter((offset) => offset >= base && offset <= maximum); diff --git a/packages/client/src/client/window-companion-styles.ts b/packages/client/src/client/window-companion-styles.ts index 755d3cbcb5..8765a14632 100644 --- a/packages/client/src/client/window-companion-styles.ts +++ b/packages/client/src/client/window-companion-styles.ts @@ -20,6 +20,8 @@ export const WINDOW_COMPANION_CSS = ` .bh-companion-capacity-controls { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; } .bh-companion-capacity-controls label { display: grid; gap: 4px; max-width: 150px; } .bh-companion { position: absolute; width: 96px; height: 96px; pointer-events: auto; } +.bh-companion-tether { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; } +.bh-companion-tether path { fill: none; stroke: var(--bh-companion-border); stroke-width: 2; stroke-linejoin: miter; } .bh-companion-character { border: 0; padding: 0; background: transparent; cursor: grab; touch-action: none; width: 96px; height: 96px; transform-origin: center 20%; transition: transform 140ms ease-out, transform-origin 140ms ease-out; } .bh-companion[data-motion='fall'] .bh-companion-character, .bh-companion[data-motion='land'] .bh-companion-character { transform-origin: center bottom; transition: transform 70ms ease-out, transform-origin 140ms ease-out; } diff --git a/packages/client/src/client/window-companion-view.tsx b/packages/client/src/client/window-companion-view.tsx index a9a857d9a4..476aabe91f 100644 --- a/packages/client/src/client/window-companion-view.tsx +++ b/packages/client/src/client/window-companion-view.tsx @@ -1,4 +1,11 @@ -import { useId, useRef, useState, useSyncExternalStore, type ReactElement } from 'react'; +import { + useCallback, + useId, + useRef, + useState, + useSyncExternalStore, + type ReactElement, +} from 'react'; import { Menu, IconEllipsisOutlineRegular, @@ -12,10 +19,11 @@ import { useMountedResource } from './mounted-resource.js'; import type { BotHarnessTranslate } from './locale.js'; import type { CompanionBot } from '../../../core/src/companions/feed.js'; import type { CompanionViewState, WindowCompanion } from './window-companion.js'; -import { CompanionMotion } from './companion-motion.js'; -import type { CompanionBubbles, BubblePlacement } from './companion-bubbles.js'; +import { CompanionMotion, type CompanionPoint } from './companion-motion.js'; +import { CompanionBubbles, type BubblePlacement } from './companion-bubbles.js'; import { isAvatarAppearance } from '../../../core/src/bots/avatar-appearance.js'; import { companionMessageIdentity } from '../../../core/src/companions/sources.js'; +import type { AvatarAnchor } from './avatar-anchor.js'; function avatarLimitation( bot: CompanionBot | undefined, @@ -57,8 +65,16 @@ export function WindowCompanionView({ latest.current = view; const [motion] = useState(() => new CompanionMotion()); const [point, setPoint] = useState(motion.point); + const displayedPoint = useRef(point); + displayedPoint.current = point; + const anchor = useRef(undefined); + const viewport = useRef({ left: 0, bottom: window.innerHeight, height: window.innerHeight }); + const anchorRef = useCallback((value: AvatarAnchor | undefined) => { + anchor.current = value; + }, []); + const [localBubbles] = useState(() => new CompanionBubbles()); + const bubbleOwner = bubbles ?? localBubbles; const [bubble, setBubble] = useState(undefined); - const bubbleOffset = bubble?.offset ?? 0; const root = useRef(null); const character = useRef(null); const pointer = useRef< @@ -144,11 +160,57 @@ export function WindowCompanionView({ let elapsed = 0; let measured = false; let visible = true; + const placeBubble = (next: CompanionPoint, sampled: ReturnType) => { + const state = latest.current; + if (state.selection) { + if (statusVisible(state) || state.cards.length) { + const placement = bubbleOwner.place( + state.selection.botId, + next.x, + next.y, + next.width, + viewport.current.height, + state.reading + ? state.cards.length + : Math.min(state.cards.length, state.capacity.layers), + state.reading, + sampled + ? { + x: next.x + sampled.x - viewport.current.left - displayedPoint.current.x, + y: next.y + viewport.current.bottom - sampled.y - displayedPoint.current.y, + } + : undefined, + ); + setBubble((previous) => + previous?.bottom === placement.bottom && + previous?.originX === placement.originX && + previous?.originY === placement.originY && + previous?.left === placement?.left && + previous?.cardHeight === placement?.cardHeight + ? previous + : placement, + ); + } else { + bubbleOwner.remove(state.selection.botId); + setBubble(undefined); + } + } + }; const measure = () => { - const width = node.getBoundingClientRect().width; + const box = node.getBoundingClientRect(); + const width = box.width; + viewport.current = { + left: box.left, + bottom: box.bottom, + height: box.height || window.innerHeight, + }; const next = measured - ? motion.resize(width, window.innerHeight) - : motion.measure(width, window.innerHeight, latest.current.selection?.position ?? 0.75); + ? motion.resize(width, viewport.current.height) + : motion.measure( + width, + viewport.current.height, + latest.current.selection?.position ?? 0.75, + ); measured = true; const drag = pointer.current; if (drag) { @@ -158,6 +220,7 @@ export function WindowCompanionView({ drag.originY = next.y; } setPoint(next); + placeBubble(next, anchor.current?.read()); }; const tick = (now: number) => { frame = 0; @@ -181,32 +244,10 @@ export function WindowCompanionView({ !reduced, ); const previousPoint = motion.point; + const sampled = + statusVisible(state) || state.cards.length ? anchor.current?.read() : undefined; const next = motion.advance(milliseconds, reduced, walking, direction.current); - if (state.selection) { - if (statusVisible(state) || state.cards.length) { - const placement = bubbles?.place( - state.selection.botId, - next.x, - next.y, - next.width, - window.innerHeight, - state.reading - ? state.cards.length - : Math.min(state.cards.length, state.capacity.layers), - state.reading, - ); - setBubble((previous) => - previous?.offset === placement?.offset && - previous?.left === placement?.left && - previous?.cardHeight === placement?.cardHeight - ? previous - : placement, - ); - } else { - bubbles?.remove(state.selection.botId); - setBubble(undefined); - } - } + placeBubble(next, sampled); if (walking && (next.x <= 8 || next.x >= Math.max(8, next.width - 104))) direction.current *= -1; if (next !== previousPoint) setPoint(next); @@ -250,11 +291,11 @@ export function WindowCompanionView({ if (exit.current !== undefined) clearTimeout(exit.current); if (clickReset.current !== undefined) clearTimeout(clickReset.current); pointer.current = undefined; - if (latest.current.selection) bubbles?.remove(latest.current.selection.botId); + if (latest.current.selection) bubbleOwner.remove(latest.current.selection.botId); root.current = null; }; }, - [companion, view.selection?.botId, bubbles], + [companion, view.selection?.botId, bubbleOwner], ); if (!view.selection || !view.bot) return null; const { selection, bot, activity } = view; @@ -294,8 +335,26 @@ export function WindowCompanionView({ const bubbleLeft = bubble ? bubble.left - point.x : Math.max(-point.x + 8, Math.min(-108, point.width - point.x - 328)); + const bubbleBottom = (bubble?.bottom ?? point.y + 134) - point.y; + const connector = + bubble && (statusVisible(view) || view.cards.length) + ? { + x: Math.max( + bubble.left + 12, + Math.min(bubble.originX, bubble.left + Math.min(308, point.width - 28)), + ), + y: viewport.current.height - bubble.bottom - (statusVisible(view) ? 0 : 40), + } + : undefined; return (
+ {connector && bubble ? ( + + ) : null}
{view.sync !== 'live' @@ -344,12 +403,12 @@ export function WindowCompanionView({ aria-label={t('companion.messages')} style={{ left: bubbleLeft, - bottom: 174 + bubbleOffset, + bottom: bubbleBottom + 40, height: view.reading ? (bubble?.cardHeight ?? Math.min( cards.length * 112, - Math.max(112, window.innerHeight - point.y - 174 - bubbleOffset - 16), + Math.max(112, viewport.current.height - point.y - bubbleBottom - 40 - 16), )) : 112, }} @@ -596,6 +655,7 @@ export function WindowCompanionView({ state={state} activity={activity?.activity} surface="companion" + anchorRef={anchorRef} mouth={view.mouth} indicator={false} still={bot.paused} diff --git a/packages/client/test/avatar-anchor.test.ts b/packages/client/test/avatar-anchor.test.ts new file mode 100644 index 0000000000..5e39c8eabf --- /dev/null +++ b/packages/client/test/avatar-anchor.test.ts @@ -0,0 +1,97 @@ +// @vitest-environment jsdom +import { expect, it, vi } from 'vitest'; +import { createAvatarAnchor } from '../src/client/avatar-anchor.js'; +import { act, createElement } from 'react'; +import { createRoot } from 'react-dom/client'; +import { PersonaBotAvatar } from '../src/client/avatar.js'; + +it('captures the head bounds once and follows the displayed transform, including an interrupted pose', () => { + const node = document.createElement('span'); + node.innerHTML = ''; + document.body.append(node); + const head = node.querySelector('g')!; + const svg = node.querySelector('svg')!; + const bounds = vi.fn(() => ({ x: 8, y: 4, width: 16, height: 20 })); + let matrix = { a: 3, b: 0, c: 0, d: 3, e: 100, f: 500 }; + const projection = vi.fn(() => matrix); + const coverProjection = vi.fn(() => ({ a: 3, b: 0, c: 0, d: 3, e: 100, f: 503 })); + Object.defineProperty(head, 'getBBox', { value: bounds }); + Object.defineProperty(head, 'getScreenCTM', { value: projection }); + Object.defineProperty(svg, 'getScreenCTM', { value: coverProjection }); + try { + const anchor = createAvatarAnchor(node); + expect(anchor.read()).toEqual({ x: 148, y: 512 }); + matrix = { a: 0, b: 3, c: -3, d: 0, e: 200, f: 400 }; + expect(anchor.read()).toEqual({ x: 188, y: 448 }); + matrix = { a: 2.7, b: 0.4, c: -0.5, d: 3.2, e: 150, f: 470 }; + expect(anchor.read()).toEqual({ x: 191.2, y: 489.2 }); + expect(bounds).toHaveBeenCalledOnce(); + svg.setAttribute('data-pixel-cover', ''); + expect(anchor.read()).toEqual({ x: 148, y: 515 }); + expect(coverProjection).toHaveBeenCalledOnce(); + node.remove(); + expect(anchor.read()).toBeUndefined(); + expect(projection).toHaveBeenCalledTimes(3); + } finally { + node.remove(); + } +}); + +it('uses the current box top for images, unsupported rigs and unavailable SVG geometry', () => { + const node = document.createElement('span'); + document.body.append(node); + const rect = vi.spyOn(node, 'getBoundingClientRect').mockReturnValue({ + left: 200, + top: 500, + right: 296, + bottom: 596, + x: 200, + y: 500, + width: 96, + height: 96, + toJSON: () => ({}), + }); + try { + const imageAnchor = createAvatarAnchor(node); + expect(imageAnchor.read()).toEqual({ x: 248, y: 500 }); + node.innerHTML = ''; + const unavailableAnchor = createAvatarAnchor(node); + expect(unavailableAnchor.read()).toEqual({ x: 248, y: 500 }); + expect(rect).toHaveBeenCalledTimes(2); + } finally { + node.remove(); + } +}); + +it('exposes a live companion anchor through Avatar ownership and clears it on replacement and disposal', async () => { + Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); + const node = document.createElement('div'); + document.body.append(node); + const root = createRoot(node); + const anchorRef = vi.fn(); + const render = (surface: 'portrait' | 'companion') => + root.render( + createElement(PersonaBotAvatar, { + personaBotId: 'ada', + name: 'Ada', + size: 96, + src: '/image', + surface, + anchorRef, + }), + ); + try { + await act(() => render('portrait')); + expect(anchorRef).not.toHaveBeenCalled(); + await act(() => render('companion')); + expect(anchorRef.mock.calls.at(-1)![0]?.read).toBeTypeOf('function'); + await act(() => render('portrait')); + expect(anchorRef).toHaveBeenLastCalledWith(undefined); + await act(() => render('companion')); + await act(() => root.unmount()); + expect(anchorRef).toHaveBeenLastCalledWith(undefined); + } finally { + await act(() => root.unmount()); + node.remove(); + } +}); diff --git a/packages/client/test/companion-bubbles.test.ts b/packages/client/test/companion-bubbles.test.ts new file mode 100644 index 0000000000..50f1443aef --- /dev/null +++ b/packages/client/test/companion-bubbles.test.ts @@ -0,0 +1,36 @@ +import { expect, it } from 'vitest'; +import { CompanionBubbles } from '../src/client/companion-bubbles.js'; + +it('follows a projected head while keeping cards above the toolbar and bounded at the viewport edge', () => { + const bubbles = new CompanionBubbles(); + const idle = bubbles.place('ada', 400, 0, 1000, 800, 3, false, { x: 448, y: 84 }); + expect(idle).toMatchObject({ left: 288, bottom: 134, originX: 448, originY: 84 }); + const tilted = bubbles.place('ada', 400, 0, 1000, 800, 3, false, { x: 430, y: 110 }); + expect(tilted.left).toBe(270); + expect(tilted.bottom).toBe(148); + expect(tilted.originX).toBe(430); + const high = bubbles.place('ada', 400, 640, 1000, 800, 3, false, { x: 445, y: 740 }); + expect(high.bottom + 152 + 16).toBeLessThanOrEqual(784); + expect(high.originY).toBe(740); + expect(high.bottom).toBeGreaterThanOrEqual(8); + const narrow = bubbles.place('ada', 600, 0, 400, 800, 1, false, { x: 648, y: 96 }); + expect(narrow.left).toBe(72); +}); + +it('retains an originating Bot across avoidance, reading and a subsequent resize without limiting the collection', () => { + const bubbles = new CompanionBubbles(); + const ada = bubbles.place('ada', 200, 0, 400, 800, 1, false); + const grace = bubbles.place('grace', 220, 0, 400, 800, 1, false); + expect(ada.originX).toBe(248); + expect(grace.originX).toBe(268); + expect(grace.bottom).not.toBe(ada.bottom); + const reading = bubbles.place('grace', 220, 0, 400, 800, 4, true, { x: 260, y: 106 }); + expect(reading.originX).toBe(260); + expect(reading.cardHeight).toBeLessThanOrEqual(800 - reading.bottom - 56); + const resized = bubbles.place('grace', 180, 0, 360, 600, 4, true, { x: 228, y: 96 }); + expect(resized.left).toBeLessThanOrEqual(32); + expect(resized.bottom + 40 + resized.cardHeight).toBeLessThanOrEqual(584); + bubbles.remove('ada'); + bubbles.remove('grace'); + expect(bubbles.place('third', 200, 0, 400, 800, 1, false).bottom).toBe(134); +}); diff --git a/packages/client/test/window-companion-view.test.ts b/packages/client/test/window-companion-view.test.ts index a57fb1432d..75024e228b 100644 --- a/packages/client/test/window-companion-view.test.ts +++ b/packages/client/test/window-companion-view.test.ts @@ -39,6 +39,95 @@ vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({ IconNewChatOutlineRegular: () => null, })); +it('projects the owning Avatar screen point into an offset overlay and remeasures it after resize', async () => { + Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); + const frames = new Map(); + let frameId = 0; + vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => { + frames.set(++frameId, callback); + return frameId; + }); + vi.stubGlobal('cancelAnimationFrame', (id: number) => frames.delete(id)); + let stage = new DOMRect(80, 40, 800, 600); + const measurement = vi + .spyOn(HTMLElement.prototype, 'getBoundingClientRect') + .mockImplementation(function (this: HTMLElement) { + if (!this.classList.contains('bh-persona-avatar')) return stage; + const surface = this.closest('.bh-companion')!; + return new DOMRect( + stage.left + Number.parseFloat(surface.style.left), + stage.bottom - Number.parseFloat(surface.style.bottom) - 96, + 96, + 96, + ); + }); + const events = new EventTarget(); + const companion = new WindowCompanion({ + context: async () => ({ profileId: 'qa' }), + source: () => ({ addEventListener: events.addEventListener.bind(events), close() {} }), + }); + await companion.start(); + companion.select('ada'); + companion.configure({ walking: false }); + events.dispatchEvent( + new MessageEvent('companion/baseline', { + data: JSON.stringify({ + profileId: 'qa', + bot: { slug: 'ada', name: 'Ada', paused: false, avatar: '/image' }, + activity: { generation: 'host', revision: 0, bots: [] }, + }), + }), + ); + const node = document.createElement('div'); + document.body.append(node); + const root = createRoot(node); + const frame = () => { + const due = [...frames.values()]; + frames.clear(); + for (const callback of due) callback(performance.now() + 50); + }; + try { + await act(() => + root.render( + createElement(WindowCompanionView, { + companion, + openDm() {}, + openAttention() {}, + openChannel() {}, + t: zhTranslate, + }), + ), + ); + await act(frame); + expect(node.querySelector('.bh-companion-tether path')?.getAttribute('d')).toMatch( + /^M 570 504 /u, + ); + expect(node.querySelector('.bh-companion-activity')?.style.bottom).toBe('134px'); + stage = new DOMRect(100, 60, 650, 500); + await act(() => window.dispatchEvent(new Event('resize'))); + await act(frame); + expect(node.querySelector('.bh-companion-tether path')?.getAttribute('d')).toMatch( + /^M 570 404 /u, + ); + stage = new DOMRect(100, 60, 320, 500); + await act(() => window.dispatchEvent(new Event('resize'))); + expect(node.querySelector('.bh-companion')?.style.left).toBe('216px'); + expect(node.querySelector('.bh-companion-tether path')?.getAttribute('d')).toMatch( + /^M 264 404 /u, + ); + const visibility = vi.spyOn(document, 'hidden', 'get').mockReturnValue(true); + await act(() => document.dispatchEvent(new Event('visibilitychange'))); + expect(frames.size).toBe(0); + visibility.mockRestore(); + } finally { + await act(() => root.unmount()); + companion.dispose(); + node.remove(); + measurement.mockRestore(); + vi.unstubAllGlobals(); + } +}); + it('enables Group playback from the native menu and explains why a Bot-only source cannot open', async () => { Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); vi.useFakeTimers(); diff --git a/packages/client/test/window-companions-view.test.ts b/packages/client/test/window-companions-view.test.ts index 2d3c8e5765..f4c66ab307 100644 --- a/packages/client/test/window-companions-view.test.ts +++ b/packages/client/test/window-companions-view.test.ts @@ -62,18 +62,23 @@ it('pins independently, exposes right-click controls and applies global bounded frames.set(++frame, callback); return frame; }); - vi.stubGlobal('cancelAnimationFrame', () => {}); - const measurement = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ - x: 0, - y: 0, - top: 0, - left: 0, - right: 1000, - bottom: 800, - width: 1000, - height: 800, - toJSON: () => ({}), - }); + vi.stubGlobal('cancelAnimationFrame', (id: number) => frames.delete(id)); + let stageWidth = 1000; + let stageHeight = window.innerHeight; + const measurement = vi + .spyOn(HTMLElement.prototype, 'getBoundingClientRect') + .mockImplementation(function (this: HTMLElement) { + if (this.classList.contains('bh-persona-avatar')) { + const companion = this.closest('.bh-companion'); + return new DOMRect( + Number.parseFloat(companion?.style.left ?? '0'), + window.innerHeight - Number.parseFloat(companion?.style.bottom ?? '0') - 96, + 96, + 96, + ); + } + return new DOMRect(0, 0, stageWidth, stageHeight); + }); const events = new EventTarget(); const owner = new WindowCompanions({ context: async () => ({ profileId: 'qa' }), @@ -167,7 +172,16 @@ it('pins independently, exposes right-click controls and applies global bounded for (const callback of [...frames.values()]) callback(performance.now()); }); const bubbles = [...node.querySelectorAll('.bh-companion-activity')]; - expect(bubbles[0]!.style.bottom).not.toBe(bubbles[1]!.style.bottom); + const positions = bubbles.map((bubble) => ({ + x: + Number.parseFloat(bubble.style.left) + + Number.parseFloat(bubble.closest('.bh-companion')!.style.left), + y: Number.parseFloat(bubble.style.bottom), + })); + expect( + Math.abs(positions[0]!.x - positions[1]!.x) >= 328 || + Math.abs(positions[0]!.y - positions[1]!.y) >= 32, + ).toBe(true); expect([...pins].map((pin) => pin.getAttribute('aria-pressed'))).toEqual(['true', 'true']); const grace = node.querySelector('[data-bot="grace"]')!; await act(() => { @@ -261,17 +275,8 @@ it('pins independently, exposes right-click controls and applies global bounded expect(owner.get('ada')!.getSnapshot().selection?.walking).toBe(false); expect(owner.get('grace')!.getSnapshot().selection?.walking).toBe(true); vi.stubGlobal('innerHeight', 640); - measurement.mockReturnValue({ - x: 0, - y: 0, - top: 0, - left: 0, - right: 360, - bottom: 640, - width: 360, - height: 640, - toJSON: () => ({}), - }); + stageWidth = 360; + stageHeight = 640; await act(() => { owner.configureCapacity({ layers: 10, retention: 10 }); for (const botId of ['ada', 'grace']) {