@linxin666/dsh-pet 0.4.8 → 0.4.9

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 (47) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +7 -2
  3. package/README.zh.md +7 -2
  4. package/contracts/voice-pack-v1.schema.json +27 -0
  5. package/lib/client.js +24 -13
  6. package/lib/client.js.map +1 -1
  7. package/lib/index.js +160 -28
  8. package/lib/types/affinity.d.ts +26 -3
  9. package/lib/types/affinity.d.ts.map +1 -1
  10. package/lib/types/affinity.js +27 -4
  11. package/lib/types/client/PetDockEntry.d.ts +5 -0
  12. package/lib/types/client/PetDockEntry.d.ts.map +1 -1
  13. package/lib/types/client/PetDockEntry.js +1 -1
  14. package/lib/types/client/PetSprite.d.ts +5 -0
  15. package/lib/types/client/PetSprite.d.ts.map +1 -1
  16. package/lib/types/client/PetSprite.js +20 -8
  17. package/lib/types/client/index.d.ts.map +1 -1
  18. package/lib/types/client/index.js +15 -1
  19. package/lib/types/index.d.ts +1 -1
  20. package/lib/types/index.d.ts.map +1 -1
  21. package/lib/types/ledger.d.ts +10 -1
  22. package/lib/types/ledger.d.ts.map +1 -1
  23. package/lib/types/ledger.js +11 -1
  24. package/lib/types/pair-access.d.ts.map +1 -1
  25. package/lib/types/pair-access.js +26 -3
  26. package/lib/types/service.d.ts +14 -12
  27. package/lib/types/service.d.ts.map +1 -1
  28. package/lib/types/service.js +22 -17
  29. package/lib/types/voice-pack.d.ts +20 -1
  30. package/lib/types/voice-pack.d.ts.map +1 -1
  31. package/lib/types/voice-pack.js +86 -3
  32. package/package.json +24 -24
  33. package/src/affinity.test.ts +42 -0
  34. package/src/affinity.ts +46 -3
  35. package/src/client/PetDockEntry.tsx +6 -0
  36. package/src/client/PetSprite.test.tsx +42 -0
  37. package/src/client/PetSprite.tsx +24 -8
  38. package/src/client/index.test.tsx +4 -0
  39. package/src/client/index.ts +15 -1
  40. package/src/index.ts +2 -0
  41. package/src/ledger.test.ts +19 -0
  42. package/src/ledger.ts +15 -1
  43. package/src/pair-access.ts +26 -3
  44. package/src/service.test.ts +61 -0
  45. package/src/service.ts +27 -18
  46. package/src/voice-pack.test.ts +112 -0
  47. package/src/voice-pack.ts +101 -3
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: 24fafbceed13d042a8f42c01637a7c879008b9de
6
- README.zh.md: eb5838637ea1f065ae1a2517f2dedc0afa0005db
5
+ README.md: a489faab0b64a6c5736bae422f9910c7057e77a3
6
+ README.zh.md: 523014fb7ce70fd4de4cd3bc0dae40a492aa165f
package/README.md CHANGED
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-pet?style=flat-square" alt="Version">
7
7
  &nbsp;
8
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
8
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.3-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
9
9
  &nbsp;
10
10
  <img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
11
11
  </p>
@@ -39,7 +39,7 @@ Re-engineered from desktop companion concepts into an official DSH cordis bundle
39
39
  | Status bubbles | Only one top-level session speaks by default — the session the GUI is currently on when it is reported, otherwise the most recently active one — and the rest collapse behind a +N badge on the main bubble instead of stacking a tall column; hover the bubble (or tap the badge, for touch) to fan every session's bubble out above it and click one to jump to its session; subagent sessions report through their spawning conversation and never occupy a bubble of their own; 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. The pet's own status bubbles can be silenced in Settings > Pet > Status bubbles, which leaves the row to a plugin driving its own bubble surface; announcements pushed through `pet.announce` keep rendering either way |
40
40
  | Inner whispers | 碎碎念: while a session streams, the pet occasionally speaks its inner voice through that session's own bubble — a fresh whisper takes over the bubble and marks it with 「」 quotes — sharing the same DeepSeek-blue glass as every status bubble, so stacked bubbles never clash — instead of stacking a second bubble — category lines woken by the SITUATION (thinking / writing / the running tool family) plus outcome lines woken only by structured results (test green from a passed test tool, error from a failed tool result, completion from a completed turn) — never from the model's words, so a discussion that merely mentions a keyword cannot wake a mood, and a whisper never quotes real content (no tool names, paths or model text); paced by cooldowns (9 s category, 5 s outcome) and an 8 s display TTL, the status copy returns after a few seconds |
