dsh-dot-life 0.17.4 → 0.18.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.
package/docs/DESIGN.md CHANGED
@@ -233,3 +233,13 @@ Kevin:"感觉现在很难给他长任务。他很容易直接结束然后就
233
233
 
234
234
  - **记下的就是能发的**:交接尾巴里她的旧话写着 `… [图片×1]`(记录用的写法),新一段她照着打了一条 `[图片]`,dot 把对话里的回复原样转给他。现在 `qq_send` 的结果(`presentationMeta`)带上真正发出去的图的 ref(`images`,QQ 拒收的不在里面),记忆把它们写成 `[表情包 sticker:<id>]` / `[图 phone:screen]` / `[图 phone:latest]` / `[图 <网址>]`——照着打出来就是那张图(`markerOf` 认得,`sendGate` 也把它当 `images` 审)。只有数量的旧结果取调用里的前 N 张。交接尾巴的说明(`memory.handoff` 的 `tail`)跟着改;`qq.channel.owner` 说清两条路:直接写的回复会原样发给他,图和表情包只能用 `images`。
235
235
  - **别人发的图她看得见**:以前进她会话的只有 `[图片 <网址>]` / `[表情包 sticker:<id>]` 这几个字。dsh 的用户消息本来就能带图(dsh-llm 的 `ImageBlock { type: 'image', attachment }`,`attachment` 是附件仓库 `ctx.attachments`——`@deepseek-ai/dsh-attachment` 的 `AttachmentStore`,cordis 服务名 `attachments`——`saveImages` 返回的 `ImageAttachmentRef`;mobile-mcp 截图走的也是这条:dsh-mcp-client 用 `ctx.get('attachments').saveImages` 存 MCP 结果里的图)。dot/qq 在会叫醒她的消息上取图、存进仓库,`m.images: [{ ref, text }]`;dot/core 把他的话和通知的叫醒文本拆成内容数组,图紧跟在它的文字后面(`withImages`)。文字部分拼起来和原来一字不差,所以记忆(只取 text 部分)、recall 索引都不变,也不会记下附件 id。模型不收图时 dsh 的请求组装自己换成文字占位(`projectImagesForTextModel`)。
236
+
237
+ ## 0.18.0:活性、闸门、可见
238
+
239
+ 起因:11-04 15:04 跑腿会话被一个没人点的审批卡了十几个小时,扣下 16 条通知,定时看手机全停。计划见 dsh-dot-research/plan-0.18.md。
240
+
241
+ - **审批有超时、有人知道**:dot 在 `approval/request` waterfall 上注册答复器(`prepend`,包在 UI 答复器外面;只管她的会话:`<home>` 里的、IM 的、跑腿)。收到就告诉他(QQ 连着走 QQ,否则 dsh-im),带工具名、原因、实时画面链接和"N 分钟没人点就当拒绝";`next()`(UI)和 `approvalWaitMs`(10 分钟)赛跑,先到先得;超时返回 `'rejected'`,记 `approval-timeout`,再给他一句"过期了"。UI 晚到的答复被丢掉(waterfall 已经返回)。请求被撤回(`signal` abort,比如这一轮被停)→ `'cancelled'`,不发过期。dsh 把 rejected 写成 `the user rejected tool "…"`;过期的那个 `callId` 在 `tools/post-execute` 里换成 `dot.approval-timeout`。
242
+ - **轮次看门狗**:每个打开的轮记最后一个会话事件的时间;60 秒一看,`turnStallMs`(5 分钟)没动静记 `turn-stalled`(每轮一次)。跑腿卡住 `errandStallMs`(10 分钟,有审批在等时等审批先过期)→ `agent.cancel({ kind: 'hook', reason: 'dot-watchdog' }, { keepInbox: true })`(`ctx.agents` 里的活 agent),这一轮从 `turns` 删掉(晚到的 `turn/end` 不再留便条),会话进 `pastErrands`,下一次跑腿开新会话;扣着的通知交给新跑腿;她对话里留 `dot.errand-stalled`("做到一半卡住了,放弃了:<最后在做的工具 / 等哪个审批>")。她的对话卡住不取消,只告诉他一次(他已经收到这轮审批提醒时不再说)。
243
+ - **闸门按地盘分**(`src/computer/gate.js`):`shellPatterns` 去掉 `rm -rf`、`python -c` / `node -e` 一类、`eval`、`nohup`、`chmod +x`、`crontab`、`systemctl`、`supervisorctl`(在她自己的虚拟机里都是正常用电脑),`truncate` 挪到下面;留 `sudo`、`curl|sh`、`curl|python`、`base64 -d|`、`ssh`/`scp`、`git push`、`dd if=`、`mkfs`、`shred`/`wipe`、`>/dev/sd`、受保护路径。新加 `sharedTouch`:把命令按 `; && || |` 和换行切段、跟着 `cd`,`rm`/`rmdir`/`unlink`/`mv`/`truncate`/`chmod`/`chown`/`chgrp`/`shred`、`find -delete`、`>` 覆盖写(`>>`、`/dev/null` 不算)的目标落在共享文件夹里或在它上面(`/Users/*`、`/`),或者是她整个家目录(`vmHome`,`~`、`$HOME`),就问。共享路径每次调用现读 `dshComputer.mounts`,经 `backend.toGuestPath`(Windows 是 `/mnt/<盘>/…`);dsh 的 `bash` 的工作目录是会话文件夹(subprocess 第一次用时就共享它),所以相对路径算共享;虚拟机自带的 shell 从她家目录开始。粗糙是故意的:`$VAR` 当工作目录,引号外的转义不管。文件工具(`sandbox_file_operations` 删除/移动)没动,照旧问。
244
+ - **`phone_zoom`**(`src/phone/phone.js`):mobile-mcp 1.0.12 的截图只能整体缩小(`scale` 0–1、`maxSize`),没有裁剪放大,她以前去电脑里裁图。现截一张(`phone.screenshot`),自带的 PNG 解码(`decodePng`,原来 `blankPng` 里那段)裁 `{x,y,w,h}`、双线性放大 ≤3 倍、`encodePng`(deflate + 自算 CRC,不加依赖),`attachments.saveImages` 存成图片块返回;值里只有坐标和 ref,不含字节。`phone.device` 加一句。幕间观察轮放行它。
245
+ - **看得见**:`dshDot.turn(id)` / `turns()` / `approvals()` 给出每个打开的轮的状态(`turnState`:`approval` 正在等审批、`stalled` 超过 `turnStallMs` 没事件、`timed-out` 审批过期后一直没动静、`running`)和最后在做什么。面板「最近 N 场」里进行中的那场按它显示「等审批 N 分钟」「卡住 N 分钟」「已超时」,顶上多一个黄 / 红徽章;`/dot` 列出每个在等的审批(在哪个会话、等了多久、上限)和每个卡住的轮(多久没事件、最后在做什么、跑腿会在多久后放弃 / 她的对话不取消),都没有时一行 `liveness: …` 带三个阈值。
package/docs/SETTINGS.md CHANGED
@@ -74,6 +74,7 @@ dsh-dot 的所有个人设置都写在**一个文件**里:
74
74
  | 换她的家目录 | `dot.home`、`memory.home`、`interlude.home` **三处写同一个路径** | 默认 `~/dot` |
75
75
  | **没有硬件虚拟化 / 不要手机** | `phone.enabled: false` | |
76
76
  | 关掉某个组件 | `qq.enabled`、`memory.enabled`、`interlude.enabled`、`dot.enabled` 设 `false` | 其余组件照常 |
77
+ | **已有自己的角色,只要手机和电脑** | `dot`、`memory`、`interlude`、`qq` 四段都写 `"enabled": false` | 手机通知不再叫醒 agent,审批不推 IM;手机的提示词会随之改口,不提叫醒、表情包和记忆 |
77
78
  | **不要电脑** | 只能用环境变量 `DSH_DOT_COMPUTER=off`(见下) | 电脑组件会改 dsh 的全局沙箱设置,必须在插件加载前决定,设置文件来不及 |
78
79
 
79
80
  ### 设置环境变量(只有关电脑等少数项需要)
@@ -195,6 +196,9 @@ setx DSH_DOT_COMPUTER off
195
196
  | `ownerTypingMaxMs` | `15000` | QQ 报「正在输入」(NapCat)时最多等多少毫秒 |
196
197
  | `ownerDenyMax` | `2` | 你有她没看的话时,她发给你的 `qq_send` 每轮最多被拦几次 |
197
198
  | `errandMaxTokens` | `60000` | 跑腿会话多长换新 |
199
+ | `turnStallMs` | `300000` | 她的一轮这么久没有任何会话事件就算卡住:记 `turn-stalled`,面板标「卡住」;是她的对话就告诉你一次(不替她取消) |
200
+ | `errandStallMs` | `600000` | 跑腿会话卡住这么久就放弃:取消这一轮(保留收件箱),扣着的通知放出去交给新的跑腿会话,她对话里留一句「做到一半卡住了,放弃了:…」 |
201
+ | `approvalWaitMs` | `600000` | 她的会话里要审批时立刻告诉你(QQ 连着发 QQ,否则 IM);这么久没人点就当拒绝,再告诉你一句过期了;0 = 一直等 |
198
202
  | `imBot` / `imTarget` | `""` | dsh-im 的投递目标,空 = 第一个 |
199
203
 
200
204
  ## 优先级和旧文件
