dsh-dot-life 0.23.1 → 0.23.2
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/README.en.md +2 -1
- package/README.md +5 -4
- package/cordis.patch.yml +3 -2
- package/docs/DESIGN.md +12 -0
- package/docs/SETTINGS.md +21 -3
- package/docs/computer.md +2 -2
- package/docs/phone.md +5 -4
- package/package.json +1 -1
- package/src/computer/backends/docker.js +5 -0
- package/src/computer/backends/microsandbox.js +6 -0
- package/src/computer/backends/proxy.js +2 -2
- package/src/computer/docker.js +1 -1
- package/src/computer/subprocess.js +2 -1
- package/src/computer/vm.js +64 -12
- package/src/dot/core.js +11 -5
- package/src/interlude/core.js +11 -5
- package/src/llm-gate.js +420 -0
- package/src/memory/memory.js +3 -1
- package/src/page/api.js +7 -1
- package/src/page/page.js +27 -3
- package/src/phone/mcp-entry.cjs +31 -0
- package/src/phone/phone.js +39 -9
- package/src/qq/qq.js +4 -1
- package/src/settings-schema.js +8 -2
package/README.en.md
CHANGED
|
@@ -124,7 +124,8 @@ flowchart LR
|
|
|
124
124
|
## ⌨️ Commands
|
|
125
125
|
|
|
126
126
|
```text
|
|
127
|
-
/phone [doctor|accept|restart|screenshot]
|
|
127
|
+
/phone [on|off|doctor|accept|restart|screenshot]
|
|
128
|
+
/computer [on|off]
|
|
128
129
|
/interlude [now|advance|seed|preset <code>|canon]
|
|
129
130
|
/dot [test|check|doctor|prompts [stop]]
|
|
130
131
|
/dot memory [now|diary|handoff|recall …]
|
package/README.md
CHANGED
|
@@ -121,8 +121,8 @@ dsh plugin --profile desktop add github:Kevinwu901113/dsh-dot # 源码
|
|
|
121
121
|
<details>
|
|
122
122
|
<summary><b>第一次设置的完整说明</b></summary>
|
|
123
123
|
|
|
124
|
-
1. **手机**:`/phone accept` 后插件下载模拟器、platform-tools、系统镜像(约 2 GB,常见 10–30 分钟;进度在 `/phone` 和 dsh-dot
|
|
125
|
-
2. **装 App
|
|
124
|
+
1. **手机**:`/phone accept` 后插件下载模拟器、platform-tools、系统镜像(约 2 GB,常见 10–30 分钟;进度在 `/phone` 和 dsh-dot 面板里),装完自动开机;手机不弹自己的窗口,画面在 dsh 里看(左侧栏 dot 页面顶部的「看画面」,或右侧栏的手机标签),她会自己跟你说一声。装的过程中照常聊天,她不会等。存储大小建好后不能再改。`/phone` 看状态。
|
|
125
|
+
2. **装 App、登录**:在手机画面里像真手机一样操作,或者让她自己装(`mobile_install_app` 会弹审批)。登录、验证码、人脸由你亲手过,她遇到会停下来叫你。**用小号**,各平台条款都不允许自动化。
|
|
126
126
|
3. **人设**:`/interlude preset <分享码>`,或把 [`examples/canon.example.json`](examples/canon.example.json) 放到 `~/dot/interlude/canon.json`。
|
|
127
127
|
4. **她逛什么**:不用配。常见社区 App 的站点 → 包名表是内置的,只对她**自己装了**的 App 生效。其他 App 在 `cordis.patch.yml` 里给 `dot-interlude` 加 `phoneApps` / `playApps`。
|
|
128
128
|
5. **QQ**:详见 [docs/qq.md](docs/qq.md)。不想用协议端,也可以按 dsh-im 的说明接官方机器人。
|
|
@@ -145,7 +145,7 @@ dsh plugin --profile desktop add github:Kevinwu901113/dsh-dot # 源码
|
|
|
145
145
|
}
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
存储、作息、主动联系、群聊规则、省 token
|
|
148
|
+
存储、作息、主动联系、群聊规则、省 token、网络镜像、后台请求限速(聊天时报 429 就调 `llm.backgroundRpm`)……每一项怎么改、哪些只在新建手机 / 虚拟机时生效,都在 **[docs/SETTINGS.md](docs/SETTINGS.md)**。
|
|
149
149
|
|
|
150
150
|
> [!TIP]
|
|
151
151
|
> 懒得自己改?直接对 dsh 说「按 docs/SETTINGS.md 把 dsh-dot 的手机存储改成 32 GB」。文档里有写给 agent 的规则,dsh 或其他 agent 照着就能改对。
|
|
@@ -204,7 +204,8 @@ flowchart LR
|
|
|
204
204
|
## ⌨️ 命令与文件
|
|
205
205
|
|
|
206
206
|
```text
|
|
207
|
-
/phone [doctor|accept|restart|screenshot]
|
|
207
|
+
/phone [on|off|doctor|accept|restart|screenshot]
|
|
208
|
+
/computer [on|off]
|
|
208
209
|
/interlude [now|advance|seed|preset <code>|canon]
|
|
209
210
|
/dot [test|check|doctor|prompts [stop]]
|
|
210
211
|
/dot memory [now|diary|handoff|recall …]
|
package/cordis.patch.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-dot: one plugin, seven components. The character lives on her own devices.
|
|
2
2
|
# phone — her phone: an Android emulator this plugin installs, boots and keeps alive;
|
|
3
|
-
# tools mcp__dot-phone__* (mobile-mcp over adb).
|
|
3
|
+
# tools mcp__dot-phone__* (mobile-mcp over adb). Headless: watched on dsh's own pages.
|
|
4
4
|
# DSH_DOT_PHONE=off turns it off.
|
|
5
5
|
# computer — optional: a microVM (microsandbox, bundled; Docker as fallback) with shell, browser,
|
|
6
6
|
# desktop, live view, approval gates, audit log. The VM is the isolation boundary.
|
|
@@ -77,7 +77,8 @@
|
|
|
77
77
|
name: 'dsh-dot-life/phone'
|
|
78
78
|
disabled: !!js "process.env.DSH_DOT_PHONE === 'off'"
|
|
79
79
|
config:
|
|
80
|
-
|
|
80
|
+
# Headless by default (she is watched on the dot page / the live view); DSH_DOT_PHONE_WINDOW=on also opens the emulator's own window.
|
|
81
|
+
window: !!js "process.env.DSH_DOT_PHONE_WINDOW === 'on' ? true : process.env.DSH_DOT_PHONE_WINDOW === 'off' ? false : undefined"
|
|
81
82
|
acceptLicense: !!js "process.env.DSH_DOT_PHONE_ACCEPT_LICENSE === 'yes' ? true : undefined"
|
|
82
83
|
# Live view + controls at <dsh>/dsh-dot/phone/, behind dsh's own login (no port of its own).
|
|
83
84
|
# publicUrl: the public origin of this dsh if you expose it (tailscale serve, remote access).
|
package/docs/DESIGN.md
CHANGED
|
@@ -342,3 +342,15 @@ Kevin:"感觉现在很难给他长任务。他很容易直接结束然后就
|
|
|
342
342
|
- **QQ**:自动忽略它的机器人号(从它的 SnowLuma 配置读)+ `qq.ignore`;防互刷熔断(`loopMax` / `loopCooldownMinutes`),对任何机器人有效。
|
|
343
343
|
- **体检**:同号、同群、读不到机器人号。
|
|
344
344
|
- `dot.scope: all` 也不再把 `qqb-*` 当她的。
|
|
345
|
+
|
|
346
|
+
## 下一版:一道模型请求闸门(和他聊天时的 429)
|
|
347
|
+
|
|
348
|
+
起因:用户和她正常聊天时报 `429 rate_limit_rpm_exceeded`。她后台的模型请求和对话共用一个 provider key,插件里没有任何东西知道每分钟请求数这回事:幕间一轮(加续写、每周成长)、记忆整理和日记、QQ 群聊评分(每群每分钟最多 6 次)、App 经验整理各自按自己的节奏触发,会撞在一起;跑腿、幕间的去看 / 玩 / 试 / 自己的时间是 agent 循环,一步一个请求(实测一次「在手机上点个赞」51 秒里几十个请求);他的请求没有优先级,429 也不会让后台退让;dsh 自己的重试(5 次、0.5 s 起、最多 10 s)全落在同一个 60 秒窗口里,必然再被拒。
|
|
349
|
+
|
|
350
|
+
- **挂在哪**:dsh-llm 的 `llm/stream` waterfall(`stream()` → `ctx.waterfall(this, 'llm/stream', options, …)`),agent 循环的每一步和直接的 `ctx.llm.stream()` 都过它。监听器是一个 async generator:要等就先等,再 `next()`,原样转发 chunk,看到终止的 `finish` 就记账。老版本 dsh 没有这个钩子就什么都不发生。
|
|
351
|
+
- **一个闸门**:`src/llm-gate.js`,每个 dsh(Cordis root)一个,dot / memory / interlude / qq 谁开着谁装(幂等),监听器挂在其中一个组件上,它被关掉就挪到另一个。逻辑是纯函数加可注入的时钟,测试不真等。
|
|
352
|
+
- **只压认得出的后台**:插件自己发的后台调用在调用处标记(`background(options)`,一个 WeakSet);agent 会话按 id 判断——dot 注册跑腿(当前的和换下来的),幕间注册 `vmSession` 和不是她对话的去看 / 试 / 自己的时间会话。她的对话(他在 dsh / IM 里说话、QQ 私聊和群聊、聊天 App 的通知)是前台;认不出的一律前台,从不被压。对照表在模块开头。
|
|
353
|
+
- **做法**(照抄成熟项目,缩到单人桌面的规模,不加依赖、不落盘):LangChain InMemoryRateLimiter 的桶——后台按 `llm.backgroundRpm`(默认 20)均匀放行、一次一个,近 60 秒的请求(两类都算)满了就等;LiteLLM 的优先级——他的请求在发时以及发完 15 秒内后台等;promptfoo 的 AIMD——任何请求收到 `RATE_LIMIT`,后台冷却(到最近一次被拒后满一分钟;一次限流只算一次——60 秒内的再被拒,比如 dsh 的 5 次快速重试,属于同一次,过了这一分钟又被拒才加倍,带抖动、最多 10 分钟,有 retry-after 按它),每次上限减半,3 分钟没再命中每分钟加回 1;每个 provider 分开。他的请求开着超过 10 分钟(拿了流没读完就丢下)就不再算在发。后台最多等 `maxBackgroundWaitSeconds`(默认 180,最多 270,小于 `dot.turnStallMs`,跑腿不会被看门狗当成卡住),信号中止就立刻交给适配器,用 dsh 自己的 aborted 结束。
|
|
354
|
+
- **让 dsh 的重试有用**(`llm.holdRetries`,默认开):同一会话同一 provider 在 `RATE_LIMIT` 之后十几秒内又发请求,就是 dsh 的重试;先按 retry-after,或等到这一分钟里最老的请求老化出去(按命中时窗口里的请求数估上限),最多 30 秒。这是闸门唯一碰前台请求的地方。
|
|
355
|
+
- **不碍事**:闸门内部任何异常只记 debug,请求照常放行。`/dot` 多一行 `model requests: …`,dot 页面「状态」多一张「模型请求」卡;冷却开始 / 结束各记一条日志和审计。
|
|
356
|
+
- 不做:不改后台工作触发的频率,不改 dsh 的重试本身,不记跨进程的状态。
|
package/docs/SETTINGS.md
CHANGED
|
@@ -26,7 +26,7 @@ dsh-dot 的所有个人设置都写在**一个文件**里:
|
|
|
26
26
|
**给 agent 的规则**(dsh、Claude、Codex 等改这个文件时照做):
|
|
27
27
|
|
|
28
28
|
1. 先读现有文件;不存在就新建 `{}`。只增改相关的键,**不要删别的段和键**。
|
|
29
|
-
2. 顶层按组件分段:`phone`、`computer`、`gate`、`qq`、`memory`、`interlude`、`dot`、`compat
|
|
29
|
+
2. 顶层按组件分段:`phone`、`computer`、`gate`、`qq`、`memory`、`interlude`、`dot`、`compat`,外加不属于哪个组件的 `llm`(模型请求闸门)。键名和类型照下面的表,不要发明新键。
|
|
30
30
|
3. 写合法 JSON(不能有注释、尾逗号)。想留说明就用 `_` 开头的键,如 `"_note": "..."`,会被忽略。
|
|
31
31
|
4. 下文标 **🔒 建立时** 的项只对新建的手机 / 虚拟机生效,改之前先告诉用户要重建、会丢什么,得到同意再动。
|
|
32
32
|
5. 有专门命令的(`/phone size`、`/dot memory recall …`、`/qq owner` 等),优先告诉用户用命令,命令不用重启。
|
|
@@ -51,7 +51,8 @@ dsh-dot 的所有个人设置都写在**一个文件**里:
|
|
|
51
51
|
|---|---|---|
|
|
52
52
|
| **手机存储大一点** | 建手机前:`/phone size 32`,或 `/phone accept 32`,或 `phone.dataGb`(8–256) | 🔒 建立时。手机建好后**扩不了**(改 AVD 的 `config.ini` 实测无效)。已经满了:卸 App、清 App 数据;或者删掉 `~/.dsh/phone/avd/dot.avd/` 和 `dot.ini` 重建(手机里的 App 和登录全丢),重建前先 `/phone size <GB>` |
|
|
53
53
|
| 手机内存 / 机型 / 语言 / 时区 | `phone.ramMb`、`phone.device`、`phone.locale`、`phone.timezone` | `ramMb`、`device` 🔒 建立时(同上,删 AVD 重建) |
|
|
54
|
-
|
|
|
54
|
+
| 也弹出模拟器自己的窗口 | `phone.window: true` | 默认不弹,画面在 dsh 的手机标签页和 dot 页面看 |
|
|
55
|
+
| 关掉手机 / 电脑 | dot 页面顶部的开关,或 `/phone off`、`/computer off` | 立刻关机,重启 dsh 也保持关着;`on` 再开。组件仍然加载着,只是机器不开 |
|
|
55
56
|
| **电脑磁盘大一点** | `computer.rootDisk`,如 `"32G"` | 🔒 建立时。已有虚拟机扩不了,要重建:`msb rm -f dsh-computer` 并删 `~/.microsandbox/snapshots/dsh-computer/`(见 [computer.md](computer.md#六维护)),装过的东西和 QQ 登录会丢。0.11.3 之前建的虚拟机只有约 4 GB |
|
|
56
57
|
| 电脑内存 / CPU | `computer.memory`(如 `"6G"`)、`computer.cpus` | 重启 dsh 生效 |
|
|
57
58
|
| 电脑里 QQ 报 `no space left` / `ENOSPC` | 先 `/qq clean`(清缓存和残留),还不够 `/qq clean napcat`(用 SnowLuma 时删掉 NapCat) | 根治是加大 `computer.rootDisk` 重建 |
|
|
@@ -70,6 +71,7 @@ dsh-dot 的所有个人设置都写在**一个文件**里:
|
|
|
70
71
|
| 她逛 / 玩的 App | `interlude.phoneApps`(站点 → 包名)、`interlude.playApps`(名字 → 包名)、`interlude.play: false` 关掉「玩」 | 只对她自己装了的 App 生效 |
|
|
71
72
|
| 省 token | `interlude.maxRoundsPerDay`、`interlude.browseDailyCap`、`memory.handoffTokens`(交班阈值,默认 150000)、`dot.phoneCheckEveryMinutes` 调大 | 每轮用量在 `~/dot/interlude/calls.jsonl`、`~/dot/memory/calls.jsonl` |
|
|
72
73
|
| 和别的记忆插件一起用 | `memory.coexist`:`auto`(默认)/ `people-only` / `full` | |
|
|
74
|
+
| **和她聊天时报 429 / `rate limit reached for RPM`** | `llm.backgroundRpm` 调小(默认 20,她后台的请求每分钟最多几次;你们的对话不受限) | 被限流后闸门自己会减半、冷却,`/dot` 有一行「model requests」看近一分钟的请求数 |
|
|
73
75
|
| 电脑审批多 / 少 | `gate.mode`:`risky`(默认)/ `browser`(每个浏览器动作都问)/ `off` | |
|
|
74
76
|
| 换她的家目录 | `dot.home`、`memory.home`、`interlude.home` **三处写同一个路径** | 默认 `~/dot` |
|
|
75
77
|
| **没有硬件虚拟化 / 不要手机** | `phone.enabled: false` | |
|
|
@@ -104,7 +106,8 @@ setx DSH_DOT_COMPUTER off
|
|
|
104
106
|
| `api` / `abi` | `35` / 跟随 CPU | 系统镜像 🔒 建立时 |
|
|
105
107
|
| `locale` / `timezone` | `"zh-CN"` / `"Asia/Shanghai"` | 语言、时区 |
|
|
106
108
|
| `number` | `""` | 她的手机号,注册登录 App 用(也可用 `/phone number`;账号密码另存 `~/.dsh/dsh-dot-accounts.json`,见 [phone.md](phone.md)) |
|
|
107
|
-
| `window` | `
|
|
109
|
+
| `window` | `false` | 另外弹出模拟器自己的窗口 |
|
|
110
|
+
| `power` | `true` | 电源开关(见上) |
|
|
108
111
|
| `gpu` | `""` | 渲染方式。空 = Windows 用 `swiftshader_indirect`(软件渲染:显卡渲染在部分 Windows 上会崩,0xC0000005),其他系统 `auto`;也可填 `auto` / `host` / `angle_indirect` |
|
|
109
112
|
| `connectivityCheck` | `"cn"` | 安卓判断"有没有网"的检测地址:`cn` = `connect.rom.miui.com/generate_204`(国内能访问;默认的 Google 地址国内访问不了,会显示"连接受限"),`google` = 系统默认,或自填返回 204 的地址 |
|
|
110
113
|
| `dnsServer` | `""` | 给模拟器指定 DNS,如 `223.5.5.5`;空 = 用电脑的。校园网等封了外部 DNS 的网络必须留空 |
|
|
@@ -128,6 +131,7 @@ setx DSH_DOT_COMPUTER off
|
|
|
128
131
|
| `memory` / `cpus` | `"4G"` / `2` | 资源上限 |
|
|
129
132
|
| `mounts` | `[]` | 共享文件夹 |
|
|
130
133
|
| `backend` | `"auto"` | `microsandbox` / `docker` |
|
|
134
|
+
| `power` | `true` | 电源开关:`false` = 关机,重启 dsh 也保持关着(dot 页面顶部的开关、`/computer on`、`/computer off`) |
|
|
131
135
|
| `image` | 国内镜像 `enterprise-public-cn-beijing.cr.volces.com/vefaas-public/all-in-one-sandbox:latest` | 镜像(作者官方的国内镜像,与 `ghcr.io/agent-infra/sandbox:latest` 同一镜像;海外用户可改回 ghcr)🔒 建立时 |
|
|
132
136
|
| `publicUrl` | `""` | 你对外暴露的 dsh 地址 |
|
|
133
137
|
|
|
@@ -231,6 +235,20 @@ setx DSH_DOT_COMPUTER off
|
|
|
231
235
|
| `approvalWaitMs` | `600000` | 她的会话里要审批时立刻告诉你(QQ 连着发 QQ,否则 IM;一轮只发第一条,后面的只计数);这么久没人点就当拒绝,再告诉你一句过期了;0 = 一直等 |
|
|
232
236
|
| `imBot` / `imTarget` | `""` | dsh-im 的投递目标,空 = 第一个 |
|
|
233
237
|
|
|
238
|
+
### `llm`(模型请求闸门,`src/llm-gate.js`)
|
|
239
|
+
|
|
240
|
+
她后台的模型请求(幕间、整理记忆和日记、跑腿会话、群聊评分、App 经验整理)和你们的对话共用同一个 provider 的 key。这道闸门在每个请求前面:只压后台的,你们的对话(以及认不出来的请求)照常发。每个 provider 分开算。`/dot` 和 dot 页面「状态」里能看到近一分钟的请求数、后台上限、是否在冷却。
|
|
241
|
+
|
|
242
|
+
| 键 | 默认 | 作用 |
|
|
243
|
+
|---|---|---|
|
|
244
|
+
| `backgroundRpm` | `20` | 后台请求每分钟最多几次(近 60 秒内所有请求都算进去,但只压后台的;间隔至少 60/上限 秒,一次放一个)。`0` = 不限速(只计数) |
|
|
245
|
+
| `foregroundQuietSeconds` | `15` | 你们的对话有请求在发时后台不发(一个请求开着超过 10 分钟就当它已经被丢下);发完后再等这么多秒(她一轮有好几步) |
|
|
246
|
+
| `maxBackgroundWaitSeconds` | `180` | 一个后台请求最多被压后多久,到了就放行。最多 270(比 `dot.turnStallMs` 的 300 秒短,跑腿不会被当成卡住;填更大也按 270) |
|
|
247
|
+
| `holdRetries` | `true` | 你们的对话被限流(429)后,dsh 自己的快速重试(几秒内连试 5 次,都在同一分钟里)先等到这一分钟有余量(或 provider 给的 retry-after)再发 |
|
|
248
|
+
| `retryHoldMaxSeconds` | `30` | 上一项最多等多久 |
|
|
249
|
+
|
|
250
|
+
被限流(任何请求收到 `RATE_LIMIT`)时:后台至少停到最近一次被拒后的 60 秒,后台上限减半(最少 1)。60 秒内的再次被拒(一批一起被拒、dsh 的几次重试)算同一次;过了这一分钟又被拒才算再一次:再减半,冷却加倍(带随机抖动,最多 10 分钟);provider 给了 retry-after 就按它。3 分钟没再被限流后每分钟加回 1。冷却开始和结束各记一行日志和审计(`kind: llm-gate`)。
|
|
251
|
+
|
|
234
252
|
### `compat`(和 qq-bridge 共处,见 [qq-bridge.md](qq-bridge.md))
|
|
235
253
|
|
|
236
254
|
| 键 | 默认 | 作用 |
|
package/docs/computer.md
CHANGED
|
@@ -56,7 +56,7 @@ Status: v0.5.0, verified on dsh desktop 0.2.0-rc.2 (macOS, Apple silicon). Want
|
|
|
56
56
|
| 系统 | macOS(Apple 芯片)、Linux(有 `/dev/kvm`)、Windows(开启 Hypervisor Platform)。Intel Mac 自动改用 Docker |
|
|
57
57
|
| 内存 | 虚拟机默认 4GB 上限,空闲约 0.5GB |
|
|
58
58
|
| 磁盘 | 约 10GB 空闲(虚拟机镜像) |
|
|
59
|
-
| 网络 |
|
|
59
|
+
| 网络 | 首次启动要下载镜像(默认从国内镜像 `enterprise-public-cn-beijing.cr.volces.com` 拉;`image` 可改回源头 `ghcr.io`);插件会自动使用系统代理 |
|
|
60
60
|
|
|
61
61
|
虚拟机由 [microsandbox](https://github.com/microsandbox/microsandbox) 运行(libkrun 微型虚拟机,macOS 用 Hypervisor.framework)。它随插件的 npm 依赖一起安装,不需要单独安装。
|
|
62
62
|
|
|
@@ -141,7 +141,7 @@ tailscale serve --bg --https=443 http://127.0.0.1:<dsh 端口> # 只在你的
|
|
|
141
141
|
| `apiKey` | 自动生成 | 虚拟机网关密钥(`SANDBOX_API_KEY`);空则用 `~/.dsh/dsh-computer.key` 里自动生成的那把 |
|
|
142
142
|
| `mcp` | `true` | 由本组件挂载虚拟机的 `mcp__dot-vm__*` 工具(MCP 客户端带网关密钥);不要再在 `cordis.patch.yml` 里单独配 dsh-mcp-client 指向 `/mcp` |
|
|
143
143
|
| `DSH_COMPUTER_PORT` | `18080` | 虚拟机网关在本机的端口(仅监听 127.0.0.1,需要密钥);只能用环境变量设置 |
|
|
144
|
-
| `image` / `DSH_COMPUTER_IMAGE` | `ghcr.io/agent-infra/sandbox:latest`
|
|
144
|
+
| `image` / `DSH_COMPUTER_IMAGE` | `enterprise-public-cn-beijing.cr.volces.com/vefaas-public/all-in-one-sandbox:latest` | 虚拟机镜像(v0.21.1 起默认用作者官方的国内镜像,与源头 `ghcr.io/agent-infra/sandbox:latest` 同一镜像;海外可改回 ghcr) |
|
|
145
145
|
| `backend` / `DSH_COMPUTER_BACKEND` | `auto` | `microsandbox` 或 `docker` |
|
|
146
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` 关闭审批,只建议在虚拟机里没有重要登录态时用 |
|
package/docs/phone.md
CHANGED
|
@@ -11,7 +11,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
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 条。
|
|
14
|
-
8.
|
|
14
|
+
8. **实时画面**:默认只有插件的网页(模拟器不弹自己的窗口;要它也弹出来设 `window: true`)。网页,挂在 **dsh 自己的 web server** 上:`<dsh 地址>/dsh-dot/phone/`——dsh 右侧栏的「手机」标签页就是它:屏幕每秒刷新几次(PNG 流),能直接点、滑、按返回/主页、输入文字,登录 App 就在这里做。**它不单独监听端口**:页面、画面流和每一次点击都先过 dsh 的 `connection` 服务(dsh 自己的登录态 + Host/Origin 围栏,转发头一概不认),只有登录了这个 dsh 的人能看能点。想在别的设备上看,把 dsh 本身暴露出去(如 `tailscale serve` dsh 的端口,或 dsh 的远程访问),再把那个地址写进 `publicUrl`,审批提醒里的链接就是 `<publicUrl>/dsh-dot/phone/`。无头跑(服务器)时 `window: false` 只用网页。网页里的文字输入走 `adb shell input text`,只支持 ASCII(账号、验证码够用);中文由她自己的工具输。
|
|
15
15
|
9. **摄像头**:后置摄像头是模拟器的虚拟场景(`hw.camera.back=virtualscene`,前置没有)——一个有电视和书架的 3D 房间。场景里的 `wall` 海报每次开机前被挪到镜头正前方 1.5 米、1 米见方(插件改写模拟器的 `resources/Toren1BD.posters`,原文件存成 `.orig`,`table` 海报不动),所以往海报上放一张图,她打开相机或扫一扫看到的就是它。`dshPhone.showToCamera(png)` 负责放:先按 HOME 回桌面(有 App 开着摄像头时换图不生效),`adb emu virtualscene-image wall` 清空海报,再设成新写的 `resources/dsh-dot-poster-<毫秒>.png`(同一路径或不先清空,模拟器会一直显示这个进程里放的第一张),旧文件删掉。QQ 扫码登录电脑端就靠它(见 [qq.md](qq.md))。0.10.8 之前开起来的手机要 `/phone restart` 一次海报才会挪过去;更早建的、没有摄像头的 AVD 会被自动补上 `virtualscene`,同样下次开机生效。
|
|
16
16
|
10. **表情包在相册里**:她电脑 QQ 那边存的表情包(`~/.dsh/stickers/`,见 qq.md)同步到手机 `/sdcard/Pictures/dot-stickers/<id>.<png|jpg|gif|webp>`(扩展名按文件头判断),推完发 `MEDIA_SCANNER_SCAN_FILE` 广播,相册里就有一个 dot-stickers 相册,任何 App 都能从相册选图发。手机就绪时、表情包有增减时各同步一次(按文件名 + 大小比,已经在的不重推;从收藏里挤掉的在手机上也删掉;文件夹里不是 `<id>.<ext>` 的文件不动)。手机提示词最后一段(`phone.stickers`)教她各 App 怎么把相册里的图加进自己的表情:QQ 长按 → 添加到表情、微信长按 → 添加表情、小黑盒评论配图从相册选;做成一次就记到 self。只教不催,用不用随她。`/qq stickers` 看同步了几张,`/qq stickers sync` 立刻推一次。
|
|
17
17
|
|
|
@@ -26,7 +26,8 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
26
26
|
| `avd` / `device` | `dot` / `pixel_6` | AVD 名和机型 |
|
|
27
27
|
| `ramMb` / `dataGb` | `3072` / `16` | 内存、数据分区(`dataGb` 也可用 `/phone accept <GB>` / `/phone size <GB>` 在建手机前设) |
|
|
28
28
|
| `port` | `5554` | 控制台端口的起点:被别的模拟器占着就往后找(+2,到 5584);adb 序列号 `emulator-<端口>` |
|
|
29
|
-
| `window` / `DSH_DOT_PHONE_WINDOW=
|
|
29
|
+
| `window` / `DSH_DOT_PHONE_WINDOW=on` | `false` | 另外弹出模拟器自己的窗口(默认不弹,画面在 dsh 里看) |
|
|
30
|
+
| `power` | `true` | 电源开关:`false` = 关机,重启 dsh 也保持关着;用 dot 页面顶部的开关或 `/phone on`、`/phone off` 改 |
|
|
30
31
|
| `liveView` | `true` | 在 dsh 的 web server 上挂实时画面页(`/dsh-dot/phone/`);`false` 关闭 |
|
|
31
32
|
| `publicUrl` | 无 | 这个 dsh 对外的地址(你自己的暴露方式);实时画面链接 = `<publicUrl>/dsh-dot/phone/`,写进审批提醒 |
|
|
32
33
|
| `gpu` | `auto` | 模拟器 `-gpu`(`auto` / `host` / `software` 等)。`auto` 在 API 35 上可能被强制成 CPU 软件渲染:`~/.dsh/phone/emulator.log` 里有 `forcing software rendering for GLES`。软件渲染下每次截屏都是宿主 CPU 重新合成整屏,持续高频截屏会让虚拟机卡过 15 秒、被模拟器的卡死检测杀掉(日志 `detected a hanging thread 'QEMU2 main loop'`)。Mac 上可改 `"host"` 用显卡,改后重启手机,确认日志里不再有 `forcing software rendering` |
|
|
@@ -48,7 +49,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
48
49
|
## 装 App 和登录
|
|
49
50
|
|
|
50
51
|
- **她自己装。** 手机没有应用商店,和一个人拿到新手机一样:她用手机上的浏览器打开官网,下载安装包,点开安装。插件开机时已允许浏览器和文件管理器安装未知应用(`installers`),所以不用进设置。这是故意的——养一个会自己折腾手机的角色,而不是替她把一切装好。`adb install` 当然也能用,但那是你的事,不是她的。
|
|
51
|
-
-
|
|
52
|
+
- 注册、登录她自己来(见下一节);你也可以在手机画面(dot 页面的「看画面」)里亲手登录。验证码、人脸、短信验证都由你过;她遇到会停下来告诉你。
|
|
52
53
|
- **用小号**:各平台条款都不允许自动化,模拟器也可能被检测。登录态在 AVD 里,重启不丢;`~/.dsh/phone/avd/` 整个目录就是这部手机,可以备份。
|
|
53
54
|
|
|
54
55
|
## 她的手机号和账号
|
|
@@ -66,7 +67,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
66
67
|
|---|---|---|
|
|
67
68
|
| macOS Apple silicon | ✅ | arm64 镜像原生速度;第一次启动系统会问是否允许模拟器用虚拟化 |
|
|
68
69
|
| macOS Intel | ✅ | x86_64 镜像,依赖 Hypervisor.framework |
|
|
69
|
-
| Linux x86_64 | ✅ | 需要 KVM(`/dev/kvm`
|
|
70
|
+
| Linux x86_64 | ✅ | 需要 KVM(`/dev/kvm` 可写);默认就是无头 |
|
|
70
71
|
| Linux arm64 | ❌ | Google 不发 Linux arm64 模拟器 |
|
|
71
72
|
| Windows x64 | ✅ | 需要 WHPX 或 Hyper-V;解压用 PowerShell |
|
|
72
73
|
| 另一台 Linux 虚拟机里 | ❌ | 嵌套虚拟化。手机和电脑是两台设备,不是一台装另一台 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dot-life",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.2",
|
|
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 (幕间), an optional microVM computer with approval gates. One plugin, seven components; lives next to qq-bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,6 +54,11 @@ export function createDockerBackend(config, logger) {
|
|
|
54
54
|
return docker(bin, ['exec', '-u', 'root', name, '/bin/bash', '-c', script]);
|
|
55
55
|
},
|
|
56
56
|
|
|
57
|
+
/** Shut the container down (the power switch). Its home volume stays; `ensure` starts it again. */
|
|
58
|
+
async stop() {
|
|
59
|
+
await docker(bin, ['stop', name], { timeout: 120_000 }).catch(() => {});
|
|
60
|
+
},
|
|
61
|
+
|
|
57
62
|
async ensure({ mounts, port }) {
|
|
58
63
|
if (!(await dockerOk(bin, ['info', '--format', '{{.ServerVersion}}']))) {
|
|
59
64
|
throw new Error(`dsh-computer: Docker is not running or not installed (looked for "${bin}"). Start Docker Desktop / OrbStack and restart dsh.`);
|
|
@@ -83,6 +83,7 @@ export function createMicrosandboxBackend(config, logger) {
|
|
|
83
83
|
maxBuffer: 16 * 1024 * 1024,
|
|
84
84
|
timeout: opts.timeout ?? 120_000,
|
|
85
85
|
env: { ...process.env, ...(opts.env || {}) },
|
|
86
|
+
windowsHide: true, // msb is a console program: without this every call flashes a console window on Windows
|
|
86
87
|
});
|
|
87
88
|
if (!quiet) logger.info(`msb ${args[0]} ok (${Date.now() - started} ms)`);
|
|
88
89
|
return stdout.trim();
|
|
@@ -179,6 +180,11 @@ export function createMicrosandboxBackend(config, logger) {
|
|
|
179
180
|
|
|
180
181
|
restartServices,
|
|
181
182
|
|
|
183
|
+
/** Shut the VM down (the power switch). Its disk stays; `ensure` wakes it again. */
|
|
184
|
+
async stop() {
|
|
185
|
+
if ((await names(true)).includes(name)) await msb(['stop', '-q', name], { timeout: 120_000 });
|
|
186
|
+
},
|
|
187
|
+
|
|
182
188
|
async ensure({ mounts, port, waitHealthy, onStage = () => {} }) {
|
|
183
189
|
// 1. Host virtualization (Hypervisor.framework / WHP / KVM).
|
|
184
190
|
try {
|
|
@@ -7,13 +7,13 @@ export function systemProxyEnv() {
|
|
|
7
7
|
let url = '';
|
|
8
8
|
try {
|
|
9
9
|
if (process.platform === 'darwin') {
|
|
10
|
-
const out = execFileSync('scutil', ['--proxy'], { encoding: 'utf8', timeout: 3000 });
|
|
10
|
+
const out = execFileSync('scutil', ['--proxy'], { encoding: 'utf8', timeout: 3000, windowsHide: true });
|
|
11
11
|
const get = (k) => (new RegExp(`\\b${k} : (\\S+)`).exec(out) || [])[1];
|
|
12
12
|
if (get('HTTPSEnable') === '1') url = `http://${get('HTTPSProxy')}:${get('HTTPSPort')}`;
|
|
13
13
|
else if (get('HTTPEnable') === '1') url = `http://${get('HTTPProxy')}:${get('HTTPPort')}`;
|
|
14
14
|
} else if (process.platform === 'win32') {
|
|
15
15
|
const key = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings';
|
|
16
|
-
const out = execFileSync('reg', ['query', key], { encoding: 'utf8', timeout: 3000 });
|
|
16
|
+
const out = execFileSync('reg', ['query', key], { encoding: 'utf8', timeout: 3000, windowsHide: true });
|
|
17
17
|
if (/ProxyEnable\s+REG_DWORD\s+0x1/.test(out)) {
|
|
18
18
|
let server = (/ProxyServer\s+REG_SZ\s+(\S+)/.exec(out) || [])[1] || '';
|
|
19
19
|
server = (/https=([^;]+)/.exec(server) || /http=([^;]+)/.exec(server) || [null, server])[1];
|
package/src/computer/docker.js
CHANGED
|
@@ -31,7 +31,7 @@ export function resolveDockerBin() {
|
|
|
31
31
|
*/
|
|
32
32
|
export async function docker(bin, args, opts = {}) {
|
|
33
33
|
try {
|
|
34
|
-
const { stdout } = await execFileAsync(bin, args, { maxBuffer: 16 * 1024 * 1024, timeout: opts.timeout ?? 120_000, signal: opts.signal });
|
|
34
|
+
const { stdout } = await execFileAsync(bin, args, { maxBuffer: 16 * 1024 * 1024, timeout: opts.timeout ?? 120_000, signal: opts.signal, windowsHide: true });
|
|
35
35
|
return stdout.trim();
|
|
36
36
|
} catch (err) {
|
|
37
37
|
const detail = (err.stderr || err.message || '').toString().trim();
|
|
@@ -72,6 +72,7 @@ export default class DshComputerSubprocess extends LocalSubprocessRuntime {
|
|
|
72
72
|
* not be cancelled and outlived the stop button. A failed computer fails the same way.
|
|
73
73
|
*/
|
|
74
74
|
usable() {
|
|
75
|
+
if (this.vm.status?.().state === 'off') throw new Error('电脑关着(他关的),现在跑不了命令。不用等,也别自己去开;要用就请他在左侧栏 dot 页面打开,或发 /computer on');
|
|
75
76
|
if (this.vm.error) throw new Error(`电脑出错了,现在跑不了命令(${this.vm.error.message})。不用等,先直接回话;/phone doctor 或左侧栏 dot 页面看详情`);
|
|
76
77
|
if (!this.vm.isReady) throw new Error(notReady(this.vm.status?.()));
|
|
77
78
|
}
|
|
@@ -99,7 +100,7 @@ export default class DshComputerSubprocess extends LocalSubprocessRuntime {
|
|
|
99
100
|
const probe = command.startsWith('/') ? 'test -x "$1" && printf %s "$1"' : 'command -v -- "$1"';
|
|
100
101
|
const argv = this.backend.execArgv({ user: this.vm.user, cwd: VM_HOME, env, argv: ['/bin/sh', '-lc', probe, 'sh', command] });
|
|
101
102
|
try {
|
|
102
|
-
const { stdout } = await run(argv[0], argv.slice(1), { signal });
|
|
103
|
+
const { stdout } = await run(argv[0], argv.slice(1), { signal, windowsHide: true });
|
|
103
104
|
const found = stdout.trim().split('\n').pop();
|
|
104
105
|
if (found) return found;
|
|
105
106
|
} catch {}
|
package/src/computer/vm.js
CHANGED
|
@@ -13,12 +13,15 @@ import { createAudit } from './audit.js';
|
|
|
13
13
|
import { computerApiKey, keyHeaders, KEY_HEADER } from './key.js';
|
|
14
14
|
import { mountComputerView, LIVE_VIEW_PAGE } from './live-view.js';
|
|
15
15
|
import { localUrl, publicUrlOf } from '../web-auth.js';
|
|
16
|
-
import { sectionOf, setValues } from '../settings.js';
|
|
16
|
+
import { sectionOf, setValues, writeSections } from '../settings.js';
|
|
17
17
|
|
|
18
18
|
export const name = 'dot-computer';
|
|
19
19
|
|
|
20
20
|
export const defaults = {
|
|
21
21
|
backend: 'auto', // auto | microsandbox | docker
|
|
22
|
+
// The power switch (the dot page, /computer on|off): false = her computer is shut down and stays
|
|
23
|
+
// down across dsh restarts until it is switched on. The component stays loaded either way.
|
|
24
|
+
power: true,
|
|
22
25
|
name: 'dsh-computer',
|
|
23
26
|
// The same image, mirrored by its authors for mainland China (most users); 'ghcr.io/agent-infra/sandbox:latest' is the origin.
|
|
24
27
|
image: 'enterprise-public-cn-beijing.cr.volces.com/vefaas-public/all-in-one-sandbox:latest',
|
|
@@ -204,13 +207,13 @@ export async function ensureServices(config, computer, logger) {
|
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
export function apply(ctx, config = {}) {
|
|
210
|
+
export function apply(ctx, config = {}, deps = {}) {
|
|
208
211
|
const logger = withFileLog(ctx.logger('dsh-computer'));
|
|
209
212
|
// The gateway port is fixed by the patch (DSH_COMPUTER_PORT): the UI relay and the gate read the same value.
|
|
210
213
|
const { port: _port, ...user } = sectionOf('computer', (m) => logger.warn(m));
|
|
211
214
|
const cfg = { ...defaults, ...readSettingsFile(), ...setValues(config, { dropEmptyArrays: true }), ...user };
|
|
212
215
|
const apiKey = computerApiKey(cfg.apiKey);
|
|
213
|
-
const backend = pickBackend({ ...cfg, apiKey }, logger);
|
|
216
|
+
const backend = deps.backend ?? pickBackend({ ...cfg, apiKey }, logger);
|
|
214
217
|
const base = `http://127.0.0.1:${cfg.port}`;
|
|
215
218
|
// Folders actually bound into the VM: what earlier runs recorded, plus the configured defaults.
|
|
216
219
|
const state = readState();
|
|
@@ -239,13 +242,14 @@ export function apply(ctx, config = {}) {
|
|
|
239
242
|
keyHeader: KEY_HEADER,
|
|
240
243
|
isReady: false,
|
|
241
244
|
};
|
|
245
|
+
let off = cfg.power === false;
|
|
242
246
|
computer.audit = createAudit(auditFile());
|
|
243
247
|
|
|
244
248
|
// Status for other plugins (dot, IM bridges): one snapshot shape plus change notifications.
|
|
245
249
|
const listeners = new Set();
|
|
246
250
|
computer.status = () => ({
|
|
247
|
-
stage: !computer.isReady && !computer.error ? computer.stage || 'starting' : undefined, // downloading | installing | starting, while not up
|
|
248
|
-
state: computer.error ? 'error' : computer.remounting ? 'remounting' : !computer.isReady ? 'starting' : computer.servicesReady ? 'ready' : computer.unsafe ? 'unsafe' : 'shell-only',
|
|
251
|
+
stage: !off && !computer.isReady && !computer.error ? computer.stage || 'starting' : undefined, // downloading | installing | starting, while not up
|
|
252
|
+
state: off ? 'off' : computer.error ? 'error' : computer.remounting ? 'remounting' : !computer.isReady ? 'starting' : computer.servicesReady ? 'ready' : computer.unsafe ? 'unsafe' : 'shell-only',
|
|
249
253
|
backend: backend.kind,
|
|
250
254
|
liveViewUrl: computer.liveViewUrl,
|
|
251
255
|
publicLiveViewUrl: computer.publicLiveViewUrl,
|
|
@@ -270,8 +274,10 @@ export function apply(ctx, config = {}) {
|
|
|
270
274
|
};
|
|
271
275
|
computer.notifyStatus = changed;
|
|
272
276
|
|
|
277
|
+
// `ready` settles once per boot: switching the computer on again makes a new one.
|
|
273
278
|
let markReady;
|
|
274
|
-
computer.ready = new Promise((r) => (markReady = r));
|
|
279
|
+
const newReady = () => { computer.ready = new Promise((r) => (markReady = r)); };
|
|
280
|
+
newReady();
|
|
275
281
|
try { rmSync(computer.lockFile, { force: true }); } catch {}
|
|
276
282
|
|
|
277
283
|
/** Covered by an existing shared folder? */
|
|
@@ -283,7 +289,7 @@ export function apply(ctx, config = {}) {
|
|
|
283
289
|
*/
|
|
284
290
|
let pending = null;
|
|
285
291
|
computer.ensureShared = (dir) => {
|
|
286
|
-
if (computer.isShared(dir) || !shareable(dir) || !backend.remount || computer.error) return null;
|
|
292
|
+
if (off || computer.isShared(dir) || !shareable(dir) || !backend.remount || computer.error) return null;
|
|
287
293
|
const previous = [...computer.mounts];
|
|
288
294
|
const next = [...previous.filter((m) => !inside(dir, m)), dir]; // a parent replaces its children
|
|
289
295
|
computer.mounts = next; // later spawns map paths as shared; they wait on the lock meanwhile
|
|
@@ -332,8 +338,12 @@ export function apply(ctx, config = {}) {
|
|
|
332
338
|
}
|
|
333
339
|
computer.mcpMounted = () => Boolean(mcpFork);
|
|
334
340
|
ctx.effect?.(() => () => { mcpFork?.dispose?.(); mcpFork = null; }, 'dsh-dot/computer: mcp client');
|
|
335
|
-
|
|
341
|
+
// One boot at a time, numbered: a boot that is overtaken by the power switch must not mark the
|
|
342
|
+
// computer ready (or leave it running) after it was switched off.
|
|
343
|
+
let bootNo = 0;
|
|
344
|
+
const boot = () => { const mine = ++bootNo; const stale = () => off || mine !== bootNo; return ensureShell(cfg, computer, logger).then(
|
|
336
345
|
async (result) => {
|
|
346
|
+
if (stale()) { if (off) await backend.stop?.().catch(() => {}); return; }
|
|
337
347
|
// An existing VM is bound to what it was bound to before, not to this run's defaults:
|
|
338
348
|
// backends that know the real bindings report them; otherwise trust the recorded state.
|
|
339
349
|
if (!result?.fresh && result?.mounts) computer.mounts = result.mounts.filter(allowed);
|
|
@@ -353,10 +363,52 @@ export function apply(ctx, config = {}) {
|
|
|
353
363
|
computer.isReady = true; markReady(true); changed();
|
|
354
364
|
logger.info('computer shell ready');
|
|
355
365
|
return ensureServices(cfg, computer, logger).then(
|
|
356
|
-
async () => { computer.servicesReady = true; await mountMcp(); logger.info(`computer ready — live view: ${computer.liveViewUrl}`); changed(); },
|
|
357
|
-
(err) => { computer.servicesError = err; logger.error(err.message); changed(); },
|
|
366
|
+
async () => { if (stale()) return; computer.servicesReady = true; await mountMcp(); logger.info(`computer ready — live view: ${computer.liveViewUrl}`); changed(); },
|
|
367
|
+
(err) => { if (stale()) return; computer.servicesError = err; logger.error(err.message); changed(); },
|
|
358
368
|
);
|
|
359
369
|
},
|
|
360
|
-
(err) => { computer.error = err; markReady(false); logger.error(err.message); changed(); },
|
|
361
|
-
);
|
|
370
|
+
(err) => { if (stale()) return; computer.error = err; markReady(false); logger.error(err.message); changed(); },
|
|
371
|
+
); };
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The power switch. Off: her computer is shut down (its disk, logins and installed software stay)
|
|
375
|
+
* and commands are refused with that reason; on: it boots like at startup. The choice is written
|
|
376
|
+
* to dsh-dot.json, so it holds across dsh restarts.
|
|
377
|
+
*/
|
|
378
|
+
computer.power = async (on) => {
|
|
379
|
+
on = Boolean(on);
|
|
380
|
+
writeSections({ computer: { power: on ? null : false } });
|
|
381
|
+
if (on === !off) return computer.status();
|
|
382
|
+
off = !on;
|
|
383
|
+
computer.audit({ kind: 'power', on });
|
|
384
|
+
if (on) {
|
|
385
|
+
computer.error = undefined; computer.servicesError = undefined; computer.stage = undefined;
|
|
386
|
+
newReady(); changed(); logger.info('computer switched on');
|
|
387
|
+
void boot();
|
|
388
|
+
return computer.status();
|
|
389
|
+
}
|
|
390
|
+
computer.isReady = false; computer.servicesReady = false; computer.error = undefined; computer.servicesError = undefined;
|
|
391
|
+
markReady(false);
|
|
392
|
+
mcpFork?.dispose?.(); mcpFork = null;
|
|
393
|
+
changed(); logger.info('computer switched off');
|
|
394
|
+
await (pending ?? Promise.resolve()).catch(() => {}); // a remount in flight finishes first: stopping mid-swap could lose the disk
|
|
395
|
+
await backend.stop?.().catch((err) => logger.warn(`stopping the computer failed: ${err.message}`));
|
|
396
|
+
return computer.status();
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
ctx.inject?.(['commands'], (scope) => {
|
|
400
|
+
scope.effect(() => scope.commands.register({
|
|
401
|
+
name: 'computer',
|
|
402
|
+
description: 'her computer: status; "on" / "off" is the power switch (off shuts it down and keeps it down across dsh restarts; nothing on its disk is lost)',
|
|
403
|
+
input: { hint: '[on | off]' },
|
|
404
|
+
handler: async ({ rawInput }) => {
|
|
405
|
+
const arg = String(rawInput ?? '').trim();
|
|
406
|
+
try { if (arg === 'on' || arg === 'off') await computer.power(arg === 'on'); } catch (err) { return { kind: 'success', text: `computer: ${err.message}` }; }
|
|
407
|
+
const s = computer.status();
|
|
408
|
+
return { kind: 'success', text: `computer: ${s.state}${s.stage ? ` (${s.stage})` : ''}${s.error ? ` — ${s.error}` : ''}${s.state === 'off' ? ' — /computer on to switch it on' : ''}` };
|
|
409
|
+
},
|
|
410
|
+
}), 'dsh-dot/computer: /computer command');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
if (off) { logger.info('computer is switched off (/computer on, or the dot page, to switch it on)'); changed(); } else void boot();
|
|
362
414
|
}
|
package/src/dot/core.js
CHANGED
|
@@ -28,6 +28,7 @@ import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
|
28
28
|
import { mountPanel } from './panel.js';
|
|
29
29
|
import { doctorFor, report as doctorReport } from '../doctor.js';
|
|
30
30
|
import { sectionOf, setValues } from '../settings.js';
|
|
31
|
+
import { background, installLlmGate, statusLine as llmGateLine } from '../llm-gate.js';
|
|
31
32
|
import { configure as configurePrompts, fill, overrideNotes, prompt, rebase, table } from '../prompts.js';
|
|
32
33
|
import { ago, describeNow, mondayOf, stamp } from '../clock.js';
|
|
33
34
|
|
|
@@ -269,11 +270,11 @@ export function setupText(phoneStatus, computerStatus) {
|
|
|
269
270
|
const lines = [];
|
|
270
271
|
const p = phoneStatus;
|
|
271
272
|
if (p && p.state !== 'ready') {
|
|
272
|
-
lines.push(`手机:${p.state === 'needs-license' ? '还没装(等他在 dsh 里发 /phone accept)' : p.state === 'downloading' ? (p.progress?.text ?? '下载中') : p.state === 'booting' ? '开机中' : p.state === 'error' ? `出错了(${p.error ?? '未知'}),/phone 看详情` : p.state}`);
|
|
273
|
+
lines.push(`手机:${p.state === 'off' ? '关着(他关的;要用就请他在 dot 页面打开,别自己想办法开)' : p.state === 'needs-license' ? '还没装(等他在 dsh 里发 /phone accept)' : p.state === 'downloading' ? (p.progress?.text ?? '下载中') : p.state === 'booting' ? '开机中' : p.state === 'error' ? `出错了(${p.error ?? '未知'}),/phone 看详情` : p.state}`);
|
|
273
274
|
}
|
|
274
275
|
const c = computerStatus;
|
|
275
|
-
if (c && (c.state === 'starting' || c.state === 'error')) {
|
|
276
|
-
lines.push(`电脑:${c.state === 'error' ? `出错了(${c.error ?? '未知'}),/phone doctor 或 dot 页面看详情` : COMPUTER_STAGE[c.stage] ?? '开机中'}`);
|
|
276
|
+
if (c && (c.state === 'starting' || c.state === 'error' || c.state === 'off')) {
|
|
277
|
+
lines.push(`电脑:${c.state === 'off' ? '关着(他关的;要用就请他在 dot 页面打开,别自己想办法开)' : c.state === 'error' ? `出错了(${c.error ?? '未知'}),/phone doctor 或 dot 页面看详情` : COMPUTER_STAGE[c.stage] ?? '开机中'}`);
|
|
277
278
|
}
|
|
278
279
|
return lines.length ? prompt('dot.setup', { devices: lines.join('\n') }) : '';
|
|
279
280
|
}
|
|
@@ -452,6 +453,8 @@ export function apply(ctx, config = {}) {
|
|
|
452
453
|
// "latest session" (his QQ message then goes into an archived errand and he never gets an answer).
|
|
453
454
|
const pastErrands = new Set(store.get('pastErrands') ?? []);
|
|
454
455
|
const isErrand = (id) => Boolean(id) && (id === errandId || pastErrands.has(id));
|
|
456
|
+
// Her model requests share his provider key: errand steps are background and wait behind his (src/llm-gate.js).
|
|
457
|
+
const llmGate = installLlmGate(ctx, { name: 'dsh-dot', backgroundSessions: isErrand });
|
|
455
458
|
// Startup self-check: the remembered pointer must be a live conversation of hers. An old state file
|
|
456
459
|
// can point at an errand or at a session archived since (11-03: his QQ messages went into an
|
|
457
460
|
// archived errand and nobody answered). What dsh cannot tell us (no registry yet, no title) is skipped.
|
|
@@ -741,11 +744,11 @@ export function apply(ctx, config = {}) {
|
|
|
741
744
|
const sel = ctx.get('agentDefaultModel')?.currentSelection?.();
|
|
742
745
|
const llm = ctx.get('llm');
|
|
743
746
|
if (!sel || !llm?.stream) return;
|
|
744
|
-
const reply = await collectReply(llm.stream({
|
|
747
|
+
const reply = await collectReply(llm.stream(background({
|
|
745
748
|
provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}),
|
|
746
749
|
system: prompt('dot.howto.reflect', { maxChars: cfg.howtoMaxChars }), tools: [howtoTool()], maxTokens: 4000,
|
|
747
750
|
messages: [createUserMessage({ content: [{ type: 'text', text: JSON.stringify(howto.input(r), null, 1) }], source: { kind: 'dsh-dot', form: 'howto' } })],
|
|
748
|
-
}));
|
|
751
|
+
})));
|
|
749
752
|
const out = JSON.parse(reply.args || reply.text.slice(reply.text.indexOf('{'), reply.text.lastIndexOf('}') + 1));
|
|
750
753
|
if (howto.keep(r.app, out, r.id)) audit('howto-learned', { app: r.app, steps: r.steps, errors: r.errors.length, worked: Boolean(out.worked) });
|
|
751
754
|
} catch (error) { logger.warn(`howto reflection (${r.app}) failed: ${error.message}`); audit('howto-failed', { app: r.app, error: String(error.message).slice(0, 200) }); }
|
|
@@ -1288,6 +1291,7 @@ export function apply(ctx, config = {}) {
|
|
|
1288
1291
|
`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` : ''}`,
|
|
1289
1292
|
...statusLiveness(),
|
|
1290
1293
|
`budget: ${ctx.get('budget') ? (blocked.length ? `BLOCKED (${blocked.join(', ')})` : 'ok') : 'not installed (optional)'}`,
|
|
1294
|
+
(() => { try { return llmGateLine(llmGate?.status()); } catch (err) { return `model requests: ${err.message}`; } })(),
|
|
1291
1295
|
`schedule: ${ctx.get('schedule') ? 'ok' : 'not installed'}`,
|
|
1292
1296
|
];
|
|
1293
1297
|
return { kind: 'success', text: lines.join('\n') + test };
|
|
@@ -1327,6 +1331,8 @@ export function apply(ctx, config = {}) {
|
|
|
1327
1331
|
ownerPending: () => ownerBatch.length,
|
|
1328
1332
|
flushOwner: () => flushOwner(),
|
|
1329
1333
|
isIm: (id) => imSessions.has(id),
|
|
1334
|
+
/** The model-request gate's status (src/llm-gate.js): per provider, requests in the last minute, background cap, cooldown, waiting. */
|
|
1335
|
+
llmGate: () => llmGate?.status() ?? null,
|
|
1330
1336
|
/** Hold deliveries to her conversation (a handoff is moving it); the returned function releases them to the new one. */
|
|
1331
1337
|
freeze() {
|
|
1332
1338
|
frozen++;
|
package/src/interlude/core.js
CHANGED
|
@@ -23,6 +23,7 @@ import { homedir } from 'node:os';
|
|
|
23
23
|
import { join, relative, isAbsolute } from 'node:path';
|
|
24
24
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
25
25
|
import { sectionOf, setValues } from '../settings.js';
|
|
26
|
+
import { background, installLlmGate } from '../llm-gate.js';
|
|
26
27
|
import { prompt, table } from '../prompts.js';
|
|
27
28
|
import { describeNow, stamp } from '../clock.js';
|
|
28
29
|
import { createDoings, tokensOf } from './doings.js';
|
|
@@ -800,8 +801,8 @@ export function apply(ctx, config = {}) {
|
|
|
800
801
|
doings: view, trying: tryOpen(),
|
|
801
802
|
upcoming: intents.filter((i) => i.id !== intent?.id).map((i) => ({ at: describeNow(new Date(i.at)), kind: i.kind, text: i.text })),
|
|
802
803
|
});
|
|
803
|
-
const options = { provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools, maxTokens: cfg.maxTokens,
|
|
804
|
-
messages: [createUserMessage({ content: [{ type: 'text', text: user }], source: { kind: 'dsh-interlude' } })] };
|
|
804
|
+
const options = background({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools, maxTokens: cfg.maxTokens,
|
|
805
|
+
messages: [createUserMessage({ content: [{ type: 'text', text: user }], source: { kind: 'dsh-interlude' } })] });
|
|
805
806
|
const r1 = await collectReply(ctx.llm.stream(options));
|
|
806
807
|
const spent = [usageOf(r1.usage)];
|
|
807
808
|
// The `interval` tool call carries the fields; a bare JSON reply is accepted too.
|
|
@@ -813,11 +814,11 @@ export function apply(ctx, config = {}) {
|
|
|
813
814
|
// call over the script just written fills every other field — the post-commit continuity
|
|
814
815
|
// refresh, widened so nothing the round should have produced is lost.
|
|
815
816
|
if (!parsed?.state) {
|
|
816
|
-
const r2 = await collectReply(ctx.llm.stream({
|
|
817
|
+
const r2 = await collectReply(ctx.llm.stream(background({
|
|
817
818
|
...options, maxTokens: 2000,
|
|
818
819
|
system: prompt('interlude.round.refresh'),
|
|
819
820
|
messages: [createUserMessage({ content: [{ type: 'text', text: JSON.stringify({ interval: { nowLocal: describeNow(now) }, previousContinuity: state ?? null, script }, null, 1) }], source: { kind: 'dsh-interlude' } })],
|
|
820
|
-
})).catch((error) => { logger.warn(`continuity refresh failed: ${error.message}`); return { text: '', args: '', usage: null }; });
|
|
821
|
+
}))).catch((error) => { logger.warn(`continuity refresh failed: ${error.message}`); return { text: '', args: '', usage: null }; });
|
|
821
822
|
spent.push(usageOf(r2.usage));
|
|
822
823
|
const refresh = r2.args || r2.text;
|
|
823
824
|
const p2 = parseReply(refresh.includes('"script"') ? refresh : `{"script":"x",${refresh.replace(/^[^{]*\{/, '')}`, now);
|
|
@@ -1009,7 +1010,7 @@ export function apply(ctx, config = {}) {
|
|
|
1009
1010
|
const system = prompt('interlude.growth.system', { name: canon?.storyDefaults?.characterName ?? 'dot', maxChars: cfg.portraitMaxChars, change: `${Math.round(cfg.portraitMaxChange * 100)}%` });
|
|
1010
1011
|
const messages = [createUserMessage({ content: [{ type: 'text', text: JSON.stringify(input, null, 1) }], source: { kind: 'dsh-interlude' } })];
|
|
1011
1012
|
const call = async (msgs) => {
|
|
1012
|
-
const r = await collectReply(ctx.llm.stream({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools: [growthTool()], maxTokens: cfg.maxTokens, messages: msgs }));
|
|
1013
|
+
const r = await collectReply(ctx.llm.stream(background({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools: [growthTool()], maxTokens: cfg.maxTokens, messages: msgs })));
|
|
1013
1014
|
const u = usageOf(r.usage);
|
|
1014
1015
|
if (u) { meta.dayTokensIn = (meta.dayTokensIn ?? 0) + u.in + u.cached; meta.dayTokensCached = (meta.dayTokensCached ?? 0) + u.cached; meta.dayTokensOut = (meta.dayTokensOut ?? 0) + u.out; saveMeta(); }
|
|
1015
1016
|
try { appendFileSync(files.calls, `${JSON.stringify({ ts: new Date().toISOString(), phase: 'growth', usage: u, reply: clip(r.args || r.text, 3000) })}\n`); } catch (error) { void error; }
|
|
@@ -1221,6 +1222,11 @@ export function apply(ctx, config = {}) {
|
|
|
1221
1222
|
}
|
|
1222
1223
|
}
|
|
1223
1224
|
ctx.effect(() => { const timer = setInterval(tick, 60000); return () => clearInterval(timer); }, 'dsh-interlude: scheduler');
|
|
1225
|
+
// Model requests (src/llm-gate.js): rounds and the growth review are marked above. With dsh-dot her
|
|
1226
|
+
// looks, plays, tries and free time run in its errand (dot registers that); without it, the session
|
|
1227
|
+
// set aside in vmSession and a look / try / free-time session that is not her conversation.
|
|
1228
|
+
const herConversation = (id) => { const d = dshDot(); return d ? id === d.session?.() : id === lastActSession && id !== cfg.vmSession; };
|
|
1229
|
+
installLlmGate(ctx, { name: 'dot-interlude', backgroundSessions: (id) => ((Boolean(cfg.vmSession) && id === cfg.vmSession) || observing.has(id) || trying.has(id) || free.has(id)) && !herConversation(id) });
|
|
1224
1230
|
|
|
1225
1231
|
// 4. 幕前: the Canon is a system-prompt section (right after the deployment persona, static per
|
|
1226
1232
|
// session so the cached prefix holds); the continuity is a dynamic context after the history.
|