41
41
  | 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 |
42
- | Voice packs and panel DIY | A per-pet voice.json plus the global $DSH_HOME/pets/.voice.json override replace every bubble word and the hover panel (button labels, stat formats, button visibility); merge precedence per-pet > global > built-in, broken packs warn and never reject a pet |
42
+ | Voice packs and panel DIY | A per-pet voice.json plus the global $DSH_HOME/pets/.voice.json override replace every bubble word and the hover panel (button labels, stat formats, button visibility, affinity rank names); merge precedence per-pet > global > built-in, broken packs warn and never reject a pet |
43
43
  | Plugin panel actions | A sibling plugin registers its own action into the hover panel's action row through the in-process pet service (`ctx.pet.registerPanelAction({ id, label, onSelect })`); the pet renders the button and dispatches the click back to the plugin's own callback, and the action goes away with the registration |
44
44
 
45
45
  ## Pet contract
@@ -128,6 +128,10 @@ Every word in the thought bubble (status / tool / whisper copy) and the hover pa
128
128
  "panel": { // hover panel; unset slots keep the plugin i18n copy
129
129
  "labels": { "feed": "Treat", "hide": "Dive", "rename": "Rename me", "confirm": "Sure" },
130
130
  "stats": { "rank": "Affinity {rank}", "treats": "Treats x{n}", "points": "{points} pts" },
131
+ "ranks": [ // display-only affinity ladder; first min must be 0
132
+ { "min": 0, "name": "小煤球", "nameEn": "Little Coal Ball" },
133
+ { "min": 25, "name": "火星伙伴", "nameEn": "Martian Buddy" }
134
+ ],
131
135
  "actions": ["feed", "rename", "hide"] // subset in canonical order; absent = all; [] = stats only
132
136
  }
133
137
  }
@@ -135,6 +139,7 @@ Every word in the thought bubble (status / tool / whisper copy) and the hover pa
135
139
 
136
140
  - Merge precedence (per slot): the pet voice.json > the global .voice.json > built-in copy. status/tools/whispers merge per key, panel merges per slot; any slot a layer misses falls through.
137
141
  - Placeholder whitelist: tools accept {tool} / {hint}; toolRemaining accepts {n}; panel.stats accept {rank} / {n} / {points}; status, whisper and panel-label lines accept no placeholders (lines carrying one are dropped with a warning).
142
+ - Rank ladder (panel.ranks): replaces the built-in whale tier names for that pet and is display-only — points, turn rewards, cooldowns and the persisted ledger are unchanged. It must be an array of 1-16 entries, start at min 0, sort ascending with unique min values, and use names of 1-24 characters. name is the default; nameEn is shown when the UI locale is English (falling back to name when omitted). An invalid ladder is dropped whole with a warning and the built-in names stay. panel.stats {rank} receives the pet's effective name.
138
143
  - Caps (warn-and-drop): at most 64 lines per pool and 160 characters per line; panel labels 40 and stats 80 characters.
139
144
  - A broken pack never breaks the pet: voice.json that is not valid JSON or whose root is not an object is ignored with a warning; every other issue drops its slot only. node scripts/dsh-pet validate <dir> fails installs on structure errors and lists content issues as warnings.
140
145
  - Semantics: an empty status/tools pool falls back to the built-in copy (a scene line always renders); an explicit empty whisper pool mutes that channel; an empty panel actions array hides all three buttons; uncovered buttons and stats keep the plugin bilingual dictionary. Legacy whispers.generic / whispers.rules fields are no longer supported and are ignored with a warning.
package/README.zh.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/npm/v/@linxin666/dsh-client-ui-pet?style=flat-square" alt="Version">
7
7
  &nbsp;
8
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.2-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
8
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.3-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
9
9
  &nbsp;
10
10
  <img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
11
11
  </p>
@@ -104,7 +104,7 @@ node scripts/dsh-pet install <dir> --force # 覆盖同名已安装宠物
104
104
 
105
105
  ## 语音包与面板定制(voice.json,宠物中心 M4,#677)
106
106
 
