@linxin666/dsh-pet 0.1.19 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +19 -12
  3. package/README.zh.md +19 -12
  4. package/assets/whale/pet.json +9 -0
  5. package/lib/client.js +202 -38
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +897 -42
  8. package/lib/invariant.js +1 -1
  9. package/lib/{state-Diiq8vjk.js → state-Ch3f4luZ.js} +51 -23
  10. package/lib/types/affinity.d.ts +22 -18
  11. package/lib/types/affinity.d.ts.map +1 -1
  12. package/lib/types/affinity.js +32 -6
  13. package/lib/types/chatter.d.ts +111 -0
  14. package/lib/types/chatter.d.ts.map +1 -0
  15. package/lib/types/chatter.js +666 -0
  16. package/lib/types/client/PetDockEntry.d.ts +2 -0
  17. package/lib/types/client/PetDockEntry.d.ts.map +1 -1
  18. package/lib/types/client/PetDockEntry.js +2 -2
  19. package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
  20. package/lib/types/client/PetSettingsCard.js +2 -2
  21. package/lib/types/client/PetSprite.d.ts +2 -0
  22. package/lib/types/client/PetSprite.d.ts.map +1 -1
  23. package/lib/types/client/PetSprite.js +100 -25
  24. package/lib/types/client/PluginSettingsCard.d.ts +7 -1
  25. package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
  26. package/lib/types/client/PluginSettingsCard.js +5 -3
  27. package/lib/types/client/index.d.ts +1 -1
  28. package/lib/types/client/index.d.ts.map +1 -1
  29. package/lib/types/client/index.js +31 -6
  30. package/lib/types/client/locales.d.ts +82 -80
  31. package/lib/types/client/locales.d.ts.map +1 -1
  32. package/lib/types/client/locales.js +2 -0
  33. package/lib/types/client/sequences.d.ts +10 -0
  34. package/lib/types/client/sequences.d.ts.map +1 -0
  35. package/lib/types/client/sequences.js +20 -0
  36. package/lib/types/client/settings-form.d.ts.map +1 -1
  37. package/lib/types/client/spritesheet.d.ts +1 -1
  38. package/lib/types/client/spritesheet.d.ts.map +1 -1
  39. package/lib/types/client/spritesheet.js +3 -12
  40. package/lib/types/event-projection.d.ts +14 -1
  41. package/lib/types/event-projection.d.ts.map +1 -1
  42. package/lib/types/event-projection.js +38 -17
  43. package/lib/types/index.d.ts +2 -1
  44. package/lib/types/index.d.ts.map +1 -1
  45. package/lib/types/index.js +15 -13
  46. package/lib/types/invariant.js +2 -2
  47. package/lib/types/ledger.d.ts.map +1 -1
  48. package/lib/types/ledger.js +18 -10
  49. package/lib/types/mount-once.d.ts +25 -0
  50. package/lib/types/mount-once.d.ts.map +1 -0
  51. package/lib/types/mount-once.js +42 -0
  52. package/lib/types/persist.d.ts.map +1 -1
  53. package/lib/types/persist.js +6 -4
  54. package/lib/types/registry.d.ts +7 -1
  55. package/lib/types/registry.d.ts.map +1 -1
  56. package/lib/types/registry.js +37 -1
  57. package/lib/types/remarks.d.ts +2 -0
  58. package/lib/types/remarks.d.ts.map +1 -1
  59. package/lib/types/remarks.js +5 -0
  60. package/lib/types/routes.js +2 -2
  61. package/lib/types/service.d.ts +16 -6
  62. package/lib/types/service.d.ts.map +1 -1
  63. package/lib/types/service.js +26 -8
  64. package/lib/types/state.d.ts +7 -4
  65. package/lib/types/state.d.ts.map +1 -1
  66. package/lib/types/state.js +20 -20
  67. package/package.json +9 -9
  68. package/src/affinity.test.ts +4 -2
  69. package/src/affinity.ts +37 -6
  70. package/src/chatter.test.ts +154 -0
  71. package/src/chatter.ts +697 -0
  72. package/src/client/PetDockEntry.tsx +3 -0
  73. package/src/client/PetSprite.test.tsx +246 -4
  74. package/src/client/PetSprite.tsx +132 -36
  75. package/src/client/PluginSettingsCard.tsx +10 -0
  76. package/src/client/index.ts +26 -3
  77. package/src/client/locales.ts +2 -0
  78. package/src/client/pet-css.test.ts +42 -0
  79. package/src/client/pet.module.css +173 -22
  80. package/src/client/sequences.test.ts +33 -0
  81. package/src/client/sequences.ts +33 -0
  82. package/src/client/spritesheet.ts +3 -13
  83. package/src/event-projection.ts +49 -16
  84. package/src/index.ts +4 -1
  85. package/src/ledger.test.ts +42 -1
  86. package/src/ledger.ts +15 -7
  87. package/src/mount-once.ts +48 -0
  88. package/src/persist.test.ts +18 -1
  89. package/src/persist.ts +3 -1
  90. package/src/registry.test.ts +50 -3
  91. package/src/registry.ts +47 -3
  92. package/src/remarks.ts +6 -0
  93. package/src/service.ts +42 -9
  94. package/src/state.test.ts +13 -0
  95. package/src/state.ts +24 -18
