dsh-dot-life 0.23.2 → 0.23.3
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 +71 -44
- package/README.md +115 -64
- package/docs/DESIGN.md +42 -0
- package/docs/DOT-PAGE.md +9 -0
- package/docs/SETTINGS.md +4 -0
- package/docs/prompts.md +1 -1
- package/docs/qq.md +2 -0
- package/package.json +1 -1
- package/scripts/prompts.mjs +3 -3
- package/src/dot/core.js +138 -17
- package/src/interlude/core.js +116 -44
- package/src/llm-gate.js +58 -4
- package/src/memory/memory.js +23 -5
- package/src/page/api.js +10 -1
- package/src/page/page.js +29 -2
- package/src/prompts/dot.owner-words.txt +1 -0
- package/src/prompts/dot.owner-words.unsent.txt +3 -0
- package/src/prompts/interlude.round.not-kept.txt +1 -0
- package/src/prompts/interlude.round.refresh.txt +1 -1
- package/src/prompts/interlude.round.txt +3 -2
- package/src/qq/qq.js +97 -15
- package/src/reset.js +129 -0
- package/src/settings-schema.js +3 -0
package/docs/DESIGN.md
CHANGED
|
@@ -226,6 +226,15 @@ Kevin:"感觉现在很难给他长任务。他很容易直接结束然后就
|
|
|
226
226
|
- **发出前拦截**:`tools/pre-execute` 里,发给他的 `qq_send` 遇到他还有没读的话——缓冲里有,或 `exec.agent.inbox.nextStep` 里还有 `qq-dot-` 来源的消息(steer 了、模型还没读)——就 `deny`,理由是 `dot.owner-interrupt`,并且立刻把缓冲 steer 进去(同步,用 `exec.agent`)。每轮最多 `ownerDenyMax`(2)次,之后放行(`owner-gate-passed`),免得他一直打字时她永远发不出去。
|
|
227
227
|
- **气泡可中断**:`qq.send` 发给他时,每个气泡(第 2 条起)发之前看 `qq.ownerSaidSince(开始时刻)`;他说了话就停,返回 `{ sent, interrupted: true, unsent }`,她看到 `qq.send-interrupted`。
|
|
228
228
|
- **规则**:`dot.rules` 加一条:他连着发几条时等他说完、按最后一条的意思回、不逐条回;回到一半他又说话,先看。
|
|
229
|
+
- **发也算忙,第一条气泡为界**(0.24):她对他只有三种状态——在写(他的话开的那一轮还开着)、在发(这一轮的回答正一条条发到他 QQ)、都不是。规则只有一条:**还没到他那的让给他刚说的,已经到他那的算数**。
|
|
230
|
+
- 在写、这一轮还没调过工具:取消这一轮(`agent.cancel(..., { keepInbox: true })`),同一拍里把他刚说的排进下一轮(`agent.send(message, 'next-turn', true)`:宿主把取消之后来的唤醒输入留给下一轮,中止落定后自己开——不等我们的 promise,顺序就是宿主收件箱的顺序)。被取消的那一轮结束时记 `owner-turn-restarted`:真中止了就什么都不留;取消来晚了、它照常写完了(`aborted: false`),那段回答不发,留作草稿。调过工具的不取消,照旧 steer。
|
|
231
|
+
- 写完要发、缓冲里有他没读的话:整条回答不发,留作草稿(`owner-reply-held`)。
|
|
232
|
+
- 在发:`qq.send` 在下一条气泡前停下,剩下的留作草稿;他的话等这次发送停稳再交给她,不并行开新一轮。
|
|
233
|
+
- 草稿跟着他的下一批话给她看一次(`dot.owner-words.unsent`),由她决定重说还是放下;记忆记他的原话时把这段去掉。五分钟内他没再说话,草稿作废,记 `owner-draft-dropped`。
|
|
234
|
+
- 发到一半 QQ 报错:已经到他那的气泡照常记,没发出去的同样留作草稿(`qq-relayed` 带 `error`);一条都没发出去才算失败。
|
|
235
|
+
- 连着让 `ownerPreemptMax`(2)次之后先把话发出去;有一条气泡到了他那就清零——她自己用 `qq_send` 回的、或这一轮她选择不说话,也清零。所以她只要发出一条,这一轮就不会再被取消。
|
|
236
|
+
- 直接回答走 `sayToOwner` 一个出口;`qq.send` 对同一个对象的发送排队,两次发送的气泡不会交错。
|
|
237
|
+
- 她的记录按送达写:QQ 轮次的回答不在 `turn/end` 记,由 dot 把真正发出去的气泡报给记忆(`dotMemory.herSaid`)。`sentToOwnerAt` 只由她自己的 `qq_send` 设置。
|
|
229
238
|
- **记忆只记发出去的**:`qq_send` 不再在 `tool/call` 时按参数记,而是等同一 `callId` 的 `tool/result`:出错或被拦(`isError`)→ 不记;否则记 `meta.said` / `meta.imagesSent`(`qq_send` 的 `output.presentationMeta`,落在持久的 `tool/result` 上:打断后没发的、丢掉的英文行、上传失败的图都不在里面)。没有 meta 的旧结果按 `sent N` 取前 N 行。时间用调用的时刻,按时间插回 `lines`(handoff 尾巴、recall 都读它),重放会话日志(`transcriptFromEvents`)走同一个 `qqSentText`。
|
|
230
239
|
|
|
231
240
|
## v0.17.2(2026-11-04):图——她发的记成能发的样子,别人发的她看得见
|
|
@@ -354,3 +363,36 @@ Kevin:"感觉现在很难给他长任务。他很容易直接结束然后就
|
|
|
354
363
|
- **让 dsh 的重试有用**(`llm.holdRetries`,默认开):同一会话同一 provider 在 `RATE_LIMIT` 之后十几秒内又发请求,就是 dsh 的重试;先按 retry-after,或等到这一分钟里最老的请求老化出去(按命中时窗口里的请求数估上限),最多 30 秒。这是闸门唯一碰前台请求的地方。
|
|
355
364
|
- **不碍事**:闸门内部任何异常只记 debug,请求照常放行。`/dot` 多一行 `model requests: …`,dot 页面「状态」多一张「模型请求」卡;冷却开始 / 结束各记一条日志和审计。
|
|
356
365
|
- 不做:不改后台工作触发的频率,不改 dsh 的重试本身,不记跨进程的状态。
|
|
366
|
+
|
|
367
|
+
## 0.23.3:后台干活的思考强度和对话分开
|
|
368
|
+
|
|
369
|
+
起因(11-17):为了聊天更像人,把她对话的思考强度从 Low 改成 Off。dsh 只有一个模型选择器,在对话里改会同时存成全局默认;幕间叙述、记忆整理、成长回顾、用法回顾这些手写请求读的正是这个默认(`agentDefaultModel.currentSelection()`),新建的跑腿会话也继承它——于是聊天关思考等于全关。当天 16:16 那一轮幕间在没有任何设备活动的情况下把「登好了 QQ」写成了事实,那一轮多半就是 Off 跑的;多半,因为 `calls.jsonl` 当时不记强度。
|
|
370
|
+
|
|
371
|
+
- 一个设置 `llm.workEffort`(默认 `high`,`''` = 跟随选择器),一个函数 `workEffort(ctx, route, want)`(`src/llm-gate.js`,和「哪些请求算后台」同一个地方):
|
|
372
|
+
- 手写请求(幕间一轮和成长回顾、记忆的 `complete()`、`reflectOnce`)发之前问它;
|
|
373
|
+
- 跑腿会话:往里送任何东西之前(`resolveLive`),用 `agent.model.select(...)` 把这个会话自己的选择设好——只记在这个会话里,持久,已经是这个值就什么都不做;审计 `errand-effort`(原来是什么、设成什么、为什么)。**不能**走 `agent/request` 瀑布:宿主(agent-loop 0.2.2)在一步开始前就把模型选择定死,瀑布里改强度会让整轮失败(`agent/request proposed reasoning effort "high" after step preparation fixed "off"`)——第一版就是这么写的,上线后一次看手机的跑腿因此失败,十几分钟后改掉。没有 `agent.model.select` 的旧宿主:跑腿跟随选择器;
|
|
374
|
+
- QQ 群聊评分固定 `off`(只出一个数字,`maxTokens: 8`);
|
|
375
|
+
- 她的对话、别的会话:不碰,选择器说什么就是什么。
|
|
376
|
+
- 模型不支持的强度不会发出去(宿主会在请求前直接拒):先用 `llm.resolveCallConfig`(没有就 `prepareCall`)问一次,按 provider/model/强度记住;明确说不支持 → 跟随选择器并在日志里说一次;问不了(适配器还没注册、宿主没有这个查询)→ 这次跟随,下次再问。dot 没有 inject `llm`,读 `ctx.llm` 会抛,所以先 `ctx.get('llm')`(第一版只包了一层 try,一抛就当成「问不了」,设置等于没生效)。
|
|
377
|
+
- 看得见:闸门记下每类请求实际带出去的强度,`/dot` 的 model requests 一行多了 `thinking: chat off, background high`;幕间 `calls.jsonl` 每条带 `effort`。
|
|
378
|
+
- 没做的:换对话 / 交接时「把对话的强度抄过去」。新对话继承的是全局默认,而全局默认就是他上一次在选择器里选的——通常正是对话那个;在别的会话里改过才会不一致,到时在新对话里再选一次。为这个加一份状态不值得。
|
|
379
|
+
|
|
380
|
+
## 0.23.3:幕间——设备上的事只认记录
|
|
381
|
+
|
|
382
|
+
起因同上(11-17 16:16 那一轮,没有任何设备活动却写她在新手机上登好了 QQ,又原样进了她的对话)。
|
|
383
|
+
|
|
384
|
+
- **输入**:每轮固定带 `deviceFacts`(`deviceFacts(items, returned)`)——上一轮以来真跑过手机 / 电脑工具的那些 act(`pending.jsonl` 的 `tools > 0` 且有 `on`)和办完回来的跑腿,一条一个 id;什么都没有就是 `[]`,提示词里写明空表的意思是「她没碰过」。`webContext` 每条也带 id(`w1…`)。
|
|
385
|
+
- **输出**:必填 `onDevices`:剧本和 continuity 里凡是说她这段时间在手机 / 电脑上做了什么的,每件一条,`basis` 填依据的 id。
|
|
386
|
+
- **核对**(`checkDeviceClaims`):有 `basis` 不在给出去的 id 里(或整栏没有)→ 带着 `notKept`(哪几件没有记录)重写一次;第二稿还不行 → 这一轮整段不留:不写剧本、不更新 continuity、不派 intents / 玩 / 试,`pending` 留给下一轮,按失败退避(`round-unbacked`、`round-rejected`)。seed 轮不核对。
|
|
387
|
+
- **这道核对能做到什么**(11-17 拿 16:16 的真实输入重放,每组 5 次,样本小):
|
|
388
|
+
|
|
389
|
+
| 提示词 | 思考 | 把没做的设备操作写成做了 |
|
|
390
|
+
|---|---|---|
|
|
391
|
+
| 旧 | off | 4/4(1 次没解析出来) |
|
|
392
|
+
| 旧 | high | 3/5 |
|
|
393
|
+
| 新(deviceFacts + onDevices) | high | 0/5 |
|
|
394
|
+
| 新,去掉 onDevices | high | 2/3(2 次没解析出来) |
|
|
395
|
+
| 新 | off | 4/5,而且 5 次 `onDevices` 全是 `[]` |
|
|
396
|
+
|
|
397
|
+
也就是:新提示词加 high 才干净;思考关掉时叙述者照编不误,并且不申报,**核对一条也拦不住**。`onDevices` 的作用是逼它动笔后回头数一遍(去掉它 high 也会编),不是一道保证。另试过让一个独立的小请求来挑(思考 off):编了的 4 稿全挑出来了,但干净的 5 稿里也有 4 稿被挑出「看了一眼屏幕」之类——误报太多,没采用。
|
|
398
|
+
- 所以保证不在这里:靠 `llm.workEffort` 不被关掉,加上下一步(她答应他的事由代码记状态,跑腿真做完才算做了)。
|
package/docs/DOT-PAGE.md
CHANGED
|
@@ -95,6 +95,15 @@
|
|
|
95
95
|
|
|
96
96
|
### 6. 危险区(页底,折叠)
|
|
97
97
|
|
|
98
|
+
**重置她**(`src/reset.js`):四个等级,后一级包含前一级——只清记忆 / 记忆 + 幕间 / 记忆 + 幕间 + 新对话(默认)/ 全部从零(再加 App 用法笔记、表情包、面板活动记录的三份运行日志、当天的计数)。选等级、输入 `dot`、再确认一次。
|
|
99
|
+
|
|
100
|
+
- 不删除:范围内的东西整体挪进 `~/.dsh/dsh-dot-resets/<时间>/`(在她的 home 之外,她自己读不到旧记忆),挪回去就恢复。人设(`interlude/canon.json*`)、设置文件、手机和电脑里装的东西从不动;手机用下面的重建。「全部从零」里的表情包例外:同步在手机相册 `dot-stickers` 里的那几张下次同步时会被清掉。
|
|
101
|
+
- 清完记忆后在 `memory/no-backfill` 留一个记号:记忆组件不再把旧对话的会话日志读回来(否则「只清记忆」「记忆 + 幕间」两级不换对话,一启动又补回去了)。
|
|
102
|
+
- 中途出错就把已经挪走的全部放回原位,结果里写 `rolledBack`;失败的不会每次启动重试。
|
|
103
|
+
- 不在运行中做:记忆、幕间、dot 的状态都在内存里,边跑边挪会被写回去。页面只写一个标记(`~/.dsh/dsh-dot-reset.json`),**下次启动**时由最先加载的组件在读任何状态之前执行(各组件 `apply` 第一行 `runPendingReset`),结果记在 `dsh-dot-reset.last.json`。重启前可以取消。「下次启动」是代码保证的:安排它的那个进程自己不执行(运行中某个组件被重新 apply 时别的组件还活着),一个进程最多执行一次。
|
|
104
|
+
- 「新对话」把旧对话记进 `pastConversations`:以后在旧对话里再跑一轮,也不会把它重新认成她的对话。
|
|
105
|
+
- 「新对话」只清掉她的对话和跑腿指针,旧会话仍在 dsh 的列表里。之后他的第一条 QQ 消息会在她的 home 里开一段新对话(`conversation-opened`);以前没有对话时他的消息是直接丢掉的(`no session yet`)。
|
|
106
|
+
|
|
98
107
|
重建手机(会丢她装的 App 和登录)、删电脑、释放下载缓存;都要输入名字确认。
|
|
99
108
|
|
|
100
109
|
## 服务端
|
package/docs/SETTINGS.md
CHANGED
|
@@ -161,6 +161,8 @@ setx DSH_DOT_COMPUTER off
|
|
|
161
161
|
| `typingMsPerChar` | `60` | 分条发送的打字停顿,0 一次发完 |
|
|
162
162
|
| `tidy` | `true` | 去掉句号、引号、破折号等书面符号 |
|
|
163
163
|
| `dropLatinLeaks` | `true` | 不发整条都是英文的气泡(思考漏出来),短英文照发 |
|
|
164
|
+
| `dropEchoOpeners` | `true` | 私聊:不发只是重复对方上一句的开头气泡(后面还有别的气泡时) |
|
|
165
|
+
| `dropChainedQuestions` | `false` | 私聊:上一轮刚问过对方时,不发这一轮里的问句(整条回复只有问句时照发);办事时要问的话也可能被拦,所以默认关 |
|
|
164
166
|
| `ignore` | `""` | 不回复的 QQ 号(别的机器人),逗号或空格分开;qq-bridge 的机器人号自动认出,不用填 |
|
|
165
167
|
| `loopMax` | `4` | 防互刷(只管群聊):一个群里和同一个号一来一回这么多轮、中间没别人说话,就暂停理它;0 关 |
|
|
166
168
|
| `loopCooldownMinutes` | `10` | 防互刷暂停多久 |
|
|
@@ -223,6 +225,7 @@ setx DSH_DOT_COMPUTER off
|
|
|
223
225
|
| `ownerMaxWaitMs` | `6000` | 你一直不停时,最多从第一条起等多少毫秒 |
|
|
224
226
|
| `ownerTypingMaxMs` | `15000` | QQ 报「正在输入」(NapCat)时最多等多少毫秒 |
|
|
225
227
|
| `ownerDenyMax` | `2` | 你有她没看的话时,她发给你的 `qq_send` 每轮最多被拦几次 |
|
|
228
|
+
| `ownerPreemptMax` | `2` | 她的话还没到你那、你又说了话时,她连着最多让几次(重写这一轮,或把写好的回答留作草稿);之后先发出去。有一条气泡到了你那就清零 |
|
|
226
229
|
| `notifyRules` | 见下 | 非聊天 App 的通知先过这张表(按顺序,第一条命中的算):每条 `{ "pkg": 包名(可省), "title": 正则, "text": 正则(可省), "action": "ignore" / "direct" }`。`ignore` 只记一笔 `notification-ignored`,不叫醒她;`direct`(@、回复、私信、关注她的)`notifyBatchMs` 后就叫醒;都没命中的按话题合并(见下一项)。默认:小黑盒的「黑盒今日热点订阅」「签到提醒」「今日未签到」和正文是「来自《…》,点击查看>>」的推广、资讯忽略,标题含「@了你 / 回复了你 / 关注了你 / 私信」的算 `direct`。写了就整张替换默认 |
|
|
227
230
|
| `threadBatchMs` | `20000` | 同一话题(App + 通知里引用的帖子「来自“…”」,没有就只按 App)这么多毫秒内来的通知合并成一次叫醒;跑腿正在处理某个话题时,这个话题新来的都留给同一个跑腿,不另开 |
|
|
228
231
|
| `heldMaxMs` | `600000` | 通知等忙着的跑腿等了这么久,就交给一个新的跑腿会话(记 `notification-rerouted`);那个跑腿正在处理的话题除外 |
|
|
@@ -241,6 +244,7 @@ setx DSH_DOT_COMPUTER off
|
|
|
241
244
|
|
|
242
245
|
| 键 | 默认 | 作用 |
|
|
243
246
|
|---|---|---|
|
|
247
|
+
| `workEffort` | `high` | 她后台干活的思考强度:幕间叙述、记忆整理和日记、成长回顾、用法笔记的回顾、跑腿会话。和对话分开——dsh 只有一个模型选择器,在任何对话里改思考强度都会变成全局默认;以前这些后台请求读的就是那个默认,把聊天的思考关掉等于把它们的也关了。可选 `off` / `low` / `high` / `max`,`''` = 跟随选择器。模型不支持所选强度时(问宿主一次)也跟随,不会发出被拒的请求。QQ 群聊评分固定 `off`。实际发出的强度在 `/dot` 的 model requests 一行(`thinking: chat …, background …`)和幕间 `calls.jsonl` 的 `effort` 里 |
|
|
244
248
|
| `backgroundRpm` | `20` | 后台请求每分钟最多几次(近 60 秒内所有请求都算进去,但只压后台的;间隔至少 60/上限 秒,一次放一个)。`0` = 不限速(只计数) |
|
|
245
249
|
| `foregroundQuietSeconds` | `15` | 你们的对话有请求在发时后台不发(一个请求开着超过 10 分钟就当它已经被丢下);发完后再等这么多秒(她一轮有好几步) |
|
|
246
250
|
| `maxBackgroundWaitSeconds` | `180` | 一个后台请求最多被压后多久,到了就放行。最多 270(比 `dot.turnStallMs` 的 300 秒短,跑腿不会被当成卡住;填更大也按 270) |
|
package/docs/prompts.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
| | 她自己的经验(进 App 时给) | `dot.howto.given` `dot.howto.no-notes`;整理经验的调用 `dot.howto.reflect` |
|
|
31
31
|
| | 说明书(第一次用时才给) | `dot.manuals.hint` `.what` `.deny` |
|
|
32
32
|
| | 说话提醒(最后一段) | `interlude.voice`(人设里的「说话提醒」优先) |
|
|
33
|
-
| 叫醒她的消息 | 他的 QQ 消息 | `dot.owner-words`(她这轮进行中插进来时多一行 `dot.owner-words.busy`) |
|
|
33
|
+
| 叫醒她的消息 | 他的 QQ 消息 | `dot.owner-words`(她这轮进行中插进来时多一行 `dot.owner-words.busy`;她上一条有话没发出去时附 `dot.owner-words.unsent`) |
|
|
34
34
|
| | 他插话了 | `dot.owner-interrupt`(发给他的 `qq_send` 被拦下的理由)/ `qq.send-interrupted`(气泡发到一半他说话) |
|
|
35
35
|
| | 审批过期 | `dot.approval-timeout`(`dot.approvalWaitMs` 没人点时她看到的工具结果,替换 dsh 的 "the user rejected tool") |
|
|
36
36
|
| | 手机通知 | `dot.notification` `.many` `.busy` `.how-qq` `.how-mixed` `.how-app` `.cards` `.unverified` |
|
package/docs/qq.md
CHANGED
|
@@ -121,6 +121,8 @@ QQ 的电脑登录码**不接受相册导入,只认摄像头**。她手机的
|
|
|
121
121
|
| `groupPolicy` | `mention` | 群消息:`mention`(@她)/ `all` / `none` / `score`。`/qq group <值>` 可改。`score`:没 @ 她的群消息先用一次很短的模型调用打 0–10 分(和她相关、问到她、她明显有话说才高分),到 `scoreThreshold`(默认 7)才叫醒她,@ 永远算;每群每分钟最多 `scoreMaxPerMinute`(6)次打分;`scoreModel`("provider/model")可指定便宜模型,默认用当前模型。这就是"价值评分插话" |
|
|
122
122
|
| `tidy` | `true` | 发出去的文字按她的聊天口吻整理:去掉行末句号、引号、破折号、冒号、星号、井号(网址和时间不动)。关掉就原样发 |
|
|
123
123
|
| `dropLatinLeaks` | `true` | 跟着 `tidy` 生效:一条 ≥ 30 字、80% 以上是英文字母/标点/空格(网址不算)的气泡,是她的思考漏进了回复(比如 `hmm, actually don't over-explain. Let's just be brief…`),不发,日志里 warn 一行(前 60 字);`ok`、`lol`、`GG` 这种短英文照发。全被拦下又没有图时,调用报错让她重写 |
|
|
124
|
+
| `dropEchoOpeners` | `true` | 跟着 `tidy` 生效,只管私聊:开头那条气泡只是把对方上一句说回去(他说「6点多吧」,她回「六点多」),后面还有别的气泡时不发它,日志里 info 一行。判断:去掉标点和语气词、数字统一写法后 3–12 个字,**每个字**都按顺序出现在对方那句里(多一个「不」「还」、换一个数字都算她自己的话,照发)。不算的:她这条以问号结尾,或带「我」「你」;对方那句以问号结尾或带疑问词(答话本来就会带上问句里的词);对方那句四个字以内又不含数字(问候、道谢、「嗯嗯好」说回去是应和) |
|
|
125
|
+
| `dropChainedQuestions` | `false` | 跟着 `tidy` 生效,只管私聊:她上一次回这个人时问过他,这一次又有问他的气泡(以问号或「吗」结尾,或带「几点」「什么」「哪」「怎么」这类疑问词;「没什么」「谁都」不算),而且还有不是问句的气泡,就不发这些问句。整条回复只有问句时照发。默认关:她办事时需要对方回答的问题也会被拦下,而且直接回复(不经 `qq_send`)时她不知道哪条没发 |
|
|
124
126
|
| `sendPolicy` | `reply` | `qq_send` 审批:`reply`(见上表)/ `always`(除了你,发谁都问)/ `off`(不问) |
|
|
125
127
|
| `replyWindowMinutes` | `30` | `reply` 策略里"最近给她发过消息"的时间窗 |
|
|
126
128
|
| `imageSeeMax` | `4` | 叫醒她的消息里,每条最多让她看几张图 / 表情包;0 = 只给文字 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dot-life",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.3",
|
|
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",
|
package/scripts/prompts.mjs
CHANGED
|
@@ -88,8 +88,8 @@ export const entries = [
|
|
|
88
88
|
{ id: 'voice', group: 'system', name: '说话提醒(最后一段)', note: '放在她对话每一轮的最后(记忆、原话、幕间数据之后),模型回话前最后读到的就是它;人设里填了「说话提醒」就用那个,空着用这个({name} 是她的名字)。只在和他的对话里,跑腿不带。interlude.voice = false 关掉', files: ['interlude.voice'],
|
|
89
89
|
render: () => P.prompt('interlude.voice', { name: '小点' }) },
|
|
90
90
|
|
|
91
|
-
{ id: 'owner', group: 'wake', name: '他的 QQ 消息', note: '他从电脑端 QQ 发来的话:等他停下(1.5 秒没新消息,最多 6 秒)一批盖一个时间戳,后面是他打的原话;她这轮还没做完时插进这一轮,多一行 dot.owner-words.busy', files: ['dot.owner-words', 'dot.owner-words.busy'],
|
|
92
|
-
render: () => variant([['她空闲', D.ownerWords([{ text: '在吗' }, { text: '帮我看个东西' }])], ['她这轮进行中', D.ownerWords([{ text: '算了' }, { text: '先别弄了' }], Date.now(), { whileBusy: true })]]) },
|
|
91
|
+
{ id: 'owner', group: 'wake', name: '他的 QQ 消息', note: '他从电脑端 QQ 发来的话:等他停下(1.5 秒没新消息,最多 6 秒)一批盖一个时间戳,后面是他打的原话;她这轮还没做完时插进这一轮,多一行 dot.owner-words.busy;她上一条有没发出去的话(他先说了话),附在后面给她看一次 dot.owner-words.unsent', files: ['dot.owner-words', 'dot.owner-words.busy', 'dot.owner-words.unsent'],
|
|
92
|
+
render: () => variant([['她空闲', D.ownerWords([{ text: '在吗' }, { text: '帮我看个东西' }])], ['她这轮进行中', D.ownerWords([{ text: '算了' }, { text: '先别弄了' }], Date.now(), { whileBusy: true })], ['她有话没发出去', D.ownerWords([{ text: '你中午吃什么' }], Date.now(), { unsent: ['回放的事我自己想办法', '你醒了再聊也行'] })]]) },
|
|
93
93
|
{ id: 'interrupt', group: 'wake', name: '他插话了', note: '她要 qq_send 给他时他还有没看的话:这次发送被拦下(工具返回的理由,每轮最多 2 次);气泡发到一半他又说话:剩下的不发(qq_send 的结果)', files: ['dot.owner-interrupt', 'qq.send-interrupted'],
|
|
94
94
|
render: () => variant([['发送被拦下', D.ownerInterruptText()], ['发到一半', Q.sendReport({ sent: 1, interrupted: true, unsent: ['那家店我去过', '还挺好吃的'] })]]) },
|
|
95
95
|
{ id: 'approval', group: 'wake', name: '审批过期', note: '她那步要审批、dot.approvalWaitMs(默认 10 分钟)没人点:当拒绝处理,这句替换 dsh 的「the user rejected tool」作为工具结果', files: ['dot.approval-timeout'],
|
|
@@ -128,7 +128,7 @@ export const entries = [
|
|
|
128
128
|
} },
|
|
129
129
|
{ id: 'diary', group: 'call', name: '日记', note: '每天 dailyAt(23:30),当天有记录才写,单独一次调用', files: ['memory.diary'],
|
|
130
130
|
render: () => M.diaryPrompt({ day: M.dayLabel(new Date(T0)), text: LINES.slice(0, 2).map(M.transcriptLine).join('\n') }) },
|
|
131
|
-
{ id: 'round', group: 'call', name: '幕间一轮', note: '写她这段时间的生活:interlude.round 是整段系统提示词,后面是按情况填进去的小段', files: ['interlude.round', 'interlude.round.canon', 'interlude.round.length', 'interlude.round.phase.advance', 'interlude.round.phase.follow-up', 'interlude.round.phase.intent', 'interlude.round.her-life', 'interlude.round.free', 'interlude.round.doings', '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.style.none', 'interlude.round.seed', 'interlude.round.play-intents', 'interlude.round.play-intents.off', 'interlude.round.tries', 'interlude.round.tries.off', 'interlude.round.contact', 'interlude.round.contact.off', 'interlude.round.refresh'],
|
|
131
|
+
{ id: 'round', group: 'call', name: '幕间一轮', note: '写她这段时间的生活:interlude.round 是整段系统提示词,后面是按情况填进去的小段', files: ['interlude.round', 'interlude.round.canon', 'interlude.round.length', 'interlude.round.phase.advance', 'interlude.round.phase.follow-up', 'interlude.round.phase.intent', 'interlude.round.her-life', 'interlude.round.free', 'interlude.round.doings', '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.style.none', 'interlude.round.seed', 'interlude.round.play-intents', 'interlude.round.play-intents.off', 'interlude.round.tries', 'interlude.round.tries.off', 'interlude.round.contact', 'interlude.round.contact.off', 'interlude.round.refresh', 'interlude.round.not-kept'],
|
|
132
132
|
render: () => {
|
|
133
133
|
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', 'post'], stickers: 2, trying: true, doings: { today: { doings: 3, tokens: 61200, livingTokens: 40100 }, last7Days: [{ what: '小黑盒 点赞', times: 9, done: 8, tokens: 52000, reactions: 0 }, { what: '去看(手机)', times: 3, done: 3, tokens: 30500, reactions: 1 }], leftAloneThisWeek: ['B站'], recent: [{ id: 'k3f0', at: '11-03 15:20', what: '小黑盒 点赞:那篇耳机测评', status: 'done', result: '点了赞', tokens: 5400, feedback: ['他:别老点赞了,去评论两句'] }] }, 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找他:不用' }] });
|
|
134
134
|
return variant([['system(生活推进、主动联系开、玩开、浏览延后、herLife 有内容、有回来的事)', r.system], ['user', r.user], ['补全那一次(第一次没给全时)', P.prompt('interlude.round.refresh')]]);
|
package/src/dot/core.js
CHANGED
|
@@ -28,8 +28,9 @@ 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
|
+
import { background, effortFor, installLlmGate, statusLine as llmGateLine, workEffort } from '../llm-gate.js';
|
|
32
32
|
import { configure as configurePrompts, fill, overrideNotes, prompt, rebase, table } from '../prompts.js';
|
|
33
|
+
import { runPendingReset } from '../reset.js';
|
|
33
34
|
import { ago, describeNow, mondayOf, stamp } from '../clock.js';
|
|
34
35
|
|
|
35
36
|
export const name = 'dsh-dot';
|
|
@@ -58,7 +59,11 @@ const firstAt = (items, now) => { const t = Date.parse(items?.[0]?.at ?? ''); re
|
|
|
58
59
|
* His QQ words as she gets them: one stamp per batch, then exactly what he typed, one message per line;
|
|
59
60
|
* `whileBusy` (steered into the turn she is in the middle of) adds one line saying so.
|
|
60
61
|
*/
|
|
61
|
-
export const ownerWords = (items, now = Date.now(), { whileBusy = false } = {}) => prompt('dot.owner-words', {
|
|
62
|
+
export const ownerWords = (items, now = Date.now(), { whileBusy = false, unsent = [] } = {}) => prompt('dot.owner-words', {
|
|
63
|
+
stamp: stamp(firstAt(items, now), now), text: items.map((n) => n.text).join('\n'), busy: whileBusy ? prompt('dot.owner-words.busy') : '',
|
|
64
|
+
// What she wrote that never reached him (held back or cut off because he spoke first): shown to her once, with his words.
|
|
65
|
+
unsent: unsent.length ? prompt('dot.owner-words.unsent', { lines: unsent.join('\n') }) : '',
|
|
66
|
+
});
|
|
62
67
|
/**
|
|
63
68
|
* A wake text with the pictures in it: the text cut right after each picture's words (`[表情包 sticker:<id>]`,
|
|
64
69
|
* `[图片]`), one `{ type: 'image', attachment }` there, in message order. The text parts joined are the text
|
|
@@ -193,6 +198,9 @@ export const defaults = {
|
|
|
193
198
|
ownerMaxWaitMs: 6000,
|
|
194
199
|
ownerTypingMaxMs: 15000,
|
|
195
200
|
ownerDenyMax: 2, // per turn: how often a qq_send to him is held back because he said something she has not read
|
|
201
|
+
// In a row: how often a reply of hers that has not reached him yet gives way to what he just said (the turn is
|
|
202
|
+
// started over, or the finished reply is kept back as a draft). Past this it goes out first. A bubble reaching him resets it.
|
|
203
|
+
ownerPreemptMax: 2,
|
|
196
204
|
phoneCheckEveryMinutes: 30, // if nothing woke her meanwhile: a "pick up your phone" turn; 0 = off
|
|
197
205
|
notifyHours: '', // optional quiet hours ('HH:MM-HH:MM'): outside them app notifications do not wake her; '' (default) = always
|
|
198
206
|
// Her errand session: phone checks, app notifications, interlude observations and plays run here,
|
|
@@ -417,6 +425,7 @@ export function createNotifier(getIm, cfg, logger, getQq = () => undefined) {
|
|
|
417
425
|
export function apply(ctx, config = {}) {
|
|
418
426
|
// An empty string means "not set", except for notifyHours, where '' is documented as "always".
|
|
419
427
|
const logger = ctx.logger('dsh-dot');
|
|
428
|
+
runPendingReset({ logger }); // a reset scheduled on the dot page: before any state is read (src/reset.js)
|
|
420
429
|
const cfg = { ...defaults, ...setValues(config, { keepEmpty: ['notifyHours'] }), ...sectionOf('dot', (m) => logger.warn(m)) };
|
|
421
430
|
if (cfg.enabled === false) { logger.info('off (dsh-dot.json: dot.enabled = false)'); return; }
|
|
422
431
|
const computer = () => ctx.get('dshComputer');
|
|
@@ -452,9 +461,29 @@ export function apply(ctx, config = {}) {
|
|
|
452
461
|
// Errands that were rotated away stay errands: their last turn/end must not make one of them her
|
|
453
462
|
// "latest session" (his QQ message then goes into an archived errand and he never gets an answer).
|
|
454
463
|
const pastErrands = new Set(store.get('pastErrands') ?? []);
|
|
464
|
+
// Conversations a reset retired (src/reset.js): a turn ending in one of them does not make it hers again.
|
|
465
|
+
const pastConversations = new Set(store.get('pastConversations') ?? []);
|
|
455
466
|
const isErrand = (id) => Boolean(id) && (id === errandId || pastErrands.has(id));
|
|
456
467
|
// Her model requests share his provider key: errand steps are background and wait behind his (src/llm-gate.js).
|
|
457
468
|
const llmGate = installLlmGate(ctx, { name: 'dsh-dot', backgroundSessions: isErrand });
|
|
469
|
+
// Her errands think at llm.workEffort whatever the model selector was last set to for a chat (src/llm-gate.js).
|
|
470
|
+
// The host fixes a step's model selection before the step runs and refuses a different effort from the
|
|
471
|
+
// `agent/request` waterfall (0.2.2: "use agent.model.select() before step preparation" — the turn fails), so the
|
|
472
|
+
// errand's own selection is set before anything is sent into it: agent.model.select records it for that session
|
|
473
|
+
// only, durably, and is a no-op when the session already says so. A host without it: her errands follow the selector.
|
|
474
|
+
let effortSeen = '';
|
|
475
|
+
const thinkAtWork = async (agent) => {
|
|
476
|
+
try {
|
|
477
|
+
const m = agent?.model;
|
|
478
|
+
const can = typeof m?.select === 'function' && typeof m?.current === 'function';
|
|
479
|
+
const cur = can ? m.current() : undefined;
|
|
480
|
+
const { effort, why } = cur?.provider && cur?.model ? await effortFor(ctx, cur) : { effort: cur?.reasoningEffort, why: can ? 'no model selected yet' : 'host has no agent.model.select' };
|
|
481
|
+
// In the activity log whenever the outcome changes (not per wake): what the session said, what it is set to, why.
|
|
482
|
+
const seen = `${cur?.reasoningEffort ?? 'default'}→${effort ?? 'default'} ${why}`;
|
|
483
|
+
if (seen !== effortSeen) { effortSeen = seen; audit('errand-effort', { ...(cur ? { model: `${cur.provider}/${cur.model}` } : {}), was: cur?.reasoningEffort ?? 'default', effort: effort ?? 'default', why }); }
|
|
484
|
+
if (cur && effort && effort !== cur.reasoningEffort) m.select({ provider: cur.provider, model: cur.model, reasoningEffort: effort });
|
|
485
|
+
} catch (err) { logger.debug?.(`errand effort not set: ${err.message}`); }
|
|
486
|
+
};
|
|
458
487
|
// Startup self-check: the remembered pointer must be a live conversation of hers. An old state file
|
|
459
488
|
// can point at an errand or at a session archived since (11-03: his QQ messages went into an
|
|
460
489
|
// archived errand and nobody answered). What dsh cannot tell us (no registry yet, no title) is skipped.
|
|
@@ -547,7 +576,7 @@ export function apply(ctx, config = {}) {
|
|
|
547
576
|
const open = turns.get(id);
|
|
548
577
|
if (open) {
|
|
549
578
|
open.lastEventAt = Date.now();
|
|
550
|
-
if (event.type === 'tool/call') open.doing = shortTool(event.data?.name);
|
|
579
|
+
if (event.type === 'tool/call') { open.doing = shortTool(event.data?.name); open.tools = (open.tools ?? 0) + 1; }
|
|
551
580
|
if (event.type === 'assistant/message' && !event.data?.interrupted) { const said = contentText(event.data?.message?.content).trim(); if (said) open.said = said; }
|
|
552
581
|
}
|
|
553
582
|
// Pending approvals (the log's pair; the answerer below adds the ones it sees first).
|
|
@@ -557,7 +586,7 @@ export function apply(ctx, config = {}) {
|
|
|
557
586
|
if (key) approvals.get(key).eventId = event.data?.id;
|
|
558
587
|
}
|
|
559
588
|
if (event.type === 'approval/decided') for (const [k, a] of approvals) if (a.eventId === event.data?.id) approvals.delete(k);
|
|
560
|
-
if (event.type === 'turn/end' && !isErrand(id)) setLast(id);
|
|
589
|
+
if (event.type === 'turn/end' && !isErrand(id) && !pastConversations.has(id)) setLast(id);
|
|
561
590
|
// A reminder enters the inbox before its turn starts, and the prompt is assembled at turn
|
|
562
591
|
// start, before the user/message event: note it here so the turn knows from its first step.
|
|
563
592
|
if (event.type === 'agent/inbox/spliced') {
|
|
@@ -612,12 +641,22 @@ export function apply(ctx, config = {}) {
|
|
|
612
641
|
}
|
|
613
642
|
if (ended) {
|
|
614
643
|
const text = t.text.trim();
|
|
615
|
-
|
|
644
|
+
// Started over because he spoke before anything of it reached him. His new words are already queued for the
|
|
645
|
+
// next turn, so whatever this turn wrote does not go out — also when the cancel came too late to abort it
|
|
646
|
+
// (it ended as completed): that answer is kept as a draft and shown to her with his next words.
|
|
647
|
+
if (t.fromQq && !t.scheduled && t.cancelled) {
|
|
648
|
+
const aborted = event.data?.reason?.kind === 'aborted';
|
|
649
|
+
if (!aborted && text && !isSilent(text)) keepUnsent(stripSilent(text).split('\n').map((l) => l.trim()).filter(Boolean));
|
|
650
|
+
audit('owner-turn-restarted', { session: id, aborted });
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (!text || isSilent(text)) { if (t.fromQq) preempts = 0; audit('silent', { session: id }); return; }
|
|
616
654
|
if (t.fromQq && !t.scheduled) {
|
|
617
|
-
// She answered him in the conversation; if no qq_send to him happened during the turn,
|
|
655
|
+
// She answered him in the conversation; if no qq_send to him happened during the turn, it goes to his QQ.
|
|
618
656
|
const q = ctx.get('dshQq');
|
|
619
|
-
if (
|
|
620
|
-
|
|
657
|
+
if ((q?.sentToOwnerAt ?? 0) >= t.startedAt) { preempts = 0; audit('qq-answered-herself', { session: id }); return; }
|
|
658
|
+
if (!q?.connected) { herSaid(id, stripSilent(text)); audit('qq-answered-herself', { session: id, why: 'qq not connected' }); return; }
|
|
659
|
+
sayToOwner(id, stripSilent(text));
|
|
621
660
|
return;
|
|
622
661
|
}
|
|
623
662
|
void im.send(stripSilent(text)).then((sent) => audit('delivered', { session: id, sent }));
|
|
@@ -744,8 +783,9 @@ export function apply(ctx, config = {}) {
|
|
|
744
783
|
const sel = ctx.get('agentDefaultModel')?.currentSelection?.();
|
|
745
784
|
const llm = ctx.get('llm');
|
|
746
785
|
if (!sel || !llm?.stream) return;
|
|
786
|
+
const effort = await workEffort(ctx, sel);
|
|
747
787
|
const reply = await collectReply(llm.stream(background({
|
|
748
|
-
provider: sel.provider, model: sel.model, ...(
|
|
788
|
+
provider: sel.provider, model: sel.model, ...(effort ? { reasoningEffort: effort } : {}),
|
|
749
789
|
system: prompt('dot.howto.reflect', { maxChars: cfg.howtoMaxChars }), tools: [howtoTool()], maxTokens: 4000,
|
|
750
790
|
messages: [createUserMessage({ content: [{ type: 'text', text: JSON.stringify(howto.input(r), null, 1) }], source: { kind: 'dsh-dot', form: 'howto' } })],
|
|
751
791
|
})));
|
|
@@ -864,17 +904,29 @@ export function apply(ctx, config = {}) {
|
|
|
864
904
|
*/
|
|
865
905
|
const resolveLive = async (id) => {
|
|
866
906
|
const live = ctx.get('agents')?.get?.(id);
|
|
867
|
-
|
|
868
|
-
|
|
907
|
+
const found = typeof live?.followup === 'function' ? { agent: live } : await ctx.get('sessionController')?.resolveAgent(id);
|
|
908
|
+
if (found?.agent && isErrand(id)) await thinkAtWork(found.agent); // before anything is sent into her errand
|
|
909
|
+
return found;
|
|
910
|
+
};
|
|
911
|
+
/** A new conversation of hers in her home; '' when dsh cannot make one. */
|
|
912
|
+
const openConversation = async (controller) => {
|
|
913
|
+
try {
|
|
914
|
+
const { sessionId } = await controller.create({ cwd: home });
|
|
915
|
+
try { await controller.rename?.({ sessionId, title: 'dot' }); } catch (error) { void error; }
|
|
916
|
+
setLast(sessionId); audit('conversation-opened', { session: sessionId });
|
|
917
|
+
return sessionId;
|
|
918
|
+
} catch (err) { logger.warn(`could not open a conversation for her: ${err.message}`); return ''; }
|
|
869
919
|
};
|
|
870
920
|
const deliver = (all, whileBusy, target) => {
|
|
871
921
|
const controller = ctx.get('sessionController');
|
|
872
|
-
const id = target ?? lastSession;
|
|
873
922
|
const pkgs = [...new Set(all.map((n) => n.pkg))];
|
|
874
|
-
if (!controller
|
|
923
|
+
if (!controller) { audit('notification-dropped', { pkgs, why: 'no sessionController' }); return; }
|
|
875
924
|
const fromOwner = all.filter((n) => n.fromOwner);
|
|
876
925
|
const items = all.filter((n) => !n.fromOwner);
|
|
877
926
|
waking = waking.then(async () => {
|
|
927
|
+
// No conversation yet (first run, or after a reset): his words open one. Anything else has nowhere to go.
|
|
928
|
+
const id = target || lastSession || (fromOwner.length ? await openConversation(controller) : '');
|
|
929
|
+
if (!id) { audit('notification-dropped', { pkgs, why: 'no session yet' }); return; }
|
|
878
930
|
// The live agent loop (ctx.agents) has steer/inject/cancel; the session controller's
|
|
879
931
|
// resolveAgent is the client API layer and hands back a thinner handle (followup only on the
|
|
880
932
|
// desktop host) — it is the fallback that also loads a session that is not live.
|
|
@@ -890,6 +942,48 @@ export function apply(ctx, config = {}) {
|
|
|
890
942
|
audit('notification-woke', { session: id, count: items.length, pkgs: [...new Set(items.map((n) => n.pkg))], whileBusy, sinceSeenMs: Date.now() - Date.parse(items[0].at), sincePostedMs: items[0].postedAt ? Date.now() - items[0].postedAt : undefined });
|
|
891
943
|
}).catch((err) => { logger.warn(`wake for notification failed: ${err.message}`); audit('notification-dropped', { pkgs, why: err.message }); });
|
|
892
944
|
};
|
|
945
|
+
// ── her side of the conversation with him ──
|
|
946
|
+
// Writing (a turn of his words is open, `turns`), sending (its bubbles are going out, `sendingCount`), or neither.
|
|
947
|
+
// One rule for both: what has not reached him yet gives way to what he just said; what has reached him stands.
|
|
948
|
+
let sending = Promise.resolve(), sendingCount = 0;
|
|
949
|
+
let unsentDraft = [], unsentAt = 0; // lines she wrote that never reached him: given to her once, with his next words (if they come soon)
|
|
950
|
+
const UNSENT_KEEP_MS = 5 * 60_000;
|
|
951
|
+
const keepUnsent = (lines) => { if (lines.length) { unsentDraft.push(...lines); unsentAt = Date.now(); } };
|
|
952
|
+
const takeUnsent = () => {
|
|
953
|
+
const fresh = Date.now() - unsentAt <= UNSENT_KEEP_MS, lines = fresh ? unsentDraft : [];
|
|
954
|
+
if (!fresh && unsentDraft.length) audit('owner-draft-dropped', { lines: unsentDraft.length, ageMs: Date.now() - unsentAt });
|
|
955
|
+
unsentDraft = []; return lines;
|
|
956
|
+
};
|
|
957
|
+
let preempts = 0; // replies in a row that gave way before a bubble reached him (see defaults.ownerPreemptMax)
|
|
958
|
+
/** Her transcript gets what reached him, not what she wrote (dsh-dot/memory). */
|
|
959
|
+
const herSaid = (id, text) => { try { if (String(text ?? '').trim()) ctx.get('dotMemory')?.herSaid?.({ session: id, text }); } catch (err) { logger.warn(`transcript: ${err.message}`); } };
|
|
960
|
+
/**
|
|
961
|
+
* The answer of a turn of his goes to his QQ — the one way out for what she says to him without qq_send.
|
|
962
|
+
* He said something she has not read (still in the buffer): the whole answer is kept back as a draft and
|
|
963
|
+
* handed to her with his words. Otherwise its bubbles go out one after another; qq.send stops between
|
|
964
|
+
* bubbles when he speaks, and what was left is kept the same way.
|
|
965
|
+
*/
|
|
966
|
+
const sayToOwner = (id, text) => {
|
|
967
|
+
const lines = String(text).split('\n').map((l) => l.trim()).filter(Boolean);
|
|
968
|
+
// His unread words: in the buffer, or held while her conversation is being handed over (frozenQueue).
|
|
969
|
+
const waiting = ownerBatch.length + frozenQueue.filter((n) => n.fromOwner).length;
|
|
970
|
+
if (waiting && preempts < cfg.ownerPreemptMax) {
|
|
971
|
+
preempts++; keepUnsent(lines);
|
|
972
|
+
audit('owner-reply-held', { session: id, lines: lines.length, waiting, preempts });
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
sendingCount++;
|
|
976
|
+
// One job per answer, wholly caught: a failure in it never leaves the chain rejected (the next answer and
|
|
977
|
+
// his waiting words hang on this chain).
|
|
978
|
+
sending = sending.then(async () => {
|
|
979
|
+
const r = await ctx.get('dshQq').send('owner', text);
|
|
980
|
+
if (r.sent > 0) preempts = 0;
|
|
981
|
+
herSaid(id, (r.said ?? []).join('\n'));
|
|
982
|
+
const left = r.interrupted ? (r.unsent ?? []).map(String) : [];
|
|
983
|
+
keepUnsent(left);
|
|
984
|
+
audit('qq-relayed', { session: id, sent: r.sent, ...(left.length ? { unsent: left.length } : {}), ...(r.error ? { error: r.error } : {}) });
|
|
985
|
+
}).catch((err) => { logger.warn(`qq relay failed: ${err.message}`); audit('qq-relay-failed', { session: id, error: err.message }); }).finally(() => { sendingCount--; });
|
|
986
|
+
};
|
|
893
987
|
/**
|
|
894
988
|
* His words into her session. Idle: a followup starts a turn, as always. In the middle of a turn:
|
|
895
989
|
* steered into it, so she reads them at her next step instead of after the turn (an agent without
|
|
@@ -898,18 +992,31 @@ export function apply(ctx, config = {}) {
|
|
|
898
992
|
let agentShapeLogged = false;
|
|
899
993
|
const toOwnerAgent = (agent, id, items) => {
|
|
900
994
|
const busy = turns.has(id);
|
|
995
|
+
const open = turns.get(id);
|
|
996
|
+
// Nothing of this turn has reached him and it has done nothing yet (a turn of his words, no tool call so far):
|
|
997
|
+
// it is started over with what he just said, so the reply she writes is to all of it. A turn that has
|
|
998
|
+
// used a tool is not undone; his words go into it at its next step.
|
|
999
|
+
const restart = busy && open?.fromQq && !open.scheduled && !open.tools && typeof agent.cancel === 'function' && preempts < cfg.ownerPreemptMax;
|
|
901
1000
|
// The host's agent handle may not expose `steer`: `send(message, 'next-step', true)` is the same
|
|
902
1001
|
// boundary in dsh-agent's inbox API; failing both, the followup (after the turn, as before).
|
|
903
|
-
const via = busy && typeof agent.steer === 'function' ? 'steer' : busy && typeof agent.send === 'function' ? 'send' : 'followup';
|
|
1002
|
+
const via = restart ? 'restart' : busy && typeof agent.steer === 'function' ? 'steer' : busy && typeof agent.send === 'function' ? 'send' : 'followup';
|
|
904
1003
|
if (!agentShapeLogged) {
|
|
905
1004
|
agentShapeLogged = true;
|
|
906
1005
|
const methods = [...new Set([...Object.keys(agent), ...Object.getOwnPropertyNames(Object.getPrototypeOf(agent) ?? {})])].filter((k) => typeof agent[k] === 'function');
|
|
907
1006
|
logger.info(`her agent handle offers: ${methods.join(', ')} (busy now: ${busy}, open turns: ${[...turns.keys()].map((k) => k.slice(0, 16)).join(' ') || 'none'})`);
|
|
908
1007
|
audit('agent-handle', { methods, busy, openTurns: turns.size });
|
|
909
1008
|
}
|
|
910
|
-
const
|
|
1009
|
+
const unsent = takeUnsent();
|
|
1010
|
+
const message = createUserMessage({ content: contentFor(ownerWords(items, Date.now(), { whileBusy: via === 'steer' || via === 'send', unsent }), items), source: ownerSource() });
|
|
911
1011
|
try {
|
|
912
|
-
if (via === '
|
|
1012
|
+
if (via === 'restart') {
|
|
1013
|
+
// The cancelled turn's own input stays in her history. His new words are queued in the same tick: waking
|
|
1014
|
+
// input submitted after an active cancellation is held by the host for the next turn and runs when the
|
|
1015
|
+
// aborted one has settled, so nothing waits on a promise of ours and the order is the host's inbox order.
|
|
1016
|
+
agent.cancel({ kind: 'hook', reason: 'dot-owner-spoke' }, { keepInbox: true });
|
|
1017
|
+
preempts++; open.cancelled = true; // only once the cancel is in: a turn that was not cancelled keeps its answer
|
|
1018
|
+
if (typeof agent.send === 'function') agent.send(message, 'next-turn', true); else agent.followup(message);
|
|
1019
|
+
} else if (via === 'steer') agent.steer(message); else if (via === 'send') agent.send(message, 'next-step', true); else agent.followup(message);
|
|
913
1020
|
} catch (err) { logger.warn(`${via} failed (${err.message}); followup instead`); agent.followup(message); }
|
|
914
1021
|
audit('owner-message', { session: id, count: items.length, whileBusy: busy, via }); bump('owner', items.length);
|
|
915
1022
|
};
|
|
@@ -1020,6 +1127,9 @@ export function apply(ctx, config = {}) {
|
|
|
1020
1127
|
/** Deliver his buffered words now. With `agent` (the qq_send gate's caller, her conversation): steered into it synchronously. */
|
|
1021
1128
|
const flushOwner = (agent) => {
|
|
1022
1129
|
clearTimeout(ownerTimer); ownerTimer = null;
|
|
1130
|
+
// Her bubbles are still going out: sending counts as busy. They stop at the next bubble (qq.send sees he
|
|
1131
|
+
// spoke); his words go in once they have, together with what was left unsent.
|
|
1132
|
+
if (!agent && sendingCount > 0 && ownerBatch.length) { void sending.finally(() => flushOwner()); return 0; }
|
|
1023
1133
|
const items = ownerBatch; ownerBatch = []; ownerTyping = ownerTypingSeen = false;
|
|
1024
1134
|
if (!items.length) return 0;
|
|
1025
1135
|
const id = lastSession;
|
|
@@ -1303,7 +1413,14 @@ export function apply(ctx, config = {}) {
|
|
|
1303
1413
|
ctx.provide?.('dshDot', {
|
|
1304
1414
|
home,
|
|
1305
1415
|
session: () => lastSession,
|
|
1306
|
-
|
|
1416
|
+
// Her conversation moves on (memory's handoff): the one she leaves is retired, so a turn still running in it
|
|
1417
|
+
// — his words restarted there a moment ago, a reminder set there — does not make it hers again when it ends.
|
|
1418
|
+
setSession: (id) => {
|
|
1419
|
+
if (!id || id === lastSession) return;
|
|
1420
|
+
if (lastSession) { pastConversations.add(lastSession); store.set('pastConversations', [...pastConversations].slice(-50)); }
|
|
1421
|
+
pastConversations.delete(id);
|
|
1422
|
+
setLast(id);
|
|
1423
|
+
},
|
|
1307
1424
|
errand: ensureErrand,
|
|
1308
1425
|
errandId: () => errandId,
|
|
1309
1426
|
/**
|
|
@@ -1329,6 +1446,10 @@ export function apply(ctx, config = {}) {
|
|
|
1329
1446
|
approvals: () => [...approvals.values()].map((a) => ({ session: a.session, tool: a.tool, reason: a.reason, since: a.since, errand: isErrand(a.session), ...(a.timedOutAt ? { timedOutAt: a.timedOutAt } : {}) })),
|
|
1330
1447
|
/** His messages waiting in the buffer; flushOwner() delivers them now. */
|
|
1331
1448
|
ownerPending: () => ownerBatch.length,
|
|
1449
|
+
/** Her bubbles to him are going out right now. */
|
|
1450
|
+
sending: () => sendingCount > 0,
|
|
1451
|
+
/** dot reports what reached him (memory.herSaid): memory does not record a QQ turn's answer on its own. */
|
|
1452
|
+
reportsSaid: true,
|
|
1332
1453
|
flushOwner: () => flushOwner(),
|
|
1333
1454
|
isIm: (id) => imSessions.has(id),
|
|
1334
1455
|
/** The model-request gate's status (src/llm-gate.js): per provider, requests in the last minute, background cap, cooldown, waiting. */
|