107
- 气泡里的状态/工具/碎碎念文案与悬浮面板的按钮/统计文案,都可以被一只宠物(或你本人)整体替换——宠物不再只能换图,还能换「话」与「面板」。载体是宠物目录内的可选 voice.json(随宠物分发),以及全局覆盖文件 $DSH_HOME/pets/.voice.json(不改宠物目录即可换词)。
107
+ 气泡里的状态/工具/碎碎念文案与悬浮面板的按钮/统计/等级名,都可以被一只宠物(或你本人)整体替换——宠物不再只能换图,还能换「话」与「面板」。载体是宠物目录内的可选 voice.json(随宠物分发),以及全局覆盖文件 $DSH_HOME/pets/.voice.json(不改宠物目录即可换词)。
108
108
 
109
109
  ```jsonc
110
110
  {
@@ -128,6 +128,10 @@ node scripts/dsh-pet install <dir> --force # 覆盖同名已安装宠物
128
128
  "panel": { // 悬浮面板(每槽未声明时回落插件 i18n 文案)
129
129
  "labels": { "feed": "投喂", "hide": "藏起来", "rename": "起名字", "confirm": "好的" },
130
130
  "stats": { "rank": "好感 {rank}", "treats": "鱼干 ×{n}", "points": "{points} 分" },
131
+ "ranks": [ // 仅显示用的等级阶梯;首条 min 必须为 0
132
+ { "min": 0, "name": "小煤球", "nameEn": "Little Coal Ball" },
133
+ { "min": 25, "name": "火星伙伴", "nameEn": "Martian Buddy" }
134
+ ],
131
135
  "actions": ["feed", "rename", "hide"] // 子集(按规范顺序);省略 = 全部;[] = 只显示统计行
132
136
  }
133
137
  }
@@ -135,6 +139,7 @@ node scripts/dsh-pet install <dir> --force # 覆盖同名已安装宠物
135
139
 
136
140
  - 合并优先级(逐槽):宠物自带 voice.json > 全局 .voice.json > 内置文案。status/tools/whispers 逐键合并、panel 逐槽合并,任何层缺失的槽位回落下一层。
137
141
  - 占位符白名单:tools 允许 {tool} / {hint};toolRemaining 允许 {n};panel.stats 允许 {rank} / {n} / {points};status、碎碎念与面板标签不允许任何占位符(含非法占位符的行被警告丢弃)。
142
+ - 等级阶梯(panel.ranks):替换该宠物内置的鲸鱼等级名,仅影响显示——点数、每轮奖励、冷却与持久化账本都不变。必须是 1-16 条的数组,首条 min 为 0,min 严格递增且唯一,名字 1-24 字符。name 为默认名字;nameEn 在 UI 语言为英文时显示(省略则两种语言都用 name)。非法阶梯整体丢弃并警告,沿用内置名字。panel.stats 的 {rank} 收到宠物当前等级名。
138
143
  - 上限(warn-and-drop):每池 64 行以内、每行 160 字符以内;面板标签 40 以内、统计 80 字符以内。
139
144
  - 坏包不影响宠物:voice.json 不是合法 JSON 或根不是对象 → 警告并整体忽略;其余问题逐槽警告丢弃。node scripts/dsh-pet validate <dir> 会把结构错误判为安装失败、内容问题列为警告。
140
145
  - 语义细节:status/tools 的空池回落内置文案(场景行始终有话说);whispers 的显式空数组是静音(关掉该通道);面板 actions 为空数组 = 三个按钮全部隐藏;未覆盖的按钮/统计继续使用插件双语字典。旧的 whispers.generic / whispers.rules 字段已不再支持,会被忽略并给出警告。
@@ -204,6 +204,33 @@
204
204
  ]
205
205
  },
206
206
  "description": "Subset of actions to render in canonical order; absent = all three, [] = none."
207
+ },
208
+ "ranks": {
209
+ "type": "array",
210
+ "minItems": 1,
211
+ "maxItems": 16,
212
+ "description": "Display-only affinity ladder replacing the built-in tier names for this pet. Points, rewards, cooldowns and the persisted ledger are unchanged. The first entry must be min 0; min values are unique and ascending; each name is 1-24 characters. An invalid ladder is dropped whole with a warning and the built-in names stay.",
213
+ "items": {
214
+ "type": "object",
215
+ "additionalProperties": false,
216
+ "required": ["min", "name"],
217
+ "properties": {
218
+ "min": {
219
+ "type": "integer",
220
+ "minimum": 0
221
+ },
222
+ "name": {
223
+ "type": "string",
224
+ "minLength": 1,
225
+ "maxLength": 24
226
+ },
227
+ "nameEn": {
228
+ "type": "string",
229
+ "minLength": 1,
230
+ "maxLength": 24
231
+ }
232
+ }
233
+ }
207
234
  }
208
235
  }
209
236
  },
package/lib/client.js CHANGED
@@ -555,11 +555,20 @@ window.__ModuleLoader__.load({
555
555
  const sequences = definition.sequences;
556
556
  const panel = definition.panel;
557
557
  const panelLabel = (slot, i18n) => panel?.labels?.[slot] ?? i18n;
558
+ const englishUi = (props.lang ?? (typeof document === "undefined" ? "zh" : document.documentElement.lang)).toLowerCase().startsWith("en");
559
+ const rankNameOf = () => {
560
+ const rawRank = snapshot?.affinity.rank ?? "?";
561
+ const rankEn = snapshot?.affinity.rankEn;
562
+ if (englishUi && rankEn !== void 0) return rankEn;
563
+ const rankKey = `pet.rank.name.${rawRank}`;
564
+ const localized = props.t(rankKey);
565
+ return localized !== rankKey ? localized : rawRank;
566
+ };
558
567
  const panelStat = (slot, i18nKey, values) => {
559
568
  const format = panel?.stats?.[slot] ?? props.t(i18nKey, values);
560
569
  if (panel?.stats?.[slot] === void 0) return format;
561
570
  const all = {
562
- rank: snapshot?.affinity.rank ?? "?",
571
+ rank: values.rank !== void 0 ? values.rank : rankNameOf(),
563
572
  n: snapshot?.treats.stocked ?? 0,
564
573
  points: snapshot?.affinity.points ?? 0
565
574
  };
@@ -1058,12 +1067,7 @@ window.__ModuleLoader__.load({
1058
1067
  children: displayName
1059
1068
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1060
1069
  className: pet_module_css_default.statRank,
1061
- children: (() => {
1062
- const rawRank = snapshot?.affinity.rank ?? "?";
1063
- const rankKey = `pet.rank.name.${rawRank}`;
1064
- const localized = props.t(rankKey);
1065
- return panelStat("rank", "pet.rank", { rank: localized !== rankKey ? localized : rawRank });
1066
- })()
1070
+ children: panelStat("rank", "pet.rank", { rank: rankNameOf() })
1067
1071
  })]
1068
1072
  }),
1069
1073
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -2075,6 +2079,7 @@ window.__ModuleLoader__.load({
2075
2079
  portalTarget: props.portalTarget,
2076
2080
  dragDisabled: snapshot.gameplay?.mode === "work",
2077
2081
  ...aux === null ? {} : { bus: aux.bus },
2082
+ lang: props.lang,
2078
2083
  ...gameplay === void 0 || aux === null ? {} : {
2079
2084
  onGameplayTap: (fx, fy) => aux.bus.tap?.(fx, fy),
2080
2085
  onGameplayMenu: () => aux.bus.openCard?.(),
@@ -4301,7 +4306,7 @@ window.__ModuleLoader__.load({
4301
4306
  /** The building package's version, when the bundle carries it. */
4302
4307
  function bakedVersion() {
4303
4308
  try {
4304
- return "0.4.8";
4309
+ return "0.4.9";
4305
4310
  } catch {
4306
4311
  return;
4307
4312
  }
@@ -4794,17 +4799,23 @@ window.__ModuleLoader__.load({
4794
4799
  container.dataset.dshPlugin = "pet";
4795
4800
  document.body.appendChild(container);
4796
4801
  const petRoot = (0, react_dom_client.createRoot)(container);
4797
- petRoot.render((0, react.createElement)(PetDockEntry, {
4798
- ...injected(),
4799
- t: ctx.locale.bind("pet"),
4800
- portalTarget: container
4801
- }));
4802
+ const renderPet = () => {
4803
+ petRoot.render((0, react.createElement)(PetDockEntry, {
4804
+ ...injected(),
4805
+ t: ctx.locale.bind("pet"),
4806
+ lang: ctx.locale.getLocale().active,
4807
+ portalTarget: container
4808
+ }));
4809
+ };
4810
+ renderPet();
4811
+ const unsubscribeLocale = ctx.locale.subscribe(renderPet);
4802
4812
  let uiGone = false;
4803
4813
  disposeUi = () => {
4804
4814
  if (uiGone) return;
4805
4815
  uiGone = true;
4806
4816
  clearUiTeardown?.();
4807
4817
  clearUiTeardown = void 0;
4818
+ unsubscribeLocale();
4808
4819
  petRoot.unmount();
4809
4820
  container.remove();
4810
4821
  disposePoll();