package/README.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: 75de064887be4289018547fba722851afd98dd5a
6
- README.zh.md: 9e396eca9b5a47425aeee972ec7a95a7e7da81ac
5
+ README.md: 2784c32e13b4f35dd94caef439f4b73d99045289
6
+ README.zh.md: f062272c21046b364510c016c97877605083689d
package/README.md CHANGED
@@ -15,16 +15,17 @@ Re-implemented from the pet feature of the Codex desktop app, as an official DSH
15
15
  | Multi-pet registry | The host scans built-in `assets/`, the hatch-pet custom pets directory, and composed config entries; each pet is a manifest plus an atlas |
16
16
  | Pet selection in settings | The plugin settings card lists every registered pet; switching persists and the sprite swaps immediately |
17
17
  | Per-pet naming | Rename from the hover panel; each pet keeps its own name (stored per pet id, migrated from the legacy flat name) |
18
- | State animation | Official session activity → 9-state animation: `thinking running`, `tool running-right`, `review review`, `waiting waiting`, `done jumping`, `failed failed` |
18
+ | State animation | Official session activity → manifest-defined sequences of 9-state tracks; each track finishes its full duration before the sequence advances and the complete sequence loops |
19
19
  | Head-pat interaction | Click the pet → bubble feedback + affinity +1 (10s cooldown) |
20
20
  | Feeding | Hover panel 喂食 (Feed) → consumes 1 dried fish + affinity +5 (30s cooldown) |
21
21
  | Treat economy | Dried-fish stock (cap 20): +1 every 30 rounds of work, +1 every 300 minutes (5 hours) — 10x rarer than the original cadence |
22
22
  | Affinity | +1 per round completed; 9 levels: 幼鲸 → 伙伴 → 挚友 → 深海羁绊 → 心有灵犀 → 传说羁绊 → 神话羁绊 → 永恒之契 → 鲸生共渡 (capped at 999,999,999) |
23
23
  | Dragging | Hold and drag the pet to reposition; position persisted |
24
- | Hide/Summon | Hover panel 隐藏 (Hide); after hiding, a 召唤{name} (Summon {name}) button appears |
25
- | Witty remarks | Built-in remark library (10 lines per event) plus per-pet custom lines from a manifest remarks block community PRs give their pet its own voice |
26
- | Status bubbles | Each concurrently active session gets its own bubble, stacked above the pet (up to 12); transient interaction feedback temporarily takes priority |
27
- | Multi-session activity | The pet is host-global: the most recent meaningful event drives the sprite animation while every active session reports its own state in a separate bubble; completed turns from every session contribute affinity and treats |
24
+ | Hide/Summon | The hover panel sits below the pet (lifted above the status bubbles when there is no room below) and provides 隐藏 (Hide); after hiding, a 召唤{name} (Summon {name}) button appears |
25
+ | Witty remarks | Built-in remark library (10 lines per event) plus per-pet custom lines; success lines rotate by persisted success counts and cooldown lines by persisted rejection counts |
26
+ | Status bubbles | Each concurrently active top-level session gets its own bubble, stacked above the pet (up to 12); subagent sessions report through their spawning conversation and never occupy a bubble of their own; click a bubble to jump to its session; transient interaction feedback temporarily takes priority. Bubble copy comes from generous rotating pools per scene (waiting / thinking / writing / done / failed...), tool calls map onto per-family witty lines carrying the real argument hint (e.g. 跑跑 npm test), and a long-lived scene re-phrases itself every few seconds |
27
+ | Inner whispers | 碎碎念: while the model streams, the pet occasionally speaks its inner voice in a distinct violet whisper bubble — keyword moods woken by the model output (errors, test greens, plans, victories...) plus ambient whispers earned by output volume; paced by a cooldown, expired after a few seconds |
28
+ | Multi-session activity | The pet is host-global: the most recent meaningful event drives the sprite animation while every active top-level session reports its own state in a separate bubble; completed turns from every session (subagents included) contribute affinity and treats |
28
29
 