package/docs/computer.md CHANGED
@@ -15,7 +15,7 @@ Give [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (dsh) i
15
15
  - **Live view inside dsh**: a monitor button in the session header opens a Computer tab in the right sidebar. Watch, click, type, or take over for a QR login or CAPTCHA.
16
16
  - **Audit log**: every command, VM tool call, approval and folder change is appended to `~/.dsh/dsh-computer-audit.jsonl`.
17
17
  - **Phone-friendly live view**: the desktop is served on dsh's own web server behind dsh's login (`/dsh-dot/computer/`); the VM gateway port is keyed (`SANDBOX_API_KEY`, generated per machine). Expose dsh itself (e.g. `tailscale serve`), set `publicUrl`, and approval messages — including IM approval cards — link to it.
18
- - **Approval gates** for risky actions (`sudo`, `rm -rf`, `curl | sh`, `git push`, payment/login/delete clicks), with a link to the live view.
18
+ - **Approval gates by territory**, with a link to the live view: the VM is the agent's own machine, so using it runs (scripts, `python -c`, cron, services, `rm -rf` in its own folders); leaving it or fetching code to run (`curl | sh`, `ssh`/`scp`, `git push`), wrecking the disk (`dd`, `mkfs`, `shred`), `sudo`, protected locations, destructive commands (`rm`, `mv`, `truncate`, `chmod`/`chown`, `>`) on a folder shared with your machine or on the agent's whole home, and payment/login/delete clicks ask.
19
19
  - **Always there**: the VM keeps running after dsh quits and dsh reconnects to the same machine on next start.
20
20
  - **Lightweight**: a bundled [microsandbox](https://github.com/microsandbox/microsandbox) microVM (Hypervisor.framework on Apple silicon, WHP on Windows, KVM on Linux); Intel Macs fall back to Docker.
21
21
 
@@ -43,7 +43,7 @@ Status: v0.5.0, verified on dsh desktop 0.2.0-rc.2 (macOS, Apple silicon). Want
43
43
  - agent 的 bash 命令在虚拟机里执行,不碰你的系统。
44
44
  - agent 的浏览器(`mcp__dot-vm__browser_*` 工具)在虚拟机里,登录态长期保留。
45
45
  - 你随时可以打开实时画面观看或接手操作(扫码、验证码)。
46
- - 虚拟机的每个工具都有分类,审批信息附实时画面链接:只读工具(截图、取文本、看目录)不问;shell(dsh 的 `bash`、虚拟机的 `sandbox_execute_bash` / `sandbox_execute_code`)按命令文本判——`sudo`、`rm -rf`、`curl | sh`、`base64 -d | sh`、`python -c`、`eval`、`git push`、`crontab` 等问;文件工具(`sandbox_file_operations`、`sandbox_str_replace_editor`)删除/移动问,普通读写不问;浏览器动作按页面内容判(支付、登录、删除等问);`browser_evaluate`(在登录态页面里跑任意 JS)和 `browser_gui_execute_action`(绕过浏览器工具的桌面级输入)**总是问**;任何工具的参数里出现受保护位置(`~/.ssh`、浏览器 profile/Cookies、`.aws`、`.env`、`/etc/shadow`、NapCat 配置等)**总是问**;镜像以后新增的、这里没见过的工具按浏览器动作对待并记一条审计。
46
+ - 虚拟机的每个工具都有分类,审批信息附实时画面链接:只读工具(截图、取文本、看目录)不问;shell(dsh 的 `bash`、虚拟机的 `sandbox_execute_bash` / `sandbox_execute_code`)**按地盘判**:虚拟机是她自己的电脑,在里面正常用电脑的都不问(`python -c`、`node -e`、`eval`、`nohup`、`chmod +x`、`crontab`、`systemctl`、在她自己目录里 `rm -rf`);问的是离开这台机器或拿远程代码来跑(`curl | sh`、`curl | python`、`base64 -d | sh`、`ssh`、`scp`、`git push`)、毁盘(`dd if=`、`mkfs`、`shred`/`wipe`、`> /dev/sd*`)、`sudo`,以及对**和你的电脑共享的文件夹**的破坏性操作——`rm`、`mv`、`truncate`、`chmod`/`chown`、`find -delete`、`>` 覆盖写(`>>` 追加不算),按当时真实的共享路径判(换绑后新加的文件夹立刻算),跟着 `cd` 走;dsh 的 `bash` 在会话文件夹里跑(就是共享的那个),所以相对路径也算你的文件;一下删掉她整个家目录(`rm -rf ~`)或 `/` 也问。她虚拟机里的东西不是一次性的(装的软件、QQ 和浏览器登录态都在磁盘上,删了要重新装、重新登录),但那是她自己的,删坏了是她的事;你的文件不一样。文件工具(`sandbox_file_operations`、`sandbox_str_replace_editor`)删除/移动问,普通读写不问;浏览器动作按页面内容判(支付、登录、删除等问);`browser_evaluate`(在登录态页面里跑任意 JS)和 `browser_gui_execute_action`(绕过浏览器工具的桌面级输入)**总是问**;任何工具的参数里出现受保护位置(`~/.ssh`、浏览器 profile/Cookies、`.aws`、`.env`、`/etc/shadow`、NapCat 配置等)**总是问**;镜像以后新增的、这里没见过的工具按浏览器动作对待并记一条审计。
47
47
  - 会话所在的工作区文件夹自动共享进虚拟机,路径不变。
48
48
  - dsh 退出后虚拟机继续运行;下次启动自动连回同一台。
49
49
 
@@ -143,7 +143,7 @@ tailscale serve --bg --https=443 http://127.0.0.1:<dsh 端口> # 只在你的
143
143
  | `DSH_COMPUTER_PORT` | `18080` | 虚拟机网关在本机的端口(仅监听 127.0.0.1,需要密钥);只能用环境变量设置 |
144
144
  | `image` / `DSH_COMPUTER_IMAGE` | `ghcr.io/agent-infra/sandbox:latest` | 虚拟机镜像 |
145
145
  | `backend` / `DSH_COMPUTER_BACKEND` | `auto` | `microsandbox` 或 `docker` |
146
- | `DSH_COMPUTER_GATE` | `risky` | `off` 不拦截;`risky` 按上面的分类拦;`browser` 另外每个浏览器动作都审批。分类表(`readOnlyTools`、`alwaysAskTools`、`fileTools`、`protectedPaths`、`shellPatterns`…)可在 `dot-gate` 的 config 里覆盖 |
146
+ | `DSH_COMPUTER_GATE` | `risky` | `off` 不拦截;`risky` 按上面的分类拦;`browser` 另外每个浏览器动作都审批。分类表(`readOnlyTools`、`alwaysAskTools`、`fileTools`、`protectedPaths`、`shellPatterns`、`vmHome`…)可在 `dot-gate` 的 config 里覆盖 |
147
147
  | `DSH_COMPUTER_PRESET` | `computer` | `computer-auto` 关闭审批,只建议在虚拟机里没有重要登录态时用 |
148
148
 
149
149
  ## 六、维护
package/docs/phone.md CHANGED
@@ -7,7 +7,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
7
7
  1. **安装**(第一次):接受 [Android SDK 许可](https://developer.android.com/studio/terms)后(`/phone accept`,或配置 `acceptLicense: true`,或 `~/.dsh/dsh-phone.json` 里 `{"acceptLicense": true}`),从 `dl.google.com/android/repository` 读索引,下载 stable 通道的 emulator、platform-tools 和 `system-images;android-<api>;google_apis;<abi>`(约 1.7 GB),解压到 `~/.dsh/phone/`。`google_apis` 镜像没有 Play 商店——检测面最小,App 用 APK 装。
8
8
  2. **AVD**:`~/.dsh/phone/avd/dot.avd/config.ini` 由插件写(Pixel 6 尺寸、1080×2400、3 GB 内存、数据分区默认 16 GB、不带 Play)。数据分区大小在手机建好之前选:`/phone accept <GB>` 或 `/phone size <GB>`(8–256);建好后模拟器不会扩大已有分区,`/phone size` 只显示当前大小。想改尺寸或内存,改配置后删掉这个目录重建(手机里的数据会没)。
9
9
  3. **开机**:`emulator -avd dot -port <端口> -no-boot-anim -gpu auto`,等 `sys.boot_completed`,然后常亮屏幕、关动画、解锁。上一次 dsh 留下的还在跑的模拟器会被直接接管,不会开两个——但只接管控制台报告 AVD 名是 `dot` 的那台(`adb emu avd name`):MuMu、雷电、BlueStacks 等也会以 `emulator-5554` 出现在 adb 里,占着端口不等于是她的手机。端口从 `port`(5554)起找第一个 adb 没列出的(到 5584 为止)。模拟器自己退出会在 `restartDelayMs` 后重开。手机在 dsh 退出后继续运行。
10
- 4. **MCP**:开机后以 stdio 挂一个 mobile-mcp(随插件一起安装,`ANDROID_HOME` 指向 `~/.dsh/phone`,`ANDROID_SERIAL` 是上一步占到的 `emulator-<端口>`),工具名 `mcp__dot-phone__mobile_*`:列设备、截图、列屏幕元素(带坐标)、点、滑、长按、输入、按键、打开/关闭 App、装卸 App、开 URL。
10
+ 4. **MCP**:开机后以 stdio 挂一个 mobile-mcp(随插件一起安装,`ANDROID_HOME` 指向 `~/.dsh/phone`,`ANDROID_SERIAL` 是上一步占到的 `emulator-<端口>`),工具名 `mcp__dot-phone__mobile_*`:列设备、截图、列屏幕元素(带坐标)、点、滑、长按、输入、按键、打开/关闭 App、装卸 App、开 URL。mobile-mcp 只会把整张截图缩小(`scale` ≤ 1、`maxSize`),所以另有一个 dot 自己的工具 `phone_zoom`:现截一张,按屏幕像素 `{x, y, w, h}` 裁一块,放大(`scale` ≤ 3,不填就放到长边约 1200 像素),PNG 经附件仓库(`ctx.attachments`)成为图片交给她;没有附件仓库时说明原因。只读,幕间的观察轮也允许。
11
11
  5. **提示**:手机就绪后系统提示里多一段 `phone:device`,告诉模型设备号和用法(先看元素再点;验证码、人脸停下来叫用户)。
12
12
  6. **闸门**:`mobile_install_app` / `mobile_uninstall_app` 弹审批(目前审批框只显示工具名,不显示是哪个 App);`mobile_type_keys` 的内容像密码 / 支付 / 验证码时弹审批(`sensitivePatterns`)。幕间的观察轮只放行只读工具(看、滑、点进去、开 App、返回),其余直接拒绝、不审批。
13
13
  7. **通知叫醒她**:插件盯着系统的事件日志(`adb logcat -b events notification_enqueue`),每有 App 发通知就立刻读一次通知栏(`dumpsys notification`),另外每 `notifyPollMs` 兜底轮询一次——QQ 这类 App 在聊天窗口开着时会立刻撤回通知,光靠轮询会漏,新出现的通知(启动时已经在栏里的不算;系统包不算;`notifyApps` 可以只挑几个 App)交给 dot,dot 往她最近的会话里追加一条 `[11-04 04:52 手机通知] QQ · 宽:……`(开头是收到的时间),她自己决定去 App 里回还是只回 `DOT_SILENT`。这条回复不会转发到任何 IM。所以她不需要定闹钟去看 QQ——有人找她,手机会响。**任何 App 都算**,包括她以后自己装的:新 App 默认叫醒;像手机自己的通知设置一样可以按 App 静音——`/phone notify mute <包名>` / `wake <包名>`(持久化在 `dsh-phone.json`),`/phone notify` 看每个 App 发过多少条和当前策略。她在 Android 设置里关掉某个 App 的通知也一样生效(通知栏里没有就不会叫)。几秒内连来的多条合成一次叫醒(dot 的 `notifyBatchMs`);dot 的 `notifyHours` 可以设一个静音时段(默认不设)。`/phone notifications` 看最近 20 条。
package/docs/prompts.md CHANGED
@@ -26,8 +26,9 @@
26
26
  | | 记忆 / 想起的原话 | `memory.standing` / `memory.recall.header` |
27
27
  | 叫醒她的消息 | 他的 QQ 消息 | `dot.owner-words`(她这轮进行中插进来时多一行 `dot.owner-words.busy`) |
28
28
  | | 他插话了 | `dot.owner-interrupt`(发给他的 `qq_send` 被拦下的理由)/ `qq.send-interrupted`(气泡发到一半他说话) |
29
+ | | 审批过期 | `dot.approval-timeout`(`dot.approvalWaitMs` 没人点时她看到的工具结果,替换 dsh 的 "the user rejected tool") |
29
30
  | | 手机通知 | `dot.notification` `.many` `.busy` `.how-qq` `.how-mixed` `.how-app` `.cards` `.unverified` |
30
- | | 拿起手机 / 跑腿回来 | `dot.phone-check` / `dot.errand-note` `dot.errand-note.what` |
31
+ | | 拿起手机 / 跑腿回来 | `dot.phone-check` / `dot.errand-note` `dot.errand-note.what`(跑腿卡住被放弃:`dot.errand-stalled`) |
31
32
  | | 交接 | `memory.handoff` |
32
33
  | | 幕间:去看一眼 | `interlude.observation` `.where` `.vm` `.phone` |
33
34
  | | 幕间:玩一会儿 | `interlude.play` `interlude.play.collect` `.verbs` `.parts` `interlude.play-rules` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dot-life",
3
- "version": "0.17.4",
3
+ "version": "0.18.0",
4
4
  "description": "dot — a character who lives on her own phone, for DeepSeek Harness (dsh): an Android phone the plugin installs and runs, her own QQ, memory and a diary from real events, a life between conversations (幕间, after HDS-Interlude), an optional microVM computer with approval gates. One plugin, six components.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -72,8 +72,8 @@ export const GROUPS = [['system', '系统提示词'], ['wake', '叫醒她的消
72
72
  export const entries = [
73
73
  { id: 'rules', group: 'system', name: '工作方式', note: '定时任务(先看已有的)、问一次就放下、静默、审批、长任务;有电脑、有手机时各多一句', files: ['dot.rules', 'dot.rules.computer', 'dot.rules.phone'],
74
74
  render: () => variant([['电脑和手机都有', D.workingRules({ computer: true, phone: true })], ['只有手机', D.workingRules({ computer: false, phone: true })]]) },
75
- { id: 'phone', group: 'system', name: '手机', note: '手机开着时才有;设了手机号(/phone number)才有那一句;最后是各 App 怎么加表情包', files: ['phone.device', 'phone.device.number', 'phone.stickers'],
76
- render: () => variant([['设了手机号', deviceText('emulator-5554', '13800138000')], ['没设手机号', deviceText('emulator-5554')]]) },
75
+ { id: 'phone', group: 'system', name: '手机', note: '手机开着时才有;通知叫醒她那句要 dot 组件在;设了手机号(/phone number)才有那一句;表情包段要 qq 组件在,最后"记到 self"要 memory 在', files: ['phone.device', 'phone.device.wake', 'phone.device.no-wake', 'phone.device.number', 'phone.stickers', 'phone.stickers.learned'],
76
+ render: () => variant([['设了手机号', deviceText('emulator-5554', '13800138000')], ['没设手机号', deviceText('emulator-5554')], ['只装手机(没有 dot、qq、memory)', deviceText('emulator-5554', '', { dot: false, qq: false, memory: false })]]) },
77
77
  { id: 'qq', group: 'system', name: '电脑上的 QQ', note: 'QQ 连上时才有', files: ['qq.channel', 'qq.channel.owner', 'qq.channel.score', 'qq.stickers', 'qq.channel.no-stickers', 'qq.faces'],
78
78
  render: () => variant([['设了主人、群消息先打分、有表情包', Q.channelText({ qq: '123456789', owner: '987654321', groupPolicy: 'score', stickers: STICKERS })], ['都没有', Q.channelText({ qq: '123456789', owner: '', groupPolicy: 'mention', stickers: '' })]]) },
79
79
  { id: 'now', group: 'system', name: '现在几点', note: '每一轮都带着(在对话历史之后):现在的时间,和离上一句话多久', files: ['dot.now'],
@@ -86,6 +86,8 @@ export const entries = [
86
86
  render: () => variant([['她空闲', D.ownerWords([{ text: '在吗' }, { text: '帮我看个东西' }])], ['她这轮进行中', D.ownerWords([{ text: '算了' }, { text: '先别弄了' }], Date.now(), { whileBusy: true })]]) },
87
87
  { id: 'interrupt', group: 'wake', name: '他插话了', note: '她要 qq_send 给他时他还有没看的话:这次发送被拦下(工具返回的理由,每轮最多 2 次);气泡发到一半他又说话:剩下的不发(qq_send 的结果)', files: ['dot.owner-interrupt', 'qq.send-interrupted'],
88
88
  render: () => variant([['发送被拦下', D.ownerInterruptText()], ['发到一半', Q.sendReport({ sent: 1, interrupted: true, unsent: ['那家店我去过', '还挺好吃的'] })]]) },
89
+ { id: 'approval', group: 'wake', name: '审批过期', note: '她那步要审批、dot.approvalWaitMs(默认 10 分钟)没人点:当拒绝处理,这句替换 dsh 的「the user rejected tool」作为工具结果', files: ['dot.approval-timeout'],
90
+ render: () => D.approvalTimeoutText(10) },
89
91
  { id: 'notification', group: 'wake', name: '手机通知', note: '通知把她叫醒时收到的那条', files: ['dot.notification', 'dot.notification.many', 'dot.notification.busy', 'dot.notification.how-qq', 'dot.notification.how-mixed', 'dot.notification.how-app', 'dot.notification.cards', 'dot.notification.unverified'],
90
92
  render: () => {
91
93
  const qqOne = [{ pkg: 'qq', title: '宽(2条新消息)', text: '在吗' }, { pkg: 'qq', title: '宽', text: '帮我看个东西' }];
@@ -93,8 +95,8 @@ export const entries = [
93
95
  return variant([['一个 QQ 对话', D.wakeText(qqOne)], ['她忙的时候来的', D.wakeText(qqOne.slice(0, 1), { whileBusy: true })], ['两个 App,带着记得的人和冒名提醒', D.wakeText(mixed, { cards: '阿满(qq:42):聊过;群里说话 3 次' })]]);
94
96
  } },
95
97
  { id: 'phonecheck', group: 'wake', name: '拿起手机', note: '一阵子没动静时,让她看一眼手机', files: ['dot.phone-check'], render: () => D.phoneCheckText() },
96
- { id: 'errand', group: 'wake', name: '跑腿回来', note: '手机上的事办完后,留在她对话里的一句', files: ['dot.errand-note', 'dot.errand-note.what'],
97
- render: () => variant(['phone-check', 'notification', 'play', 'other'].map((o) => [o, D.errandNote(o, '小黑盒上暮看云回了我的评论,说他也觉得低频糊。')])) },
98
+ { id: 'errand', group: 'wake', name: '跑腿回来', note: '手机上的事办完后,留在她对话里的一句;跑腿卡住 dot.errandStallMs(默认 10 分钟)被放弃时是 dot.errand-stalled', files: ['dot.errand-note', 'dot.errand-note.what', 'dot.errand-stalled'],
99
+ render: () => variant([...['phone-check', 'notification', 'play', 'other'].map((o) => [o, D.errandNote(o, '小黑盒上暮看云回了我的评论,说他也觉得低频糊。')]), ['卡住了,放弃', D.errandNote('phone-check', D.errandStalledText('等 mobile_install_app 的审批', 10))]]) },
98
100
  { id: 'handoff', group: 'wake', name: '交接', note: '对话太长换新会话时,新会话的开头', files: ['memory.handoff'],
99
101
  render: () => M.renderHandoff({ now: '窝在床上改简历,有点困', inFlight: ['帮他查广州降温'], promises: ['周五提醒他交 benchmark'], openQuestions: ['他感冒好了没'] }, LINES.slice(-2), 3) },
100
102
  { id: 'observation', group: 'wake', name: '幕间:去看一眼', note: '她自己想去看看的时候,只看不动', files: ['interlude.observation', 'interlude.observation.where', 'interlude.observation.vm', 'interlude.observation.phone'],
@@ -7,7 +7,14 @@
7
7
  // second layer, not the first: a shell command is judged as text, a file operation by what it does
8
8
  // and where, a browser action by what the page is about, and the protected locations in the VM
9
9
  // (keys, browser profile, credentials) are watched in every argument of every tool.
10
+ //
11
+ // The shell is gated by territory: the VM is her computer, so using it (scripts, `python -c`, cron,
12
+ // services, `rm -rf` in her own folders) runs. What asks is leaving the machine or fetching code to
13
+ // run (curl|sh, ssh/scp, git push), wrecking the disk (dd, mkfs, shred, > /dev/sd*), the protected
14
+ // locations, and destructive operations (rm, mv, truncate, chmod/chown, `>`) on a folder shared with
15
+ // the host — those are his files — or on her whole home.
10
16
 
17
+ import { posix } from 'node:path';
11
18
  import { VM_TOOL_PREFIX } from '../tool-prefixes.js';
12
19
  import { clip } from './audit.js';
13
20
  import { sectionOf } from '../settings.js';
@@ -22,14 +29,16 @@ export const defaults = {
22
29
  // Tools whose arguments reach a shell in the VM. dsh's own `bash` is routed into the VM; the VM's
23
30
  // MCP server also exposes its own shell and code runners, which must pass the same gate.
24
31
  shellTools: ['bash', `${VM_TOOL_PREFIX}sandbox_execute_bash`, `${VM_TOOL_PREFIX}sandbox_execute_code`],
32
+ // Leaving the machine, fetching code to run, wrecking the disk. Destructive operations on shared
33
+ // folders are judged separately (sharedTouch), with the real mount paths at call time.
25
34
  shellPatterns: [
26
- String.raw`\brm\s+-[a-zA-Z]*[rf]`, String.raw`\bsudo\b`, String.raw`\b(curl|wget)\b[^|]*\|\s*(ba|z|da)?sh\b`,
35
+ String.raw`\bsudo\b`, String.raw`\b(curl|wget)\b[^|]*\|\s*(ba|z|da)?sh\b`,
27
36
  String.raw`\b(curl|wget)\b[^|]*\|\s*(python|node|perl)`, String.raw`\bbase64\s+(-d|--decode)\b[^|]*\|`,
28
- String.raw`\beval\b`, String.raw`\b(python3?|node|perl|ruby)\s+-[ce]\b`, String.raw`\bchmod\s+[0-7]*[+]?[xs]`,
29
37
  String.raw`\bssh\b`, String.raw`\bscp\b`, String.raw`\bgit\s+push\b`, String.raw`\bdd\s+if=`, String.raw`\bmkfs`,
30
- String.raw`\bcrontab\b`, String.raw`\bnohup\b`, String.raw`\bsystemctl\b`, String.raw`\bsupervisorctl\b`,
31
- String.raw`\b(shred|wipe|truncate)\b`, String.raw`>\s*/dev/sd`,
38
+ String.raw`\b(shred|wipe)\b`, String.raw`>\s*/dev/sd`,
32
39
  ],
40
+ // Her home in the VM: wiping all of it (her QQ login, browser profile, everything installed) asks.
41
+ vmHome: '/home/gem',
33
42
  // VM tools that read or write files directly (no shell): asked when the operation is destructive
34
43
  // or touches a protected location.
35
44
  fileTools: [`${VM_TOOL_PREFIX}sandbox_file_operations`, `${VM_TOOL_PREFIX}sandbox_str_replace_editor`],
@@ -59,6 +68,60 @@ export const defaults = {
59
68
  /** Browser/desktop action tools this file knows; any other mcp__dot-vm__ tool is audited once as unknown and treated like them. */
60
69
  const KNOWN_ACTIONS = new Set(['browser_navigate', 'browser_go_back', 'browser_go_forward', 'browser_form_input_fill', 'browser_new_tab', 'browser_switch_tab', 'browser_close_tab', 'browser_click', 'browser_select', 'browser_close', 'browser_press_key']);
61
70
 
71
+ const DESTRUCTIVE = new Set(['rm', 'rmdir', 'unlink', 'mv', 'truncate', 'chmod', 'chown', 'chgrp', 'shred']);
72
+ const PREFIXES = new Set(['sudo', 'env', 'nice', 'nohup', 'time', 'command', 'xargs', 'doas']);
73
+ const NULL_SINKS = /^\/dev\/(null|stdout|stderr|tty|fd\/\d+)$/;
74
+
75
+ /** Words of one shell segment, quotes removed (rough: no expansion, no escapes beyond quotes). */
76
+ const words = (seg) => [...seg.matchAll(/"([^"]*)"|'([^']*)'|(\S+)/g)].map((m) => m[1] ?? m[2] ?? m[3]);
77
+ /** The command text of a shell tool's arguments (JSON), or the text itself. */
78
+ export function commandOf(args) {
79
+ try { const a = JSON.parse(args); if (typeof a === 'string') return a; for (const k of ['command', 'cmd', 'script', 'code']) if (typeof a?.[k] === 'string') return a[k]; } catch { /* not JSON */ }
80
+ return String(args ?? '');
81
+ }
82
+ const insideOf = (root, p) => p === root || p.startsWith(root.endsWith('/') ? root : `${root}/`);
83
+
84
+ /**
85
+ * Does this shell command destroy (rm, mv, truncate, chmod/chown, `>`) something in a shared folder, or
86
+ * her whole VM home? Returns the path it would hit, or ''. Rough by design: segments split on
87
+ * ; && || | and newlines, `cd` followed, a target that cannot be resolved ($VAR, `$(…)`) counts as the
88
+ * working folder.
89
+ * @param {string} command
90
+ * @param {{ shared: string[], cwd?: string, home?: string }} where - shared folders as the VM sees them; the working folder.
91
+ */
92
+ export function sharedTouch(command, { shared = [], cwd = '', home = defaults.vmHome } = {}) {
93
+ const roots = shared.filter(Boolean).map((p) => p.replace(/\/+$/, '') || '/');
94
+ let dir = cwd || home;
95
+ const resolve = (t) => {
96
+ if (/^\$\{?HOME\b\}?/.test(t) || t === '~' || t.startsWith('~/')) return posix.normalize(t.replace(/^(\$\{?HOME\}?|~)/, home));
97
+ if (t.startsWith('$') || t.startsWith('`')) return dir;
98
+ return posix.normalize(t.startsWith('/') ? t : posix.join(dir, t));
99
+ };
100
+ const hits = (t) => {
101
+ const p = resolve(t).replace(/\/+$/, '') || '/';
102
+ const base = p.replace(/\/?[^/]*[*?[].*$/, '') || '/'; // a glob reaches everything under where it starts
103
+ if (base === '/' || base === home) return p;
104
+ return roots.some((r) => insideOf(r, p) || insideOf(base, r)) ? p : '';
105
+ };
106
+ for (const seg of String(command).split(/\n|;|&&|\|\||\|/)) {
107
+ // Redirects that overwrite (not >>, not >&, not to /dev/null).
108
+ for (const m of seg.matchAll(/(?<![>&0-9])[0-9]?>(?![>&])\s*("[^"]*"|'[^']*'|[^\s;&|<>]+)/g)) {
109
+ const t = m[1].replace(/^["']|["']$/g, '');
110
+ if (!NULL_SINKS.test(t)) { const h = hits(t); if (h) return h; }
111
+ }
112
+ const w = words(seg.replace(/[0-9]?>{1,2}\s*("[^"]*"|'[^']*'|[^\s;&|<>]+)/g, ' ').replace(/[0-9]?>&[0-9-]/g, ' '));
113
+ while (w.length && (/^\w+=/.test(w[0]) || PREFIXES.has(w[0]))) w.shift();
114
+ const cmd = (w[0] ?? '').split('/').pop();
115
+ const rest = w.slice(1).filter((x) => !x.startsWith('-'));
116
+ if (cmd === 'cd') { dir = rest[0] ? resolve(rest[0]) : home; continue; }
117
+ if (cmd === 'find' && w.some((x) => x === '-delete' || x === 'rm')) { const h = hits(rest[0] ?? '.'); if (h) return h; continue; }
118
+ if (!DESTRUCTIVE.has(cmd)) continue;
119
+ const targets = cmd === 'chmod' || cmd === 'chown' || cmd === 'chgrp' ? rest.slice(1) : rest;
120
+ for (const t of targets) { const h = hits(t); if (h) return h; }
121
+ }
122
+ return '';
123
+ }
124
+
62
125
  export function compile(cfg) {
63
126
  const rx = (list) => (list ?? []).map((p) => new RegExp(p, 'i'));
64
127
  return { shell: rx(cfg.shellPatterns), destructive: rx(cfg.destructivePatterns), protectedPaths: rx(cfg.protectedPaths), sensitive: rx(cfg.sensitivePatterns) };
@@ -66,7 +129,8 @@ export function compile(cfg) {
66
129
 
67
130
  /**
68
131
  * Decide for one tool call: null (allow) or the reason to ask. Pure.
69
- * @param {{ name: string, args: string }} call - tool name and its arguments as JSON text.
132
+ * @param {{ name: string, args: string, shared?: string[], cwd?: string }} call - tool name, its
133
+ * arguments as JSON text, the folders shared with the host as the VM sees them, the shell's working folder.
70
134
  */
71
135
  export function decide(call, cfg, compiled = compile(cfg)) {
72
136
  if (cfg.mode === 'off') return null;
@@ -75,7 +139,11 @@ export function decide(call, cfg, compiled = compile(cfg)) {
75
139
  if (!vmTool && !cfg.shellTools.includes(tool)) return null;
76
140
  // A protected location in any argument of any VM tool is a reason on its own.
77
141
  if (compiled.protectedPaths.some((r) => r.test(args))) return `dsh-computer: touches a protected location in the VM (${vmTool || tool})`;
78
- if (cfg.shellTools.includes(tool)) return compiled.shell.some((r) => r.test(args)) ? 'dsh-computer: risky shell command in the VM' : null;
142
+ if (cfg.shellTools.includes(tool)) {
143
+ if (compiled.shell.some((r) => r.test(args))) return 'dsh-computer: risky shell command in the VM';
144
+ const hit = sharedTouch(commandOf(args), { shared: call.shared ?? [], cwd: call.cwd, home: cfg.vmHome });
145
+ return hit ? `dsh-computer: destructive command on ${hit === cfg.vmHome || hit === '/' ? 'her whole computer' : 'a folder shared with the host'} (${hit})` : null;
146
+ }
79
147
  if (cfg.fileTools.includes(tool)) return compiled.destructive.some((r) => r.test(args)) ? `dsh-computer: destructive file operation (${vmTool})` : null;
80
148
  if (cfg.readOnlyTools.includes(vmTool)) return cfg.mode === 'browser' && vmTool.startsWith('browser_') ? `dsh-computer: browser action ${vmTool}` : null;
81
149
  if (cfg.alwaysAskTools.includes(vmTool)) return `dsh-computer: ${vmTool} (runs code or raw input in her computer)`;
@@ -110,14 +178,32 @@ export function apply(ctx, config = {}) {
110
178
  const classified = new Set([...cfg.readOnlyTools, ...cfg.alwaysAskTools, ...KNOWN_ACTIONS, ...cfg.shellTools, ...cfg.fileTools].map((t) => t.replace(new RegExp(`^${VM_TOOL_PREFIX}`), '')));
111
179
  const unknown = new Set();
112
180
 
181
+ // The host folders shared into the VM, as the VM sees them (read per call: a remount adds one).
182
+ const guest = (p) => (vm.backend?.toGuestPath ? vm.backend.toGuestPath(p) : p);
183
+ const sharedNow = () => (vm.mounts ?? vm.status?.()?.mounts ?? []).map(guest);
184
+ // dsh's bash runs in the session's folder, which the VM shares on first use (subprocess.js vmCwd);
185
+ // the VM's own shell tools start in her home unless told otherwise.
186
+ const cwdOf = (exec, input) => {
187
+ const given = input?.cwd ?? input?.workdir ?? input?.exec_dir;
188
+ if (typeof given === 'string' && given) return exec.name === 'bash' ? guest(given) : given;
189
+ const host = exec.name === 'bash' ? exec.agent?.session?.header?.cwd : '';
190
+ return host ? guest(host) : cfg.vmHome;
191
+ };
113
192
  ctx.on('tools/pre-execute', async (exec, next) => {
114
- const args = JSON.stringify(exec.input ?? exec.args ?? exec.arguments ?? {});
193
+ const input = exec.input ?? exec.args ?? exec.arguments ?? {};
194
+ const args = typeof input === 'string' ? input : JSON.stringify(input);
115
195
  const vmTool = exec.name.startsWith(VM_TOOL_PREFIX) ? exec.name.slice(VM_TOOL_PREFIX.length) : '';
116
196
  if (vmTool && !classified.has(vmTool) && !unknown.has(vmTool)) {
117
197
  unknown.add(vmTool);
118
198
  audit({ kind: 'unknown-vm-tool', tool: exec.name, note: 'not classified here; treated as a browser/desktop action' });
119
199
  }
120
- const reason = decide({ name: exec.name, args }, cfg, compiled);
200
+ const shell = cfg.shellTools.includes(exec.name);
201
+ let parsed = input;
202
+ if (typeof input === 'string') try { parsed = JSON.parse(input); } catch { parsed = {}; }
203
+ const cwd = shell ? cwdOf(exec, parsed) : '';
204
+ // A bash session folder not shared yet will be by the time the command runs.
205
+ const shared = shell ? [...sharedNow(), ...(exec.name === 'bash' && exec.agent?.session?.header?.cwd ? [cwd] : [])] : [];
206
+ const reason = decide({ name: exec.name, args, shared, cwd }, cfg, compiled);
121
207
  if (!reason) return next();
122
208
  audit({ kind: 'approval-asked', tool: exec.name, session: sessionOf(exec), args: clip(exec.arguments, 300), reason });
123
209
  return { kind: 'ask', reason: `${reason}${watch()}` };
@@ -63,12 +63,14 @@ const PHASE = { advance: 'advance', 'follow-up': 'follow-up', intent: 'intent',
63
63
  /**
64
64
  * Turn the records into scenes, newest first.
65
65
  * @param {object} src - parsed records: audit (computer+phone audit), qq, transcript, interludeCalls, script, memoryCalls, diary.
66
- * @param {object} opts - now, limit, days, busy(session) → bool, isErrand(session) → bool.
67
- * Each scene: { at, end, session, source: { kind, name? }, status: 'running'|'done'|'failed', trigger?,
66
+ * @param {object} opts - now, limit, days, busy(session) → bool, isErrand(session) → bool,
67
+ * turnOf(session) → { state: 'running'|'stalled'|'approval'|'timed-out', idleMs, waitMs? } for an open turn.
68
+ * Each scene: { at, end, session, source: { kind, name? }, status: 'running'|'stalled'|'approval'|'timed-out'|'done'|'failed',
69
+ * minutes? (stalled: since the last event; approval: waiting), trigger?,
68
70
  * actions: [{ k, text, via? }], stats: { tools, model, in, out } }. Action and source kinds are keys;
69
71
  * the page words them (zh/en).
70
72
  */
71
- export function buildScenes(src, { now = Date.now(), limit = DEFAULT_SCENES, days = 3, busy = () => false, isErrand = () => false } = {}) {
73
+ export function buildScenes(src, { now = Date.now(), limit = DEFAULT_SCENES, days = 3, busy = () => false, isErrand = () => false, turnOf = () => null } = {}) {
72
74
  const since = now - days * DAY;
73
75
  const ev = [];
74
76
  const push = (t, type, e) => { if (t >= since && t <= now + 60000) ev.push({ t, type, e }); };
@@ -206,9 +208,12 @@ export function buildScenes(src, { now = Date.now(), limit = DEFAULT_SCENES, day
206
208
  for (const s of scenes) {
207
209
  if (s.status === 'failed') continue;
208
210
  if (s.round ? s.roundOpen && now - s.at < 15 * 60000 : s.session && latest.get(s.session) === s && busy(s.session)) s.status = 'running';
211
+ // Her open turn as the watchdog sees it: stalled, waiting on an approval, or stalled after one expired.
212
+ const t = s.status === 'running' && !s.round ? turnOf(s.session) : null;
213
+ if (t && t.state !== 'running') { s.status = t.state; s.minutes = Math.floor((t.state === 'approval' ? t.waitMs : t.idleMs) / 60000); }
209
214
  }
210
- return scenes.slice(-limit).reverse().map(({ at, end, session, source, status, trigger, actions, stats, quiet, count }) => ({
211
- at, end, session, source, status, ...(trigger ? { trigger } : {}), ...(quiet && !actions.length ? { quiet: true } : {}), ...(count ? { count } : {}),
215
+ return scenes.slice(-limit).reverse().map(({ at, end, session, source, status, minutes, trigger, actions, stats, quiet, count }) => ({
216
+ at, end, session, source, status, ...(minutes !== undefined ? { minutes } : {}), ...(trigger ? { trigger } : {}), ...(quiet && !actions.length ? { quiet: true } : {}), ...(count ? { count } : {}),
212
217
  actions: actions.slice(0, 20).map(({ key, ...a }) => { void key; return a; }), stats,
213
218
  }));
214
219
  }
package/src/dot/core.js CHANGED
@@ -9,7 +9,8 @@
9
9
  // What is left, because no plugin does it:
10
10
  // 1. results of scheduled turns in <home> go to IM through dsh-im's public `send()`,
11
11
  // unless the reply is only DOT_SILENT (nothing worth reporting);
12
- // 2. an approval asked during such a turn is announced on IM with the live-view link;
12
+ // 2. an approval asked in her sessions is announced to the owner (QQ when connected, else IM) with
13
+ // the live-view link, and taken as rejected when nobody answers within approvalWaitMs;
13
14
  // 3. dsh-budget blocks are announced on IM, and the `daily` block is lifted at local midnight;
14
15
  // 4. VM failures are announced on IM; /dot shows the status.
15
16
  import { PHONE_TOOL_PREFIX, VM_TOOL_PREFIX } from '../tool-prefixes.js';
@@ -174,8 +175,39 @@ export const defaults = {
174
175
  // Notifications from these apps are conversations: they wake her conversation, not the errand.
175
176
  conversationApps: ['qq', 'com.tencent.mobileqq', 'com.tencent.mm'],
176
177
  promptsPort: 7870, // /dot prompts: the prompt and persona editor page (scripts/prompts.mjs) on 127.0.0.1
178
+ // Liveness. An approval in her sessions nobody answers within approvalWaitMs is taken as rejected
179
+ // (0 = wait for ever). A turn with no session event for turnStallMs is stalled; an errand stalled
180
+ // for errandStallMs is cancelled (her conversation never is: he is told once).
181
+ approvalWaitMs: 600000,
182
+ turnStallMs: 300000,
183
+ errandStallMs: 600000,
177
184
  };
178
185
 
186
+ /** What she reads when an approval nobody answered expired (in place of dsh's "the user rejected tool"). */
187
+ export const approvalTimeoutText = (minutes) => prompt('dot.approval-timeout', { minutes });
188
+ /** The note a stalled errand leaves in her conversation: what it was doing when it was given up. */
189
+ export const errandStalledText = (doing, minutes) => prompt('dot.errand-stalled', { doing, minutes });
190
+ /** The owner's message for an approval she is waiting on. */
191
+ export function approvalNotice({ tool, reason = '', link = '', minutes = 0 }) {
192
+ const r = String(reason ?? '').trim();
193
+ const lines = [`🔐 dot 需要你审批:${tool || '工具调用'}`, r, `在 DeepSeek Harness 里批准或拒绝${minutes ? `;${minutes} 分钟没人点就当拒绝` : ''}。`];
194
+ if (link && !r.includes(link)) lines.push(`实时画面:${link}`);
195
+ return lines.filter(Boolean).join('\n');
196
+ }
197
+ /** Tool name without its MCP server prefix (mcp__dot-vm__browser_click → browser_click). */
198
+ export const shortTool = (name) => String(name ?? '').replace(/^mcp__.+?__/, '');
199
+ /**
200
+ * An open turn as the panel and /dot show it: 'approval' (waiting on one, not yet expired),
201
+ * 'timed-out' (stalled after an approval expired), 'stalled' (no session event for turnStallMs), 'running'.
202
+ */
203
+ export function turnState(t, { now = Date.now(), turnStallMs = defaults.turnStallMs, approval } = {}) {
204
+ const idleMs = Math.max(0, now - (t.lastEventAt ?? t.startedAt ?? now));
205
+ const stalled = turnStallMs > 0 && idleMs >= turnStallMs;
206
+ if (approval && !approval.timedOutAt) return { state: 'approval', idleMs, waitMs: Math.max(0, now - approval.since), tool: approval.tool };
207
+ if (stalled) return { state: t.approvalTimedOutAt || approval?.timedOutAt ? 'timed-out' : 'stalled', idleMs };
208
+ return { state: 'running', idleMs };
209
+ }
210
+
179
211
  /** Source of the note an errand leaves in her conversation (injected; it does not wake her). */
180
212
  export const ERRAND_NOTE_SOURCE = Object.freeze({ kind: 'dsh-dot', form: 'errand-note' });
181
213
  /** The note an errand leaves in her conversation: what she did on her phone, in her own words. */
@@ -406,7 +438,7 @@ export function apply(ctx, config = {}) {
406
438
  const controller = ctx.get('sessionController');
407
439
  if (!id || !controller) return;
408
440
  try {
409
- const found = await controller.resolveAgent(id);
441
+ const found = await resolveLive(id);
410
442
  if (!found || 'error' in found || typeof found.agent.inject !== 'function') return;
411
443
  found.agent.inject(createUserMessage({ content: [{ type: 'text', text: errandNote(origin, text) }], source: ERRAND_NOTE_SOURCE }));
412
444
  audit('errand-noted', { session: id, origin });
@@ -418,7 +450,9 @@ export function apply(ctx, config = {}) {
418
450
  const bump = (k, n = 1) => { const st = stats(); st[k] = (st[k] ?? 0) + n; store.set('stats', st); };
419
451
 
420
452
  // 1 + 2. Scheduled turns in dot's sessions: silence or deliver; announce approvals.
421
- const turns = new Map(); // session id → { turn, scheduled, text }
453
+ const turns = new Map(); // session id → { turn, scheduled, text, startedAt, lastEventAt, doing, said }
454
+ const approvals = new Map(); // callId (else the log's id) → { session, tool, reason, since, eventId?, notified?, timedOutAt? }
455
+ const expiredCalls = new Map(); // callId → minutes waited: its tool result is rewritten (tools/post-execute)
422
456
  const ownerDenies = new Map(); // session id → qq_send calls to him held back this turn (read-before-send gate)
423
457
  const incoming = new Set(); // sessions whose inbox holds a reminder for the next turn
424
458
  ctx.on('session/event', (session, event) => {
@@ -428,6 +462,19 @@ export function apply(ctx, config = {}) {
428
462
  if (wantIm && event.type === 'agent/inbox/spliced' && (event.data?.inserted ?? []).some(isImMessage)) imSessions.add(id);
429
463
  if (wantIm && event.type === 'user/message' && isImMessage(event.data)) imSessions.add(id);
430
464
  if (!isDotSession(id, cwd)) return;
465
+ const open = turns.get(id);
466
+ if (open) {
467
+ open.lastEventAt = Date.now();
468
+ if (event.type === 'tool/call') open.doing = shortTool(event.data?.name);
469
+ if (event.type === 'assistant/message' && !event.data?.interrupted) { const said = contentText(event.data?.message?.content).trim(); if (said) open.said = said; }
470
+ }
471
+ // Pending approvals (the log's pair; the answerer below adds the ones it sees first).
472
+ if (event.type === 'approval/asked') {
473
+ const key = event.data?.callId ?? event.data?.id;
474
+ if (key && !approvals.has(key)) approvals.set(key, { session: id, tool: String(event.data?.toolName ?? ''), reason: String(event.data?.reason ?? ''), since: Date.now() });
475
+ if (key) approvals.get(key).eventId = event.data?.id;
476
+ }
477
+ if (event.type === 'approval/decided') for (const [k, a] of approvals) if (a.eventId === event.data?.id) approvals.delete(k);
431
478
  if (event.type === 'turn/end' && lastSession !== id && !isErrand(id)) { lastSession = id; store.set('lastSession', id); }
432
479
  // A reminder enters the inbox before its turn starts, and the prompt is assembled at turn
433
480
  // start, before the user/message event: note it here so the turn knows from its first step.
@@ -437,7 +484,7 @@ export function apply(ctx, config = {}) {
437
484
  }
438
485
  if (event.type === 'turn/start') {
439
486
  ownerDenies.delete(id);
440
- turns.set(id, { turn: event.data?.turn, scheduled: incoming.delete(id), text: '', startedAt: Date.now() });
487
+ turns.set(id, { turn: event.data?.turn, scheduled: incoming.delete(id), text: '', startedAt: Date.now(), lastEventAt: Date.now() });
441
488
  return;
442
489
  }
443
490
  const t = turns.get(id);
@@ -469,18 +516,6 @@ export function apply(ctx, config = {}) {
469
516
  if (text.trim()) t.text = text; // the last non-empty reply of the turn is its answer
470
517
  return;
471
518
  }
472
- if (event.type === 'approval/asked') {
473
- // Payload: { id, toolName, reason? }. dsh-computer's gate puts the live-view link in reason.
474
- const onPhone = String(event.data?.toolName ?? '').startsWith(PHONE_TOOL_PREFIX);
475
- const vm = (onPhone ? phone()?.status?.() : computer()?.status?.()) ?? {};
476
- const link = vm.publicLiveViewUrl || vm.liveViewUrl;
477
- const reason = String(event.data?.reason ?? '').trim();
478
- const lines = [`🔐 dot 需要你审批:${event.data?.toolName ?? '工具调用'}`, reason, '在 DeepSeek Harness 里批准或拒绝。'];
479
- if (link && !reason.includes(link)) lines.push(`实时画面:${link}`);
480
- void im.send(lines.filter(Boolean).join('\n'), 'plain');
481
- audit('approval-notified', { session: id, tool: event.data?.toolName });
482
- return;
483
- }
484
519
  if (ended) {
485
520
  const text = t.text.trim();
486
521
  if (!text || isSilent(text)) { audit('silent', { session: id }); return; }
@@ -495,6 +530,58 @@ export function apply(ctx, config = {}) {
495
530
  }
496
531
  });
497
532
 
533
+ // 2. Approvals in her sessions: he is told at once (QQ when connected, else IM), and an ask nobody
534
+ // answers within approvalWaitMs is rejected — an unanswered one held an errand for 13 hours
535
+ // (11-04). Prepended, so it wraps the answerers behind it (the UI); their late answer is dropped.
536
+ const liveLink = (toolName) => {
537
+ const vm = (String(toolName ?? '').startsWith(PHONE_TOOL_PREFIX) ? phone()?.status?.() : computer()?.status?.()) ?? {};
538
+ return vm.publicLiveViewUrl || vm.liveViewUrl || '';
539
+ };
540
+ const hers = (agent) => { const s = agent?.session; return Boolean(s?.id) && (isDotSession(s.id, s.header?.cwd) || isErrand(s.id) || turns.has(s.id)); };
541
+ const EXPIRED = Symbol('expired'), WITHDRAWN = Symbol('withdrawn');
542
+ ctx.on('approval/request', async (req, next) => {
543
+ if (!hers(req.agent)) return next();
544
+ const id = req.agent.session.id;
545
+ const key = req.callId ?? Symbol('approval');
546
+ const a = approvals.get(key) ?? { session: id, tool: String(req.toolName ?? ''), reason: String(req.reason ?? ''), since: Date.now() };
547
+ approvals.set(key, a);
548
+ const wait = Number(cfg.approvalWaitMs) || 0;
549
+ const minutes = wait > 0 ? Math.max(1, Math.round(wait / 60000)) : 0;
550
+ a.notified = true;
551
+ void im.send(approvalNotice({ tool: req.toolName, reason: req.reason, link: liveLink(req.toolName), minutes }), 'plain');
552
+ audit('approval-notified', { session: id, tool: req.toolName, errand: isErrand(id) });
553
+ if (!wait) { try { return await next(); } finally { approvals.delete(key); } }
554
+ let timer, onAbort;
555
+ const expired = new Promise((r) => {
556
+ timer = setTimeout(() => r(EXPIRED), wait); timer.unref?.();
557
+ onAbort = () => r(WITHDRAWN);
558
+ req.signal?.addEventListener?.('abort', onAbort, { once: true });
559
+ });
560
+ try {
561
+ const out = await Promise.race([Promise.resolve().then(() => next()), expired]);
562
+ if (out === WITHDRAWN) return 'cancelled';
563
+ if (out !== EXPIRED) return out;
564
+ a.timedOutAt = Date.now();
565
+ const t = turns.get(id);
566
+ if (t) { t.approvalTimedOutAt = a.timedOutAt; t.doing = `${shortTool(req.toolName)}(审批过期)`; }
567
+ if (req.callId !== undefined) expiredCalls.set(req.callId, minutes);
568
+ audit('approval-timeout', { session: id, tool: req.toolName, waitedMs: wait, errand: isErrand(id) });
569
+ void im.send(`⌛ dot: ${req.toolName} 的审批 ${minutes} 分钟没人点,过期了,当拒绝处理——她放下了这步。`, 'plain');
570
+ return 'rejected';
571
+ } finally {
572
+ clearTimeout(timer); req.signal?.removeEventListener?.('abort', onAbort);
573
+ approvals.delete(key);
574
+ }
575
+ }, { prepend: true });
576
+ // dsh words a rejection as "the user rejected tool …": an expired one says what happened instead.
577
+ ctx.on('tools/post-execute', async (exec, result, next) => {
578
+ const minutes = expiredCalls.get(exec?.callId);
579
+ if (minutes === undefined) return next();
580
+ expiredCalls.delete(exec.callId);
581
+ const d = await next();
582
+ return { kind: 'block', feedback: [{ type: 'text', text: approvalTimeoutText(minutes) }], ...(d?.additionalContexts?.length ? { additionalContexts: d.additionalContexts } : {}) };
583
+ });
584
+
498
585
  // Working rules are a system-prompt section for sessions in <home> (static per session, so the
499
586
  // cached prefix holds). The silence rule is additionally put in front of the model on the turn a
500
587
  // schedule wakes, as a dynamic context; only those turns get it.
@@ -562,6 +649,16 @@ export function apply(ctx, config = {}) {
562
649
  let deliverTracked; let phoneCheckNow; // assigned below (phone check), used by flush/releaseHeld
563
650
  // Conversations (the owner, QQ, WeChat) wake her conversation; every other app's notification is an errand.
564
651
  const isConversation = (n) => n.fromOwner || cfg.conversationApps.includes(n.pkg);
652
+ /**
653
+ * Her agent for a session: the live agent loop from ctx.agents (steer/inject/cancel) when it is
654
+ * running; otherwise the session controller's resolveAgent — the client API layer, whose handle on
655
+ * the desktop host only offers followup — which also loads a session that is not live.
656
+ */
657
+ const resolveLive = async (id) => {
658
+ const live = ctx.get('agents')?.get?.(id);
659
+ if (typeof live?.followup === 'function') return { agent: live };
660
+ return ctx.get('sessionController')?.resolveAgent(id);
661
+ };
565
662
  const deliver = (all, whileBusy, target) => {
566
663
  const controller = ctx.get('sessionController');
567
664
  const id = target ?? lastSession;
@@ -570,7 +667,10 @@ export function apply(ctx, config = {}) {
570
667
  const fromOwner = all.filter((n) => n.fromOwner);
571
668
  const items = all.filter((n) => !n.fromOwner);
572
669
  waking = waking.then(async () => {
573
- const found = await controller.resolveAgent(id);
670
+ // The live agent loop (ctx.agents) has steer/inject/cancel; the session controller's
671
+ // resolveAgent is the client API layer and hands back a thinner handle (followup only on the
672
+ // desktop host) — it is the fallback that also loads a session that is not live.
673
+ const found = await resolveLive(id);
574
674
  if (!found || 'error' in found) { audit('notification-dropped', { pkgs, why: found?.error?.message ?? 'session not found' }); return; }
575
675
  // The owner's words, exactly as typed (several messages → several lines), as human input.
576
676
  if (fromOwner.length) toOwnerAgent(found.agent, id, fromOwner);
@@ -597,6 +697,7 @@ export function apply(ctx, config = {}) {
597
697
  agentShapeLogged = true;
598
698
  const methods = [...new Set([...Object.keys(agent), ...Object.getOwnPropertyNames(Object.getPrototypeOf(agent) ?? {})])].filter((k) => typeof agent[k] === 'function');
599
699
  logger.info(`her agent handle offers: ${methods.join(', ')} (busy now: ${busy}, open turns: ${[...turns.keys()].map((k) => k.slice(0, 16)).join(' ') || 'none'})`);
700
+ audit('agent-handle', { methods, busy, openTurns: turns.size });
600
701
  }
601
702
  const message = createUserMessage({ content: contentFor(ownerWords(items, Date.now(), { whileBusy: via !== 'followup' }), items), source: ownerSource() });
602
703
  try {
@@ -749,17 +850,62 @@ export function apply(ctx, config = {}) {
749
850
  if (!controller) return;
750
851
  lastWakeAt = Date.now();
751
852
  waking = waking.then(async () => {
752
- const main = await controller.resolveAgent(lastSession);
853
+ const main = await resolveLive(lastSession);
753
854
  // She is on a long task: the goal driver brings her back round after round; don't cut in.
754
855
  if (main && !('error' in main) && goalActive(main.agent)) { audit('phone-check-skipped', { why: 'goal active' }); return; }
755
856
  const target = (await ensureErrand()) || lastSession;
756
- const found = target === lastSession ? main : await controller.resolveAgent(target);
857
+ const found = target === lastSession ? main : await resolveLive(target);
757
858
  if (!found || 'error' in found) return;
758
859
  found.agent.followup(createUserMessage({ content: [{ type: 'text', text: phoneCheckText() }], source: PHONE_CHECK_SOURCE }));
759
860
  audit('phone-check', { session: target, errand: target !== lastSession });
760
861
  }).catch((err) => logger.warn(`phone check failed: ${err.message}`));
761
862
  };
762
- ctx.effect(() => { const timer = setInterval(phoneCheck, 60000); return () => clearInterval(timer); }, 'dsh-dot: phone check');
863
+ // Turn watchdog: a turn of hers with no session event for turnStallMs is stalled (audited once).
864
+ // A stalled errand is given up after errandStallMs — cancelled keeping its inbox, what was held for it
865
+ // released, a note in her conversation, and the next errand gets a fresh session. Her conversation
866
+ // is never cancelled: he is told once per turn (unless he was already told about its approval).
867
+ const pendingApproval = (id) => { let first; for (const a of approvals.values()) if (a.session === id && (!first || a.since < first.since)) first = a; return first; };
868
+ const doingOf = (t, a) => (a ? `等 ${shortTool(a.tool)} 的审批` : t.doing || (t.said ? t.said.replace(/\s+/g, ' ').slice(0, 60) : '') || '(不清楚)');
869
+ const noteOrigin = (o) => (o === 'phone-notification' ? 'notification' : o || 'other');
870
+ const abandonErrand = (id, t, idle) => {
871
+ const doing = doingOf(t, pendingApproval(id));
872
+ let cancelled = false;
873
+ try {
874
+ const agent = ctx.get('agents')?.get?.(id);
875
+ if (typeof agent?.cancel === 'function') { agent.cancel({ kind: 'hook', reason: 'dot-watchdog' }, { keepInbox: true }); cancelled = true; }
876
+ } catch (err) { logger.warn(`errand cancel failed: ${err.message}`); }
877
+ turns.delete(id);
878
+ if (errandId === id) { errandId = ''; store.set('errandSession', ''); }
879
+ pastErrands.add(id); store.set('pastErrands', [...pastErrands].slice(-20));
880
+ audit('errand-cancelled', { session: id, idleMs: idle, cancelled, doing });
881
+ const r = setTimeout(() => { void releaseHeld(id); }, 50); r.unref?.();
882
+ void noteToConversation(noteOrigin(t.origin), errandStalledText(doing, Math.round(idle / 60000)));
883
+ };
884
+ const turnInfo = (id, now = Date.now()) => {
885
+ const t = turns.get(id);
886
+ if (!t) return null;
887
+ const a = pendingApproval(id);
888
+ return { session: id, errand: isErrand(id), conversation: id === lastSession, startedAt: t.startedAt, lastEventAt: t.lastEventAt, doing: doingOf(t, a), ...turnState(t, { now, turnStallMs: cfg.turnStallMs, approval: a }) };
889
+ };
890
+ const watchTurns = (now = Date.now()) => {
891
+ if (!(cfg.turnStallMs > 0)) return;
892
+ for (const [id, t] of [...turns]) {
893
+ const idle = now - (t.lastEventAt ?? t.startedAt);
894
+ if (idle < cfg.turnStallMs) continue;
895
+ const a = pendingApproval(id);
896
+ if (!t.stallAudited) { t.stallAudited = true; audit('turn-stalled', { session: id, errand: isErrand(id), idleMs: idle, doing: doingOf(t, a), ...(a ? { approval: a.tool } : {}) }); }
897
+ if (isErrand(id)) {
898
+ // An approval still inside its own wait is left to expire first.
899
+ const approvalDone = !a || (cfg.approvalWaitMs > 0 && now - a.since >= cfg.approvalWaitMs);
900
+ if (cfg.errandStallMs > 0 && idle >= cfg.errandStallMs && approvalDone) abandonErrand(id, t, idle);
901
+ continue;
902
+ }
903
+ if (id !== lastSession || t.ownerTold || a?.notified) continue;
904
+ t.ownerTold = true;
905
+ void im.send(`⏳ dot: 她这一轮 ${Math.round(idle / 60000)} 分钟没动静了(最后在做:${doingOf(t, a)})。没替她取消;要停就在 DeepSeek Harness 里点停止。`, 'plain');
906
+ }
907
+ };
908
+ ctx.effect(() => { const timer = setInterval(() => { watchTurns(); phoneCheck(); }, 60000); return () => clearInterval(timer); }, 'dsh-dot: turn watchdog + phone check');
763
909
  phoneCheckNow = phoneCheck;
764
910
  ctx.inject(['dshPhone'], (c) => c.effect(() => c.dshPhone.onStatus?.((s) => {
765
911
  if (s.state === 'error') void im.send(`⚠️ dot: 手机出错\n${s.error ?? '未知错误'}\n日志:~/.dsh/dsh-phone.log`, 'plain');
@@ -769,6 +915,18 @@ export function apply(ctx, config = {}) {
769
915
  const prompts = promptsPage({ home, port: Number(cfg.promptsPort) || 7870 });
770
916
  ctx.effect(() => () => { void prompts.stop(); }, 'dsh-dot: prompts page');
771
917
 
918
+ // /dot: what is waiting and what is stuck, one line each.
919
+ const mins = (ms) => `${Math.floor(ms / 60000)} min`;
920
+ const statusLiveness = (now = Date.now()) => {
921
+ const who = (id) => `${isErrand(id) ? 'errand' : id === lastSession ? 'her conversation' : 'session'} ${id.slice(0, 16)}`;
922
+ const out = [...approvals.values()].map((a) => `approval waiting: ${shortTool(a.tool)} in ${who(a.session)} · ${mins(now - a.since)}${cfg.approvalWaitMs > 0 ? ` of ${mins(cfg.approvalWaitMs)}` : ''}${a.timedOutAt ? ' · timed out' : ''}`);
923
+ for (const id of turns.keys()) {
924
+ const t = turnInfo(id, now);
925
+ if (t && (t.state === 'stalled' || t.state === 'timed-out')) out.push(`stalled turn: ${who(id)} · no event for ${mins(t.idleMs)} · ${t.state === 'timed-out' ? 'after an approval timed out · ' : ''}last: ${t.doing}${t.errand ? ` · given up at ${mins(cfg.errandStallMs)}` : ' · not cancelled'}`);
926
+ }
927
+ return out.length ? out : [`liveness: no approval waiting, no stalled turn (approval wait ${cfg.approvalWaitMs > 0 ? mins(cfg.approvalWaitMs) : 'unlimited'}, stalled after ${mins(cfg.turnStallMs)}, errand given up after ${mins(cfg.errandStallMs)})`];
928
+ };
929
+
772
930
  // /dot
773
931
  // The command registry can come up after dot, so register through a child that waits for it.
774
932
  ctx.inject(['commands'], (commandCtx) => {
@@ -800,6 +958,7 @@ export function apply(ctx, config = {}) {
800
958
  // Where his next message goes: when she "does not answer", look here first.
801
959
  `her conversation: ${lastSession ? `${lastSession}${turns.has(lastSession) ? ' (in a turn)' : ''}` : '(none yet: say something to her in a session under home)'} · errand: ${errandId || '(none)'}`,
802
960
  `his messages: wait ${cfg.ownerQuietMs} ms of quiet, at most ${cfg.ownerMaxWaitMs} ms (${cfg.ownerTypingMaxMs} ms while typing) · mid-turn: steered · qq_send to him held ≤${cfg.ownerDenyMax}×/turn while unread${ownerBatch.length ? ` · ${ownerBatch.length} waiting` : ''}`,
961
+ ...statusLiveness(),
803
962
  `budget: ${ctx.get('budget') ? (blocked.length ? `BLOCKED (${blocked.join(', ')})` : 'ok') : 'not installed (optional)'}`,
804
963
  `schedule: ${ctx.get('schedule') ? 'ok' : 'not installed'}`,
805
964
  ];
@@ -818,6 +977,12 @@ export function apply(ctx, config = {}) {
818
977
  stats,
819
978
  isErrand,
820
979
  busy: (id) => turns.has(id),
980
+ /** One open turn as the watchdog sees it (turnState + who and what), or null. */
981
+ turn: (id) => turnInfo(id),
982
+ /** Every open turn of hers. */
983
+ turns: () => [...turns.keys()].map((id) => turnInfo(id)).filter(Boolean),
984
+ /** Approvals waiting in her sessions. */
985
+ approvals: () => [...approvals.values()].map((a) => ({ session: a.session, tool: a.tool, reason: a.reason, since: a.since, errand: isErrand(a.session), ...(a.timedOutAt ? { timedOutAt: a.timedOutAt } : {}) })),
821
986
  /** His messages waiting in the buffer; flushOwner() delivers them now. */
822
987
  ownerPending: () => ownerBatch.length,
823
988
  flushOwner: () => flushOwner(),
package/src/dot/panel.js CHANGED
@@ -25,6 +25,7 @@ function activityOf(dot, opts = {}) {
25
25
  limit: Math.max(1, Math.min(100, Number(opts.scenes) || DEFAULT_SCENES)),
26
26
  busy: (id) => Boolean(dot?.busy?.(id)),
27
27
  isErrand: (id) => Boolean(dot?.isErrand?.(id)),
28
+ turnOf: (id) => dot?.turn?.(id) ?? null,
28
29
  });
29
30
  }
30
31
 
@@ -45,7 +46,7 @@ export async function collectState(ctx, opts = {}) {
45
46
  qq: qq ? await safe(() => qq.status()) : null,
46
47
  computer: computer ? await safe(() => computer.status()) : null,
47
48
  },
48
- dot: dot ? { session: dot.session?.() || '', errand: dot.errandId?.() || '', today: dot.stats?.() ?? null } : null,
49
+ dot: dot ? { session: dot.session?.() || '', errand: dot.errandId?.() || '', today: dot.stats?.() ?? null, turns: dot.turns?.() ?? [], approvals: dot.approvals?.() ?? [] } : null,
49
50
  interlude: interlude ? await safe(() => interlude.status()) : null,
50
51
  memory: memory ? await safe(() => memory.panel()) : null,
51
52
  // The last N scenes (one wake until its turn ended), read back from the records that exist.
@@ -81,7 +82,7 @@ details summary{cursor:pointer;color:var(--mute)}
81
82
  .scene>summary::-webkit-details-marker{display:none}
82
83
  .smeta{display:flex;flex-wrap:wrap;gap:4px;align-items:baseline;min-width:0}.smeta b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}
83
84
  .sprev{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
84
- .st{font-size:11px;padding:0 6px;border-radius:999px;border:1px solid var(--line);color:var(--mute)}.st.run{color:var(--ok);border-color:var(--ok)}.st.fail{color:var(--bad);border-color:var(--bad)}
85
+ .st{font-size:11px;padding:0 6px;border-radius:999px;border:1px solid var(--line);color:var(--mute)}.st.run{color:var(--ok);border-color:var(--ok)}.st.fail{color:var(--bad);border-color:var(--bad)}.st.warn{color:var(--warn);border-color:var(--warn)}
85
86
  .tag{display:inline-block;font-size:11px;padding:0 5px;margin-right:4px;border-radius:4px;background:var(--line);color:var(--fg);white-space:nowrap}
86
87
  .sbody{margin:4px 0 6px;padding-left:8px;border-left:2px solid var(--line)}
87
88
  .acts{list-style:none;padding:0;margin:2px 0}.acts li{margin:3px 0;word-break:break-word}
@@ -107,12 +108,12 @@ const badge=(cls,label,text)=>'<span class="badge '+cls+'"><i class="dotc"></i>'
107
108
  const tile=(n,label)=>'<div class="tile"><b>'+esc(n)+'</b><span>'+esc(label)+'</span></div>';
108
109
  const bar=(v,max)=>'<div class="bar"><i style="width:'+Math.min(100,Math.round(100*(v||0)/(max||1)))+'%"></i></div>';
109
110
  const ZH=true; // the rest of this page is Chinese; Electron's navigator.language said en on a Chinese Mac
110
- const T=ZH?{title:(n)=>'最近 '+n+' 场',none:'还没有记录(她被叫醒、幕间、玩过之后这里会出现)',run:'进行中',done:'完成',fail:'出错',quiet:'没出声',tools:'工具',model:'模型',times:' 次',tin:'token 入',tout:'出',
111
+ const T=ZH?{title:(n)=>'最近 '+n+' 场',none:'还没有记录(她被叫醒、幕间、玩过之后这里会出现)',run:'进行中',done:'完成',fail:'出错',stalled:(m)=>'卡住 '+m+' 分钟',approval:(m)=>'等审批 '+m+' 分钟',timedOut:'已超时',quiet:'没出声',tools:'工具',model:'模型',times:' 次',tin:'token 入',tout:'出',
111
112
  src:{owner:'你',qq:'QQ',phone:'手机',check:'拿手机',interlude:'幕间',schedule:'定时',play:'玩'},
112
113
  phase:{advance:'推进','follow-up':'跟进',intent:'打算到点',seed:'开场',diary:'日记'},
113
114
  act:{qq:'回 QQ',reply:'回你',image:'发图',sticker:'存表情',saw:'看了',like:'点赞',comment:'评论',follow:'关注',play:'玩',install:'装 App',diary:'写日记',interlude:'幕间',contact:'主动联系',approval:'审批',look:'去看'},
114
115
  via:{web:'web',phone:'手机',computer:'电脑'}}
115
- :{title:(n)=>'Last '+n+' scenes',none:'Nothing yet (scenes appear once she is woken, has an interlude round, or plays)',run:'running',done:'done',fail:'failed',quiet:'stayed quiet',tools:'tools',model:'model',times:'×',tin:'tokens in',tout:'out',
116
+ :{title:(n)=>'Last '+n+' scenes',none:'Nothing yet (scenes appear once she is woken, has an interlude round, or plays)',run:'running',done:'done',fail:'failed',stalled:(m)=>'stalled '+m+' min',approval:(m)=>'approval '+m+' min',timedOut:'timed out',quiet:'stayed quiet',tools:'tools',model:'model',times:'×',tin:'tokens in',tout:'out',
116
117
  src:{owner:'You',qq:'QQ',phone:'Phone',check:'Picked up phone',interlude:'Interlude',schedule:'Scheduled',play:'Play'},
117
118
  phase:{advance:'advance','follow-up':'follow-up',intent:'intent',seed:'seed',diary:'diary'},
118
119
  act:{qq:'QQ reply',reply:'Replied',image:'Image',sticker:'Kept sticker',saw:'Saw',like:'Like',comment:'Comment',follow:'Follow',play:'Play',install:'Install app',diary:'Diary',interlude:'Interlude',contact:'Reached out',approval:'Approval',look:'Looked'},
@@ -128,7 +129,7 @@ function renderActivity(act){
128
129
  if(!list||!list.length){$('activity').innerHTML='<span class="mute">'+esc(T.none)+'</span>';return}
129
130
  $('activity').innerHTML=list.map((sc)=>{
130
131
  const id=sc.at+'|'+sc.session+'|'+sc.source.kind;
131
- const st=sc.status==='running'?'<span class="st run">'+T.run+'</span>':sc.status==='failed'?'<span class="st fail">'+T.fail+'</span>':'<span class="st">'+T.done+'</span>';
132
+ const st=sc.status==='running'?'<span class="st run">'+T.run+'</span>':sc.status==='stalled'?'<span class="st fail">'+esc(T.stalled(sc.minutes||0))+'</span>':sc.status==='approval'?'<span class="st warn">'+esc(T.approval(sc.minutes||0))+'</span>':sc.status==='timed-out'?'<span class="st fail">'+T.timedOut+'</span>':sc.status==='failed'?'<span class="st fail">'+T.fail+'</span>':'<span class="st">'+T.done+'</span>';
132
133
  const first=sc.actions[0];
133
134
  const prev=first?'<span class="tag">'+esc(actLabel(first))+'</span>'+esc(first.text)+(sc.actions.length>1?' <span class="mute">+'+(sc.actions.length-1)+'</span>':''):'<span class="mute">'+esc(sc.quiet?T.quiet:(sc.trigger||''))+'</span>';
134
135
  const f=sc.stats||{},foot=[];
@@ -153,6 +154,7 @@ function render(s){
153
154
  if(d.computer) b+=badge(d.computer.state==='ready'?'ok':d.computer.state==='error'?'bad':'warn','电脑',cstate[d.computer.state]||d.computer.state||'');
154
155
  if(d.computer&&(d.computer.gatewayOpen||d.computer.portRelayOpen)) b+=badge('bad','电脑网关',d.computer.gatewayOpen?'无密钥开放':'端口转发未关');
155
156
  if(m&&m.conversation) b+=badge(m.conversation.session?'ok':'warn','她的对话','第 '+m.gen+' 段 · '+fmt(m.conversation.tokens)+' / '+fmt(m.conversation.handoffAt)+' token');
157
+ for(const t of (dot&&dot.turns)||[]){if(t.state==='running')continue;const who=t.errand?'跑腿':t.conversation?'她的对话':'会话';const mins=Math.floor((t.state==='approval'?t.waitMs:t.idleMs)/60000);b+=badge(t.state==='approval'?'warn':'bad',who,t.state==='approval'?'等审批 '+mins+' 分钟 · '+(t.tool||''):t.state==='timed-out'?'审批已超时,卡住 '+mins+' 分钟':'卡住 '+mins+' 分钟 · '+(t.doing||''));}
156
158
  $('badges').innerHTML=b||'<span class="mute">没有组件在线</span>';
157
159
  if(it){
158
160
  const st=it.state||{};
@@ -15,7 +15,7 @@
15
15
  // continuity snapshot (state.json), intents; slow change in who she is lives in dsh-dot/memory's self bank
16
16
  // (intents.json). Not ported: long-term facts with retrieval, Alter (mood drift), Perspective,
17
17
  // multi-participant stories, seen/delayed replies inside a conversation.
18
- import { VM_TOOL_PREFIX, PHONE_TOOL_PREFIX } from '../tool-prefixes.js';
18
+ import { VM_TOOL_PREFIX, PHONE_TOOL_PREFIX, PHONE_ZOOM_TOOL } from '../tool-prefixes.js';
19
19
  import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
20
20
  import { homedir } from 'node:os';
21
21
  import { join, relative, isAbsolute } from 'node:path';
@@ -584,7 +584,7 @@ export function apply(ctx, config = {}) {
584
584
  if (!sessionId || !observing.has(sessionId)) return next();
585
585
  const vmTool = exec.name.startsWith(VM_TOOL_PREFIX) ? exec.name.slice(VM_TOOL_PREFIX.length) : '';
586
586
  const phoneTool = exec.name.startsWith(PHONE_TOOL_PREFIX) ? exec.name.slice(PHONE_TOOL_PREFIX.length) : '';
587
- if ((vmTool && cfg.vmObservationTools.includes(vmTool)) || (phoneTool && cfg.phoneObservationTools.includes(phoneTool))) return { kind: 'allow' };
587
+ if ((vmTool && cfg.vmObservationTools.includes(vmTool)) || (phoneTool && cfg.phoneObservationTools.includes(phoneTool)) || exec.name === PHONE_ZOOM_TOOL) return { kind: 'allow' };
588
588
  audit('observation-refused', { session: sessionId, tool: exec.name });
589
589
  return { kind: 'deny', reason: `dsh-interlude: this is an observation — looking only, nothing to approve. "${exec.name}" is not available here; look with ${cfg.vmObservationTools.slice(0, 2).join(', ')}, ${cfg.phoneObservationTools.slice(5, 7).join(', ')}… or write down what you saw.` };
590
590
  }, { prepend: true });
@@ -4,7 +4,7 @@
4
4
  // Google's repository (after the SDK license is accepted), writes the AVD itself (no Java, no
5
5
  // sdkmanager), boots it, and mounts the MCP server once the phone answers. The phone's window is its
6
6
  // live view; state (apps, logins) lives in the AVD's data partition and survives dsh restarts.
7
- import { PHONE_SERVER, PHONE_TOOL_PREFIX } from '../tool-prefixes.js';
7
+ import { PHONE_SERVER, PHONE_TOOL_PREFIX, PHONE_ZOOM_TOOL } from '../tool-prefixes.js';
8
8
  import { spawn, execFile } from 'node:child_process';
9
9
  import { chmodSync, closeSync, readdirSync, createWriteStream, existsSync, openSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, appendFileSync } from 'node:fs';
10
10
  import { homedir, platform, arch as osArch } from 'node:os';
@@ -12,7 +12,7 @@ import { join, dirname } from 'node:path';
12
12
  import { createRequire } from 'node:module';
13
13
  import { pipeline } from 'node:stream/promises';
14
14
  import { Readable, Transform } from 'node:stream';
15
- import { inflateSync } from 'node:zlib';
15
+ import { deflateSync, inflateSync } from 'node:zlib';
16
16
  import { createAudit } from '../computer/audit.js';
17
17
  import { systemProxyEnv } from '../computer/backends/proxy.js';
18
18
  import { mountLiveView, LIVE_VIEW_PATH } from './live-view.js';
@@ -219,39 +219,87 @@ async function unzip(zip, into) {
219
219
  }
220
220
 
221
221
  /**
222
- * Is this PNG one flat colour, all white or all black? (`screencap` gives that mid-transition or with
223
- * the screen off.) Decodes 8-bit RGB/RGBA, the screencap formats; anything else counts as not blank.
222
+ * Decode an 8-bit RGB/RGBA, non-interlaced PNG (the screencap formats) → { width, height, bpp, pixels }
223
+ * with `pixels` the unfiltered rows; anything else → null. CRCs are not checked.
224
224
  */
225
- export function blankPng(buf) {
225
+ export function decodePng(buf) {
226
226
  try {
227
- if (!Buffer.isBuffer(buf) || buf.length < 33 || buf.readUInt32BE(0) !== 0x89504e47) return false;
227
+ if (!Buffer.isBuffer(buf) || buf.length < 33 || buf.readUInt32BE(0) !== 0x89504e47) return null;
228
228
  const width = buf.readUInt32BE(16), height = buf.readUInt32BE(20), depth = buf[24], color = buf[25], interlace = buf[28];
229
229
  const bpp = color === 6 ? 4 : color === 2 ? 3 : 0;
230
- if (!bpp || depth !== 8 || interlace || !width || !height) return false;
230
+ if (!bpp || depth !== 8 || interlace || !width || !height) return null;
231
231
  const idat = [];
232
232
  for (let o = 8; o + 8 <= buf.length;) { const len = buf.readUInt32BE(o), type = buf.toString('latin1', o + 4, o + 8); if (type === 'IDAT') idat.push(buf.subarray(o + 8, o + 8 + len)); if (type === 'IEND') break; o += 12 + len; }
233
233
  const raw = inflateSync(Buffer.concat(idat));
234
234
  const stride = width * bpp;
235
- if (raw.length < (stride + 1) * height) return false;
236
- let prev = Buffer.alloc(stride), first = -1;
235
+ if (raw.length < (stride + 1) * height) return null;
236
+ const pixels = Buffer.alloc(stride * height);
237
+ let prev = Buffer.alloc(stride);
237
238
  for (let y = 0; y < height; y++) {
238
- const f = raw[y * (stride + 1)], line = Buffer.from(raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1)));
239
- for (let i = 0; i < stride; i++) {
240
- if (!f) break;
239
+ const f = raw[y * (stride + 1)], line = pixels.subarray(y * stride, (y + 1) * stride);
240
+ raw.copy(line, 0, y * (stride + 1) + 1, (y + 1) * (stride + 1));
241
+ if (f) for (let i = 0; i < stride; i++) {
241
242
  const a = i >= bpp ? line[i - bpp] : 0, b = prev[i], c = i >= bpp ? prev[i - bpp] : 0;
242
243
  let add = f === 1 ? a : f === 2 ? b : f === 3 ? (a + b) >> 1 : 0;
243
244
  if (f === 4) { const p = a + b - c, pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c); add = pa <= pb && pa <= pc ? a : pb <= pc ? b : c; }
244
245
  line[i] = (line[i] + add) & 0xff;
245
246
  }
246
- for (let x = 0; x < stride; x += bpp) {
247
- const r = line[x], g = line[x + 1], bl = line[x + 2];
248
- if (r !== g || g !== bl || (r !== 0 && r !== 255)) return false;
249
- if (first < 0) first = r; else if (r !== first) return false;
250
- }
251
247
  prev = line;
252
248
  }
253
- return true;
254
- } catch { return false; }
249
+ return { width, height, bpp, pixels };
250
+ } catch { return null; }
251
+ }
252
+
253
+ const CRC = Array.from({ length: 256 }, (_, n) => { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; return c >>> 0; });
254
+ const crc32 = (buf) => { let c = 0xffffffff; for (const b of buf) c = CRC[(c ^ b) & 0xff] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; };
255
+ /** Encode 8-bit RGB (bpp 3) or RGBA (bpp 4) rows as a PNG. */
256
+ export function encodePng({ width, height, bpp, pixels }) {
257
+ const chunk = (type, data) => { const t = Buffer.from(type, 'latin1'), len = Buffer.alloc(4), crc = Buffer.alloc(4); len.writeUInt32BE(data.length); crc.writeUInt32BE(crc32(Buffer.concat([t, data]))); return Buffer.concat([len, t, data, crc]); };
258
+ const ihdr = Buffer.alloc(13);
259
+ ihdr.writeUInt32BE(width, 0); ihdr.writeUInt32BE(height, 4); ihdr[8] = 8; ihdr[9] = bpp === 4 ? 6 : 2;
260
+ const stride = width * bpp, raw = Buffer.alloc((stride + 1) * height);
261
+ for (let y = 0; y < height; y++) pixels.copy(raw, y * (stride + 1) + 1, y * stride, (y + 1) * stride);
262
+ return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', ihdr), chunk('IDAT', deflateSync(raw)), chunk('IEND', Buffer.alloc(0))]);
263
+ }
264
+
265
+ export const ZOOM_MAX_SCALE = 3;
266
+ const ZOOM_LONG_EDGE = 1200; // default output size: the long edge, unless scale says otherwise
267
+ /**
268
+ * Crop {x, y, w, h} (screen px; clamped to the image) out of a PNG and enlarge it `scale` times
269
+ * (bilinear; ≤ ZOOM_MAX_SCALE; default: as large as fits ZOOM_LONG_EDGE, at least 1×).
270
+ * → { png, x, y, w, h, scale, width, height } or { error }.
271
+ */
272
+ export function zoomPng(buf, { x, y, w, h, scale } = {}) {
273
+ const img = decodePng(buf);
274
+ if (!img) return { error: 'the screenshot is not a PNG this can read' };
275
+ const x0 = Math.max(0, Math.min(img.width - 1, Math.round(Number(x) || 0))), y0 = Math.max(0, Math.min(img.height - 1, Math.round(Number(y) || 0)));
276
+ const cw = Math.max(1, Math.min(img.width - x0, Math.round(Number(w) || 0))), ch = Math.max(1, Math.min(img.height - y0, Math.round(Number(h) || 0)));
277
+ const k = Math.min(ZOOM_MAX_SCALE, Math.max(1, Number(scale) > 0 ? Number(scale) : ZOOM_LONG_EDGE / Math.max(cw, ch)));
278
+ const ow = Math.max(1, Math.round(cw * k)), oh = Math.max(1, Math.round(ch * k)), { bpp } = img;
279
+ const out = Buffer.alloc(ow * oh * bpp), src = img.pixels, stride = img.width * bpp;
280
+ for (let j = 0; j < oh; j++) {
281
+ const sy = Math.min(ch - 1, Math.max(0, (j + 0.5) / k - 0.5)), y1 = Math.floor(sy), y2 = Math.min(ch - 1, y1 + 1), fy = sy - y1;
282
+ for (let i = 0; i < ow; i++) {
283
+ const sx = Math.min(cw - 1, Math.max(0, (i + 0.5) / k - 0.5)), x1 = Math.floor(sx), x2 = Math.min(cw - 1, x1 + 1), fx = sx - x1;
284
+ const a = (y0 + y1) * stride + (x0 + x1) * bpp, b = (y0 + y1) * stride + (x0 + x2) * bpp, c = (y0 + y2) * stride + (x0 + x1) * bpp, d = (y0 + y2) * stride + (x0 + x2) * bpp;
285
+ for (let n = 0; n < bpp; n++) out[(j * ow + i) * bpp + n] = Math.round((src[a + n] * (1 - fx) + src[b + n] * fx) * (1 - fy) + (src[c + n] * (1 - fx) + src[d + n] * fx) * fy);
286
+ }
287
+ }
288
+ return { png: encodePng({ width: ow, height: oh, bpp, pixels: out }), x: x0, y: y0, w: cw, h: ch, scale: Math.round(k * 100) / 100, width: ow, height: oh };
289
+ }
290
+
291
+ /**
292
+ * Is this PNG one flat colour, all white or all black? (`screencap` gives that mid-transition or with
293
+ * the screen off.) Decodes 8-bit RGB/RGBA, the screencap formats; anything else counts as not blank.
294
+ */
295
+ export function blankPng(buf) {
296
+ const img = decodePng(buf);
297
+ if (!img) return false;
298
+ const { pixels, bpp } = img;
299
+ const first = pixels[0];
300
+ if (first !== 0 && first !== 255) return false;
301
+ for (let i = 0; i < pixels.length; i += bpp) if (pixels[i] !== first || pixels[i + 1] !== first || pixels[i + 2] !== first) return false;
302
+ return true;
255
303
  }
256
304
 
257
305
  /** One screenshot; a blank one (all white/black) is taken once more after `waitMs`. */
@@ -263,7 +311,21 @@ export async function screencapRetry(grab, { waitMs = 400, wait = sleep } = {})
263
311
  }
264
312
 
265
313
  /** Her system-prompt section about the phone (only while it is ready): the device, her number, accounts, how each app adds her stickers. */
266
- export const deviceText = (serial, number = '') => prompt('phone.device', { serial, phonePrefix: PHONE_TOOL_PREFIX, number: number ? prompt('phone.device.number', { number }) : '', stickers: prompt('phone.stickers') });
314
+ /**
315
+ * The phone section. Parts that only hold with a sibling component are said only when it is there
316
+ * (the phone also runs alone, next to someone else's character): notifications wake her only
317
+ * through dot, the sticker album is fed by qq, and "remember it" needs memory. Defaults: all on.
318
+ */
319
+ export const deviceText = (serial, number = '', has = {}) => {
320
+ const { dot = true, qq = true, memory = true } = has;
321
+ return prompt('phone.device', {
322
+ serial,
323
+ phonePrefix: PHONE_TOOL_PREFIX,
324
+ notify: prompt(dot ? 'phone.device.wake' : 'phone.device.no-wake'),
325
+ number: number ? prompt('phone.device.number', { number }) : '',
326
+ stickers: qq ? prompt('phone.stickers', { learned: memory ? prompt('phone.stickers.learned') : '' }) : '',
327
+ });
328
+ };
267
329
 
268
330
  /** A phone number as typed (spaces, dashes allowed); '' clears it. Throws on anything else. */
269
331
  export function parseNumber(s) {
@@ -658,7 +720,7 @@ export function apply(ctx, config = {}, deps = {}) {
658
720
  name: 'phone:device',
659
721
  order: 60,
660
722
  text: () => (phone.state === 'ready'
661
- ? deviceText(serial, cfg.number)
723
+ ? deviceText(serial, cfg.number, { dot: Boolean(ctx.get?.('dshDot')), qq: Boolean(ctx.get?.('dshQq')), memory: Boolean(ctx.get?.('dotMemory')) })
662
724
  : ''),
663
725
  }), 'dsh-dot/phone: device section');
664
726
  });
@@ -683,6 +745,34 @@ export function apply(ctx, config = {}, deps = {}) {
683
745
  }), 'dsh-dot/phone: account tool');
684
746
  });
685
747
 
748
+ // A part of the screen, enlarged: mobile-mcp only scales the whole screenshot down (scale ≤ 1, maxSize),
749
+ // so small text and details were cropped in the computer instead. The image goes through the
750
+ // attachment store, like mobile_take_screenshot's (dsh-mcp-client); without one, no zoom.
751
+ ctx.inject(['tools'], (scope) => {
752
+ scope.effect(() => scope.tools.register({
753
+ name: PHONE_ZOOM_TOOL,
754
+ description: '把手机屏幕的一块放大来看(现截一张)。x、y 是那块的左上角,w、h 是宽和高,单位是屏幕像素(和 mobile_list_elements_on_screen 的坐标一样);scale 是放大倍数,最多 3,不填就放到看得清的大小。小字、图里的细节看不清时用。',
755
+ parameters: { type: 'object', properties: { x: { type: 'number' }, y: { type: 'number' }, w: { type: 'number' }, h: { type: 'number' }, scale: { type: 'number', exclusiveMinimum: 0, maximum: ZOOM_MAX_SCALE } }, required: ['x', 'y', 'w', 'h'], additionalProperties: false },
756
+ output: {
757
+ schema: { type: 'object', properties: { error: { type: 'string' } }, additionalProperties: true },
758
+ render: (_a, v) => (v.error ? [{ type: 'text', text: `没放大成:${v.error}` }] : [{ type: 'text', text: `屏幕 (${v.x}, ${v.y}) 起 ${v.w}×${v.h},放大 ${v.scale} 倍:` }, { type: 'image', attachment: v.image }]),
759
+ },
760
+ async execute(args) {
761
+ if (!phone.isReady) return { error: `手机还没就绪(${phone.state})` };
762
+ const store = ctx.get?.('attachments');
763
+ if (typeof store?.saveImages !== 'function') return { error: '没有附件仓库(ctx.attachments),图传不过去;用 mobile_take_screenshot' };
764
+ try {
765
+ const z = zoomPng(await phone.screenshot(), args);
766
+ if (z.error) return { error: z.error };
767
+ const { png, ...at } = z;
768
+ const [image] = await store.saveImages([{ data: new Uint8Array(png), mediaType: 'image/png', name: 'phone-zoom' }]);
769
+ audit({ kind: 'phone-zoom', ...at, bytes: png.length });
770
+ return { ...at, image };
771
+ } catch (err) { return { error: err.message }; }
772
+ },
773
+ }), 'dsh-dot/phone: zoom tool');
774
+ });
775
+
686
776
  ctx.inject(['commands'], (scope) => {
687
777
  scope.effect(() => scope.commands.register({
688
778
  name: 'phone',
@@ -0,0 +1 @@
1
+ 没人批(等了 {minutes} 分钟没人点),这步先放下:换别的办法,或者以后再说。
@@ -0,0 +1 @@
1
+ 做到一半卡住了({minutes} 分钟没动静),放弃了:{doing}
@@ -0,0 +1 @@
1
+ 手机上的通知不会叫醒你:想知道有没有新消息,就自己打开手机看。
@@ -1,4 +1,4 @@
1
- 你有一部自己的手机:Android(设备 {serial},工具 {phonePrefix}*)。手机上来了通知(QQ 消息之类)会直接叫醒你,用不着定闹钟去看——但 App 开在前台时不会有通知,所以每次用完 App 记得按 HOME 回到桌面。用法:先 mobile_list_elements_on_screen 看屏幕上有什么(带坐标),再 mobile_click_on_screen_at_coordinates 点;看不清就 mobile_take_screenshot;mobile_launch_app 打开 App,mobile_press_button BACK/HOME 返回。这部手机没有应用商店:想要什么 App 就像人一样自己装——用手机上的浏览器打开官网下载安装包,点开安装(浏览器已被允许安装)。验证码、人脸、短信验证由用户来做:停下来告诉他,不要自己绕。
1
+ 你有一部自己的手机:Android(设备 {serial},工具 {phonePrefix}*)。{notify}用法:先 mobile_list_elements_on_screen 看屏幕上有什么(带坐标),再 mobile_click_on_screen_at_coordinates 点;看不清就 mobile_take_screenshot,截图里还看不清就用 phone_zoom 放大截图的一块,不用去电脑里裁图;mobile_launch_app 打开 App,mobile_press_button BACK/HOME 返回。这部手机没有应用商店:想要什么 App 就像人一样自己装——用手机上的浏览器打开官网下载安装包,点开安装(浏览器已被允许安装)。验证码、人脸、短信验证由用户来做:停下来告诉他,不要自己绕。
2
2
  {number}
3
3
  账号密码不要自己编、也不要记在记忆里:注册或登录前先 `account get <app>`,拿到手机号和密码;注册成功、或 App 逼你改了密码,马上 `account set` 记下来。
4
4
  {stickers}
@@ -0,0 +1 @@
1
+ 手机上来了通知(QQ 消息之类)会直接叫醒你,用不着定闹钟去看——但 App 开在前台时不会有通知,所以每次用完 App 记得按 HOME 回到桌面。
@@ -0,0 +1 @@
1
+ 第一次在某个 App 里做成了,用 memory 工具记到 self(学会了什么),下次就不用再摸。
@@ -2,4 +2,4 @@
2
2
  - QQ:聊天里别人发的表情长按 → 添加到表情;从相册发出去的图,发出后长按 → 添加到表情。加过的就在表情面板的"收藏"里。
3
3
  - 微信:聊天里的图或表情长按 → 添加表情。
4
4
  - 小黑盒:评论配图从相册选。
5
- 第一次在某个 App 里做成了,用 memory 工具记到 self(学会了什么),下次就不用再摸。
5
+ {learned}
@@ -9,3 +9,5 @@ export const PHONE_TOOL_PREFIX = `mcp__${PHONE_SERVER}__`;
9
9
  // SnowLuma's own MCP server (qq.js, backend 'snowluma'): her 219 OneBot actions, gated by qqToolGate.
10
10
  export const QQ_SERVER = 'dot-qq';
11
11
  export const QQ_TOOL_PREFIX = `mcp__${QQ_SERVER}__`;
12
+ // dot's own phone tool (phone.js): a part of the screen, enlarged. Read-only, so observation turns allow it.
13
+ export const PHONE_ZOOM_TOOL = 'phone_zoom';