dsh-dot-life 0.17.4 → 0.19.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 +20 -0
- package/docs/SETTINGS.md +17 -2
- package/docs/computer.md +3 -3
- package/docs/interlude.md +1 -0
- package/docs/memory.md +9 -3
- package/docs/phone.md +2 -2
- package/docs/prompts.md +5 -2
- package/package.json +1 -1
- package/scripts/prompts.mjs +12 -8
- package/src/clock.js +30 -0
- package/src/computer/gate.js +94 -8
- package/src/dot/activity.js +10 -5
- package/src/dot/core.js +380 -61
- package/src/dot/panel.js +10 -5
- package/src/interlude/core.js +87 -12
- package/src/memory/memory.js +42 -14
- package/src/memory/recall.js +122 -10
- package/src/memory/store.js +61 -6
- package/src/phone/live-view.js +38 -13
- package/src/phone/notifications.js +17 -4
- package/src/phone/phone.js +167 -21
- package/src/prompts/dot.approval-timeout.txt +1 -0
- package/src/prompts/dot.errand-inflight.txt +4 -0
- package/src/prompts/dot.errand-no-owner.txt +1 -0
- package/src/prompts/dot.errand-note.txt +1 -1
- package/src/prompts/dot.errand-report.txt +5 -0
- package/src/prompts/dot.errand-stalled.txt +1 -0
- package/src/prompts/dot.interlude-say.txt +1 -0
- package/src/prompts/dot.loop-stopped.txt +1 -0
- package/src/prompts/dot.now.txt +1 -1
- package/src/prompts/interlude.play.txt +1 -1
- package/src/prompts/interlude.round.returned.txt +1 -0
- package/src/prompts/interlude.round.txt +3 -0
- package/src/prompts/memory.extract.input.txt +5 -0
- package/src/prompts/memory.extract.txt +8 -2
- package/src/prompts/memory.standing.txt +2 -1
- package/src/prompts/phone.device.no-wake.txt +1 -0
- package/src/prompts/phone.device.txt +1 -1
- package/src/prompts/phone.device.wake.txt +1 -0
- package/src/prompts/phone.stickers.learned.txt +1 -0
- package/src/prompts/phone.stickers.txt +1 -1
- package/src/prompts.js +56 -17
- package/src/tool-prefixes.js +2 -0
package/docs/DESIGN.md
CHANGED
|
@@ -233,3 +233,23 @@ 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: …` 带三个阈值。
|
|
246
|
+
|
|
247
|
+
## 0.19.0:一个她当家、手机租约、幕间派活
|
|
248
|
+
|
|
249
|
+
- **一个她当家**:只有她的对话跟他说话,跑腿只干活、交汇报;通知按会话线程过滤和合批;被忙会话扣住超过 `dot.heldMaxMs` 的通知改投新跑腿;同一轮里同一工具、几乎相同的参数达到 `dot.loopRepeat`(5)次就拒绝再调(`dot.loop-stopped`,审计 `loop-stopped`);一轮里的审批提醒只发一条。
|
|
250
|
+
- **手机租约**:同一时间只有一个会话操作手机(她的对话优先,幕间观察轮也走租约);QQ 只用 `qq_send` 发;dsh 停机期间漏掉的通知开机补回。
|
|
251
|
+
- **手机实时画面**:所有观看者共用一个截图循环,两帧之间至少歇截图耗时的 3 倍,失败退避,页面隐藏时暂停。起因:11-06 09:59 模拟器被自己的卡死检测杀掉(`detected a hanging thread 'QEMU2 main loop'`,主循环和 4 个 vCPU 同时 15 秒无响应);API 35 + `-gpu auto` 被强制成 CPU 软件渲染,每次截屏都在宿主 CPU 上重合成整屏。`gpu` 的说明见 phone.md。
|
|
252
|
+
- **幕间**:不再自己动手,改为给跑腿派任务(排在真实工作后面、会过期),结果和延迟作为剧情回来;虚构生活跟着她真实做过的事走,虚构人物不引发真实动作,人设只在 canon。
|
|
253
|
+
- **记忆**:BM25 + 人名两路检索用 RRF 融合;改动的碎片替换旧的,日期写成绝对日期;使用记忆的规则(只答所问、不补细节、按记录时的状态说、不猜动机)。附 chat-memory-benchmark 适配器(`bench/`)。
|
|
254
|
+
- **提示词覆盖**记下它基于哪一版内置,内置更新后面板和 `/dot prompts` 标出,`/dot prompts rebase` 对齐。
|
|
255
|
+
- 小黑盒推广通知按通知正文(来自《…》,点击查看>>)识别。
|
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
|
### 设置环境变量(只有关电脑等少数项需要)
|
|
@@ -104,8 +105,12 @@ setx DSH_DOT_COMPUTER off
|
|
|
104
105
|
| `locale` / `timezone` | `"zh-CN"` / `"Asia/Shanghai"` | 语言、时区 |
|
|
105
106
|
| `number` | `""` | 她的手机号,注册登录 App 用(也可用 `/phone number`;账号密码另存 `~/.dsh/dsh-dot-accounts.json`,见 [phone.md](phone.md)) |
|
|
106
107
|
| `window` | `true` | 显示模拟器窗口 |
|
|
107
|
-
| `gpu` | `"auto"` | 模拟器 GPU
|
|
108
|
+
| `gpu` | `"auto"` | 模拟器 GPU 模式。`auto` 在 API 35 上可能被强制成 CPU 软件渲染(`emulator.log` 里有 `forcing software rendering`),长时间跑会被模拟器的卡死检测杀掉;Mac 上可试 `"host"`(用 Mac 显卡),见 [phone.md](phone.md) |
|
|
108
109
|
| `notifyMuted` | `[]` | 不叫醒她的包名(也可用 `/phone notify mute`) |
|
|
110
|
+
| `notifyCatchUpMs` | `43200000`(12 小时) | dsh 没开时到的通知,重启后这么久以内的照样叫醒她;更早的不叫 |
|
|
111
|
+
| `leaseIdleMs` | `120000` | 同一时间只有一件事在用手机:占着的那件事这么久没碰手机(或它这一轮结束)就让出来 |
|
|
112
|
+
| `leaseWaitMs` | `60000` | 别的事要用手机时最多等这么久,等不到就告诉她稍后再试;和你的对话排在最前 |
|
|
113
|
+
| `qqSendOnPhone` | `false` | `false` = 手机 QQ 里只看不发(打字、回车会被拦下),发 QQ 用 `qq_send` |
|
|
109
114
|
| `keepAppsAlive` | `true` | 不让后台 App 被冻结(聊天 App 收消息靠它) |
|
|
110
115
|
| `publicUrl` | `""` | 你对外暴露的 dsh 地址,用于实时画面链接 |
|
|
111
116
|
|
|
@@ -160,6 +165,7 @@ setx DSH_DOT_COMPUTER off
|
|
|
160
165
|
| `recallModel` | `""` | 本机默认 `Xenova/multilingual-e5-small`;只用中文可填 `BAAI/bge-small-zh-v1.5`(更轻,23 MB / 约 0.13 GB)。建议用 `/dot memory recall model` |
|
|
161
166
|
| `recallTopK` / `recallMaxTokens` | `8` / `1500` | 每次叫醒注入多少旧对话 |
|
|
162
167
|
| `recallMinQueryLength` / `recallContrast` / `recallMinScore` | `4` / `0.35` / `0` | 话太少不查;命中要比整个索引的中位数高出一截;可选的绝对分数下限(和模型绑死,默认不用)。见 [memory.md](memory.md) |
|
|
168
|
+
| `recallLexical` / `recallNames` / `recallRrfK` | `true` / `true` / `60` | 向量之外的两条字面通道:BM25(汉字 + 两字)和人名(人物卡别名、碎片 who),按名次(RRF)合并。见 [memory.md](memory.md) |
|
|
163
169
|
| `recallMirror` | `""` | 本机模型下载镜像,默认 hf-mirror |
|
|
164
170
|
|
|
165
171
|
### `interlude`
|
|
@@ -176,7 +182,7 @@ setx DSH_DOT_COMPUTER off
|
|
|
176
182
|
| `vmSites` | `[]` | 用电脑浏览器看的网站(她登录过的) |
|
|
177
183
|
| `phoneApps` / `playApps` | 内置表 | 逛 / 玩的 App |
|
|
178
184
|
| `play` | `true` | 「玩」(点赞、评论、关注) |
|
|
179
|
-
| `speak` | `false` |
|
|
185
|
+
| `speak` | `false` | 主动找你;有 dot 时不自己发,交给她的对话(留一句「想跟他说的」),合不合适由她定,交过去才算一次 |
|
|
180
186
|
| `maxContactsPerDay` / `willingnessThreshold` | `2` / `0.6` | 主动联系的上限和门槛 |
|
|
181
187
|
| `presetHub` | `https://typ0.space` | HDSI 预设站 |
|
|
182
188
|
|
|
@@ -194,7 +200,16 @@ setx DSH_DOT_COMPUTER off
|
|
|
194
200
|
| `ownerMaxWaitMs` | `6000` | 你一直不停时,最多从第一条起等多少毫秒 |
|
|
195
201
|
| `ownerTypingMaxMs` | `15000` | QQ 报「正在输入」(NapCat)时最多等多少毫秒 |
|
|
196
202
|
| `ownerDenyMax` | `2` | 你有她没看的话时,她发给你的 `qq_send` 每轮最多被拦几次 |
|
|
203
|
+
| `notifyRules` | 见下 | 非聊天 App 的通知先过这张表(按顺序,第一条命中的算):每条 `{ "pkg": 包名(可省), "title": 正则, "text": 正则(可省), "action": "ignore" / "direct" }`。`ignore` 只记一笔 `notification-ignored`,不叫醒她;`direct`(@、回复、私信、关注她的)`notifyBatchMs` 后就叫醒;都没命中的按话题合并(见下一项)。默认:小黑盒的「黑盒今日热点订阅」「签到提醒」「今日未签到」和正文是「来自《…》,点击查看>>」的推广、资讯忽略,标题含「@了你 / 回复了你 / 关注了你 / 私信」的算 `direct`。写了就整张替换默认 |
|
|
204
|
+
| `threadBatchMs` | `20000` | 同一话题(App + 通知里引用的帖子「来自“…”」,没有就只按 App)这么多毫秒内来的通知合并成一次叫醒;跑腿正在处理某个话题时,这个话题新来的都留给同一个跑腿,不另开 |
|
|
205
|
+
| `heldMaxMs` | `600000` | 通知等忙着的跑腿等了这么久,就交给一个新的跑腿会话(记 `notification-rerouted`);那个跑腿正在处理的话题除外 |
|
|
206
|
+
| `loopRepeat` | `5` | 一轮里同一个工具、参数几乎一样(忽略空白和数字)调这么多次后,再调就被拦下,让她换个办法或说明卡在哪(记 `loop-stopped`);0 关 |
|
|
197
207
|
| `errandMaxTokens` | `60000` | 跑腿会话多长换新 |
|
|
208
|
+
| `interludeQueueMax` | `3` | 幕间想做的事(玩、用手机 / 电脑去看)不自己动手,排队交给跑腿:优先级最低,没有通知在排、在等,也没有跑腿在跑时才做,一次一件;同一件事再来只刷新过期时间;排满这么多件,最早的作废(`dropped`) |
|
|
209
|
+
| `interludeTaskTtlMs` | `1800000` | 排队这么久还没轮到就作废(`expired`)。做完、过期、作废都回给幕间:她当时想做什么、那会儿在忙什么、拖到几点才做(或没做成),下一轮写进剧情 |
|
|
210
|
+
| `turnStallMs` | `300000` | 她的一轮这么久没有任何会话事件就算卡住:记 `turn-stalled`,面板标「卡住」;是她的对话就告诉你一次(不替她取消) |
|
|
211
|
+
| `errandStallMs` | `600000` | 跑腿会话卡住这么久就放弃:取消这一轮(保留收件箱),扣着的通知放出去交给新的跑腿会话,她对话里留一句「做到一半卡住了,放弃了:…」 |
|
|
212
|
+
| `approvalWaitMs` | `600000` | 她的会话里要审批时立刻告诉你(QQ 连着发 QQ,否则 IM;一轮只发第一条,后面的只计数);这么久没人点就当拒绝,再告诉你一句过期了;0 = 一直等 |
|
|
198
213
|
| `imBot` / `imTarget` | `""` | dsh-im 的投递目标,空 = 第一个 |
|
|
199
214
|
|
|
200
215
|
## 优先级和旧文件
|
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
|
|
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
|
|
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/interlude.md
CHANGED
|
@@ -54,6 +54,7 @@ dsh 这边不需要重做一个对话系统——对话由 dsh 自己跑,IM
|
|
|
54
54
|
- `browser: auto`(默认):先走 web;URL 的主机在 `vmSites` 里就直接走 vm(她的站从不匿名看);web 结果太薄或被挡(JS 墙、验证码、登录墙)也升级到 vm,一天最多 `vmDailyCap` 次。
|
|
55
55
|
6. **玩**:幕间里她可以写一个 `playIntent`——此刻真想在手机上做的一件小事:给哪篇点个赞、评论一句、关注谁(`playActions`,发帖 / 私信 / 花钱不在其中,也写不进去)。这一轮写完后变成她会话里的一条 `[想玩会儿手机] …` 消息,她用手机去做(正常轮次,手机闸门的审批照常),做完只回 `DOT_SILENT`。门控和主动联系一样:活跃时段、意愿 ≥ 阈值、每天 ≤ `maxPlaysPerDay`(默认不限)、App 在 `playApps` 里**且装在她手机上**(没装一个就等于关)。行为准则不是我们写的,是 [Moltbook](https://www.moltbook.com/heartbeat.md) 给住在社交网络上的 agent 定的守则(节译):先回别人的回复,再慷慨点赞,再用心评论,再关注,最后才发新内容——而且只在真有话说时;参与 > 创造;真诚,不为凑数。
|
|
56
56
|
7. **主动联系(Agency,默认关)**:`speak: true` 时,模型给出的 `contact` 过四道闸——在活跃时段、意愿 ≥ `willingnessThreshold`、当天未超 `maxContactsPerDay`、dsh-im 有投递目标——才通过 `dshIm.send()` 发出去。被拦下的会记在审计日志里。
|
|
57
|
+
8. **有 dot 时幕间不自己动手**:玩和用手机 / 电脑去看,都排队交给 dot 的跑腿(`dot.interludeQueueMax`、`dot.interludeTaskTtlMs`,优先级最低:通知的活先做),这一轮不等结果;做完、过期或作废后回到 `meta.json` 的 `returned`,下一轮读到:她当时想做什么、那会儿在忙什么、拖到几点才做(或没做成)、结果如何,写进剧情和 continuity。主动联系也不自己发:交给她的对话留一句,说不说由她定。网页(web)观察照旧当场看。没装 dot 时一切照上面的老办法。
|
|
57
58
|
|
|
58
59
|
### 三、和 HDSI 的对照
|
|
59
60
|
|
package/docs/memory.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
| **画像**([Hermes](https://hermes-agent.nousresearch.com/docs/user-guide/features/memory),经 dsh-hermes-memory) | `owner`:关于你(1375 字以内);`self`:她自己的笔记——学会了什么、习惯、看法(2200 字以内)。满了要合并或删旧的 | 整理时由模型写;她自己用 `memory` 工具改 | 是 |
|
|
8
8
|
| **人物卡**(一张身份表,所有 App 共用) | 每个人一张卡,卡上有多个「把手」:`qq:919231551`(有号码时)、`qq:name:宽`(手机通知只显示名字时)、`xiaoheihe:name:暮看云`……不管从电脑 QQ、手机 QQ、小黑盒还是以后任何 App 来,都先在这张表里认人。「主人」是这张表里某个人身上的标记,不是单独的配置。档位:你 / 说过话 / 只在帖子里打过交道(只有次数和一句印象)/ 好友列表里但没说过话 | 互动次数、最后出现时间、名字、把手由**代码**按真实事件记;印象和事由模型写。关于别人的事先进**待核实** | 只在这个人叫醒她的那条消息后面附上 |
|
|
9
9
|
| **碎片**([dsh-whale-inurqq](https://github.com/FABAGV/dsh-whale-inurqq)) | 发生过的具体的事,60 字以内,带 tag(0 知道就行 / 1 影响接下来怎么说话 / 2 不记住就会出错)。同一件事再被说起:被提到次数 +1、重要度 + tag;每 5 段老化一次;可以钉住 | 整理时由模型写 | 按重要度取,约 600 token |
|
|
10
|
+
| **取代**(0.19) | 同一件事变了(新状态、改主意、改时间或数字、他更正了说法),整理时给新碎片填 `replaces`(旧碎片 id):新文字替换旧的,旧文字留在 `was` 里(不给她看),新旧不再并存。改口和更正时,新文字里带上原来的说法。为了让模型找得到要替换的旧碎片,整理时除了最要紧的 40 条,还按这段记录(BM25)列出最相关的 20 条 | 整理时由模型写 | 同碎片 |
|
|
11
|
+
| **还没了的事**(0.19) | plan / promise 碎片里还没结果的(他说要做、她答应了、"先搁着回头再说"、在等别人回):整理时标 `open`,办完、取消、他说不用了就在 `closed` 里填 id 关掉。碎片还可以带 `who`(里面的人名、昵称、店名,最多 4 个),给召回的人名通道用 | 整理时由模型写 | 单独一栏「还没了的事」,新的在前,约 200 token(`openBudgetTokens`),不和「最近的事」重复;老化和 300 条上限都不删没了的 |
|
|
10
12
|
|
|
11
13
|
## 不记的东西
|
|
12
14
|
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
|
|
33
35
|
每天 `dailyAt`(23:30)固定一次:把这一天新的记录整理掉,并让她写日记。
|
|
34
36
|
|
|
35
|
-
一次模型调用,读上次整理之后的记录(一次最多 `inputChars` 40000 字;积压更多就从最旧的开始分几次读,游标只走到真正读过的位置,不会跳过),输出画像的增删改、人物、碎片、待核实的确认。记录每行带时间:今年的写 `MM-DD HH:MM`,往年的写 `YYYY-MM-DD HH:MM`;碎片里写下的日期跟着记录走。往年记下的碎片在她面前前面会加上当时的日期(`[2025-05-08] …`),免得去年的「05-08」被读成今年;今年的照旧不加,平时的 prompt
|
|
37
|
+
一次模型调用,读上次整理之后的记录(一次最多 `inputChars` 40000 字;积压更多就从最旧的开始分几次读,游标只走到真正读过的位置,不会跳过),输出画像的增删改、人物、碎片、待核实的确认。记录每行带时间:今年的写 `MM-DD HH:MM`,往年的写 `YYYY-MM-DD HH:MM`;碎片里写下的日期跟着记录走。往年记下的碎片在她面前前面会加上当时的日期(`[2025-05-08] …`),免得去年的「05-08」被读成今年;今年的照旧不加,平时的 prompt 不变长。日期(0.19):整理输入里附一张日历(这段记录前 1 周到后 3 周,一行一周、周一开头),提示词要求把「明天」「下周三」「月底」这类说法换成具体日期写进碎片,例如「答应下周三(07-01)前寄出」,算不准就照原话。她每轮的「现在」那行也带上这周一的日期(`现在 2026-11-04 04:51 星期三 深夜(这周一是 11-02)`),问到「上周二」「前天」时有个锚点。触发:新记录满 `consolidateEveryLines`(20)条;或安静 `consolidateIdleMinutes`(30)分钟且有 3 条以上;或交班;或 `/dot memory now`。
|
|
36
38
|
|
|
37
39
|
## 日记
|
|
38
40
|
|
|
@@ -66,6 +68,10 @@ dsh 自己的压缩要到窗口的 80%(DeepSeek 是约 84 万 token)才发
|
|
|
66
68
|
- **话太少不查**(`recallMinQueryLength` 4):叫醒她的那句话去掉标点后,不同的汉字 / 假名 / 谚文个数 + 其他文字里不同的词数,少于 4 就不召回(连关键词也不翻)。`好的`、`哈哈哈哈`、`在吗?`、`ok thanks` 都不查;`我回来了`、`阿岑会修什么?`、`What did Caroline research?` 照查。
|
|
67
69
|
- **要比大多数高出一截**(`recallContrast` 0.35):一条命中的余弦要 ≥ 中位数 + 0.35 ×(最高分 − 中位数),中位数和最高分按她整个索引(当前会话之外)算。真问题总有几轮明显高出其他;含糊的话和什么都差不多像,留不下几条。索引不到 20 轮时不用这条。云端重排之后不用这条(重排分本身就是相关度)。
|
|
68
70
|
- `recallMinScore`:可选的绝对下限,默认 0(不用)。它和模型绑死:bge-small-zh 的 0.45 到 e5 上等于不过滤,e5 上要 0.87 才有同样效果,可那样英文问题一条都留不下。
|
|
71
|
+
- **三条通道,按名次合并**(0.19):向量之外再查两次字面——
|
|
72
|
+
- **BM25**(`recallLexical`):同一批块按汉字和相邻两字(其他文字按词)算 BM25,不用分词器,生造的名字也切得开。一个少见的名字(阿兰、签名牌)在 BM25 里分量很重,一句话的向量里却会被其他字冲淡。同样用「高出一截」那条过滤(对 BM25 分数算),取前 20。
|
|
73
|
+
- **人名**(`recallNames`):她认识的人的名字(人物卡,别名算一组)和碎片 `who` 里记下的名字,消息里提到哪个(2 个字起),就把提到这一组任何一个名字的轮次拉进来,提到的组越多、越新越靠前,取前 20。问"小秦"也能找到写着"秦渡"的那轮。
|
|
74
|
+
- 三张名单用 **RRF**(每条得 1/(`recallRrfK` 60 + 名次),各通道相加)合成一张,取前 `recallTopK`,不用把余弦和 BM25 分数换成同一个刻度。云端重排时,三条通道的候选一起交给重排模型打分。两个开关都关掉就和 0.18 一样只看向量。
|
|
69
75
|
- **只给她的对话**:作为动态 context 注入(dsh 放在历史之后,不破坏前缀缓存);跑腿会话看不到。
|
|
70
76
|
- **密码 / key 不进**:和碎片同一个过滤,含密码、API key 的那行不入索引、不发给云端、不注入;问话本身像密钥时不查。
|
|
71
77
|
- **后端**:
|
|
@@ -133,9 +139,9 @@ dsh 自己的压缩要到窗口的 80%(DeepSeek 是约 84 万 token)才发
|
|
|
133
139
|
|
|
134
140
|
## 配置(`dot-memory`)
|
|
135
141
|
|
|
136
|
-
`handoffTokens` 150000 · `minTokensBetweenHandoffs` 40000 · `consolidateEveryLines` 20 · `consolidateIdleMinutes` 30 · `dailyAt` 23:30 · `fragmentBudgetTokens` 600 · `agingEveryGens` 5 · `maxFragments` 300 · `handoffTailLines` 12 · `maxTokens` 16384 · `limits: { owner: 1375, self: 2200, person: 400, impression: 40 }` · `coexist` auto · `otherMemoryServices` [hermesMemory, autoMemory, dshMemory, memoryBank]
|
|
142
|
+
`handoffTokens` 150000 · `minTokensBetweenHandoffs` 40000 · `consolidateEveryLines` 20 · `consolidateIdleMinutes` 30 · `dailyAt` 23:30 · `fragmentBudgetTokens` 600 · `openBudgetTokens` 200 · `agingEveryGens` 5 · `maxFragments` 300 · `handoffTailLines` 12 · `maxTokens` 16384 · `limits: { owner: 1375, self: 2200, person: 400, impression: 40 }` · `coexist` auto · `otherMemoryServices` [hermesMemory, autoMemory, dshMemory, memoryBank]
|
|
137
143
|
|
|
138
|
-
自动召回:`recallBackend` local · `recallModel` ''(后端默认;本机是 `Xenova/multilingual-e5-small`)· `recallRerankModel` ''(云端默认;`none` 不重排)· `recallMirror` ''(`HF_ENDPOINT`,否则 hf-mirror.com)· `recallInstall` true · `recallTransformersVersion` 4.3.2 · `recallTopK` 8 · `recallMaxTokens` 1500 · `recallMinQueryLength` 4(0 关掉)· `recallContrast` 0.35(0 关掉)· `recallMinScore` 0(可选的绝对下限:本机余弦 / 云端重排分)· `recallCandidates` 40 · `recallWindowTurns` 0(整个当前会话不取)· `recallChunkChars` 1200 · `recallWaitMs` 3000 · `recallSiliconflowUrl` · `recallDashscopeUrl`。命令改的值存在 `$DSH_HOME/dsh-memory.json`,优先于这里。
|
|
144
|
+
自动召回:`recallBackend` local · `recallModel` ''(后端默认;本机是 `Xenova/multilingual-e5-small`)· `recallRerankModel` ''(云端默认;`none` 不重排)· `recallMirror` ''(`HF_ENDPOINT`,否则 hf-mirror.com)· `recallInstall` true · `recallTransformersVersion` 4.3.2 · `recallTopK` 8 · `recallMaxTokens` 1500 · `recallMinQueryLength` 4(0 关掉)· `recallContrast` 0.35(0 关掉)· `recallMinScore` 0(可选的绝对下限:本机余弦 / 云端重排分)· `recallCandidates` 40 · `recallWindowTurns` 0(整个当前会话不取)· `recallChunkChars` 1200 · `recallLexical` true · `recallNames` true · `recallRrfK` 60 · `recallWaitMs` 3000 · `recallSiliconflowUrl` · `recallDashscopeUrl`。命令改的值存在 `$DSH_HOME/dsh-memory.json`,优先于这里。
|
|
139
145
|
|
|
140
146
|
`DSH_DOT_MEMORY=off` 整个组件不加载。
|
|
141
147
|
|
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 条。
|
|
@@ -29,7 +29,7 @@ An Android phone the plugin installs and runs for the character, exposed to the
|
|
|
29
29
|
| `window` / `DSH_DOT_PHONE_WINDOW=off` | `true` | 显示模拟器窗口 |
|
|
30
30
|
| `liveView` | `true` | 在 dsh 的 web server 上挂实时画面页(`/dsh-dot/phone/`);`false` 关闭 |
|
|
31
31
|
| `publicUrl` | 无 | 这个 dsh 对外的地址(你自己的暴露方式);实时画面链接 = `<publicUrl>/dsh-dot/phone/`,写进审批提醒 |
|
|
32
|
-
| `gpu` | `auto` | 模拟器 `-gpu` |
|
|
32
|
+
| `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` |
|
|
33
33
|
| `keepAppsAlive` / `keepAliveEveryMinutes` | `true` / `10` | 关掉 doze、standby、cached-apps freezer,给所有第三方 App(含她以后装的)后台运行许可,否则 QQ 退后台几分钟就被冻结、收不到消息(真机实测:发出到弹通知差 3.5 分钟) |
|
|
34
34
|
| `locale` / `timezone` | `zh-CN` / `Asia/Shanghai` | 手机的语言和时区 |
|
|
35
35
|
| `number` | 无 | 她的手机号(注册、登录 App 用);也可用 `/phone number <号码>` 设 |
|
package/docs/prompts.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
插件交给模型的每一段话都是 `src/prompts/` 里的一个 UTF-8 纯文本文件,文件名就是它的代号(`dot.rules.txt` → `dot.rules`)。代码只负责拼:按情况选文件、把 `{名字}` 换成实际内容。
|
|
4
4
|
|
|
5
|
-
**覆盖**:把文件复制到 `<home>/prompts/`(`<home>` 是她的家目录,默认 `~/dot`,即 `dot.home`)再改,同名文件优先于内置的。按修改时间重新读,改完她下一轮就用新的,不用重启 dsh
|
|
5
|
+
**覆盖**:把文件复制到 `<home>/prompts/`(`<home>` 是她的家目录,默认 `~/dot`,即 `dot.home`)再改,同名文件优先于内置的。按修改时间重新读,改完她下一轮就用新的,不用重启 dsh;删掉覆盖文件就回到内置版本。升级插件不会动你的覆盖。
|
|
6
|
+
|
|
7
|
+
**基线**:覆盖文件第一行可以是 `# base: <hash>`,记着它是照哪版内置改的(内置文本的 sha256 前 12 位,这一行不算进提示词);页面「保存」会自动写上。内置变了,`/dot prompts` 和 dot 面板会列出「默认已更新」的代号,没有这一行的列为「未记录基线」。`/dot prompts rebase <id>` 把你的覆盖和现在的内置逐行对比(`-` 只在覆盖里,`+` 只在内置里),并记下新基线,表示看过了;`/dot prompts rebase <id> --reset` 删掉覆盖,回到内置。
|
|
6
8
|
|
|
7
9
|
**写法**:
|
|
8
10
|
- `{名字}` 是占位符,代码填;没填到的原样留着,并在日志里提醒一次。别删,删了那部分内容就不出现了。
|
|
@@ -26,8 +28,9 @@
|
|
|
26
28
|
| | 记忆 / 想起的原话 | `memory.standing` / `memory.recall.header` |
|
|
27
29
|
| 叫醒她的消息 | 他的 QQ 消息 | `dot.owner-words`(她这轮进行中插进来时多一行 `dot.owner-words.busy`) |
|
|
28
30
|
| | 他插话了 | `dot.owner-interrupt`(发给他的 `qq_send` 被拦下的理由)/ `qq.send-interrupted`(气泡发到一半他说话) |
|
|
31
|
+
| | 审批过期 | `dot.approval-timeout`(`dot.approvalWaitMs` 没人点时她看到的工具结果,替换 dsh 的 "the user rejected tool") |
|
|
29
32
|
| | 手机通知 | `dot.notification` `.many` `.busy` `.how-qq` `.how-mixed` `.how-app` `.cards` `.unverified` |
|
|
30
|
-
| | 拿起手机 / 跑腿回来 | `dot.phone-check` / `dot.errand-note` `dot.errand-note.what
|
|
33
|
+
| | 拿起手机 / 跑腿回来 | `dot.phone-check` / `dot.errand-note` `dot.errand-note.what`(跑腿卡住被放弃:`dot.errand-stalled`) |
|
|
31
34
|
| | 交接 | `memory.handoff` |
|
|
32
35
|
| | 幕间:去看一眼 | `interlude.observation` `.where` `.vm` `.phone` |
|
|
33
36
|
| | 幕间:玩一会儿 | `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.
|
|
3
|
+
"version": "0.19.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",
|
package/scripts/prompts.mjs
CHANGED
|
@@ -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: '
|
|
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,10 @@ 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: '
|
|
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;幕间里她想跟他说的话也这样留进对话(dot.interlude-say),说不说由对话里的她定', files: ['dot.errand-note', 'dot.errand-note.what', 'dot.errand-stalled', 'dot.interlude-say'],
|
|
99
|
+
render: () => variant([...['phone-check', 'notification', 'play', 'other'].map((o) => [o, D.errandNote(o, '小黑盒上暮看云回了我的评论,说他也觉得低频糊。')]), ['卡住了,放弃', D.errandNote('phone-check', D.errandStalledText('等 mobile_install_app 的审批', 10))], ['幕间想跟他说的', P.prompt('dot.interlude-say', { text: '降温了,你那边冷不冷' })]]) },
|
|
100
|
+
{ id: 'onevoice', group: 'wake', name: '跑腿只汇报', note: '跑腿那一轮带着 dot.errand-report;跑腿给他发 qq_send 被拦下时的工具结果;跑腿还在做时她对话里的一行;一轮里同一个调用重复 dot.loopRepeat 次后被拦下的工具结果', files: ['dot.errand-report', 'dot.errand-no-owner', 'dot.errand-inflight', 'dot.loop-stopped'],
|
|
101
|
+
render: () => { const t = P.table('dot.errand-inflight'); return variant([['跑腿那一轮', P.prompt('dot.errand-report', { silent: D.SILENT })], ['跑腿找他被拦', P.prompt('dot.errand-no-owner')], ['她对话里:还在做的', P.fill(t.line, { doing: `${P.fill(t.thread, { app: '小黑盒', source: '《耳机测评》', count: 3 })};${t.other}` })], ['重复调用被拦', P.prompt('dot.loop-stopped', { times: 5 })]]); } },
|
|
98
102
|
{ id: 'handoff', group: 'wake', name: '交接', note: '对话太长换新会话时,新会话的开头', files: ['memory.handoff'],
|
|
99
103
|
render: () => M.renderHandoff({ now: '窝在床上改简历,有点困', inFlight: ['帮他查广州降温'], promises: ['周五提醒他交 benchmark'], openQuestions: ['他感冒好了没'] }, LINES.slice(-2), 3) },
|
|
100
104
|
{ id: 'observation', group: 'wake', name: '幕间:去看一眼', note: '她自己想去看看的时候,只看不动', files: ['interlude.observation', 'interlude.observation.where', 'interlude.observation.vm', 'interlude.observation.phone'],
|
|
@@ -107,10 +111,10 @@ export const entries = [
|
|
|
107
111
|
const m = sampleMemory();
|
|
108
112
|
return M.extractPrompt({ recent: LINES.slice(0, 2).map(M.transcriptLine).join('\n'), text: LINES.slice(2).map(M.transcriptLine).join('\n'), owner: m.owner, self: m.self, known: 'u0002 · 阿满 · qq:42 · talked', frags: m.fragments.map((f) => `${f.id} | ${f.text}`).join('\n'), pending: m.pending.map((x) => `${x.id} | ${x.person} | ${x.text}`).join('\n'), withHandoff: true, withDiary: true, day: M.dayLabel(new Date()) });
|
|
109
113
|
} },
|
|
110
|
-
{ id: 'round', group: 'call', name: '幕间一轮', note: '写她这段时间的生活:interlude.round 是整段系统提示词(HDS-Interlude 的规则,译成中文),后面是按情况填进去的小段', files: ['interlude.round', 'interlude.round.canon', 'interlude.round.length', 'interlude.round.length.deepseek', 'interlude.round.length.claude', 'interlude.round.length.gemini-flash', 'interlude.round.length.gpt', 'interlude.round.phase.advance', 'interlude.round.phase.follow-up', 'interlude.round.phase.intent', 'interlude.round.her-life', 'interlude.round.contact-rule', 'interlude.round.contact-rule.off', 'interlude.round.browsing.deferred', 'interlude.round.browsing.disabled', 'interlude.round.agency', 'interlude.round.play', 'interlude.round.play.collect', 'interlude.round.glm', 'interlude.round.style.none', 'interlude.round.seed', 'interlude.round.play-intents', 'interlude.round.play-intents.off', 'interlude.round.contact', 'interlude.round.contact.off', 'interlude.round.refresh'],
|
|
114
|
+
{ id: 'round', group: 'call', name: '幕间一轮', note: '写她这段时间的生活:interlude.round 是整段系统提示词(HDS-Interlude 的规则,译成中文),后面是按情况填进去的小段', files: ['interlude.round', 'interlude.round.canon', 'interlude.round.length', 'interlude.round.length.deepseek', 'interlude.round.length.claude', 'interlude.round.length.gemini-flash', 'interlude.round.length.gpt', 'interlude.round.phase.advance', 'interlude.round.phase.follow-up', 'interlude.round.phase.intent', 'interlude.round.her-life', 'interlude.round.returned', 'interlude.round.contact-rule', 'interlude.round.contact-rule.off', 'interlude.round.browsing.deferred', 'interlude.round.browsing.disabled', 'interlude.round.agency', 'interlude.round.play', 'interlude.round.play.collect', 'interlude.round.glm', 'interlude.round.style.none', 'interlude.round.seed', 'interlude.round.play-intents', 'interlude.round.play-intents.off', 'interlude.round.contact', 'interlude.round.contact.off', 'interlude.round.refresh'],
|
|
111
115
|
render: () => {
|
|
112
|
-
const r = I.buildPrompt({ phase: 'advance', identity: I.renderCanon(CANON), state: STATE, script: '11-03 14:00:她把窗帘拉开一半,靠在床头改简历。', cursor: Date.now() - 90 * 6e4, now: new Date(), speak: true, model: 'deepseek-chat', entries: [{ owner: 'user', at: '11-03 15:10', content: '在吗' }], browser: 'deferred', play: true, playApps: ['小黑盒', 'B站'], playActions: ['like', 'comment', 'follow', 'collect'], stickers: 2, memories: ['他叫宽,在广州做 AI agent 开发'], herLife: ['装了小黑盒,常在晚上逛'] });
|
|
113
|
-
return variant([['system(生活推进、主动联系开、玩开、浏览延后、herLife
|
|
116
|
+
const r = I.buildPrompt({ phase: 'advance', identity: I.renderCanon(CANON), state: STATE, script: '11-03 14:00:她把窗帘拉开一半,靠在床头改简历。', cursor: Date.now() - 90 * 6e4, now: new Date(), speak: true, model: 'deepseek-chat', entries: [{ owner: 'user', at: '11-03 15:10', content: '在吗' }], browser: 'deferred', play: true, playApps: ['小黑盒', 'B站'], playActions: ['like', 'comment', 'follow', 'collect'], stickers: 2, memories: ['他叫宽,在广州做 AI agent 开发'], herLife: ['装了小黑盒,常在晚上逛'], returned: [{ kind: 'play', wanted: '小黑盒 like:那篇耳机测评', status: 'done', queuedAt: '2026-11-03 15:20 星期二 下午', busyWith: '看小黑盒《帖子A》的 3 条', startedAt: '2026-11-03 15:41 星期二 下午', doneAt: '2026-11-03 15:43 星期二 下午', report: '做了:点了赞\n结果:成了\n找他:不用' }] });
|
|
117
|
+
return variant([['system(生活推进、主动联系开、玩开、浏览延后、herLife 有内容、有回来的事、DeepSeek 模型)', r.system], ['user', r.user], ['补全那一次(第一次没给全时)', P.prompt('interlude.round.refresh')]]);
|
|
114
118
|
} },
|
|
115
119
|
{ id: 'score', group: 'call', name: '群消息打分', note: '群消息值不值得她插一句(群消息设成打分时)', files: ['qq.score.system', 'qq.score.who', 'qq.score.user'],
|
|
116
120
|
render: () => { const r = Q.scorePrompt({ who: '小点:二十三岁,话少、直接', recent: '阿满:今晚谁打瓦\n老王:我', message: '小点你上次说的那个耳机多少钱', group: '123456' }); return variant([['system', r.system], ['user', r.user]]); } },
|
|
@@ -171,7 +175,7 @@ function save(id, text, src) {
|
|
|
171
175
|
const body = `${String(text).replace(/\r\n/g, '\n').replace(/\n*$/, '')}\n`;
|
|
172
176
|
const path = src ? P.builtinPath(id) : P.overridePath(id);
|
|
173
177
|
mkdirSync(dirname(path), { recursive: true });
|
|
174
|
-
writeFileSync(path, body);
|
|
178
|
+
writeFileSync(path, src ? body : P.stamp(id, body));
|
|
175
179
|
const lost = placeholders(readFileSync(P.builtinPath(id), 'utf8')).filter((k) => !body.includes(`{${k}}`));
|
|
176
180
|
return { text: `已保存:${path}`, warn: lost.length ? `注意:${lost.map((k) => `{${k}}`).join(' ')} 不见了,那里的内容就不会再出现` : '' };
|
|
177
181
|
}
|
package/src/clock.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// stamp MM-DD HH:MM (year rule as dayMark) — the stamp every message that wakes her carries
|
|
4
4
|
// describeNow YYYY-MM-DD HH:MM 星期X 时段 (the interlude's nowLocal; her `dot:now` line)
|
|
5
5
|
// ago "3 小时 12 分" since a moment; '' under a minute
|
|
6
|
+
// calendar whole weeks around a span, one line per week (Monday first), for turning 下周三 into a date
|
|
7
|
+
// mondayOf MM-DD of the Monday of a moment's week
|
|
6
8
|
// unstamp a stamped wake line back to what it said (the transcript keeps its own time)
|
|
7
9
|
|
|
8
10
|
const p2 = (n) => String(n).padStart(2, '0');
|
|
@@ -43,3 +45,31 @@ export function ago(ms, now = Date.now()) {
|
|
|
43
45
|
const STAMP = String.raw`(?:\d{4}-)?\d{2}-\d{2} \d{2}:\d{2}`;
|
|
44
46
|
/** "[11-04 04:51] 在吗" → "在吗"; "[11-04 04:52 手机通知] …" → "[手机通知] …"; anything else as is. */
|
|
45
47
|
export const unstamp = (text) => String(text ?? '').replace(new RegExp(`^\\[${STAMP}\\] `), '').replace(new RegExp(`^\\[${STAMP} `), '[');
|
|
48
|
+
|
|
49
|
+
const WEEKDAY = '日一二三四五六';
|
|
50
|
+
const DAY = 86400000;
|
|
51
|
+
const startOfDay = (ms) => { const d = new Date(ms); d.setHours(0, 0, 0, 0); return d.getTime(); };
|
|
52
|
+
/** Midnight of the Monday of `ms`'s week (local time). */
|
|
53
|
+
export function mondayMs(ms) {
|
|
54
|
+
const d = new Date(startOfDay(ms));
|
|
55
|
+
d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
|
|
56
|
+
return d.getTime();
|
|
57
|
+
}
|
|
58
|
+
/** "06-29" (dayMark rule) of the Monday of `ms`'s week. */
|
|
59
|
+
export const mondayOf = (ms, now = ms) => dayMark(mondayMs(ms), now);
|
|
60
|
+
/**
|
|
61
|
+
* Whole weeks from `before` days before `from` to `after` days after `to`, a line per week, Monday
|
|
62
|
+
* first: "06-29一 06-30二 07-01三 … 07-05日". Dates follow dayMark (another year → YYYY-MM-DD).
|
|
63
|
+
*/
|
|
64
|
+
export function calendar(from, to, { before = 7, after = 21, now = to } = {}) {
|
|
65
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) return '';
|
|
66
|
+
const lines = [];
|
|
67
|
+
// Step by calendar days (setDate), not by 24 h, so a DST change never skips or repeats a day.
|
|
68
|
+
const end = startOfDay(to + after * DAY);
|
|
69
|
+
for (let d = new Date(mondayMs(from - before * DAY)); d.getTime() <= end;) {
|
|
70
|
+
const week = [];
|
|
71
|
+
for (let i = 0; i < 7; i++) { week.push(`${dayMark(d.getTime(), now)}${WEEKDAY[d.getDay()]}`); d.setDate(d.getDate() + 1); }
|
|
72
|
+
lines.push(week.join(' '));
|
|
73
|
+
}
|
|
74
|
+
return lines.join('\n');
|
|
75
|
+
}
|
package/src/computer/gate.js
CHANGED
|
@@ -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`\
|
|
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`\
|
|
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
|
|
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))
|
|
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
|
|
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
|
|
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()}` };
|
package/src/dot/activity.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
}
|