29
30
  ## Pet contract
30
31
 
@@ -38,10 +39,14 @@ A pet is a directory holding one `pet.json` manifest and one atlas image. Nothin
38
39
  "spritesheetPath": "spritesheet.webp", // atlas, relative to the manifest
39
40
  "cell": { "width": 192, "height": 208 }, // optional; defaults to the Codex contract
40
41
  "columns": 8, // optional; default 8
42
+ "spriteVersionNumber": 1, // optional; 2 marks an 11-row v2 atlas (9 animation rows + 2 look rows)
41
43
  "frames": [6, 8, 8, 4, 5, 8, 6, 6, 6], // optional per-row frame counts
42
44
  "tracks": { // optional per-track rhythm overrides
43
45
  "idle": { "durations": [400, 400, 500, 400, 400, 500] }
44
46
  },
47
+ "sequences": { // optional per-scene track sequences (at least 5 items each)
48
+ "thinking": ["running", "running-right", "running", "running-left", "waiting"]
49
+ },
45
50
  "remarks": { // optional witty remarks (one line or a pool per slot)
46
51
  "pet": "摸摸水獭的头~",
47
52
  "feed": ["小鱼干真香", "再来一条~"]
@@ -49,9 +54,10 @@ A pet is a directory holding one `pet.json` manifest and one atlas image. Nothin
49
54
  }
50
55
  ```
51
56
 
52
- - The atlas is an 8-column × 9-row grid (192×208 cells by default); rows are fixed in this order: 0 idle, 1 running-right, 2 running-left, 3 waving, 4 jumping, 5 failed, 6 waiting, 7 running, 8 review. Unused cells stay fully transparent.
53
- - The optional remarks block overrides the reaction bubbles the pet speaks on pet / petCooldown / feed / feedCooldown / noTreats events. Each slot accepts one line or a pool of lines (cycled round-robin); a declared slot replaces the built-in pool for that slot only. This is how community contributions give their pet its own witty voice.
57
+ - The atlas is an 8-column × 9-row grid (192×208 cells by default); rows are fixed in this order: 0 idle, 1 running-right, 2 running-left, 3 waving, 4 jumping, 5 failed, 6 waiting, 7 running, 8 review. Unused cells stay fully transparent. v2 Codex atlases declare `"spriteVersionNumber": 2` and hold 11 rows — the same 9 animation rows plus 2 trailing look rows; the plugin renders the 9 animation rows and ignores the look rows.
58
+ - The optional remarks block overrides the reaction bubbles the pet speaks on pet / petCooldown / feed / feedCooldown / noTreats events. Each slot accepts one line or a pool of lines; a declared slot replaces the built-in pool for that slot only. Success and cooldown pools use the corresponding persisted success or rejection count, while noTreats cycles independently. This is how community contributions give their pet its own witty voice.
54
59
  - `frames` counts the used columns per row (defaults to the hatch-pet contract table `[6, 8, 8, 4, 5, 8, 6, 6, 6]`); `tracks` overrides per-frame durations (cycled to the row's frame count), `loop`, and `fallback` per animation (defaults: everything loops; `jumping` and `failed` hold their last frame, then fall back to `idle`).
60
+ - `sequences` optionally maps activity scenes (`idle` / `waiting` / `thinking` / `tool` / `review` / `done` / `failed`) to at least 5 animation tracks. Each item plays every frame for the durations in `tracks`, then the next item starts; the complete sequence loops. An omitted scene keeps its canonical single-track playback.
55
61
 
56
62
  Where pets come from (later sources override earlier ones on id collision):
57
63
 
@@ -82,16 +88,17 @@ dsh-pet/
82
88
  | |-- registry.ts # multi-pet contract: manifest scan + normalization (assets + custom pets)
83
89
  | |-- service.ts # PetService: pet selection + state machine + affinity + config
84
90
  | |-- state.ts # pet state machine: projected session activity → 9 state animations
85
- | |-- remarks.ts # witty-remark library: built-in pools + per-pet overrides + picker
91
+ | |-- remarks.ts # witty-remark library: built-in pools + per-pet overrides + counted picker
86
92
  | |-- affinity.ts # affinity ledger (pure functions + cooldowns)
87
93
  | |-- treats.ts # dried-fish stock ledger
88
- | |-- persist.ts # persistence ($DSH_HOME/pet.json: selection + per-pet names, atomic write)
94
+ | |-- persist.ts # persistence ($DSH_HOME/pet.json: selection + names + interaction counts)
89
95
  | |-- routes.ts # /api/pet/* JSON API + /pet/<id>/* asset routes
90
96
  | `-- client/ # browser half
