dsh-task-mascot 1.0.1 → 2.0.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 (82) hide show
  1. package/README.md +7 -3
  2. package/assets/packs/dafeiyu/busy.png +0 -0
  3. package/assets/packs/dafeiyu/busy.webm +0 -0
  4. package/assets/packs/dafeiyu/busy.webp +0 -0
  5. package/assets/packs/dafeiyu/cheer.png +0 -0
  6. package/assets/packs/dafeiyu/cheer.webm +0 -0
  7. package/assets/packs/dafeiyu/cheer.webp +0 -0
  8. package/assets/packs/dafeiyu/cmd_b.png +0 -0
  9. package/assets/packs/dafeiyu/cmd_b.webm +0 -0
  10. package/assets/packs/dafeiyu/cmd_b.webp +0 -0
  11. package/assets/packs/dafeiyu/coding_b.png +0 -0
  12. package/assets/packs/dafeiyu/coding_b.webm +0 -0
  13. package/assets/packs/dafeiyu/coding_b.webp +0 -0
  14. package/assets/packs/dafeiyu/create.png +0 -0
  15. package/assets/packs/dafeiyu/create.webm +0 -0
  16. package/assets/packs/dafeiyu/create.webp +0 -0
  17. package/assets/packs/dafeiyu/delete.png +0 -0
  18. package/assets/packs/dafeiyu/delete.webm +0 -0
  19. package/assets/packs/dafeiyu/delete.webp +0 -0
  20. package/assets/packs/dafeiyu/denied.png +0 -0
  21. package/assets/packs/dafeiyu/denied.webm +0 -0
  22. package/assets/packs/dafeiyu/denied.webp +0 -0
  23. package/assets/packs/dafeiyu/diff.png +0 -0
  24. package/assets/packs/dafeiyu/diff.webm +0 -0
  25. package/assets/packs/dafeiyu/diff.webp +0 -0
  26. package/assets/packs/dafeiyu/download.png +0 -0
  27. package/assets/packs/dafeiyu/download.webm +0 -0
  28. package/assets/packs/dafeiyu/download.webp +0 -0
  29. package/assets/packs/dafeiyu/editing_b.png +0 -0
  30. package/assets/packs/dafeiyu/editing_b.webm +0 -0
  31. package/assets/packs/dafeiyu/editing_b.webp +0 -0
  32. package/assets/packs/dafeiyu/git.png +0 -0
  33. package/assets/packs/dafeiyu/git.webm +0 -0
  34. package/assets/packs/dafeiyu/git.webp +0 -0
  35. package/assets/packs/dafeiyu/install.png +0 -0
  36. package/assets/packs/dafeiyu/install.webm +0 -0
  37. package/assets/packs/dafeiyu/install.webp +0 -0
  38. package/assets/packs/dafeiyu/interrupted.png +0 -0
  39. package/assets/packs/dafeiyu/interrupted.webm +0 -0
  40. package/assets/packs/dafeiyu/interrupted.webp +0 -0
  41. package/assets/packs/dafeiyu/manifest.json +183 -0
  42. package/assets/packs/dafeiyu/mcp.png +0 -0
  43. package/assets/packs/dafeiyu/mcp.webm +0 -0
  44. package/assets/packs/dafeiyu/mcp.webp +0 -0
  45. package/assets/packs/dafeiyu/media.png +0 -0
  46. package/assets/packs/dafeiyu/media.webm +0 -0
  47. package/assets/packs/dafeiyu/media.webp +0 -0
  48. package/assets/packs/dafeiyu/memory.png +0 -0
  49. package/assets/packs/dafeiyu/memory.webm +0 -0
  50. package/assets/packs/dafeiyu/memory.webp +0 -0
  51. package/assets/packs/dafeiyu/reading_b.png +0 -0
  52. package/assets/packs/dafeiyu/reading_b.webm +0 -0
  53. package/assets/packs/dafeiyu/reading_b.webp +0 -0
  54. package/assets/packs/dafeiyu/retry.png +0 -0
  55. package/assets/packs/dafeiyu/retry.webm +0 -0
  56. package/assets/packs/dafeiyu/retry.webp +0 -0
  57. package/assets/packs/dafeiyu/search_b.png +0 -0
  58. package/assets/packs/dafeiyu/search_b.webm +0 -0
  59. package/assets/packs/dafeiyu/search_b.webp +0 -0
  60. package/assets/packs/dafeiyu/subtask.png +0 -0
  61. package/assets/packs/dafeiyu/subtask.webm +0 -0
  62. package/assets/packs/dafeiyu/subtask.webp +0 -0
  63. package/assets/packs/dafeiyu/sweat.png +0 -0
  64. package/assets/packs/dafeiyu/sweat.webm +0 -0
  65. package/assets/packs/dafeiyu/sweat.webp +0 -0
  66. package/assets/packs/dafeiyu/test.png +0 -0
  67. package/assets/packs/dafeiyu/test.webm +0 -0
  68. package/assets/packs/dafeiyu/test.webp +0 -0
  69. package/assets/packs/dafeiyu/thinking_b.png +0 -0
  70. package/assets/packs/dafeiyu/thinking_b.webm +0 -0
  71. package/assets/packs/dafeiyu/thinking_b.webp +0 -0
  72. package/assets/packs/dafeiyu/tired.png +0 -0
  73. package/assets/packs/dafeiyu/tired.webm +0 -0
  74. package/assets/packs/dafeiyu/tired.webp +0 -0
  75. package/assets/packs/dafeiyu/web.png +0 -0
  76. package/assets/packs/dafeiyu/web.webm +0 -0
  77. package/assets/packs/dafeiyu/web.webp +0 -0
  78. package/assets/packs/dafeiyu/worried.png +0 -0
  79. package/assets/packs/dafeiyu/worried.webm +0 -0
  80. package/assets/packs/dafeiyu/worried.webp +0 -0
  81. package/lib/client.js +159 -41
  82. package/package.json +1 -1
package/README.md CHANGED
@@ -24,11 +24,13 @@ dsh plugin --profile web add github:sherconan/dsh-task-mascot
24
24
  | 显示内容 | 一个动画 | 动作 + **工具参数**("正在改 src/app.js"、"运行 npm test"、"正在搜索 \"function\"") |
25
25
  | 步骤感 | 无 | **第 N 步**、本步耗时、总耗时、迷你时间线 |
26
26
  | 聊天里 | 无 | 对话流里的**内联步骤卡片**,每步 ✓ 成功 / ✗ 失败,本轮结束有总结 + 回放 |
27
- | 状态粒度 | 2–3 种 | 读文件 / 写代码 / 改代码 / 写文档 / 搜索 / 跑命令 / 做计划 / 派子代理 / 等你确认 / 完成 / 出错 … |
27
+ | 状态粒度 | 2–3 种 | 读文件 / 写代码 / 新建 / 改代码 / 对比 / 搜索 / 上网 / 跑命令(git·测试·装依赖·下载·删除)/ MCP / 做计划 / 派子代理 / 等你确认 / 完成 / 出错 … 共 37 种(v2) |
28
+ | 看懂循环 | 无 | **第 N 轮**、重试、连续失败会着急、连发工具会手忙脚乱、子任务完成、被拒绝 / 被中断(v2) |
29
+ | 时长 | 无 | 一步超过 20 s 冒汗、60 s 犯困,长任务结束欢呼,阈值可调(v2) |
28
30
  | 审批 | 会挡住按钮 | 显示"等你确认",并**自动避让**审批按钮和输入框 |
29
31
  | 角色 | 固定 | **可替换角色包**(自带 大肥鱼、Claude娘),丢个文件夹就能加 |
30
32
  | 映射 | 写死 | 设置里可编辑 **工具 → 动画** 映射规则(正则) |
