@kadaliao/dsh-bots 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +17 -13
- package/README.zh-CN.md +16 -13
- package/client.js +1 -1
- package/index.js +22 -6
- package/lib/channels/discord.mjs +1 -1
- package/lib/memory.mjs +39 -5
- package/package.json +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kada Liao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ It is built for two situations:
|
|
|
17
17
|
- **Work that is naturally split between roles**: code needs a builder, a tester and a reviewer; content
|
|
18
18
|
needs a researcher, a writer and a designer; research needs a skeptic.
|
|
19
19
|
|
|
20
|
-

|
|
20
|
+

|
|
21
21
|
|
|
22
22
|
## Hire a whole team in one click
|
|
23
23
|
|
|
@@ -41,7 +41,7 @@ Hiring:
|
|
|
41
41
|
- adds the team's scheduled tasks and makes its lead the dispatcher;
|
|
42
42
|
- offers to send the lead a kickoff message, so the team starts working right away.
|
|
43
43
|
|
|
44
|
-

|
|
44
|
+

|
|
45
45
|
|
|
46
46
|
## An example (one-person company)
|
|
47
47
|
|
|
@@ -278,7 +278,7 @@ A bot works in ordinary Harness conversations, so everything Harness can do, a b
|
|
|
278
278
|
- **Schedules** are ordinary Harness scheduled tasks, also on the Automation page. A scheduled task missed while
|
|
279
279
|
Harness was closed runs when it starts again, once (its latest occurrence): that is Harness's rule, and Bots adds
|
|
280
280
|
no runs of its own. A team with many schedules can open several tasks at once after a start, and use many tokens.
|
|
281
|
-
- **AI avatars**: with the [Images plugin](
|
|
281
|
+
- **AI avatars**: with the [Images plugin](https://github.com/kadaliao/dsh-images), draw a bot's avatar from its persona. A bot can do it too:
|
|
282
282
|
ask the dispatcher to give the team new avatars and describe the look, or point it at an image file. A bot's
|
|
283
283
|
drawing runs in the background, so it goes on answering you: a ring turns around the avatar while the picture is
|
|
284
284
|
drawn, the new one shows when it is ready, and the bot hears that it is ready (or why it failed) and tells you. A restart of
|
|
@@ -302,7 +302,7 @@ model's thinking levels when it has them. Besides the models Harness already has
|
|
|
302
302
|
tokens, and neither signs the other out. Claude Code's login is shown but not offered: Anthropic allows a
|
|
303
303
|
Claude subscription only in Claude Code and claude.ai, so add Claude with an API key instead.
|
|
304
304
|
|
|
305
|
-

|
|
305
|
+

|
|
306
306
|
|
|
307
307
|
## Topics: conversations that don't grow forever
|
|
308
308
|
|
|
@@ -336,7 +336,9 @@ Every bot keeps **notes** that outlast its topics, and the team shares one more
|
|
|
336
336
|
lines and tasks of that task, the task that asked for it and its sub-tasks, and no digests.
|
|
337
337
|
- **Every night** (03:00 by default) memory is **consolidated**: each bot's notes are merged, corrected
|
|
338
338
|
and trimmed with its recent journal, the shared notes too, and the day's work is written up as the
|
|
339
|
-
team's **daily digest**. **Consolidate now** runs it at once.
|
|
339
|
+
team's **daily digest**. **Consolidate now** runs it at once. Notes and digests are written in the
|
|
340
|
+
language you write to the bots in, judged from your recent messages; a note left in another language
|
|
341
|
+
is rewritten in it.
|
|
340
342
|
- A bot reads its notes, the team notes, its last few journal lines and the latest digest when a topic
|
|
341
343
|
or a task's conversation starts, and again at the next run after you edit memory or the nightly
|
|
342
344
|
consolidation ran. Within a topic the memory part of its prompt stays the same, so the model's prompt
|
|
@@ -348,9 +350,9 @@ Every bot keeps **notes** that outlast its topics, and the team shares one more
|
|
|
348
350
|
or token is never stored.
|
|
349
351
|
- Memory work runs on each bot's own model unless Settings names a cheaper one.
|
|
350
352
|
|
|
351
|
-

|
|
353
|
+

|
|
352
354
|
|
|
353
|
-

|
|
355
|
+

|
|
354
356
|
|
|
355
357
|
## Usage
|
|
356
358
|
|
|
@@ -362,7 +364,7 @@ takes one run or more, **By task** adds them up, and a task's own page shows its
|
|
|
362
364
|
estimates from your own prices or LiteLLM's public price list (**Prices**); a model with no price shows its
|
|
363
365
|
tokens only.
|
|
364
366
|
|
|
365
|
-

|
|
367
|
+

|
|
366
368
|
|
|
367
369
|
## Message your team from Feishu, Telegram, Slack or Discord
|
|
368
370
|
|
|
@@ -513,7 +515,7 @@ one connection. If you change scopes later, reinstall the app to the workspace a
|
|
|
513
515
|
`memory_forget` and `memory_search`. `bot_reply` sends an answer to a named chat; `bot_recall` reads a
|
|
514
516
|
task, its reports or its conversation, or a chat thread, a page at a time, so a bot looks things up
|
|
515
517
|
instead of guessing; `bot_ticket` stops, closes or retries a task the bot asked for, or asks it for a
|
|
516
|
-
status report. [API.md](API.md) lists their parameters. A sub-agent started in a bot's or a task's
|
|
518
|
+
status report. [API.md](https://github.com/kadaliao/dsh-bots/blob/main/API.md) lists their parameters. A sub-agent started in a bot's or a task's
|
|
517
519
|
conversation uses them as that bot or task; one that cannot be traced back to where it started (that
|
|
518
520
|
conversation is gone) is refused.
|
|
519
521
|
- A bot's memory is a section of its system prompt, read when a topic or a task's conversation starts
|
|
@@ -557,7 +559,7 @@ permission and restart it.
|
|
|
557
559
|
|
|
558
560
|
## Install
|
|
559
561
|
|
|
560
|
-
Add
|
|
562
|
+
Add the [DSH Plugins](https://github.com/kadaliao/dsh-plugins) index in DeepSeek Harness (**Plugins → Discover → Sources**):
|
|
561
563
|
|
|
562
564
|
```
|
|
563
565
|
https://raw.githubusercontent.com/kadaliao/dsh-plugins/main/marketplace.json
|
|
@@ -566,13 +568,15 @@ https://raw.githubusercontent.com/kadaliao/dsh-plugins/main/marketplace.json
|
|
|
566
568
|
then install **Bots**. The Discover tab is part of the experimental **Custom plugin markets**
|
|
567
569
|
feature; turn it on under **Plugins → Experimental plugins** if you don't see it.
|
|
568
570
|
|
|
569
|
-
Without Discover, paste the
|
|
571
|
+
Without Discover, paste the package name into the plugin manager:
|
|
570
572
|
|
|
571
573
|
```
|
|
572
|
-
|
|
574
|
+
@kadaliao/dsh-bots
|
|
573
575
|
```
|
|
574
576
|
|
|
575
|
-
|
|
577
|
+
For the latest unreleased code, use the Git spec `git+https://github.com/kadaliao/dsh-bots.git#main` instead.
|
|
578
|
+
|
|
579
|
+
Refresh the page once after installing. For AI avatars, install [Images](https://github.com/kadaliao/dsh-images) too.
|
|
576
580
|
|
|
577
581
|
## Upgrading from 0.9
|
|
578
582
|
|
package/README.zh-CN.md
CHANGED
|
@@ -13,7 +13,7 @@ bot 在它的**讨论串**里回答,只看得到这条消息和它之前的内
|
|
|
13
13
|
- **一人公司(OPC)**:一个人经营业务,需要一整个「员工团队」——研发、增长、客户、财务,再加一个每天早上给你简报的幕僚长。
|
|
14
14
|
- **需要分工协作的工作**:开发要有人写、有人测、有人审;内容要有人调研、有人写、有人做图;研究要有人挑刺。
|
|
15
15
|
|
|
16
|
-

|
|
16
|
+

|
|
17
17
|
|
|
18
18
|
## 一键雇用一支团队
|
|
19
19
|
|
|
@@ -35,7 +35,7 @@ bot 在它的**讨论串**里回答,只看得到这条消息和它之前的内
|
|
|
35
35
|
- 建好定时任务,让负责人成为调度员;
|
|
36
36
|
- 最后可以一键把「开场任务」发给负责人,团队就开始干活了。
|
|
37
37
|
|
|
38
|
-

|
|
38
|
+

|
|
39
39
|
|
|
40
40
|
## 一段示例(一人公司)
|
|
41
41
|
|
|
@@ -212,7 +212,7 @@ Bot 在普通的 Harness 会话里工作,所以 Harness 能做的它都能做
|
|
|
212
212
|
|
|
213
213
|
- **定时任务**:就是 Harness 的定时任务,也出现在「自动化」页面。Harness 没开着时错过的定时任务,下次启动时由 Harness 补跑,
|
|
214
214
|
每个只补最近的那一次(这是 Harness 的规则,Bots 不另外补);团队的定时任务多时,启动后会一下子开出好几个任务、用掉不少 token。
|
|
215
|
-
- **AI 头像**:装了 [图片插件](
|
|
215
|
+
- **AI 头像**:装了 [图片插件](https://github.com/kadaliao/dsh-images) 就能按 bot 的人设生成头像。bot 自己也能做:让调度员给团队换一批头像,
|
|
216
216
|
说清楚想要的样子就行,也可以指给它一张本地图片。bot 画头像是在后台进行的,不耽误它回你的话:画的时候头像上有一圈在转,
|
|
217
217
|
画好就换上;画好了(或没画成、为什么)bot 会收到通知并告诉你。Harness 重启会丢掉正在画的头像。
|
|
218
218
|
- **图标**:应用库里每个应用都用它自己的官方 logo(有 App 的用 App Store 图标,没有的用官网或官方仓库里的 logo)。
|
|
@@ -231,7 +231,7 @@ Bot 在普通的 Harness 会话里工作,所以 Harness 能做的它都能做
|
|
|
231
231
|
另一边都会拿到新令牌,谁也不会把谁踢下线。Claude Code 的登录会显示出来但不提供:Anthropic 只允许
|
|
232
232
|
在 Claude Code 和 claude.ai 里使用 Claude 订阅,请改用 API Key 添加 Claude。
|
|
233
233
|
|
|
234
|
-

|
|
234
|
+

|
|
235
235
|
|
|
236
236
|
## 话题:对话不会无限变长
|
|
237
237
|
|
|
@@ -260,7 +260,8 @@ bot 知道的事靠记忆延续。下面几种情况会开新话题:
|
|
|
260
260
|
用 `memory_search` 查笔记、团队工作日志、每日摘要和任务(标题和汇报)。在任务的会话里,除了笔记,
|
|
261
261
|
只查得到这个任务、它的所属任务和子任务的工作日志与任务,查不到每日摘要。
|
|
262
262
|
- **每天夜里**(默认 03:00)**整理**一次:结合最近的工作日志,合并、更正、精简每个 bot 的笔记和共享笔记,
|
|
263
|
-
并把当天的工作写成团队的**每日摘要**。**立即整理**
|
|
263
|
+
并把当天的工作写成团队的**每日摘要**。**立即整理** 可以马上运行。笔记和摘要用你和 bot 说话的语言写(看你最近的
|
|
264
|
+
消息判断),写成别的语言的笔记会被改写过来。
|
|
264
265
|
- 话题或任务的会话开始时,bot 会读到自己的笔记、团队笔记、最近几条工作日志和最新的每日摘要;
|
|
265
266
|
你在面板里改了记忆、或每晚整理之后,下一个回合会重新读一次。同一个话题里,提示词中的记忆部分保持不变,模型对整段对话的
|
|
266
267
|
提示缓存照常命中(话题里学到的东西本来就在这段对话里)。很短的往来(一句确认、给队友的一行回复)只记一行
|
|
@@ -269,9 +270,9 @@ bot 知道的事靠记忆延续。下面几种情况会开新话题:
|
|
|
269
270
|
置顶的笔记不会被自动整理改动;看起来像 Key 或 Token 的内容一律不存。
|
|
270
271
|
- 记忆工作默认使用各 bot 自己的模型,也可以在设置里指定一个更便宜的。
|
|
271
272
|
|
|
272
|
-

|
|
273
|
+

|
|
273
274
|
|
|
274
|
-

|
|
275
|
+

|
|
275
276
|
|
|
276
277
|
## 用量
|
|
277
278
|
|
|
@@ -281,7 +282,7 @@ bot 知道的事靠记忆延续。下面几种情况会开新话题:
|
|
|
281
282
|
直到 bot 重新空闲);一个任务有一个或多个回合,**按任务** 把它们加在一起,任务详情页里也有它自己的用量。
|
|
282
283
|
费用是估算:用你填的价格,或 LiteLLM 公开价格表(**价格**);没有价格的模型只显示 tokens。
|
|
283
284
|
|
|
284
|
-

|
|
285
|
+

|
|
285
286
|
|
|
286
287
|
## 在飞书、Telegram、Slack 或 Discord 里给团队发消息
|
|
287
288
|
|
|
@@ -406,7 +407,7 @@ Slack 走 Socket Mode:由 Harness 主动连到 Slack,电脑不需要公网
|
|
|
406
407
|
- 所有会话都能用 `bot_list`、`bot_create`、`bot_update`、`bot_delete`、`bot_send_message`、`bot_reply`、`bot_recall`、
|
|
407
408
|
`bot_ticket`、`bot_schedule` 管理 bot 和任务,以及 `memory_save`、`memory_forget`、`memory_search`。
|
|
408
409
|
`bot_reply` 把答复发到指定的聊天;`bot_recall` 分页读取任务、任务的汇报或会话,以及聊天讨论串,让 bot 去查而不是猜;
|
|
409
|
-
`bot_ticket` 停止、关闭或重试自己发起的任务,或者请它汇报进度。参数见 [API.md](API.md)。
|
|
410
|
+
`bot_ticket` 停止、关闭或重试自己发起的任务,或者请它汇报进度。参数见 [API.md](https://github.com/kadaliao/dsh-bots/blob/main/API.md)。
|
|
410
411
|
在 bot 或任务的会话里启动的子代理,以那个 bot 或任务的身份使用这些工具;追溯不到来源(启动它的会话已经不在)的子代理会被拒绝。
|
|
411
412
|
- bot 的记忆是它系统提示词里的一段,在话题或任务的会话开始时读取(面板里改了记忆或每晚整理后,在下一个回合开始时重读),
|
|
412
413
|
回合进行中不会变。bot 的 Agent 空闲时回合结束;记忆总结读的是这个回合的过程(提示、回复、工具调用和简短的工具结果),
|
|
@@ -436,7 +437,7 @@ Slack 走 Socket Mode:由 Harness 主动连到 Slack,电脑不需要公网
|
|
|
436
437
|
|
|
437
438
|
## 安装
|
|
438
439
|
|
|
439
|
-
在 DeepSeek Harness
|
|
440
|
+
在 DeepSeek Harness 里加入 [DSH Plugins](https://github.com/kadaliao/dsh-plugins) 的索引(**Plugins → Discover → Sources**):
|
|
440
441
|
|
|
441
442
|
```
|
|
442
443
|
https://raw.githubusercontent.com/kadaliao/dsh-plugins/main/marketplace.json
|
|
@@ -445,13 +446,15 @@ https://raw.githubusercontent.com/kadaliao/dsh-plugins/main/marketplace.json
|
|
|
445
446
|
然后安装 **Bots**。Discover 标签属于实验性的 **Custom plugin markets** 功能;看不到的话先在
|
|
446
447
|
**Plugins → Experimental plugins** 里打开。
|
|
447
448
|
|
|
448
|
-
不用 Discover
|
|
449
|
+
不用 Discover 的话,把包名贴进插件管理器:
|
|
449
450
|
|
|
450
451
|
```
|
|
451
|
-
|
|
452
|
+
@kadaliao/dsh-bots
|
|
452
453
|
```
|
|
453
454
|
|
|
454
|
-
|
|
455
|
+
想用还没发布的最新代码,改用 Git spec `git+https://github.com/kadaliao/dsh-bots.git#main`。
|
|
456
|
+
|
|
457
|
+
安装后刷新一次页面。想要 AI 头像,再装上[图片插件](https://github.com/kadaliao/dsh-images)。
|
|
455
458
|
|
|
456
459
|
## 从 0.9 升级
|
|
457
460
|
|
package/client.js
CHANGED
|
@@ -21,7 +21,7 @@ window.__ModuleLoader__.load({
|
|
|
21
21
|
const NS = 'bots';
|
|
22
22
|
const PANEL_ID = 'bots';
|
|
23
23
|
/** The Bots this page is (package.json): the Host says which one it runs, and a stale Host is pointed out. */
|
|
24
|
-
const BOTS_VERSION = '0.10.
|
|
24
|
+
const BOTS_VERSION = '0.10.2';
|
|
25
25
|
/** How close to a new topic Harness closing the panel counts as caused by it (it archived the conversation behind). */
|
|
26
26
|
const ROTATE_WINDOW_MS = 3000;
|
|
27
27
|
const R = '/__dsh_bots/';
|
package/index.js
CHANGED
|
@@ -58,7 +58,7 @@ import { createSlots, createTickets, parkedOf, REPORT_STATUSES, sessionIdOf, sta
|
|
|
58
58
|
import { assignmentText, clip, discussionNoteText, failedNoticeText, followUpNoticeText, NEWS_MESSAGES, nudgeText, panelHeaderText, PREVIEW_CHARS, readResource, recoveryNoteText, reminderText, reportRelayText, retryText, shownNoticeText, stalledNoticeText, threadNewsText } from './lib/cards.mjs';
|
|
59
59
|
import { checkTickets, isTransient, requesterReminders, retryDelay } from './lib/watchdog.mjs';
|
|
60
60
|
import { isLiveSubscriber, isPanelThread, isTopicThread, panelThreadKey, panelTopicOf, parseThreadKey, threadLabel, toThreadKey } from './lib/threads.mjs';
|
|
61
|
-
import { createMemory, dreamBotPrompt, dreamTeamPrompt, KINDS as MEMORY_KINDS, looksSecret, parseJsonReply, reflectionPrompt, searchTickets } from './lib/memory.mjs';
|
|
61
|
+
import { createMemory, dreamBotPrompt, dreamTeamPrompt, KINDS as MEMORY_KINDS, languageOf, looksSecret, parseJsonReply, reflectionPrompt, searchTickets } from './lib/memory.mjs';
|
|
62
62
|
import { createTopics, rotationReason } from './lib/topics.mjs';
|
|
63
63
|
import { chatMessageRef, createDiscussions, forkPoint, messageRef, seqByTime } from './lib/discussions.mjs';
|
|
64
64
|
import { API_KINDS, CODEX_ROUTE, PI_SCOPE, ROUTE_PREFIX, codexAuthFile, createCodexSync, detectLogins, discoverModels, endpointView, keyRefFor, profileFor, readCodexAuth, codexCredential } from './lib/models.mjs';
|
|
@@ -882,6 +882,15 @@ export function apply(ctx, config, deps = {}) {
|
|
|
882
882
|
: task.trigger === 'chat'
|
|
883
883
|
? `a ${task.via ?? 'chat'} message from the user`
|
|
884
884
|
: 'a message from the user';
|
|
885
|
+
/**
|
|
886
|
+
* The language the person writes to the bots in (`zh` | `en`), for memory written without them
|
|
887
|
+
* in view: their last messages (panel and chat apps), else `material` (the memory itself), else
|
|
888
|
+
* this machine's language.
|
|
889
|
+
*/
|
|
890
|
+
function userLanguage(material = []) {
|
|
891
|
+
const said = store.messages({ limit: 2000, roots: false }).filter((m) => m.from === 'user').slice(-40).map((m) => m.text);
|
|
892
|
+
return languageOf(said) || languageOf(material) || (zh ? 'zh' : 'en');
|
|
893
|
+
}
|
|
885
894
|
async function reflect(bot, task) {
|
|
886
895
|
// A bot deleted while its summary waited keeps nothing.
|
|
887
896
|
if (!store.get(bot.id)) return;
|
|
@@ -893,7 +902,7 @@ export function apply(ctx, config, deps = {}) {
|
|
|
893
902
|
let summary = '';
|
|
894
903
|
if (sel) {
|
|
895
904
|
try {
|
|
896
|
-
const p = reflectionPrompt({ bot, notes: memory.notes(bot.id), team: memory.notes('team'), transcript, trigger: triggerWords(task) });
|
|
905
|
+
const p = reflectionPrompt({ bot, notes: memory.notes(bot.id), team: memory.notes('team'), transcript, trigger: triggerWords(task), language: userLanguage([transcript]) });
|
|
897
906
|
const r = await complete(sel, p.system, p.user, { purpose: 'bots-memory', sessionId: task.s });
|
|
898
907
|
ledger.record(usageRow({ botId: bot.id, sessionId: task.s, taskId: task.id, ticketId: task.ticket, kind: 'memory', provider: sel.provider, model: sel.model, usage: r.usage }));
|
|
899
908
|
const parsed = parseJsonReply(r.text) ?? {};
|
|
@@ -911,6 +920,12 @@ export function apply(ctx, config, deps = {}) {
|
|
|
911
920
|
}
|
|
912
921
|
|
|
913
922
|
let dreaming = null;
|
|
923
|
+
/**
|
|
924
|
+
* Output budget of a consolidation call. A thinking model spends most of it reasoning (DeepSeek
|
|
925
|
+
* Flash: ~2–3K tokens on a 5-bot team), and rewriting notes left in another language adds to the
|
|
926
|
+
* answer; 4000 came back empty now and then.
|
|
927
|
+
*/
|
|
928
|
+
const DREAM_TOKENS = 16_000;
|
|
914
929
|
/** Consolidate every bot's notes and write the team digest (the daily "dream"). */
|
|
915
930
|
function dream({ reason = 'schedule' } = {}) {
|
|
916
931
|
if (dreaming) return dreaming;
|
|
@@ -921,6 +936,7 @@ export function apply(ctx, config, deps = {}) {
|
|
|
921
936
|
const since = Number(before.lastAt) || now - DAY_MS;
|
|
922
937
|
const bots = store.list();
|
|
923
938
|
const result = { at: now, reason, bots: [], digest: null, errors: [] };
|
|
939
|
+
const language = userLanguage(memory.journal({ since: now - 7 * DAY_MS, limit: 300 }).map((j) => j.summary || j.title));
|
|
924
940
|
for (const bot of bots) {
|
|
925
941
|
const journal = memory.journal({ bot: bot.id, since: now - 7 * DAY_MS, limit: 300 });
|
|
926
942
|
const fresh = journal.some((j) => j.at >= since);
|
|
@@ -929,8 +945,8 @@ export function apply(ctx, config, deps = {}) {
|
|
|
929
945
|
const sel = memoryModelOf(bot);
|
|
930
946
|
if (!sel) continue;
|
|
931
947
|
try {
|
|
932
|
-
const p = dreamBotPrompt({ bot, notes, journal, tz });
|
|
933
|
-
const r = await complete(sel, p.system, p.user, { purpose: 'bots-dream', maxTokens:
|
|
948
|
+
const p = dreamBotPrompt({ bot, notes, journal, tz, language });
|
|
949
|
+
const r = await complete(sel, p.system, p.user, { purpose: 'bots-dream', maxTokens: DREAM_TOKENS, timeoutMs: 180_000 });
|
|
934
950
|
ledger.record(usageRow({ botId: bot.id, kind: 'dream', provider: sel.provider, model: sel.model, usage: r.usage }));
|
|
935
951
|
const parsed = parseJsonReply(r.text);
|
|
936
952
|
if (!parsed) throw new Error('the model did not answer with JSON');
|
|
@@ -946,8 +962,8 @@ export function apply(ctx, config, deps = {}) {
|
|
|
946
962
|
const date = memory.dayOf(journal[journal.length - 1].at, tz);
|
|
947
963
|
if (sel) {
|
|
948
964
|
try {
|
|
949
|
-
const p = dreamTeamPrompt({ bots, team: memory.notes('team'), journal, date, tz });
|
|
950
|
-
const r = await complete(sel, p.system, p.user, { purpose: 'bots-dream', maxTokens:
|
|
965
|
+
const p = dreamTeamPrompt({ bots, team: memory.notes('team'), journal, date, tz, language });
|
|
966
|
+
const r = await complete(sel, p.system, p.user, { purpose: 'bots-dream', maxTokens: DREAM_TOKENS, timeoutMs: 180_000 });
|
|
951
967
|
ledger.record(usageRow({ botId: lead?.id ?? 'team', kind: 'dream', provider: sel.provider, model: sel.model, usage: r.usage }));
|
|
952
968
|
const parsed = parseJsonReply(r.text);
|
|
953
969
|
if (!parsed) throw new Error('the model did not answer with JSON');
|
package/lib/channels/discord.mjs
CHANGED
|
@@ -41,7 +41,7 @@ export const TEXT_LIMIT = 2000;
|
|
|
41
41
|
export const INTENTS = (1 << 0) | (1 << 9) | (1 << 12) | (1 << 15);
|
|
42
42
|
|
|
43
43
|
const API_BASE = 'https://discord.com/api/v10';
|
|
44
|
-
const USER_AGENT = 'DiscordBot (https://github.com/kadaliao/dsh-
|
|
44
|
+
const USER_AGENT = 'DiscordBot (https://github.com/kadaliao/dsh-bots, 0.4)';
|
|
45
45
|
const GATEWAY_QUERY = '/?v=10&encoding=json';
|
|
46
46
|
const MIN_BACKOFF = 1000;
|
|
47
47
|
const MAX_BACKOFF = 60_000;
|
package/lib/memory.mjs
CHANGED
|
@@ -223,9 +223,40 @@ const opsSpec = [
|
|
|
223
223
|
'- {"op":"update","id":"<id>","text":"…"} — a note that changed or was wrong',
|
|
224
224
|
'- {"op":"remove","id":"<id>"} — a note that is no longer true',
|
|
225
225
|
'- {"op":"merge","ids":["<id>","<id>"],"text":"…"} — notes that say the same thing',
|
|
226
|
-
'Each note is one self-contained sentence of at most 200 characters
|
|
226
|
+
'Each note is one self-contained sentence of at most 200 characters. Never store secrets (keys, passwords, tokens), one-off details or anything already in memory.',
|
|
227
227
|
].join('\n');
|
|
228
228
|
|
|
229
|
+
const LANGUAGES = { zh: 'Simplified Chinese', en: 'English' };
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The language the user writes to the bots in, from what they wrote: `zh` when Han characters
|
|
233
|
+
* outweigh Latin words, `en` when Latin words do, '' when there is too little to tell. Code,
|
|
234
|
+
* links and @handles don't count.
|
|
235
|
+
* @param {Iterable<string>} texts
|
|
236
|
+
* @returns {'zh'|'en'|''}
|
|
237
|
+
*/
|
|
238
|
+
export function languageOf(texts) {
|
|
239
|
+
let han = 0;
|
|
240
|
+
let latin = 0;
|
|
241
|
+
for (const t of texts ?? []) {
|
|
242
|
+
const s = String(t ?? '').replace(/```[\s\S]*?```|`[^`\n]*`|https?:\/\/\S+|@[\w-]+/g, ' ');
|
|
243
|
+
han += (s.match(/[\u3400-\u9fff]/g) ?? []).length;
|
|
244
|
+
latin += (s.match(/[A-Za-z]{2,}/g) ?? []).length;
|
|
245
|
+
}
|
|
246
|
+
if (han + latin < 3) return '';
|
|
247
|
+
return han >= latin ? 'zh' : 'en';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The line telling a memory pass which language to write in. The model never sees the user's
|
|
252
|
+
* own words in a consolidation, so it is named; `fix` asks to rewrite notes left in another one.
|
|
253
|
+
*/
|
|
254
|
+
function languageLine(language, { fix = false } = {}) {
|
|
255
|
+
const name = LANGUAGES[language];
|
|
256
|
+
if (!name) return 'Write everything in the language the user writes to the bots in.';
|
|
257
|
+
return `Write everything in ${name}, the language the user writes to the bots in, whatever language the material below is in.${fix ? ` A note written in another language is rewritten in ${name} (an "update").` : ''}`;
|
|
258
|
+
}
|
|
259
|
+
|
|
229
260
|
const notesBlock = (notes) => (notes.length ? notes.map((n) => `[${n.id}]${n.pinned ? ' (pinned)' : ''} ${n.text}`).join('\n') : '(none)');
|
|
230
261
|
|
|
231
262
|
/** Shorten a transcript to its head and tail. */
|
|
@@ -237,7 +268,7 @@ export function clip(text, max = 12_000) {
|
|
|
237
268
|
}
|
|
238
269
|
|
|
239
270
|
/** After a task: summarize it and update the bot's notes (and propose team notes). */
|
|
240
|
-
export function reflectionPrompt({ bot, notes, team, transcript, trigger }) {
|
|
271
|
+
export function reflectionPrompt({ bot, notes, team, transcript, trigger, language = '' }) {
|
|
241
272
|
return {
|
|
242
273
|
system: [
|
|
243
274
|
`You keep the long-term memory of ${bot.name} (@${bot.handle}), one of the user's AI bots${bot.bio ? ` — ${bot.bio}` : ''}.`,
|
|
@@ -245,6 +276,7 @@ export function reflectionPrompt({ bot, notes, team, transcript, trigger }) {
|
|
|
245
276
|
'{"summary": "<one or two sentences: what was asked and what came of it, with names, numbers and links that matter>", "notes": [<edits to the bot\'s own notes>], "team": [<edits to the team notes>]}',
|
|
246
277
|
'',
|
|
247
278
|
opsSpec,
|
|
279
|
+
languageLine(language),
|
|
248
280
|
'Save only what will still matter in a week: stable preferences and facts about the user, people, projects and decisions; procedures that worked; lessons from mistakes. Most tasks need no note at all — then answer with empty lists. Team notes are only for what every bot should know.',
|
|
249
281
|
].join('\n'),
|
|
250
282
|
user: [`# The bot's notes\n${notesBlock(notes)}`, `# Team notes\n${notesBlock(team)}`, `# The task (${trigger})\n${clip(transcript)}`].join('\n\n'),
|
|
@@ -289,7 +321,7 @@ export function searchTickets(query, tickets, { limit = 10 } = {}) {
|
|
|
289
321
|
}
|
|
290
322
|
|
|
291
323
|
/** Once a day per bot: tidy the notes with the last days of its journal. */
|
|
292
|
-
export function dreamBotPrompt({ bot, notes, journal, tz = 0 }) {
|
|
324
|
+
export function dreamBotPrompt({ bot, notes, journal, tz = 0, language = '' }) {
|
|
293
325
|
return {
|
|
294
326
|
system: [
|
|
295
327
|
`You consolidate the long-term memory of ${bot.name} (@${bot.handle}), one of the user's AI bots${bot.bio ? ` — ${bot.bio}` : ''}, as it sleeps.`,
|
|
@@ -297,13 +329,14 @@ export function dreamBotPrompt({ bot, notes, journal, tz = 0 }) {
|
|
|
297
329
|
'Answer with one JSON object and nothing else: {"notes": [<edits>]}',
|
|
298
330
|
'',
|
|
299
331
|
opsSpec,
|
|
332
|
+
languageLine(language, { fix: true }),
|
|
300
333
|
].join('\n'),
|
|
301
334
|
user: [`# Notes\n${notesBlock(notes)}`, `# Journal of recent tasks\n${clip(journal.map((j) => `${stamp(j.at, tz)} ${j.summary || j.title}`).join('\n'), 14_000) || '(none)'}`].join('\n\n'),
|
|
302
335
|
};
|
|
303
336
|
}
|
|
304
337
|
|
|
305
338
|
/** Once a day for the team: a digest of what every bot did, and the shared notes tidied. */
|
|
306
|
-
export function dreamTeamPrompt({ bots, team, journal, date, tz = 0 }) {
|
|
339
|
+
export function dreamTeamPrompt({ bots, team, journal, date, tz = 0, language = '' }) {
|
|
307
340
|
const name = (id) => {
|
|
308
341
|
const b = bots.find((x) => x.id === id);
|
|
309
342
|
return b ? `@${b.handle}` : 'a removed bot';
|
|
@@ -311,10 +344,11 @@ export function dreamTeamPrompt({ bots, team, journal, date, tz = 0 }) {
|
|
|
311
344
|
return {
|
|
312
345
|
system: [
|
|
313
346
|
"You keep the shared memory of the user's team of AI bots.",
|
|
314
|
-
`Write the team's digest for ${date}: what was done (by whom), results worth remembering, what is still open or blocked, and what comes next — in Markdown, at most 1000 characters
|
|
347
|
+
`Write the team's digest for ${date}: what was done (by whom), results worth remembering, what is still open or blocked, and what comes next — in Markdown, at most 1000 characters. Then tidy the shared team notes: merge repeats, drop outdated ones, add facts every bot should know that the journal shows.`,
|
|
315
348
|
'Answer with one JSON object and nothing else: {"digest": "…", "team": [<edits>]}',
|
|
316
349
|
'',
|
|
317
350
|
opsSpec,
|
|
351
|
+
languageLine(language, { fix: true }),
|
|
318
352
|
].join('\n'),
|
|
319
353
|
user: [
|
|
320
354
|
`# Team: ${bots.map((b) => `@${b.handle} (${b.name})`).join(', ')}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kadaliao/dsh-bots",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Grok-style bots for DeepSeek Harness: create bots with their own avatar, persona, model, skills, apps, scheduled tasks and memory; they message each other, a dispatcher bot hands out the work, and a usage view counts tokens by bot, task and day.",
|
|
6
6
|
"exports": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "git+https://github.com/kadaliao/dsh-
|
|
48
|
-
"directory": "plugins/bots"
|
|
47
|
+
"url": "git+https://github.com/kadaliao/dsh-bots.git"
|
|
49
48
|
},
|
|
50
|
-
"homepage": "https://github.com/kadaliao/dsh-
|
|
49
|
+
"homepage": "https://github.com/kadaliao/dsh-bots#readme",
|
|
50
|
+
"bugs": "https://github.com/kadaliao/dsh-bots/issues",
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"keywords": ["dsh", "deepseek-harness", "dsh-plugin", "bots", "agents", "multi-agent", "persona", "schedule", "mcp", "computer-use", "memory", "usage"]
|
|
53
53
|
}
|