91
97
  | |-- index.ts # global mount (createRoot → body) + registry fetch + polling + wiring
92
98
  | |-- PetDockEntry.tsx # global floating entry (document.body, always shown)
93
99
  | |-- PetSprite.tsx # definition-driven floating sprite (portal + rAF + dragging)
94
100
  | |-- PetSettingsCard.tsx # settings card: pet selector + display layout
101
+ | |-- sequences.ts # full-track scene sequence timing
95
102
  | |-- spritesheet.ts # atlas geometry helpers + track trimming
96
103
  | `-- pet.module.css
97
104
  |-- assets/whale/ # built-in whale-girl (pet.json + spritesheet.webp + previews)
@@ -113,9 +120,9 @@ global React root (createRoot → document.body) <-- polling 2s -- pet-client (b
113
120
  - **Status source**: the host projects official `turn/start`, `step/start`, `assistant/chunk`, `assistant/message`, `tool/call`, `tool/result`, and `turn/end` events into waiting/thinking/tool/review/done/failed states. Optional legacy `activity/status` events remain a compatibility input.
114
121
  - **Registry**: the host normalizes every manifest into a full render definition (geometry, per-row frame counts, per-track durations) and serves it over `/api/pet/pets`; the browser half renders any entry from that definition and carries no per-pet code.
115
122
  - **Selection & naming**: `petId` lives in the settings namespace; per-pet names live in `pet.json` under `names`, edited through the hover-panel rename of the active pet. Legacy installs migrate their flat `name` onto the whale girl.
116
- - **Multi-session semantics**: the API and browser mount are host-global and expose no foreground-session identity. Concurrent sessions each keep their own projected state: the most recent meaningful event drives the sprite animation, while every active session reports its stage in its own bubble (the state view's sessions list, capped at 12 most-recent). Every session's completed turns are still rewarded independently; disposing a session removes its bubble, and disposing the display session falls back to the most recent remaining one.
123
+ - **Multi-session semantics**: the API and browser mount are host-global and expose no foreground-session identity. Concurrent sessions each keep their own projected state: the most recent meaningful event drives the sprite animation, while every active TOP-LEVEL session reports its stage in its own bubble (the state view's sessions list, capped at 12 most-recent). Subagent children are tracked for animation, rewards, and the single display bubble but render no bubble of their own, so N conversations never multiply into an N-plus-subagents stack. Every session's completed turns are still rewarded independently; disposing a session removes its bubble, and disposing the display session falls back to the most recent remaining one.
117
124
  - **Mount point**: `document.body` (global React root, always shown: no session / new session / mid-session — the old mount point `conversation.composer.dock` only rendered in an active session, hiding the pet in new sessions); the component uses `createPortal` internally to render the global floating layer.
118
- - **Rendering**: CSS sprite (background-position) per-frame animation; frame durations come from the served definition's tracks.
125
+ - **Rendering**: CSS sprite (background-position) per-frame animation; frame durations and optional scene sequences come from the served definition. The hover panel is anchored below the pet with a pointer bridge across the gap; when the viewport leaves no room below, it flips above the pet and is lifted clear of the status bubble stack so the two never overlap.
119
126
  - **Communication**: browser ↔ host over the same-origin `/api/pet/*` JSON endpoints (state/pets/interact/set-visible/set-config/set-name/set-pet); each pet's atlas loads from `/pet/<id>/<spritesheetPath>` — the plugin self-sufficiently provides its own API and assets (the same pattern as dsh-remote-web-ui's `/api/pair`).
120
127
 
121
128
  ## Install
@@ -149,7 +156,7 @@ The browser bundle rides the `window.__ModuleLoader__.load` contract; React/cord
149
156
 
150
157
  ## Sprites and animation-track calibration
151
158
 
152
- The built-in whale-girl atlas is generated by the hatch-pet pipeline as 9 states × 8 columns: `assets/whale/spritesheet.webp` (1536×1872, 8 columns × 9 rows of 192×208 cells) + `assets/whale/pet.json`. The frame count and rhythm of each row live in that manifest's `frames` and `tracks` fields — the whale girl carries its own slower healing durations, while pets without overrides follow the hatch-pet contract rhythm. Redoing artwork therefore only edits `assets/whale/pet.json` (row-order contract: 0 idle / 1 running-right / 2 running-left / 3 waving / 4 jumping / 5 failed / 6 waiting / 7 running / 8 review).
159
+ The built-in whale-girl atlas is generated by the hatch-pet pipeline as 9 states × 8 columns: `assets/whale/spritesheet.webp` (1536×1872, 8 columns × 9 rows of 192×208 cells) + `assets/whale/pet.json`. The frame count, rhythm, and scene rotation live in that manifest's `frames`, `tracks`, and `sequences` fields; pets without overrides follow the hatch-pet contract rhythm and canonical single-track scene mapping. Redoing artwork therefore only edits `assets/whale/pet.json` (row-order contract: 0 idle / 1 running-right / 2 running-left / 3 waving / 4 jumping / 5 failed / 6 waiting / 7 running / 8 review).
153
160
 
154
161
  ## License
155
162
 
package/README.zh.md CHANGED
@@ -15,16 +15,17 @@
15
15
  | 多宠物注册表 | 宿主扫描内置 `assets/`、hatch-pet 自定义宠物目录和组合配置条目;每只宠物 = manifest + 图集 |
16
16
  | 设置中选择宠物 | 插件设置卡片列出所有已注册宠物;切换即持久化,精灵立即更换 |
17
17
  | 每只宠物独立命名 | 在悬浮面板改名;每只宠物保存自己的名字(按宠物 id 存储,旧版平铺名字自动迁移) |
18
- | 状态动画 | 官方会话活动 → 9 态动画:`thinking running`、`tool → running-right`、`review → review`、`waiting → waiting`、`done → jumping`、`failed → failed` |
18
+ | 状态动画 | 官方会话活动 → manifest 定义的 9 态轨道序列;每条轨道播完自身完整时长后切换,整条序列循环 |
19
19
  | 摸头互动 | 点击宠物 → 气泡反馈 + 亲密度 +1(10s 冷却) |
20
20
  | 喂食 | 悬浮面板 喂食 → 消耗 1 条小鱼干 + 亲密度 +5(30s 冷却) |
21
21
  | 小鱼干经济 | 库存(上限 20):每工作 30 轮 +1,每 300 分钟(5 小时)+1 —— 获取难度为原来的 10 倍 |
22
22
  | 亲密度 | 每完成一轮 +1;9 级:幼鲸 → 伙伴 → 挚友 → 深海羁绊 → 心有灵犀 → 传说羁绊 → 神话羁绊 → 永恒之契 → 鲸生共渡(上限 999,999,999) |
23
23
  | 拖动 | 按住拖动宠物换位置;位置持久化 |
24
- | 隐藏/召唤 | 悬浮面板 隐藏;隐藏后出现 召唤{name} 按钮 |
25
- | 妙语库 | 内置默认妙语库(每类事件 10 句)+ 宠物 manifest 的 remarks 块自定义台词——社区 PR 可以给自家宠物配上专属妙语 |
26
- | 状态气泡 | 并行会话各自一个气泡,在宠物头顶堆叠(最多 12 个);瞬时互动反馈临时优先 |
27
- | 多会话活动 | 宠物是宿主全局的:最近一次有意义事件驱动精灵动画,同时每个活动会话用自己的气泡报告各自状态;每个会话完成的轮次都计入亲密度与小鱼干 |
24
+ | 隐藏/召唤 | 悬浮面板位于宠物下方(下方空间不足时上移到状态气泡之上)并提供 隐藏;隐藏后出现 召唤{name} 按钮 |
25
+ | 妙语库 | 内置默认妙语库(每类事件 10 句)+ 宠物自定义台词;成功文案按持久化成功次数轮换,冷却文案按持久化拒绝次数轮换 |
26
+ | 状态气泡 | 每个并行活动的顶层会话各自一个气泡,在宠物头顶堆叠(最多 12 个);子代理会话借由其发起会话体现,不占用独立气泡;点击气泡跳转到对应会话;瞬时互动反馈临时优先。气泡文案按场景准备了大量轮换词库(等待 / 思考 / 整理 / 完成 / 失败……),工具调用按工具族映射俏皮文案并带上真实参数(如 跑跑 npm test),同一场景持续数秒会自动换一种说法 |
27
+ | 碎碎念 | 模型流式输出期间,宠物会偶尔用专属的紫粉色悄悄话气泡说出内心独白——由模型输出里的关键词触发对应心境(报错、测试全绿、做计划、打胜仗……),输出量累积也会换来日常碎碎念;有冷却节制,数秒后自动消散 |
28
+ | 多会话活动 | 宠物是宿主全局的:最近一次有意义事件驱动精灵动画,同时每个活动的顶层会话用自己的气泡报告各自状态;每个会话(含子代理)完成的轮次都计入亲密度与小鱼干 |
28
29
 
29
30
  ## 宠物契约
30
31
 
@@ -38,10 +39,14 @@
38
39
  "spritesheetPath": "spritesheet.webp", // 图集,相对 manifest 所在目录
39
40
  "cell": { "width": 192, "height": 208 }, // 可选;默认 Codex 契约
40
41
  "columns": 8, // 可选;默认 8
42
+ "spriteVersionNumber": 1, // 可选;2 表示 11 行 v2 图集(9 行动画行 + 2 行视线跟随行)
41
43
  "frames": [6, 8, 8, 4, 5, 8, 6, 6, 6], // 可选的每行帧数
42
44
  "tracks": { // 可选的每轨节奏覆盖
43
45
  "idle": { "durations": [400, 400, 500, 400, 400, 500] }
44
46
  },
47
+ "sequences": { // 可选的每场景轨道序列(每条至少 5 项)
48
+ "thinking": ["running", "running-right", "running", "running-left", "waiting"]
49
+ },
45
50
  "remarks": { // 可选妙语(每个槽位一行或多行)
46
51
  "pet": "摸摸水獭的头~",
47
52
  "feed": ["小鱼干真香", "再来一条~"]
@@ -49,9 +54,10 @@
49
54
  }
50
55
  ```
51
56
 
52
- - 图集是 8 列 × 9 行网格(默认 192×208 单元格);行序固定:0 idle、1 running-right、2 running-left、3 waving、4 jumping、5 failed、6 waiting、7 running、8 review。未使用的格子保持全透明。
53
- - 可选 remarks 块覆盖宠物在 pet(摸头)/ petCooldown / feed(喂食)/ feedCooldown / noTreats(缺粮)事件上的气泡台词。每个槽位接受一句或一组台词(轮询循环);声明过的槽位只替换该槽位的内置默认池。社区贡献就是这样给自家宠物配上专属妙语的。
57
+ - 图集是 8 列 × 9 行网格(默认 192×208 单元格);行序固定:0 idle、1 running-right、2 running-left、3 waving、4 jumping、5 failed、6 waiting、7 running、8 review。未使用的格子保持全透明。v2(Codex)图集在 manifest 里声明 `"spriteVersionNumber": 2`,共 11 行——同样的 9 行动画行外加末尾 2 行视线跟随行;插件渲染这 9 行动画行、忽略视线行。
58
+ - 可选 remarks 块覆盖宠物在 pet(摸头)/ petCooldown / feed(喂食)/ feedCooldown / noTreats(缺粮)事件上的气泡台词。每个槽位接受一句或一组台词;声明过的槽位只替换该槽位的内置默认池。成功与冷却池使用对应的持久化成功或拒绝次数,noTreats 则独立轮询。社区贡献就是这样给自家宠物配上专属妙语的。
54
59
  - `frames` 记录每行用到的列数(缺省按 hatch-pet 契约表 `[6, 8, 8, 4, 5, 8, 6, 6, 6]`);`tracks` 按动画覆盖每帧时长(按该行帧数循环补足)、`loop` 与 `fallback`(默认:全部循环;`jumping` 与 `failed` 停在最后一帧后回到 `idle`)。
60
+ - `sequences` 可选地把活动场景(`idle` / `waiting` / `thinking` / `tool` / `review` / `done` / `failed`)映射到至少 5 条动画轨道。每项按 `tracks` 中的时长播完所有帧后进入下一项,整条序列循环;未声明的场景保持标准单轨播放。
55
61
 
56
62
  宠物的来源(后注册的来源在同 id 冲突时覆盖前者):
57
63
 
@@ -82,16 +88,17 @@ dsh-pet/
82
88
  | |-- registry.ts # 多宠物契约:manifest 扫描 + 归一化(内置 + 自定义宠物)
83
89
  | |-- service.ts # PetService:宠物选择 + 状态机 + 亲密度 + 配置
84
90
  | |-- state.ts # 宠物状态机:会话活动投影 → 9 态动画
85
- | |-- remarks.ts # 妙语库:内置默认池 + 每宠物覆盖 + 轮询选取
91
+ | |-- remarks.ts # 妙语库:内置默认池 + 每宠物覆盖 + 计数选取
86
92
  | |-- affinity.ts # 亲密度账本(纯函数 + 冷却)
87
93
  | |-- treats.ts # 小鱼干库存账本
88
- | |-- persist.ts # 持久化($DSH_HOME/pet.json:选择 + 每宠物名字,原子写入)
94
+ | |-- persist.ts # 持久化($DSH_HOME/pet.json:选择 + 名字 + 互动计数)
89
95
  | |-- routes.ts # /api/pet/* JSON API + /pet/<id>/* 静态资源路由
90
96
  | `-- client/ # 浏览器半区
91
97
  | |-- index.ts # 全局挂载(createRoot → body)+ 注册表拉取 + 轮询 + 接线
92
98
  | |-- PetDockEntry.tsx # 全局浮层入口(document.body,始终显示)
93
99
  | |-- PetSprite.tsx # 由定义驱动的浮层精灵(portal + rAF + 拖动)
94
100
  | |-- PetSettingsCard.tsx # 设置卡片:宠物选择器 + 显示布局
101
+ | |-- sequences.ts # 完整轨道场景序列计时
95
102
  | |-- spritesheet.ts # 图集几何辅助 + 轨道裁剪
96
103
  | `-- pet.module.css
97
104
  |-- assets/whale/ # 内置鲸鱼娘(pet.json + spritesheet.webp + 预览)
@@ -113,9 +120,9 @@ dsh-pet/
113
120
  - **状态来源**:宿主把官方 `turn/start`、`step/start`、`assistant/chunk`、`assistant/message`、`tool/call`、`tool/result`、`turn/end` 事件投影为 waiting/thinking/tool/review/done/failed 状态。可选兼容 `activity/status` 事件仍作为输入。
114
121
  - **注册表**:宿主把每份 manifest 归一化为完整渲染定义(几何、每行帧数、每轨时长),经 `/api/pet/pets` 下发;浏览器半区用该定义渲染任意条目,不携带任何宠物专属代码。
115
122
  - **选择与命名**:`petId` 存于设置命名空间;每只宠物的名字存于 `pet.json` 的 `names`,通过悬浮面板对当前宠物改名编辑。旧版安装的平铺 `name` 自动迁移到鲸鱼娘名下。
116
- - **多会话语义**:API 与浏览器挂载都是宿主全局的,不暴露前台会话身份。并行会话各自保留投影状态:最近一次有意义事件驱动精灵动画,同时每个活动会话在独立气泡里报告自己的阶段(state 视图的 sessions 列表,最多保留最近 12 个)。每个会话完成的轮次仍独立计奖;销毁会话移除它的气泡,销毁当前显示会话则回退到最近仍在活动的会话。
123
+ - **多会话语义**:API 与浏览器挂载都是宿主全局的,不暴露前台会话身份。并行会话各自保留投影状态:最近一次有意义事件驱动精灵动画,同时每个活动的顶层会话在独立气泡里报告自己的阶段(state 视图的 sessions 列表,最多保留最近 12 个)。子代理会话仍参与动画、计奖与单一显示气泡,但不占独立气泡位——N 个对话不会变成"N + 子代理数"的气泡堆。每个会话完成的轮次仍独立计奖;销毁会话移除它的气泡,销毁当前显示会话则回退到最近仍在活动的会话。
117
124
  - **挂载点**:`document.body`(全局 React 根,始终显示:无会话 / 新会话 / 会话中都可见——旧挂载点 `conversation.composer.dock` 只在活动会话里渲染,新会话里宠物消失);组件内部用 `createPortal` 渲染全局浮层。
118
- - **渲染**:CSS 精灵(background-position)逐帧动画;帧时长来自下发定义里的轨道表。
125
+ - **渲染**:CSS 精灵(background-position)逐帧动画;帧时长和可选场景序列来自下发定义。悬浮面板锚定在宠物下方,间隙由指针桥接覆盖;当视口下方空间不足时,面板翻转到宠物上方并抬升到状态气泡栈之上,两者互不遮挡。
119
126
  - **通信**:浏览器 ↔ 宿主走同源 `/api/pet/*` JSON 端点(state/pets/interact/set-visible/set-config/set-name/set-pet);每只宠物的图集从 `/pet/<id>/<spritesheetPath>` 加载——插件自给自足地提供自己的 API 与资源(与 dsh-remote-web-ui 的 `/api/pair` 同一模式)。
120
127
 
121
128
  ## 安装
@@ -149,7 +156,7 @@ pnpm typecheck # 仅类型检查
149
156
 
150
157
  ## 精灵图与动画轨道校准
151
158
 
152
- 内置鲸鱼娘图集由 hatch-pet 流水线生成,9 态 × 8 列:`assets/whale/spritesheet.webp`(1536×1872,8 列 × 9 行,192×208 单元格)+ `assets/whale/pet.json`。每行的帧数与节奏就写在该 manifest 的 `frames` 与 `tracks` 字段里——鲸鱼娘带着自己更慢的治愈系时长,未覆盖的宠物沿用 hatch-pet 契约节奏。重做美术因此只需修改 `assets/whale/pet.json`(行序契约:0 idle / 1 running-right / 2 running-left / 3 waving / 4 jumping / 5 failed / 6 waiting / 7 running / 8 review)。
159
+ 内置鲸鱼娘图集由 hatch-pet 流水线生成,9 态 × 8 列:`assets/whale/spritesheet.webp`(1536×1872,8 列 × 9 行,192×208 单元格)+ `assets/whale/pet.json`。每行的帧数、节奏与场景轮换写在该 manifest 的 `frames`、`tracks` 与 `sequences` 字段里;未覆盖的宠物沿用 hatch-pet 契约节奏和标准单轨场景映射。重做美术因此只需修改 `assets/whale/pet.json`(行序契约:0 idle / 1 running-right / 2 running-left / 3 waving / 4 jumping / 5 failed / 6 waiting / 7 running / 8 review)。
153
160
 
154
161
  ## 许可证
155
162
 
@@ -14,5 +14,14 @@
14
14
  "waiting": { "durations": [450, 450, 500, 450, 450, 500] },
15
15
  "running": { "durations": [250, 250, 250, 250, 250, 250] },
16
16
  "review": { "durations": [550, 550, 550, 550, 550, 550] }
17
+ },
18
+ "sequences": {
19
+ "idle": ["idle", "waving", "idle", "waiting", "idle", "idle"],
20
+ "waiting": ["waiting", "idle", "waving", "waiting", "idle", "waiting"],
21
+ "thinking": ["running", "running-right", "running", "running-left", "running", "waiting", "running"],
22
+ "tool": ["running-right", "running", "running-left", "running", "running-right", "running"],
23
+ "review": ["review", "waiting", "review", "running", "review", "idle"],
24
+ "done": ["jumping", "waving", "jumping", "waving", "jumping", "idle"],
25
+ "failed": ["failed", "waiting", "failed", "idle", "waiting", "failed"]
17
26
  }
18
27
  }