31
- | 体积 | — | 两个角色包合计约 13 MB(VP9 透明 webm + Safari 用 WebP 兜底) |
33
+ | 体积 | — | 两个角色包合计约 18 MB(VP9 透明 webm + Safari 用 WebP 兜底) |
32
34
 
33
35
  其他细节:每步至少停留 600 ms 排队播放不丢步;流式参数只显示已闭合的值不闪烁;三种展示面(内联卡片 / 输入框上方 Dock 条 / 悬浮宠物)可任意组合;宠物可拖动、双击归位;可选提示音(默认关)。
34
36
 
@@ -37,6 +39,8 @@ dsh plugin --profile web add github:sherconan/dsh-task-mascot
37
39
 
38
40
  ## 工具 → 动画映射 / Tool → state mapping
39
41
 
42
+ > v2 新增的状态、bash 命令细分、轮次/重试/时长规则见 [docs/states-v2.md](docs/states-v2.md)。
43
+
40
44
  按顺序匹配,第一条命中生效(`tool`、`ext` 均为正则,`ext` 匹配目标文件扩展名)。在设置里可以编辑 JSON 覆盖。
41
45
  First match wins (`tool`/`ext` are regexes; `ext` = target file extension). Editable in Settings.
42
46
 
@@ -105,7 +109,7 @@ First match wins (`tool`/`ext` are regexes; `ext` = target file extension). Edit
105
109
 
106
110
  3. 可用状态:`idle thinking reading search coding editing writingdoc cmd data planning subagents tools summary waiting done error`。
107
111
  4. 编码:把带透明通道的母版放到 `masters/<pack>/`,运行 `npm run encode`(`scripts/encode-packs.sh`:384px 30fps VP9 yuva420p;WebP 256px 15fps)。
108
- 5. 重启 dsh,在设置里选择新角色。欢迎 PR 分享你的角色包(请写清授权)。
112
+ 5. 重启 dsh,在设置里选择新角色。完整教程见 [docs/make-a-pack.md](docs/make-a-pack.md)。欢迎 PR 分享你的角色包(请写清授权)。
109
113
 
110
114
  ## 隐私
111
115
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -77,6 +77,162 @@
77
77
  "poster": "error.png",
78
78
  "loop": false,
79
79
  "durationMs": 3000
80
+ },
81
+ "web": {
82
+ "webm": "web.webm",
83
+ "webp": "web.webp",
84
+ "poster": "web.png",
85
+ "loop": true
86
+ },
87
+ "download": {
88
+ "webm": "download.webm",
89
+ "webp": "download.webp",
90
+ "poster": "download.png",
91
+ "loop": true
92
+ },
93
+ "git": {
94
+ "webm": "git.webm",
95
+ "webp": "git.webp",
96
+ "poster": "git.png",
97
+ "loop": true
98
+ },
99
+ "test": {
100
+ "webm": "test.webm",
101
+ "webp": "test.webp",
102
+ "poster": "test.png",
103
+ "loop": true
104
+ },
105
+ "install": {
106
+ "webm": "install.webm",
107
+ "webp": "install.webp",
108
+ "poster": "install.png",
109
+ "loop": true
110
+ },
111
+ "create": {
112
+ "webm": "create.webm",
113
+ "webp": "create.webp",
114
+ "poster": "create.png",
115
+ "loop": true
116
+ },
117
+ "delete": {
118
+ "webm": "delete.webm",
119
+ "webp": "delete.webp",
120
+ "poster": "delete.png",
121
+ "loop": true
122
+ },
123
+ "mcp": {
124
+ "webm": "mcp.webm",
125
+ "webp": "mcp.webp",
126
+ "poster": "mcp.png",
127
+ "loop": true
128
+ },
129
+ "memory": {
130
+ "webm": "memory.webm",
131
+ "webp": "memory.webp",
132
+ "poster": "memory.png",
133
+ "loop": true
134
+ },
135
+ "media": {
136
+ "webm": "media.webm",
137
+ "webp": "media.webp",
138
+ "poster": "media.png",
139
+ "loop": true
140
+ },
141
+ "diff": {
142
+ "webm": "diff.webm",
143
+ "webp": "diff.webp",
144
+ "poster": "diff.png",
145
+ "loop": true
146
+ },
147
+ "retry": {
148
+ "webm": "retry.webm",
149
+ "webp": "retry.webp",
150
+ "poster": "retry.png",
151
+ "loop": true
152
+ },
153
+ "worried": {
154
+ "webm": "worried.webm",
155
+ "webp": "worried.webp",
156
+ "poster": "worried.png",
157
+ "loop": true
158
+ },
159
+ "busy": {
160
+ "webm": "busy.webm",
161
+ "webp": "busy.webp",
162
+ "poster": "busy.png",
163
+ "loop": true
164
+ },
165
+ "subtask": {
166
+ "webm": "subtask.webm",
167
+ "webp": "subtask.webp",
168
+ "poster": "subtask.png",
169
+ "loop": true
170
+ },
171
+ "denied": {
172
+ "webm": "denied.webm",
173
+ "webp": "denied.webp",
174
+ "poster": "denied.png",
175
+ "loop": true
176
+ },
177
+ "interrupted": {
178
+ "webm": "interrupted.webm",
179
+ "webp": "interrupted.webp",
180
+ "poster": "interrupted.png",
181
+ "loop": true
182
+ },
183
+ "sweat": {
184
+ "webm": "sweat.webm",
185
+ "webp": "sweat.webp",
186
+ "poster": "sweat.png",
187
+ "loop": true
188
+ },
189
+ "tired": {
190
+ "webm": "tired.webm",
191
+ "webp": "tired.webp",
192
+ "poster": "tired.png",
193
+ "loop": true
194
+ },
195
+ "cheer": {
196
+ "webm": "cheer.webm",
197
+ "webp": "cheer.webp",
198
+ "poster": "cheer.png",
199
+ "loop": true
200
+ },
201
+ "coding_b": {
202
+ "webm": "coding_b.webm",
203
+ "webp": "coding_b.webp",
204
+ "poster": "coding_b.png",
205
+ "loop": true
206
+ },
207
+ "reading_b": {
208
+ "webm": "reading_b.webm",
209
+ "webp": "reading_b.webp",
210
+ "poster": "reading_b.png",
211
+ "loop": true
212
+ },
213
+ "cmd_b": {
214
+ "webm": "cmd_b.webm",
215
+ "webp": "cmd_b.webp",
216
+ "poster": "cmd_b.png",
217
+ "loop": true
218
+ },
219
+ "search_b": {
220
+ "webm": "search_b.webm",
221
+ "webp": "search_b.webp",
222
+ "poster": "search_b.png",
223
+ "loop": true
224
+ },
225
+ "thinking_b": {
226
+ "webm": "thinking_b.webm",
227
+ "webp": "thinking_b.webp",
228
+ "poster": "thinking_b.png",
229
+ "loop": true
230
+ },
231
+ "editing_b": {
232
+ "webm": "editing_b.webm",
233
+ "webp": "editing_b.webp",
234
+ "poster": "editing_b.png",
235
+ "loop": true
80
236
  }
81
237
  },
82
238
  "fallback": {
@@ -102,5 +258,32 @@
102
258
  "*": [
103
259
  "thinking"
104
260
  ]
261
+ },
262
+ "version": 2,
263
+ "variants": {
264
+ "coding": [
265
+ "coding",
266
+ "coding_b"
267
+ ],
268
+ "reading": [
269
+ "reading",
270
+ "reading_b"
271
+ ],
272
+ "cmd": [
273
+ "cmd",
274
+ "cmd_b"
275
+ ],
276
+ "search": [
277
+ "search",
278
+ "search_b"
279
+ ],
280
+ "thinking": [
281
+ "thinking",
282
+ "thinking_b"
283
+ ],
284
+ "editing": [
285
+ "editing",
286
+ "editing_b"
287
+ ]
105
288
  }
106
289
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/lib/client.js CHANGED
@@ -12,12 +12,23 @@ window.__ModuleLoader__.load({
12
12
  // ---------------------------------------------------------------- mapping
13
13
  /** Default tool → state rules, first match wins. `ext` (optional) matches the target file extension. */
14
14
  const DEFAULT_RULES = [
15
+ // v2: shell commands are sub-classified by the command text (`cmd` regex, browser-side only)
16
+ { tool: '^(bash|pwsh)$', cmd: '^\\s*(git\\s+diff|diff|cmp)\\b', state: 'diff' },
17
+ { tool: '^(bash|pwsh)$', cmd: '^\\s*(git|gh)\\b', state: 'git' },
18
+ { tool: '^(bash|pwsh)$', cmd: '(^|[;&|]\\s*)((npm|pnpm|yarn|bun)\\s+(run\\s+)?test|npx\\s+(jest|vitest|playwright)|pytest|jest|vitest|go\\s+test|cargo\\s+test|node\\s+--test|make\\s+test|mvn\\s+test)\\b', state: 'test' },
19
+ { tool: '^(bash|pwsh)$', cmd: '(^|[;&|]\\s*)(sudo\\s+)?((npm|pnpm|yarn|bun)\\s+(i|install|add|ci)|pip3?\\s+install|uv\\s+(add|pip\\s+install|sync)|apt(-get)?\\s+install|brew\\s+install|cargo\\s+(add|install)|go\\s+get|gem\\s+install|Install-Module)\\b', state: 'install' },
20
+ { tool: '^(bash|pwsh)$', cmd: '(^|[;&|]\\s*)(curl|wget|aria2c|Invoke-WebRequest|iwr|scp|rsync)\\b', state: 'download' },
21
+ { tool: '^(bash|pwsh)$', cmd: '(^|[;&|]\\s*)(sudo\\s+)?(rm|rmdir|unlink|del|Remove-Item|shred)\\b', state: 'delete' },
15
22
  { tool: '^(write|edit|str_replace_editor)$', ext: '^(md|mdx|txt|rst|adoc|docx?|tex)$', state: 'writingdoc' },
16
23
  { tool: '^write$', state: 'coding' },
17
24
  { tool: '^(edit|str_replace_editor)$', state: 'editing' },
18
- { tool: '^(read|read_image|read_mcp_resource|lsp)$', state: 'reading' },
19
- { tool: '^(glob|grep|session_.*)$', state: 'search' },
20
- { tool: '^(web_search|web_fetch|stagehand_.*)$', state: 'search' },
25
+ { tool: '^read_image$', state: 'media' },
26
+ { tool: '^(mcp__.*|mcp[_-].*|list_mcp_resources|read_mcp_resource)$', state: 'mcp' },
27
+ { tool: '^(read|lsp|cordis_inspect_.*)$', state: 'reading' },
28
+ { tool: '^session_.*$', state: 'memory' },
29
+ { tool: '^(glob|grep)$', state: 'search' },
30
+ { tool: '^(web_search|web_fetch|stagehand_.*)$', state: 'web' },
31
+ { tool: '^(create_worktree|load_workspace_dependencies)$', state: 'git' },
21
32
  { tool: '^(bash|pwsh|terminal_.*|job_.*)$', state: 'cmd' },
22
33
  { tool: '^(run_code|workflow)$', state: 'data' },
23
34
  { tool: '^(todo_write|exit_plan_mode|create_goal|get_goal|update_goal|schedule_.*)$', state: 'planning' },
@@ -27,26 +38,47 @@ window.__ModuleLoader__.load({
27
38
  { tool: '^(skill|plugin_manager|plugin_market|working_directory)$', state: 'tools' },
28
39
  { tool: '.*', state: 'tools' },
29
40
  ];
30
- const ALL_STATES = ['idle', 'thinking', 'reading', 'search', 'coding', 'editing', 'writingdoc', 'cmd', 'data', 'planning', 'subagents', 'tools', 'summary', 'waiting', 'done', 'error'];
41
+ const ALL_STATES = ['idle', 'thinking', 'reading', 'search', 'coding', 'editing', 'writingdoc', 'cmd', 'data', 'planning', 'subagents', 'tools', 'summary', 'waiting', 'done', 'error',
42
+ // v2
43
+ 'web', 'download', 'git', 'test', 'install', 'create', 'delete', 'mcp', 'memory', 'media', 'diff',
44
+ 'retry', 'worried', 'busy', 'subtask', 'denied', 'interrupted', 'sweat', 'tired', 'cheer'];
31
45
 
32
46
  function compileRules(rules) {
33
47
  const out = [];
34
48
  for (const r of rules || []) {
35
- try { out.push({ tool: new RegExp(r.tool || '.*', 'i'), ext: r.ext ? new RegExp(r.ext, 'i') : null, state: String(r.state || 'tools') }); } catch (_e) { /* skip bad regex */ }
49
+ try { out.push({ tool: new RegExp(r.tool || '.*', 'i'), ext: r.ext ? new RegExp(r.ext, 'i') : null, cmd: r.cmd ? new RegExp(r.cmd, 'i') : null, state: String(r.state || 'tools') }); } catch (_e) { /* skip bad regex */ }
36
50
  }
37
51
  return out;
38
52
  }
39
53
  function stateForTool(tool, args, compiled) {
40
54
  const ext = args && typeof args === 'object' ? args.ext : undefined;
55
+ const cmd = args && typeof args === 'object' && typeof args.command === 'string' ? args.command : undefined;
41
56
  for (const r of compiled) {
42
57
  if (!r.tool.test(tool || '')) continue;
43
58
  if (r.ext && !(ext && r.ext.test(ext))) continue;
59
+ if (r.cmd && !(cmd && r.cmd.test(cmd))) continue;
44
60
  return r.state;
45
61
  }
46
62
  return 'tools';
47
63
  }
48
64
  /** Resolve a logical state to a state the pack actually has, via manifest fallbacks then a global chain. */
49
- const GLOBAL_FALLBACK = { writingdoc: ['editing', 'coding'], data: ['cmd', 'thinking'], tools: ['cmd', 'thinking'], subagents: ['planning', 'tools'], summary: ['done', 'thinking'], idle: ['waiting', 'thinking'], generating: ['thinking'] };
65
+ const GLOBAL_FALLBACK = { writingdoc: ['editing', 'coding'], data: ['cmd', 'thinking'], tools: ['cmd', 'thinking'], subagents: ['planning', 'tools'], summary: ['done', 'thinking'], idle: ['waiting', 'thinking'], generating: ['thinking'],
66
+ // v2 states degrade gracefully on packs that only ship the v1 set (e.g. claude)
67
+ web: ['search'], download: ['web', 'cmd'], git: ['cmd'], test: ['cmd'], install: ['download', 'cmd'], create: ['coding'], delete: ['cmd'], mcp: ['tools', 'cmd'], memory: ['search', 'reading'], media: ['reading'], diff: ['editing', 'reading'],
68
+ retry: ['error', 'thinking'], worried: ['error'], busy: ['cmd', 'thinking'], subtask: ['done'], denied: ['error'], interrupted: ['waiting', 'idle'], sweat: ['thinking'], tired: ['waiting', 'thinking'], cheer: ['done'] };
69
+ /**
70
+ * A/B variants: manifest.variants = { coding: ['coding','coding_b'], ... }. `mode` 'alternate' picks by
71
+ * seed parity (step number), 'random' hashes the seed, 'off' keeps the base state. Deterministic per seed so
72
+ * a step never flickers between variants across re-renders.
73
+ */
74
+ function pickVariant(state, manifest, seed, mode) {
75
+ const list = manifest && manifest.variants && manifest.variants[state];
76
+ if (!state || !Array.isArray(list) || list.length < 2 || mode === 'off') return state;
77
+ const ok = list.filter((s) => manifest.states && manifest.states[s]); if (!ok.length) return state;
78
+ let i = seed | 0;
79
+ if (mode === 'random') { let x = (i + 0x9e3779b9) | 0; x = Math.imul(x ^ (x >>> 16), 0x45d9f3b); x = Math.imul(x ^ (x >>> 16), 0x45d9f3b); i = (x ^ (x >>> 16)) >>> 0; }
80
+ return ok[Math.abs(i) % ok.length];
81
+ }
50
82
  function resolveState(state, manifest) {
51
83
  const has = (s) => !!(manifest && manifest.states && manifest.states[s]);
52
84
  const seen = new Set(); const queue = [state];
@@ -155,7 +187,12 @@ window.__ModuleLoader__.load({
155
187
  case 'glob': return '正在查找文件 ' + clip(a.pattern, 36);
156
188
  case 'web_search': return '正在联网搜索 "' + clip((a.queries && a.queries[0]) || a.query, 30) + '"';
157
189
  case 'web_fetch': return '正在抓取 ' + clip(a.url, 40);
158
- case 'bash': case 'pwsh': return '运行 ' + clip(a.command, 44);
190
+ case 'bash': case 'pwsh': return a.command ? '运行 ' + clip(a.command, 44) : '准备运行命令…';
191
+ case 'session_search': case 'session_read': case 'session_list': return '翻看历史会话' + (a.query ? ' "' + clip(a.query, 24) + '"' : '');
192
+ case 'list_mcp_resources': return '列出 MCP 资源';
193
+ case 'read_mcp_resource': return '读取 MCP 资源 ' + clip(a.uri || a.server, 30);
194
+ case 'create_worktree': return '新建 Git worktree';
195
+ case 'wait_agent': return '等子代理回来';
159
196
  case 'todo_write': return '正在更新待办' + (Array.isArray(a.todos) ? '(' + a.todos.length + ' 项)' : '');
160
197
  case 'subagent': case 'spawn_teammate': return '派出子代理:' + clip(a.description || a.prompt, 36);
161
198
  case 'send_message': return '给子代理发消息';
@@ -166,10 +203,18 @@ window.__ModuleLoader__.load({
166
203
  default: return '调用工具 ' + t + (f ? ' · ' + f : '');
167
204
  }
168
205
  }
169
- function resultBrief(message) {
206
+ // DSH reports a non-zero shell exit as a normal (isError:false) result ending in "[exit code: N]". Treat it as a failure,
207
+ // except for commands whose non-zero exit is an answer rather than an error (diff/cmp/grep/test/[).
208
+ function shellFailed(st, m) {
209
+ if (!/^(bash|pwsh|powershell|shell)$/.test(st.tool)) return false;
210
+ const c = m.content; const txt = typeof c === 'string' ? c : Array.isArray(c) ? c.map((x) => (x && x.text) || '').join('\n') : '';
211
+ const mm = /\[exit code: (\d+)\]\s*$/.exec(txt); if (!mm || mm[1] === '0') return false;
212
+ return !/^\s*(git\s+diff|diff|cmp|grep|rg|test|\[)\b/.test(String(st.args.command || ''));
213
+ }
214
+ function resultBrief(message) {
170
215
  const m = message || {}; const c = m.content;
171
216
  const text = typeof c === 'string' ? c : Array.isArray(c) ? c.map((x) => (x && x.text) || '').join('\n') : '';
172
- const line = text.split('\n').map((x) => x.replace(/<\/?[a-z_]+>/g, '').trim()).find((x) => x) || '';
217
+ const line = text.split('\n').map((x) => x.replace(/<\/?[a-z_]+>/g, '').trim()).find((x) => x && !/^\[(stderr|stdout)\]$/.test(x)) || '';
173
218
  return clip(line.replace(/^Error:\s*/i, ''), 70);
174
219
  }
175
220
  let frameSeq = 0;
@@ -179,9 +224,13 @@ window.__ModuleLoader__.load({
179
224
  * for at least `dwellMs`; history entries rebuild state silently.
180
225
  */
181
226
  function createTracker(opts) {
182
- const o = Object.assign({ dwellMs: 600, now: () => Date.now(), schedule: (fn, ms) => setTimeout(fn, ms), rules: null }, opts || {});
227
+ // v2 knobs: stepSlowMs = one step/think this long -> sweat (x3 -> tired); loopLongMs = whole turn this long ->
228
+ // tired while thinking, cheer on success; busyN = this many tool calls without thinking in between -> busy;
229
+ // worriedN = this many consecutive failures -> worried.
230
+ const o = Object.assign({ dwellMs: 600, now: () => Date.now(), schedule: (fn, ms) => setTimeout(fn, ms), rules: null, stepSlowMs: 20000, loopLongMs: 120000, busyN: 5, worriedN: 2 }, opts || {});
183
231
  let compiled = compileRules(o.rules || DEFAULT_RULES);
184
- const S = { turn: 0, active: false, turnStart: 0, turnEnd: 0, steps: [], byCall: new Map(), queue: [], cur: null, curShownAt: 0, version: 0, turns: new Map(), lastSeq: -1, lastLiveAt: 0, outcome: null, subagents: 0 };
232
+ const S = { turn: 0, active: false, turnStart: 0, turnEnd: 0, steps: [], byCall: new Map(), queue: [], cur: null, curShownAt: 0, version: 0, turns: new Map(), lastSeq: -1, lastLiveAt: 0, outcome: null, subagents: 0,
233
+ round: 0, stepField: false, afterResult: false, burst: 0, failStreak: 0, retries: 0, seenPaths: new Set(), lastFail: null, todoDone: 0 };
185
234
  const listeners = new Set(); let timer = null;
186
235
  const emit = () => { S.version++; listeners.forEach((f) => { try { f(); } catch (_e) { /* ignore */ } }); };
187
236
  function show(fr) { S.cur = fr; S.curShownAt = o.now(); fr.shownAt = S.curShownAt; }
@@ -190,8 +239,13 @@ window.__ModuleLoader__.load({
190
239
  const wait = Math.max(0, o.dwellMs - (o.now() - S.curShownAt));
191
240
  timer = o.schedule(() => { timer = null; if (S.queue.length) { show(S.queue.shift()); emit(); } arm(); }, wait);
192
241
  }
242
+ /** Round = LLM step inside the loop. Prefer the explicit `step` field; else count "model spoke again after a tool result". */
243
+ function bumpRound(d) {
244
+ if (d && typeof d.step === 'number') { S.stepField = true; if (d.step > S.round) S.round = d.step; S.afterResult = false; return; }
245
+ if (!S.stepField && S.afterResult) { S.round++; S.afterResult = false; }
246
+ }
193
247
  function push(fr, ctx) {
194
- fr.id = ++frameSeq; fr.turn = S.turn; fr.eventTime = ctx.time; fr.recvAt = ctx.recvAt;
248
+ fr.id = ++frameSeq; fr.turn = S.turn; fr.round = S.round; fr.eventTime = ctx.time; fr.recvAt = ctx.recvAt;
195
249
  if (!ctx.live) { S.queue.length = 0; S.cur = fr; S.curShownAt = 0; return; }
196
250
  const last = S.queue[S.queue.length - 1] || S.cur;
197
251
  if (last && fr.kind === 'thinking' && last.kind === 'thinking' && last.turn === fr.turn) { last.text = fr.text; return; }
@@ -200,12 +254,25 @@ window.__ModuleLoader__.load({
200
254
  function stepFor(id, tool, ctx) {
201
255
  let st = id ? S.byCall.get(id) : null; let created = false;
202
256
  if (!st) {
203
- st = { n: S.steps.length + 1, callId: id, tool: tool || '', raw: '', args: {}, status: 'streaming', startAt: ctx.time, endAt: 0, result: '', text: '' };
257
+ st = { n: S.steps.length + 1, callId: id, tool: tool || '', raw: '', args: {}, status: 'streaming', startAt: ctx.time, recvAt: ctx.recvAt, endAt: 0, result: '', text: '' };
204
258
  S.steps.push(st); if (id) S.byCall.set(id, st); created = true;
205
259
  }
206
260
  return [st, created];
207
261
  }
208
- function finishStep(st) { st.state = stateForTool(st.tool, { ext: extOf(st.args.file_path || st.args.path) }, compiled); st.text = actionText(st.tool, st.args); }
262
+ function finishStep(st) {
263
+ const path = st.args.file_path || st.args.path;
264
+ let state = stateForTool(st.tool, { ext: extOf(path), command: st.args.command }, compiled);
265
+ // write to a path this session has never read/edited/written -> "create" (decided once, when the path is first known)
266
+ if (st.tool === 'write' && path && st.isNew === undefined) st.isNew = !S.seenPaths.has(path);
267
+ if (st.tool === 'write' && state === 'coding' && st.isNew) state = 'create';
268
+ st.state = state; st.text = actionText(st.tool, st.args);
269
+ }
270
+ const sig = (st) => st.tool + '|' + (st.args.command || st.args.file_path || st.args.path || st.args.pattern || st.args.url || st.args.query || (st.args.queries && st.args.queries[0]) || '');
271
+ function onNewStep(st, ctx) {
272
+ S.burst++; st.round = S.round;
273
+ if (S.lastFail && S.lastFail.sig === sig(st)) st.retry = (S.lastFail.retry || 0) + 1;
274
+ push({ kind: 'tool', step: st, busy: S.burst >= o.busyN }, ctx);
275
+ }
209
276
  function feed(entry, live, recvAt) {
210
277
  const ev = entry && entry.event; if (!ev || !ev.type) return;
211
278
  if (entry.type === 'event' && typeof ev.seq === 'number') { if (ev.seq <= S.lastSeq) return; S.lastSeq = ev.seq; }
@@ -215,23 +282,27 @@ window.__ModuleLoader__.load({
215
282
  case 'turn/start': {
216
283
  S.turn = d.turn || S.turn + 1; S.active = true; S.turnStart = ctx.time; S.turnEnd = 0; S.outcome = null;
217
284
  S.steps = []; S.byCall = new Map(); S.turns.set(S.turn, { steps: S.steps, startAt: ctx.time, endAt: 0, outcome: null });
285
+ S.lastTurnRecv = ctx.recvAt; S.round = 1; S.stepField = false; S.afterResult = false; S.burst = 0; S.failStreak = 0; S.retries = 0; S.lastFail = null; S.todoDone = 0;
218
286
  push({ kind: 'thinking', state: 'thinking', text: '正在思考…' }, ctx); break;
219
287
  }
220
288
  case 'assistant/live-chunk': {
221
289
  const c = d.chunk || {}; if (!S.active) break;
222
- if (c.type === 'reasoning-delta') push({ kind: 'thinking', state: 'thinking', text: '思考中…' }, ctx);
223
- else if (c.type === 'text-delta') push({ kind: 'thinking', state: 'thinking', text: '正在组织回复…' }, ctx);
290
+ if (c.type === 'reasoning-delta' || c.type === 'text-delta' || c.type === 'tool-call-delta') bumpRound(d);
291
+ if (c.type === 'reasoning-delta') { S.burst = 0; push({ kind: 'thinking', state: 'thinking', text: '思考中…' }, ctx); }
292
+ else if (c.type === 'text-delta') { S.burst = 0; push({ kind: 'thinking', state: 'thinking', text: '正在组织回复…' }, ctx); }
224
293
  else if (c.type === 'tool-call-delta') {
225
294
  const [st, created] = stepFor(c.id, c.name, ctx);
226
295
  if (c.name) st.tool = c.name; st.raw += c.argumentsDelta || ''; st.args = partialArgs(st.raw); finishStep(st);
227
- if (created) push({ kind: 'tool', step: st, partial: true }, ctx);
296
+ if (created) { st.partial = true; onNewStep(st, ctx); }
228
297
  } else return;
229
298
  break;
230
299
  }
231
300
  case 'tool/call': {
301
+ bumpRound(d);
232
302
  const [st, created] = stepFor(d.callId, d.name, ctx);
233
303
  st.tool = d.name || st.tool; st.args = partialArgs(d.arguments); if (st.status === 'streaming') st.status = 'running'; finishStep(st);
234
- if (created) push({ kind: 'tool', step: st }, ctx);
304
+ if (created) onNewStep(st, ctx);
305
+ else if (S.lastFail && st.retry === undefined && S.lastFail.sig === sig(st)) st.retry = (S.lastFail.retry || 0) + 1;
235
306
  break;
236
307
  }
237
308
  case 'approval/asked': {
@@ -242,7 +313,7 @@ window.__ModuleLoader__.load({
242
313
  case 'approval/decided': {
243
314
  const st = S.steps.find((x) => x.approvalId === d.id);
244
315
  if (d.outcome === 'allowed-once') { if (st) st.status = 'running'; push({ kind: 'tool', step: st, text: st ? '已批准 · ' + st.text : '已批准' }, ctx); }
245
- else { if (st) { st.status = 'error'; st.result = d.outcome === 'rejected' ? '已拒绝' : '审批' + d.outcome; } push({ kind: 'error', state: 'error', step: st, text: '审批未通过(' + d.outcome + ')' }, ctx); }
316
+ else { if (st) { st.status = 'error'; st.denied = true; st.result = d.outcome === 'rejected' ? '已拒绝' : '审批' + d.outcome; } push({ kind: 'error', state: 'denied', step: st, text: d.outcome === 'rejected' ? '你拒绝了这一步,换个办法' : '审批未通过(' + d.outcome + ')' }, ctx); }
246
317
  break;
247
318
  }
248
319
  case 'job/registered': { const st = d.toolCall && S.byCall.get(d.toolCall.callId); if (st) st.job = true; break; }
@@ -252,44 +323,79 @@ window.__ModuleLoader__.load({
252
323
  case 'tool/result': {
253
324
  const m = d.message || {}; const id = m.toolCallId || (m.source && m.source.callId);
254
325
  const st = S.byCall.get(id); if (!st) break;
255
- st.status = m.isError ? 'error' : 'ok'; st.endAt = ctx.time; st.result = resultBrief(m) || (m.isError ? '失败' : '完成');
256
- if (m.isError) push({ kind: 'error', state: 'error', step: st, text: '失败:' + st.result }, ctx);
257
- else emit();
326
+ const failed = !!m.isError || shellFailed(st, m);
327
+ st.status = failed ? 'error' : 'ok'; st.endAt = ctx.time; st.result = resultBrief(m) || (failed ? '失败' : '完成');
328
+ S.afterResult = true;
329
+ const path = st.args.file_path || st.args.path; if (path && /^(read|write|edit|str_replace_editor)$/.test(st.tool)) S.seenPaths.add(path);
330
+ if (failed) {
331
+ S.failStreak++; S.lastFail = { sig: sig(st), retry: st.retry || 0 };
332
+ const worried = S.failStreak >= o.worriedN;
333
+ push({ kind: 'error', state: worried ? 'worried' : 'error', step: st, fails: S.failStreak, text: (worried ? '又失败了(连续 ' + S.failStreak + ' 次):' : '失败:') + st.result }, ctx);
334
+ } else {
335
+ S.failStreak = 0; if (S.lastFail && S.lastFail.sig === sig(st)) S.lastFail = null;
336
+ let sub = null;
337
+ if (/^(subagent|spawn_teammate|wait_agent|team_task_(complete|done|update))$/.test(st.tool)) sub = '子任务完成:' + clip(st.args.description || st.args.prompt || st.result, 30);
338
+ else if (st.tool === 'todo_write' && Array.isArray(st.args.todos)) {
339
+ const done = st.args.todos.filter((x) => x && /^(completed|done)$/i.test(x.status || '')).length;
340
+ if (done > S.todoDone) sub = '完成一项待办(' + done + '/' + st.args.todos.length + ')';
341
+ S.todoDone = done;
342
+ }
343
+ if (sub) push({ kind: 'subtask', state: 'subtask', step: st, text: sub }, ctx); else emit();
344
+ }
258
345
  break;
259
346
  }
260
- case 'llm/retry': push({ kind: 'error', state: 'error', text: '模型请求失败,正在重试' }, ctx); break;
347
+ case 'llm/retry': S.retries++; push({ kind: 'retry', state: 'retry', text: '模型请求失败,正在重试' + (S.retries > 1 ? '(第 ' + S.retries + ' 次)' : '') }, ctx); break;
348
+ case 'user/interrupt': case 'turn/interrupt': case 'session/interrupt': if (S.active) push({ kind: 'interrupted', state: 'interrupted', text: '收到,马上停下…' }, ctx); break;
261
349
  case 'turn/end': {
262
350
  const k = (d.reason && d.reason.kind) || 'completed'; const ok = /^(completed|complete|stop|end_turn|done|ok)$/i.test(k);
263
351
  const cancelled = /cancel|interrupt|abort/i.test(k);
264
352
  S.active = false; S.turnEnd = ctx.time; S.outcome = ok ? 'ok' : cancelled ? 'cancelled' : 'error';
265
353
  const rec = S.turns.get(S.turn); if (rec) { rec.endAt = ctx.time; rec.outcome = S.outcome; }
266
354
  for (const st of S.steps) if (st.status === 'running' || st.status === 'streaming' || st.status === 'waiting') st.status = cancelled ? 'cancelled' : 'error';
267
- push({ kind: ok ? 'done' : 'error', state: ok ? 'done' : cancelled ? 'idle' : 'error', text: ok ? '完成 · 共 ' + S.steps.length + ' 步' : cancelled ? '已中断' : '本轮出错(' + k + ')' }, ctx);
355
+ const long = S.turnStart && ctx.time - S.turnStart >= o.loopLongMs;
356
+ push({ kind: ok ? 'done' : cancelled ? 'interrupted' : 'error', state: ok ? (long ? 'cheer' : 'done') : cancelled ? 'interrupted' : 'error',
357
+ text: ok ? (long ? '终于搞定!' : '完成') + ' · 共 ' + S.steps.length + ' 步' + (S.round > 1 ? ' · ' + S.round + ' 轮' : '') + (long ? ' · 用时 ' + fmtDur(ctx.time - S.turnStart) : '') : cancelled ? '已中断' : '本轮出错(' + k + ')' }, ctx);
268
358
  break;
269
359
  }
270
360
  default: return;
271
361
  }
272
362
  if (live) emit();
273
363
  }
274
- function reset() { S.steps = []; S.byCall = new Map(); S.queue.length = 0; S.cur = null; S.lastSeq = -1; S.active = false; S.turns = new Map(); }
364
+ function reset() { S.steps = []; S.byCall = new Map(); S.queue.length = 0; S.cur = null; S.lastSeq = -1; S.active = false; S.turns = new Map(); S.round = 0; S.burst = 0; S.failStreak = 0; S.seenPaths = new Set(); S.lastFail = null; }
275
365
  /** Current display: frame state resolved for a tool frame, live step reference. */
276
366
  function view() {
277
367
  const fr = S.cur; const now = o.now();
278
- let state = 'idle'; let text = '待机中';
368
+ let state = 'idle'; let text = '待机中'; let base = 'idle'; let mood = null; let hint = '';
279
369
  if (fr) {
280
370
  state = fr.kind === 'tool' ? (fr.step && fr.step.state) || 'tools' : fr.state;
281
371
  text = fr.text || (fr.step && fr.step.text) || '';
282
- if (fr.kind === 'tool' && fr.step && fr.step.status === 'waiting') state = 'waiting';
372
+ base = state;
373
+ if (fr.kind === 'tool' && fr.step && fr.step.retry) { mood = 'retry'; text = '再试一次(第 ' + (fr.step.retry + 1) + ' 次尝试)· ' + fr.step.text; }
374
+ else if (fr.kind === 'tool' && fr.busy) mood = 'busy';
375
+ if (fr.kind === 'tool' && fr.step && fr.step.status === 'waiting') { state = base = 'waiting'; mood = null; }
376
+ if (mood) state = mood;
377
+ }
378
+ // duration escalation (live only, never over waiting/error/one-shot frames, and only for the frame that is "now")
379
+ if (S.active && fr && !S.queue.length && (fr.kind === 'tool' || fr.kind === 'thinking')) {
380
+ const running = fr.kind === 'thinking' || (fr.step && (fr.step.status === 'running' || fr.step.status === 'streaming'));
381
+ const since = fr.kind === 'thinking' ? (fr.shownAt || S.curShownAt || now) : (fr.step.recvAt || fr.shownAt || now);
382
+ const el = running ? now - since : 0; const loop = S.turnStart ? now - S.lastTurnRecv : 0;
383
+ if (running && el >= o.stepSlowMs * 3) { state = 'tired'; mood = 'tired'; }
384
+ else if (running && el >= o.stepSlowMs) { state = 'sweat'; mood = 'sweat'; if (fr.kind === 'thinking') text = '深度思考中…'; }
385
+ else if (fr.kind === 'thinking' && loop >= o.loopLongMs) { state = 'tired'; mood = 'tired'; }
386
+ if (running && el >= o.stepSlowMs / 2) hint = '已 ' + fmtDur(el);
387
+ if (loop >= o.loopLongMs) hint = (hint ? hint + ' · ' : '') + '本轮 ' + fmtDur(loop);
283
388
  }
284
- if (!S.active && fr && (fr.kind === 'done' || fr.kind === 'error') && !S.queue.length && now - S.curShownAt > 4000 && S.curShownAt) { state = 'idle'; text = '待机中'; }
285
- return { state, text, frame: fr, active: S.active, turn: S.turn, turnStart: S.turnStart, turnEnd: S.turnEnd, steps: S.steps, queued: S.queue.length, outcome: S.outcome, version: S.version };
389
+ if (!S.active && fr && (fr.kind === 'done' || fr.kind === 'error' || fr.kind === 'interrupted') && !S.queue.length && now - S.curShownAt > 4000 && S.curShownAt) { state = base = 'idle'; mood = null; text = '待机中'; }
390
+ const seed = fr && fr.step ? fr.step.n : fr ? fr.round || 0 : 0;
391
+ return { state, base, mood, hint, text, seed, round: S.round, frame: fr, active: S.active, turn: S.turn, turnStart: S.turnStart, turnEnd: S.turnEnd, steps: S.steps, queued: S.queue.length, outcome: S.outcome, failStreak: S.failStreak, version: S.version };
286
392
  }
287
- return { feed, reset, view, S, setRules: (r) => { compiled = compileRules(r && r.length ? r : DEFAULT_RULES); }, setDwell: (ms) => { o.dwellMs = ms; }, subscribe: (f) => { listeners.add(f); return () => listeners.delete(f); }, emit };
393
+ return { feed, reset, view, S, setRules: (r) => { compiled = compileRules(r && r.length ? r : DEFAULT_RULES); }, setDwell: (ms) => { o.dwellMs = ms; }, setTiming: (stepSec, loopSec) => { if (stepSec > 0) o.stepSlowMs = stepSec * 1000; if (loopSec > 0) o.loopLongMs = loopSec * 1000; }, subscribe: (f) => { listeners.add(f); return () => listeners.delete(f); }, emit };
288
394
  }
289
395
 
290
396
  // ---------------------------------------------------------------- settings store (shared by every surface)
291
397
  const LS_KEY2 = 'dsh-task-mascot:settings:v2';
292
- const DEFAULT_SETTINGS = { inline: true, dock: true, pet: false, pack: 'dafeiyu', size: 160, cardSize: 96, corner: 'bottom-right', pos: null, rules: null, showChip: true, opacity: 1, dwellMs: 600, sound: false, avoid: true };
398
+ const DEFAULT_SETTINGS = { inline: true, dock: true, pet: false, pack: 'dafeiyu', size: 160, cardSize: 96, corner: 'bottom-right', pos: null, rules: null, showChip: true, opacity: 1, dwellMs: 600, sound: false, avoid: true, variants: 'alternate', stepSlowSec: 20, loopLongSec: 120 };
293
399
  function loadSettings() {
294
400
  try {
295
401
  const v2 = localStorage.getItem(LS_KEY2);
@@ -367,8 +473,14 @@ window.__ModuleLoader__.load({
367
473
  }
368
474
 
369
475
  // ---------------------------------------------------------------- v2 surfaces: tracker registry, inline card, dock bar, turn summary, pet
370
- const STATE_ZH = { idle: '待机', thinking: '思考中', reading: '读文件', search: '搜索', coding: '写代码', editing: '改代码', writingdoc: '写文档', cmd: '跑命令', data: '跑数据', planning: '做计划', subagents: '派子代理', tools: '用工具', summary: '总结', waiting: '等你确认', done: '完成', error: '出错了' };
371
- const STATE_ICON = { thinking: '💭', reading: '📖', search: '🔍', coding: '⌨️', editing: '✏️', writingdoc: '📝', cmd: '💻', data: '📊', planning: '🗂️', subagents: '🤝', tools: '🧰', summary: '📋', waiting: '✋', done: '✅', error: '❌', idle: '😴' };
476
+ const STATE_ZH = { idle: '待机', thinking: '思考中', reading: '读文件', search: '搜索', coding: '写代码', editing: '改代码', writingdoc: '写文档', cmd: '跑命令', data: '跑数据', planning: '做计划', subagents: '派子代理', tools: '用工具', summary: '总结', waiting: '等你确认', done: '完成', error: '出错了',
477
+ web: '上网', download: '下载', git: 'Git', test: '跑测试', install: '装依赖', create: '新建文件', delete: '删除', mcp: '调 MCP', memory: '翻记忆', media: '看图', diff: '对比改动',
478
+ retry: '重试', worried: '有点慌', busy: '忙不过来', subtask: '子任务完成', denied: '被拒绝了', interrupted: '被打断', sweat: '有点久', tired: '好累', cheer: '终于搞定' };
479
+ const STATE_ICON = { thinking: '💭', reading: '📖', search: '🔍', coding: '⌨️', editing: '✏️', writingdoc: '📝', cmd: '💻', data: '📊', planning: '🗂️', subagents: '🤝', tools: '🧰', summary: '📋', waiting: '✋', done: '✅', error: '❌', idle: '😴',
480
+ web: '🌐', download: '⬇️', git: '🌿', test: '🧪', install: '📦', create: '🆕', delete: '🗑️', mcp: '🔌', memory: '🧠', media: '🖼️', diff: '🔀',
481
+ retry: '🔁', worried: '😰', busy: '🌀', subtask: '☑️', denied: '🚫', interrupted: '⏸️', sweat: '💦', tired: '🥱', cheer: '🎉' };
482
+ /** Pack state to actually play: logical -> resolved (fallbacks) -> A/B variant. */
483
+ function displayState(v, manifest, mode) { return pickVariant(resolveState(v.state, manifest), manifest, v.seed, mode || 'alternate'); }
372
484
  const STATUS_MARK = { ok: { c: '#30a46c', m: '✓' }, error: { c: '#e5484d', m: '✗' }, waiting: { c: '#f5a524', m: '⏳' }, running: { c: '#3e63dd', m: '•' }, streaming: { c: '#8e4ec6', m: '…' }, cancelled: { c: '#888', m: '–' } };
373
485
  const ReactDOM = require('react-dom');
374
486
  const host = { ctx: null, trackers: new Map(), lastLive: null, subs: new Set() };
@@ -395,7 +507,8 @@ window.__ModuleLoader__.load({
395
507
  const have = host.trackers.get(sid); if (have) return have;
396
508
  let binding; try { binding = host.ctx.sessions.binding(sid); } catch (_e) { binding = null; }
397
509
  if (!binding || !binding.eventSource) return null;
398
- const tr = createTracker({ dwellMs: store.value.dwellMs, rules: store.value.rules }); tr.sid = sid;
510
+ const sv = store.value;
511
+ const tr = createTracker({ dwellMs: sv.dwellMs, rules: sv.rules, stepSlowMs: (sv.stepSlowSec || 20) * 1000, loopLongMs: (sv.loopLongSec || 120) * 1000 }); tr.sid = sid;
399
512
  const src = binding.eventSource;
400
513
  const replay = (w) => { tr.reset(); for (const e of w.entries || []) tr.feed(e, false); tr.emit(); };
401
514
  replay(src.getSnapshot());
@@ -420,7 +533,7 @@ window.__ModuleLoader__.load({
420
533
  const live = !!(v && (v.active || v.queued || (v.turnEnd && Date.now() - v.turnEnd < 6000)));
421
534
  React.useEffect(() => { if (!live) return undefined; const iv = setInterval(() => force((n) => n + 1), 250); return () => clearInterval(iv); }, [live]);
422
535
  const s = useSettings();
423
- React.useEffect(() => { if (tr) { tr.setRules(s.rules); tr.setDwell(s.dwellMs || 600); } }, [tr, s.rules, s.dwellMs]);
536
+ React.useEffect(() => { if (tr) { tr.setRules(s.rules); tr.setDwell(s.dwellMs || 600); tr.setTiming(s.stepSlowSec, s.loopLongSec); } }, [tr, s.rules, s.dwellMs, s.stepSlowSec, s.loopLongSec]);
424
537
  return v;
425
538
  }
426
539
  /** Record event→DOM latency once per (frame, surface). recvAt/eventTime are ms epoch; paint is the next animation frame. */
@@ -461,13 +574,13 @@ window.__ModuleLoader__.load({
461
574
  const ref = React.useRef(null); useLatency(v, surface, ref); ensureCss();
462
575
  const [open, setOpen] = React.useState(false);
463
576
  const now = Date.now(); const fr = v.frame || {}; const st = fr.step;
464
- const resolved = resolveState(v.state, manifest);
577
+ const resolved = displayState(v, manifest, useSettings().variants);
465
578
  const stepNo = st ? st.n : v.steps.length;
466
579
  const stepElapsed = st ? (st.endAt || (v.active ? now : v.turnEnd || now)) - st.startAt : 0;
467
580
  const turnElapsed = v.turnStart ? (v.active ? now : v.turnEnd || now) - v.turnStart : 0;
468
581
  const lastDone = v.steps.slice().reverse().find((x) => x.status === 'ok' || x.status === 'error');
469
- const tone = v.state === 'error' ? '#e5484d' : v.state === 'waiting' ? '#f5a524' : v.state === 'done' ? '#30a46c' : '#3e63dd';
470
- return h('div', { onClick: compact ? undefined : () => setOpen((x) => !x), title: compact ? undefined : '点击展开/收起本轮全部步骤', style: { cursor: compact ? 'default' : 'pointer' } }, h('div', { ref, 'data-mascot-card': surface, 'data-state': v.state, 'data-resolved': resolved || '', 'data-step': stepNo, 'data-queued': v.queued,
582
+ const tone = /^(error|worried|denied)$/.test(v.state) ? '#e5484d' : /^(waiting|interrupted|sweat|tired|retry)$/.test(v.state) ? '#f5a524' : /^(done|cheer|subtask)$/.test(v.state) ? '#30a46c' : '#3e63dd';
583
+ return h('div', { onClick: compact ? undefined : () => setOpen((x) => !x), title: compact ? undefined : '点击展开/收起本轮全部步骤', style: { cursor: compact ? 'default' : 'pointer' } }, h('div', { ref, 'data-mascot-card': surface, 'data-state': v.state, 'data-resolved': resolved || '', 'data-step': stepNo, 'data-queued': v.queued, 'data-round': v.round || 0, 'data-mood': v.mood || '',
471
584
  style: { display: 'flex', gap: compact ? 10 : 14, alignItems: 'center', padding: compact ? '6px 10px' : '10px 14px', borderRadius: 12, border: '1px solid ' + tone + '55', background: 'var(--dsw-alias-bg-l1, rgba(127,127,127,.06))', boxShadow: '0 1px 6px rgba(0,0,0,.06)', font: '13px/1.45 system-ui, sans-serif', color: 'inherit', maxWidth: '100%' } },
472
585
  h('div', { style: { flex: 'none', width: size, height: size } }, manifest ? h(Player, { pack, manifest, state: resolved, size }) : null),
473
586
  h('div', { style: { minWidth: 0, flex: 1, display: 'flex', flexDirection: compact ? 'row' : 'column', gap: compact ? 12 : 4, alignItems: compact ? 'center' : 'stretch' } },
@@ -475,10 +588,12 @@ window.__ModuleLoader__.load({
475
588
  h('span', { style: { flex: 'none', fontSize: 11, padding: '0 6px', borderRadius: 8, color: '#fff', background: tone } }, STATE_ZH[v.state] || v.state),
476
589
  h('span', { key: v.text, 'data-mascot-action': '', style: { fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, v.text || '')),
477
590
  h('div', { style: { display: 'flex', gap: 10, fontSize: 12, opacity: 0.75, flex: 'none', whiteSpace: 'nowrap' } },
591
+ v.round > 1 ? h('span', { 'data-mascot-round': '', title: 'Agent 循环轮次(模型第几次发言)' }, '第 ' + v.round + ' 轮') : null,
478
592
  stepNo ? h('span', { 'data-mascot-stepno': '' }, '第 ' + stepNo + ' 步') : null,
479
593
  st ? h('span', null, '本步 ' + fmtDur(stepElapsed)) : null,
480
594
  turnElapsed ? h('span', { 'data-mascot-elapsed': '' }, '总计 ' + fmtDur(turnElapsed)) : null,
481
- v.queued ? h('span', { title: '排队等待展示的步骤' }, '队列 ' + v.queued) : null),
595
+ v.queued ? h('span', { title: '排队等待展示的步骤' }, '队列 ' + v.queued) : null,
596
+ v.hint ? h('span', { 'data-mascot-hint': '', style: { opacity: 0.8, fontStyle: 'italic' } }, '⏱ ' + v.hint) : null),
482
597
  !compact && v.steps.length ? h(StepIcons, { steps: v.steps, max: 14, current: st }) : null,
483
598
  compact && v.steps.length ? h(StepIcons, { steps: v.steps, max: 8, current: st }) : null,
484
599
  !compact && lastDone ? h('div', { 'data-mascot-result': lastDone.status, style: { fontSize: 12, color: lastDone.status === 'error' ? '#e5484d' : '#30a46c', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } },
@@ -586,7 +701,7 @@ window.__ModuleLoader__.load({
586
701
  return () => clearInterval(iv);
587
702
  }, [settings.pet, settings.avoid, dodge]);
588
703
  if (!settings.pet || !manifest) return null;
589
- const resolved = resolveState(act.state, manifest);
704
+ const resolved = v ? displayState(v, manifest, settings.variants) : resolveState(act.state, manifest);
590
705
  const size = Math.max(64, Math.min(480, settings.size | 0));
591
706
  const anchor = pos ? { left: pos.x, top: pos.y } : ({ 'bottom-right': { right: 24, bottom: 96 }, 'bottom-left': { left: 24, bottom: 96 }, 'top-right': { right: 24, top: 64 }, 'top-left': { left: 24, top: 64 } }[settings.corner] || { right: 24, bottom: 96 });
592
707
  const onDown = (e) => { if (e.button !== 0) return; const el = e.currentTarget; const r = el.getBoundingClientRect(); drag.current = { dx: e.clientX - r.left, dy: e.clientY - r.top, moved: false }; el.setPointerCapture(e.pointerId); };
@@ -623,6 +738,9 @@ window.__ModuleLoader__.load({
623
738
  row('每步最短展示 Min dwell: ' + s.dwellMs + 'ms', h('input', { type: 'range', min: 0, max: 2000, step: 100, value: s.dwellMs, onChange: (e) => setSettings({ dwellMs: +e.target.value }) })),
624
739
  row('悬浮角色大小 Pet size: ' + s.size + 'px', h('input', { type: 'range', min: 64, max: 480, step: 8, value: s.size, onChange: (e) => setSettings({ size: +e.target.value }) })),
625
740
  row('悬浮位置 Pet position', h('select', { value: s.corner, onChange: (e) => setSettings({ corner: e.target.value, pos: null }) }, ['bottom-right', 'bottom-left', 'top-right', 'top-left'].map((c) => h('option', { key: c, value: c }, c)))),
741
+ row('动作 A/B 变体 Pose variants', h('select', { 'data-setting': 'variants', value: s.variants || 'alternate', onChange: (e) => setSettings({ variants: e.target.value }) }, [['alternate', '交替 alternate'], ['random', '随机 random'], ['off', '关闭 off']].map(([k, l]) => h('option', { key: k, value: k }, l)))),
742
+ row('单步多久算"有点久" Slow step: ' + (s.stepSlowSec || 20) + 's', h('input', { type: 'range', min: 5, max: 120, step: 5, value: s.stepSlowSec || 20, onChange: (e) => setSettings({ stepSlowSec: +e.target.value }) })),
743
+ row('一轮多久算"好累" Long loop: ' + (s.loopLongSec || 120) + 's', h('input', { type: 'range', min: 30, max: 900, step: 30, value: s.loopLongSec || 120, onChange: (e) => setSettings({ loopLongSec: +e.target.value }) })),
626
744
  row('悬浮状态标签 Pet chip', cb('showChip')),
627
745
  row('悬浮角色自动避让按钮/审批框 Pet avoids buttons', cb('avoid')),
628
746
  row('提示音(审批/完成/出错)Sound cues', cb('sound')),
@@ -648,7 +766,7 @@ window.__ModuleLoader__.load({
648
766
  }
649
767
  exports.apply = apply;
650
768
  exports.inject = inject;
651
- exports.__internals = { DEFAULT_RULES, ALL_STATES, compileRules, stateForTool, resolveState, createMachine, createTracker, actionText, partialArgs, resultBrief, GLOBAL_FALLBACK };
769
+ exports.__internals = { DEFAULT_RULES, ALL_STATES, compileRules, stateForTool, resolveState, pickVariant, displayState, createMachine, createTracker, actionText, partialArgs, resultBrief, GLOBAL_FALLBACK, STATE_ZH, STATE_ICON };
652
770
  return module.exports;
653
771
  },
654
772
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-task-mascot",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "metsh · Task Mascot — 真跟着 Agent 每一步工具调用在动。A DeepSeek Harness Web plugin whose mascot acts out every live tool call (read / write / edit / search / run / plan / sub-agent / wait / error) with step cards in chat. Swappable character packs (大肥鱼, Claude娘).",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",