dsh-team-bots 0.2.289 → 0.2.338
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.md +12 -136
- package/docs/README.zh.md +15 -139
- package/docs/assets/channel-redesign.png +0 -0
- package/docs/assets/global-config-dark.png +0 -0
- package/docs/assets/global-config-light.png +0 -0
- package/docs/assets/global-config-light.zh.png +0 -0
- package/docs/assets/global-config-redesign.png +0 -0
- package/docs/assets/secrets-redesign.png +0 -0
- package/docs/assets/tasks.png +0 -0
- package/docs/assets/tasks.zh.png +0 -0
- package/docs/assets/usage-redesign-global.png +0 -0
- package/docs/assets/usage.png +0 -0
- package/docs/assets/usage.zh.png +0 -0
- package/package.json +17 -5
- package/scripts/doctor.mjs +4 -4
- package/src/api.js +6 -3
- package/src/botmsg.js +1 -1
- package/src/config.js +18 -8
- package/src/db-migrations.js +76 -9
- package/src/db.js +28 -2
- package/src/http.js +22 -3
- package/src/paths.js +32 -1
- package/src/pricing.js +2 -2
- package/src/runtime.js +1 -1
- package/src/secrets.js +4 -4
- package/src/service.js +10 -5
- package/src/services/approvals.js +109 -24
- package/src/services/bot-quota.js +242 -0
- package/src/services/bots.js +35 -6
- package/src/services/chat.js +15 -9
- package/src/services/core.js +33 -5
- package/src/services/hygiene.js +8 -4
- package/src/services/locale.js +17 -0
- package/src/services/memory.js +112 -1
- package/src/services/message-images.js +3 -3
- package/src/services/notify.js +99 -0
- package/src/services/projects.js +119 -10
- package/src/services/proposals.js +2 -3
- package/src/services/questions.js +75 -32
- package/src/services/review-watchdog.js +261 -30
- package/src/services/run-finish.js +119 -7
- package/src/services/runs.js +42 -13
- package/src/services/runtime/lifecycle.js +3 -1
- package/src/services/runtime/model-restore.js +5 -5
- package/src/services/runtime/prompt.js +106 -45
- package/src/services/runtime/session.js +38 -14
- package/src/services/runtime/trajectory.js +1 -1
- package/src/services/scheduler.js +139 -13
- package/src/services/secrets.js +1 -1
- package/src/services/system.js +23 -6
- package/src/services/task-notify.js +49 -7
- package/src/services/task-stage.js +4 -0
- package/src/services/tasks.js +121 -12
- package/src/services/terminal.js +2 -2
- package/src/services/vision-proxy.js +3 -3
- package/src/services/wechat.js +228 -7
- package/src/services/workspace-groups.js +4 -3
- package/src/skill-parse.js +1 -1
- package/src/skills.js +1 -1
- package/src/tools.js +275 -6
- package/src/updater.js +52 -0
- package/src/usage-reconcile.js +1 -1
- package/src/usage.js +52 -11
- package/src/wechat/channel.js +14 -20
- package/src/wechat/commands.js +129 -81
- package/src/wechat/format.js +247 -0
- package/src/wechat/store.js +30 -2
- package/ui/app.js +56 -52
- package/ui/i18n/en/chat.js +140 -0
- package/ui/i18n/en/common.js +189 -0
- package/ui/i18n/en/nav.js +90 -0
- package/ui/i18n/en/settings.js +354 -0
- package/ui/i18n/en/tasks.js +232 -0
- package/ui/i18n/en/usage.js +141 -0
- package/ui/i18n/en/wechat.js +24 -0
- package/ui/i18n/en.js +17 -237
- package/ui/i18n/zh/chat.js +140 -0
- package/ui/i18n/zh/common.js +189 -0
- package/ui/i18n/zh/nav.js +90 -0
- package/ui/i18n/zh/settings.js +354 -0
- package/ui/i18n/zh/tasks.js +232 -0
- package/ui/i18n/zh/usage.js +141 -0
- package/ui/i18n/zh/wechat.js +24 -0
- package/ui/i18n/zh.js +17 -236
- package/ui/modules/api.js +4 -3
- package/ui/modules/bot-quota.js +27 -0
- package/ui/modules/cards.js +96 -58
- package/ui/modules/chat.js +28 -30
- package/ui/modules/composer.js +41 -37
- package/ui/modules/dom-morph.js +292 -0
- package/ui/modules/events-board.js +22 -22
- package/ui/modules/events-click.js +100 -68
- package/ui/modules/events-misc.js +34 -34
- package/ui/modules/events-submit.js +28 -28
- package/ui/modules/global-pages.js +127 -116
- package/ui/modules/i18n.js +0 -5
- package/ui/modules/icons.js +0 -1
- package/ui/modules/markdown.js +1 -1
- package/ui/modules/modal-forms.js +195 -202
- package/ui/modules/modal-layer.js +6 -9
- package/ui/modules/page-shell.js +62 -0
- package/ui/modules/settings.js +211 -198
- package/ui/modules/solo-archive.js +0 -4
- package/ui/modules/state.js +57 -50
- package/ui/modules/tasks.js +168 -171
- package/ui/modules/typing-linger.js +1 -4
- package/ui/modules/usage.js +65 -78
- package/ui/modules/util.js +92 -25
- package/ui/styles/avatars.css +14 -0
- package/ui/styles/cards.css +49 -0
- package/ui/styles/chat-cards.css +17 -21
- package/ui/styles/global-config.css +59 -2
- package/ui/styles/modal.css +13 -0
- package/ui/styles/usage.css +3 -61
- package/CONTRIBUTING.md +0 -20
- package/docs/assets/usage-dark.png +0 -0
|
@@ -11,8 +11,9 @@ import { join } from 'node:path'
|
|
|
11
11
|
import { scanProjectSkills } from '../../project-skills.js'
|
|
12
12
|
import { id, nowIso, parseDisabledSkills } from '../../util.js'
|
|
13
13
|
import { dmPrompt, replyDeliveryPrompt } from '../../botmsg.js'
|
|
14
|
-
import { rolloverSummaryKey } from '../../config.js'
|
|
14
|
+
import { rolloverPendingKey, rolloverSummaryKey } from '../../config.js'
|
|
15
15
|
import { readWriteScopes } from '../write-scopes.js'
|
|
16
|
+
import { sanitizeTmpBotDirName } from '../../paths.js'
|
|
16
17
|
|
|
17
18
|
// 与 DSH 宿主 dsh-sandbox-policy 的 SANDBOX_MODES 保持一致;库里值不合法时不向宿主写覆盖。
|
|
18
19
|
export const SANDBOX_MODES = ['read-only', 'workspace-write', 'danger-full-access']
|
|
@@ -56,7 +57,7 @@ export function effectiveSandbox(run, bot, task) {
|
|
|
56
57
|
|
|
57
58
|
const sessionIdOf = context => context?.agent?.id ?? context?.session?.id ?? context?.sessionId
|
|
58
59
|
|
|
59
|
-
// 任务描述超长截断管线(DSHBOTS-113,事故 m_33bddb;DSHBOTS-
|
|
60
|
+
// 任务描述超长截断管线(DSHBOTS-113,事故 m_33bddb;DSHBOTS-254 起任务分支与 review/handle 同口径):
|
|
60
61
|
// 任务全文拼进提示词可能顶爆 400 上下文,超过 8K 字符截断并注明,消费方据此只基于
|
|
61
62
|
// 截断内可见的部分下结论并声明盲区;标题/状态/写范围/任务评论在截断点之外恒在场。
|
|
62
63
|
function truncateTaskDescription(raw) {
|
|
@@ -157,21 +158,40 @@ export const promptMethods = {
|
|
|
157
158
|
'- Commits, deploys and anything irreversible wait for the owner bot or the user.',
|
|
158
159
|
'- Use `team_remember` only for durable lessons from this task. Never store secrets or credentials.',
|
|
159
160
|
]
|
|
160
|
-
:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
161
|
+
: owner
|
|
162
|
+
? [
|
|
163
|
+
'- You are a long-lived teammate. Your replies in the project group are visible to the user and other bots.',
|
|
164
|
+
'- Use `team_assign_task` to hand concrete work to another project bot, or to re-dispatch an existing task by its KEY-N number; passing title/description/priority alongside `task` amends the card and the assignee is notified to correct course. Consolidate before dispatch: one requirement goes into one card — amend and re-dispatch the existing card instead of opening several cards for the same need. Do not claim work is assigned unless the tool succeeds.',
|
|
165
|
+
'- Use `team_block_task` to force-stop a runaway in-progress task: it moves the task to blocked and aborts its queued/running runs (audited). Typical correction loop: block the wrong-headed run, amend the card, re-dispatch.',
|
|
166
|
+
'- Use `team_message_bot` for a quick direct question or coordination with one project bot; the reply arrives in your own session as a later message. It does not create a task and is not visible in the group.',
|
|
167
|
+
'- Use `team_list_members` to see who is in this project group (project role, job role, status) before dispatching or coordinating.',
|
|
168
|
+
'- Use `team_list_bots` to see the whole team bot pool, including bots not yet in this project; `team_add_member` invites one by name, and `team_create_bot` requests a new bot through the normal creation path (validation still applies, and the new bot is not auto-joined).',
|
|
169
|
+
'- `ask_user_question` asks the user a structured question (choices or free text); it appears as a question card in the project group that only the project owner may answer. Director-only: you are this project\'s director bot, the only one allowed to call it; usable in project-bound sessions like this one, not in solo sessions.',
|
|
170
|
+
'- Tasks you dispatch are reviewed by you: when a delivery arrives, `team_review_task` accepts it or returns it with a rework reason.',
|
|
171
|
+
'- Use `team_remember` for durable facts, preferences, decisions or lessons worth keeping. Never store secrets or credentials.',
|
|
172
|
+
'- Memory hygiene is director work: run `team_memory_list` per scope to inspect stored memories, and clean when a newer final state supersedes an entry — a closed card\'s process records go with `team_memory_cleanup` plus its KEY-N; an older wording that conflicts with the latest decision goes by explicit `topics`. Judge by final state only, and keep entries recording the user\'s explicit decisions. Write replacement wordings with `team_memory_write` (same-name overwrite, no duplicate pile-up). Every cleanup is audited as memory.cleanup with the cleaned entries listed.',
|
|
173
|
+
'- When a task can be split, use `subagent` / `subagent_fork` to spawn child agents for parallel acceleration. Child-agent file writes are not governed by tasks.write_scopes dispatch gates (they inherit the parent session sandbox); before dispatching, check for write-scope conflicts with other members, and review child-agent output yourself before delivering it.',
|
|
174
|
+
'- Use `team_propose_evolution` to suggest a durable instruction or skill change. You cannot approve your own proposal.',
|
|
175
|
+
'- When executing a task, do the work, verify it, then return a concise result with changed paths and any risks.',
|
|
176
|
+
]
|
|
177
|
+
: [
|
|
178
|
+
'- You are a long-lived teammate. Your replies in the project group are visible to the user and other bots.',
|
|
179
|
+
'- `team_assign_task` and `team_review_task` are director-only: member bots cannot call them. To get work dispatched, re-dispatched or reviewed, ask the project director bot in the group.',
|
|
180
|
+
'- Use `team_message_bot` for a quick direct question or coordination with one project bot; the reply arrives in your own session as a later message. It does not create a task and is not visible in the group.',
|
|
181
|
+
'- Use `team_list_members` to see your teammates in this project (project role, job role, status).',
|
|
182
|
+
'- Team staffing is director-only: `team_list_bots`, `team_add_member` and `team_create_bot` cannot be called by member bots. Ask the project director bot to invite or create teammates.',
|
|
183
|
+
'- `ask_user_question` is director-only: member bots cannot call it. When you need the user to decide something, hand the question to the project director bot to raise instead of calling the tool yourself.',
|
|
184
|
+
'- Use `team_remember` for durable facts, preferences, decisions or lessons worth keeping. Never store secrets or credentials.',
|
|
185
|
+
'- Use `team_propose_evolution` to suggest a durable instruction or skill change. You cannot approve your own proposal.',
|
|
186
|
+
'- When executing a task, do the work, verify it, then return a concise result with changed paths and any risks.',
|
|
187
|
+
]
|
|
188
|
+
// DSHBOTS-238:成员 bot 子代理并行指引(静态段,前缀缓存区)。
|
|
189
|
+
// 「生成子代理/组建临时团队」能力由宿主 preset 全局注册(subagent / subagent_fork /
|
|
190
|
+
// spawn_teammate 等),成员 bot 默认可见;本段只补「何时拆、怎么汇总」的使用口径。
|
|
191
|
+
// agentTeam 关闭时不注入,与运行提示词的 # Parallel work 段同一门控。
|
|
192
|
+
const memberSubagentGuide = !owner && this.config.agentTeam ? `
|
|
193
|
+
# Subagent parallelization
|
|
194
|
+
You can spawn child agents (\`subagent\` / \`subagent_fork\`) or named teammates (\`spawn_teammate\`) to parallelize independent work inside your own task. Split only when the task has two or more independent parts with disjoint write scopes; small or single-file work, do it yourself. Before delivering, merge their results into your report and review their output yourself. Child-agent writes inherit your session sandbox and are not governed by the task write-scope gates — check for conflicts with other members first.` : ''
|
|
175
195
|
const teamRules = ['## How this team works', ...collaborationRules, secretRule, ...sharedRules, ...projectSkillRules].join('\n')
|
|
176
196
|
return [
|
|
177
197
|
'# Team bot identity',
|
|
@@ -183,9 +203,11 @@ export const promptMethods = {
|
|
|
183
203
|
`- Name: ${project.name}`,
|
|
184
204
|
`- Key: ${project.key}`,
|
|
185
205
|
`- Workspace: ${project.production_dir || join(this.config.workspace, project.slug)}`,
|
|
206
|
+
`- Temp files discipline: write every temporary or intermediate file (scratch scripts, probe outputs, downloaded artifacts) under \`.tmp/bots/${sanitizeTmpBotDirName(bot.name)}/\` inside the workspace; create that directory if it is missing. Never scatter temp files elsewhere in the project.`,
|
|
186
207
|
roleLine,
|
|
187
208
|
'',
|
|
188
209
|
teamRules,
|
|
210
|
+
memberSubagentGuide,
|
|
189
211
|
].filter(Boolean).join('\n')
|
|
190
212
|
},
|
|
191
213
|
|
|
@@ -259,7 +281,7 @@ export const promptMethods = {
|
|
|
259
281
|
// DSHBOTS-156:档位口径含任务派发覆盖(只收紧不放大);带运行上下文时把生效档与来源
|
|
260
282
|
// 落 run_events(type='sandbox_mode',复用会话也每次留档——run_events 是运行时间线,
|
|
261
283
|
// 每条运行都该有自己的一档记录,与 sandbox/mode 追加的去重无关)。
|
|
262
|
-
applyFilePolicy(agent, bot, run, task) {
|
|
284
|
+
applyFilePolicy(agent, bot, run , task ) {
|
|
263
285
|
const { mode, source } = effectiveSandbox(run, bot, task)
|
|
264
286
|
if (!SANDBOX_MODES.includes(mode)) return
|
|
265
287
|
if (run?.id) {
|
|
@@ -278,7 +300,7 @@ export const promptMethods = {
|
|
|
278
300
|
const current = policy?.overrideOf?.(liveSession)
|
|
279
301
|
if (current === mode) return
|
|
280
302
|
liveSession.append('sandbox/mode', { mode })
|
|
281
|
-
} catch (error) {
|
|
303
|
+
} catch (error ) {
|
|
282
304
|
this.logger.warn?.(`应用文件权限 ${mode} 失败(${bot?.name ?? bot?.id}):${error?.message ?? error}`)
|
|
283
305
|
}
|
|
284
306
|
},
|
|
@@ -316,11 +338,14 @@ export const promptMethods = {
|
|
|
316
338
|
|
|
317
339
|
// 结转摘要块(DSHBOTS-145):新会话首轮提示词注入旧会话的交接摘要。
|
|
318
340
|
// 一次性语义(照 recovery note 手法):读到的同时即刻清零,同一摘要只注入一次。
|
|
319
|
-
//
|
|
320
|
-
|
|
341
|
+
// 消费闸(DSHBOTS-213):仅当本轮会话就是结转新建的目标会话(pending 标记命中)才消费;
|
|
342
|
+
// 无摘要或目标不是本会话时返回空串,摘要保留到真正的结转,防止被无关轮次提前清零。
|
|
343
|
+
rolloverSummaryBlock(bot, project, sessionId) {
|
|
321
344
|
const summary = this.store.setting(rolloverSummaryKey(bot.id, project?.id))
|
|
322
345
|
if (!summary) return ''
|
|
346
|
+
if (this.store.setting(rolloverPendingKey(bot.id, project?.id)) !== sessionId) return ''
|
|
323
347
|
this.store.setSetting(rolloverSummaryKey(bot.id, project?.id), '')
|
|
348
|
+
this.store.setSetting(rolloverPendingKey(bot.id, project?.id), '')
|
|
324
349
|
return `
|
|
325
350
|
|
|
326
351
|
# Handoff summary from the previous session
|
|
@@ -342,7 +367,7 @@ This conversation has reached its turn limit and will be rolled over to a fresh
|
|
|
342
367
|
- Do not call any tool and do not write files. Reply with the summary text only.`
|
|
343
368
|
},
|
|
344
369
|
// 单聊运行提示词:没有项目上下文,只带本会话增量新消息。
|
|
345
|
-
soloRunPrompt({ bot, chatMessage, sessionId }) {
|
|
370
|
+
soloRunPrompt({ bot, chatMessage, extraMessages, sessionId }) {
|
|
346
371
|
const header = [
|
|
347
372
|
`You are: ${bot.name}`,
|
|
348
373
|
'Mode: one-on-one conversation (outside projects)',
|
|
@@ -357,7 +382,8 @@ This conversation has reached its turn limit and will be rolled over to a fresh
|
|
|
357
382
|
excludeId: chatMessage?.id,
|
|
358
383
|
})
|
|
359
384
|
// P3-1:单聊同款,无信息量 system 短状态不进尾窗。
|
|
360
|
-
const
|
|
385
|
+
const mergedIds = new Set((extraMessages ?? []).map(item => item.id))
|
|
386
|
+
const visible = recent.filter(item => !mergedIds.has(item.id) && !(item.sender_type === 'system' && NOISE_SYSTEM_BODY.test(item.body)))
|
|
361
387
|
const context = visible.map((item) => {
|
|
362
388
|
const body = item.body.length > 240 ? `${item.body.slice(0, 240)}…` : item.body
|
|
363
389
|
return `- [m_${item.id.slice(-6)}] ${item.sender_type}:${item.sender_id}: ${body}`
|
|
@@ -370,7 +396,7 @@ This conversation has reached its turn limit and will be rolled over to a fresh
|
|
|
370
396
|
Reply as ${bot.name} in this one-on-one chat. Keep it under ${this.config.chatReplyMaxChars} characters unless the user asked for a full write-up or files. There is no project here: do not use team_assign_task or team_review_task. Use team_recall with a m_ id when you need the full text of a truncated item. When the user asks you to produce or store files, work inside the workspace above.
|
|
371
397
|
|
|
372
398
|
# Solo message
|
|
373
|
-
${(chatMessage?.body ?? '(no message)').slice(0, 4_000)}${this.rolloverSummaryBlock(bot)}
|
|
399
|
+
${(chatMessage?.body ?? '(no message)').slice(0, 4_000)}${this.mergedMessagesBlock(extraMessages)}${this.rolloverSummaryBlock(bot, null, sessionId)}
|
|
374
400
|
|
|
375
401
|
${recentBlock}`
|
|
376
402
|
},
|
|
@@ -396,8 +422,8 @@ Transcription requirements:
|
|
|
396
422
|
Original message from ${chatMessage?.sender_type ?? 'user'}:${chatMessage?.sender_id ?? ''}
|
|
397
423
|
${(chatMessage?.body ?? '(no text)').slice(0, 2_000)}`
|
|
398
424
|
},
|
|
399
|
-
promptFor({ run, bot, project, task, chatMessage, sessionId }) {
|
|
400
|
-
if (run.kind === 'solo_chat') return this.soloRunPrompt({ run, bot, chatMessage, sessionId })
|
|
425
|
+
promptFor({ run, bot, project, task, chatMessage, extraMessages, sessionId } ) {
|
|
426
|
+
if (run.kind === 'solo_chat') return this.soloRunPrompt({ run, bot, chatMessage, extraMessages, sessionId })
|
|
401
427
|
if (run.kind === 'vision') return this.visionRunPrompt({ run, bot, project, chatMessage })
|
|
402
428
|
// 结转摘要(DSHBOTS-145):先于 header 判定——单聊摘要运行没有项目,
|
|
403
429
|
// header 直接解引用 project 会炸。
|
|
@@ -407,17 +433,20 @@ ${(chatMessage?.body ?? '(no text)').slice(0, 2_000)}`
|
|
|
407
433
|
`Workspace: ${project.production_dir || join(this.config.workspace, project.slug)}`,
|
|
408
434
|
`You are: ${bot.name}`,
|
|
409
435
|
].join('\n')
|
|
436
|
+
// 任务评论注入(DSHBOTS-254 收口):最近 3 条、合计 ≤1.5k——每条正文 500 上限(1.5k/3 的
|
|
437
|
+
// 按比例缩减)+ 拼接后 1500 硬顶(兜住行前缀开销),最坏 ~4k → 1.5k。
|
|
410
438
|
const taskComments = task
|
|
411
439
|
? this.store.all(
|
|
412
|
-
'SELECT id, author_type, author_id, body FROM task_comments WHERE task_id = ? ORDER BY created_at DESC LIMIT
|
|
440
|
+
'SELECT id, author_type, author_id, body FROM task_comments WHERE task_id = ? ORDER BY created_at DESC LIMIT 3',
|
|
413
441
|
task.id,
|
|
414
442
|
).reverse()
|
|
415
443
|
: []
|
|
416
444
|
const threads = taskComments.length === 0
|
|
417
445
|
? ''
|
|
418
446
|
: `\nRecent task comments:\n${taskComments
|
|
419
|
-
.map(item => `- [c_${item.id.slice(-6)}] ${item.author_type}:${item.author_id}: ${item.body.length >
|
|
420
|
-
.join('\n')
|
|
447
|
+
.map(item => `- [c_${item.id.slice(-6)}] ${item.author_type}:${item.author_id}: ${item.body.length > 500 ? `${item.body.slice(0, 500)}…` : item.body}`)
|
|
448
|
+
.join('\n')
|
|
449
|
+
.slice(0, 1_500)}`
|
|
421
450
|
// 时效要求(DSHBOTS-125/131):time_budget_minutes 未传/NULL 则完全不注入。
|
|
422
451
|
// 任务派生运行(review/handle/memory_review)与该任务共用同一时效上限,提示词必须同步告知,
|
|
423
452
|
// 否则运行会在代理不知情的情况下被超时中止。
|
|
@@ -432,7 +461,7 @@ The effective timeout is the smaller of this budget and the global run timeout (
|
|
|
432
461
|
}
|
|
433
462
|
if ((run.kind === 'review' || run.kind === 'handle') && task) {
|
|
434
463
|
// 超长防护(DSHBOTS-113,事故 m_33bddb;DSHBOTS-140 扩到 owner review / handle):
|
|
435
|
-
//
|
|
464
|
+
// 任务派生分支共用 truncateTaskDescription 的同一截断点与盲区口径(任务分支见 DSHBOTS-254)。
|
|
436
465
|
const writeScopes = readWriteScopes(task.write_scopes)
|
|
437
466
|
const declaredScopes = writeScopes.length ? writeScopes.join(', ') : '(none declared)'
|
|
438
467
|
const description = truncateTaskDescription(task.description)
|
|
@@ -553,6 +582,9 @@ Your reply:
|
|
|
553
582
|
${(sourceRun?.output ?? '').slice(0, 4000)}`
|
|
554
583
|
}
|
|
555
584
|
if (task) {
|
|
585
|
+
// 超长防护(DSHBOTS-254):任务分支与 review/handle 同口径复用 truncateTaskDescription
|
|
586
|
+
// (8k 截断 + 盲区标记),建卡上限 40k 的长卡不再整段进提示词。
|
|
587
|
+
const description = truncateTaskDescription(task.description)
|
|
556
588
|
// 时效要求(DSHBOTS-125/131):time_budget_minutes 未传/NULL 则完全不注入,提示词与无时效任务一致。
|
|
557
589
|
const timeBudgetBlock = timeBudgetBlockFor(task)
|
|
558
590
|
// 紧急豁免(DSHBOTS-126):urgent 任务卡追加豁免指令(用户口径 m08196-2)——
|
|
@@ -561,14 +593,24 @@ ${(sourceRun?.output ?? '').slice(0, 4000)}`
|
|
|
561
593
|
|
|
562
594
|
# Urgent exemption
|
|
563
595
|
This task is urgent and exempt from lane queuing discipline: start immediately, without waiting for other tasks' file lanes to clear. If in-flight edits to the same files exist in the workspace, first run git status to record the scene, then commit only this card's files by exact pathspec — never add/checkout/stash others' changes.` : ''
|
|
564
|
-
// subtask-discipline:start —— 子任务拆解纪律(DSHBOTS-132
|
|
565
|
-
//
|
|
566
|
-
//
|
|
596
|
+
// subtask-discipline:start —— 子任务拆解纪律(DSHBOTS-132;DSHBOTS-254 与提速拆分/并行段
|
|
597
|
+
// 语义去重,三段合计 ≤1200 字符,tests/prompt-budget.test.ts 守门):主项做不完或出现新
|
|
598
|
+
// 收口条件 → 立产品级子卡。所有任务卡无条件注入,与时效段(D-125)、紧急豁免段(D-126)
|
|
599
|
+
// 互不干扰:本段不读 priority/time_budget,后两者不读本段。
|
|
567
600
|
const subtaskDisciplineBlock = `
|
|
568
601
|
|
|
569
602
|
# Subtask discipline
|
|
570
|
-
Before closing: if this task cannot be finished in one run
|
|
603
|
+
Before closing: if this task cannot be finished in one run or new closing conditions emerge, file subtasks via team_assign_task with parent_task_id and report in the group — no verbal-only follow-ups. Subtasks are product-grade (general capability, full tests, real persistence), no throwaway patches. Do not split what one run can finish. List every subtask KEY-N in the closing report.`
|
|
571
604
|
// subtask-discipline:end
|
|
605
|
+
// splitting-guidance:start —— 提速拆分引导(DSHBOTS-212;DSHBOTS-254 去重收口):
|
|
606
|
+
// 拆分判据(2+ 独立部分 + 写范围不相交 + 拆后合并成本更低)+ 角色现实(无派单权限就在
|
|
607
|
+
// 交付报告里提拆分方案)。静态段(不随卡变化):与纪律段同为全局前缀,置于 # Assigned task
|
|
608
|
+
// 之前,护住前缀缓存。
|
|
609
|
+
const splittingGuidanceBlock = `
|
|
610
|
+
|
|
611
|
+
# Splitting for speed
|
|
612
|
+
Split only when all hold: the task has 2+ independent parts, parts have disjoint write scopes, and the joined cost of split cards stays below one-run delivery. One card per part: parent_task_id to this task, blocked_by where order matters. Not the project owner? Propose the split in your delivery report. Example: API card (src/api/) + docs card, run concurrently.`
|
|
613
|
+
// splitting-guidance:end
|
|
572
614
|
// recovery note(DSHBOTS-135):宿主重启重排队的运行(core.js 置 recovery=1)追加恢复提醒,
|
|
573
615
|
// 对齐 superagent 原型语义——核实现状再续做、不重复外部动作。startRun 注入后即刻清零,
|
|
574
616
|
// 本段只在重排队后的第一次执行出现。与时效段(D-125)、豁免段(D-126)、纪律段(D-132)互不干扰。
|
|
@@ -576,15 +618,15 @@ Before closing: if this task cannot be finished in one run (e.g. quota-capped pa
|
|
|
576
618
|
|
|
577
619
|
# Recovery note
|
|
578
620
|
The previous run was interrupted by a host restart. Check the workspace and git status first to verify the current state, then resume from where it stopped; do not repeat external actions already performed (commits/publishes/messages).` : ''
|
|
621
|
+
// agentTeam 门控(DSHBOTS-254 收口):单卡内并行的执行口径——teammates/子代理、
|
|
622
|
+
// 部件落项目 KEY-N 卡、交付前 wait_agent 汇总。拆分判据不在此重复(见上方提速拆分段)。
|
|
579
623
|
const parallel = this.config.agentTeam ? `
|
|
580
624
|
|
|
581
625
|
# Parallel work inside this task
|
|
582
|
-
-
|
|
583
|
-
-
|
|
584
|
-
-
|
|
585
|
-
|
|
586
|
-
- The checkout is shared and unlocked. If a teammate reports a conflicting edit, resolve it yourself instead of retrying blindly.` : ''
|
|
587
|
-
return `${header}${subtaskDisciplineBlock}
|
|
626
|
+
- Parallelize independent parts via teammates (at most ${this.config.maxTeammates}) or child agents (subagent/subagent_fork).
|
|
627
|
+
- Record every part as a project task card (project KEY-N) with a disjoint write_scope, never on the host shared task board (task-N).
|
|
628
|
+
- Before delivering: list_agents, wait_agent until idle, merge results into your report; resolve conflicting edits yourself.` : ''
|
|
629
|
+
return `${header}${subtaskDisciplineBlock}${splittingGuidanceBlock}
|
|
588
630
|
|
|
589
631
|
Do the task in the project workspace. Use tools as needed. End with a concise delivery report containing what changed, verification performed, and blockers or risks. Do not just describe what you would do.
|
|
590
632
|
When the deliverable includes images, put the files in the workspace and reference them with markdown image syntax using workspace-relative paths (e.g. ); chat renders them as thumbnails. Only png/jpg/jpeg/gif/webp are served.${parallel}
|
|
@@ -594,7 +636,7 @@ Title: ${task.title}
|
|
|
594
636
|
Priority: ${task.priority}
|
|
595
637
|
Status: ${task.status}
|
|
596
638
|
Description:
|
|
597
|
-
${
|
|
639
|
+
${description}${threads}${timeBudgetBlock}${urgentExemptionBlock}${recoveryNoteBlock}`
|
|
598
640
|
}
|
|
599
641
|
const { rows: recent, incremental } = this.watermarkWindow({
|
|
600
642
|
sessionId,
|
|
@@ -605,8 +647,9 @@ ${task.description || '(no description)'}${threads}${timeBudgetBlock}${urgentExe
|
|
|
605
647
|
params: [project.id],
|
|
606
648
|
excludeId: chatMessage?.id,
|
|
607
649
|
})
|
|
608
|
-
// P3-1:无信息量 system
|
|
609
|
-
const
|
|
650
|
+
// P3-1:无信息量 system 短状态不进尾窗;合批消息已在专门段落呈现,同样不进尾窗(不双份)。
|
|
651
|
+
const mergedIds = new Set((extraMessages ?? []).map(item => item.id))
|
|
652
|
+
const visible = recent.filter(item => !mergedIds.has(item.id) && !(item.sender_type === 'system' && NOISE_SYSTEM_BODY.test(item.body)))
|
|
610
653
|
const context = visible.map((item) => {
|
|
611
654
|
const body = item.body.length > 240 ? `${item.body.slice(0, 240)}…` : item.body
|
|
612
655
|
return `- [m_${item.id.slice(-6)}] ${item.sender_type}:${item.sender_id}${item.task_id ? ' (task thread)' : ''}: ${body}`
|
|
@@ -625,19 +668,37 @@ ${task.description || '(no description)'}${threads}${timeBudgetBlock}${urgentExe
|
|
|
625
668
|
: openTasks.map(item => `- ${project.key}-${item.number} [${item.status}] ${item.title}`).join('\n')
|
|
626
669
|
// 引用回复上下文:本次消息带 reply_to 时,明确告知 bot 用户在回哪条消息(含 m_ 短 id 供 team_recall 取全文)。
|
|
627
670
|
const quoteLine = this.quotedLineFor(chatMessage)
|
|
671
|
+
// DSHBOTS-215 微信直达语境:多轮连续对话(项目会话复用),不要每条当新指令;
|
|
672
|
+
// 派活意图要真建卡/派单;需要用户决策时用 ask_user_question(会转发到微信)。
|
|
673
|
+
const wechatBlock = run.trigger_type === 'wechat' ? `
|
|
674
|
+
|
|
675
|
+
# WeChat direct conversation
|
|
676
|
+
This message is from the project owner on WeChat — a real multi-turn conversation, not a one-off command. The project session is shared, so keep continuity across turns instead of restarting context each time. If the owner asks you to get work done, actually create and assign the task (team_assign_task — cards carry the project KEY-N number; do not create project-less task-N cards on the host shared board) instead of only acknowledging it. If you need the owner to decide something, use ask_user_question: it is forwarded to their WeChat and their reply comes back to you.` : ''
|
|
628
677
|
return `${header}
|
|
629
678
|
|
|
630
|
-
Reply as ${bot.name} in the project group. Keep it under ${this.config.chatReplyMaxChars} characters unless the user asked for a full write-up. If the message requires another bot to do work, use team_assign_task instead of pretending to assign it. Use team_recall with a m_/c_/run id when you need the full text of a truncated item
|
|
679
|
+
Reply as ${bot.name} in the project group. Keep it under ${this.config.chatReplyMaxChars} characters unless the user asked for a full write-up. If the message requires another bot to do work, use team_assign_task instead of pretending to assign it. Use team_recall with a m_/c_/run id when you need the full text of a truncated item.${wechatBlock}
|
|
631
680
|
|
|
632
681
|
# Group message
|
|
633
682
|
${(chatMessage?.body ?? '(no message)').slice(0, 4_000)}
|
|
634
|
-
${quoteLine}${this.rolloverSummaryBlock(bot, project)}
|
|
683
|
+
${this.mergedMessagesBlock(extraMessages)}${quoteLine}${this.rolloverSummaryBlock(bot, project, sessionId)}
|
|
635
684
|
${recentBlock}
|
|
636
685
|
|
|
637
686
|
Open tasks:
|
|
638
687
|
${taskList}`
|
|
639
688
|
},
|
|
640
689
|
|
|
690
|
+
// 合批消息段(DSHBOTS-231):领取时合并进来的同通道排队消息,与触发消息同一轮注入。
|
|
691
|
+
// 无合批消息时返回空串,单条消息的提示词格式与原来完全一致(既有锚点测试不受影响)。
|
|
692
|
+
mergedMessagesBlock(extraMessages) {
|
|
693
|
+
if (!extraMessages?.length) return ''
|
|
694
|
+
const lines = extraMessages.map(item => {
|
|
695
|
+
const body = String(item.body ?? '')
|
|
696
|
+
const shown = body.length > 4_000 ? `${body.slice(0, 4_000)}…` : body
|
|
697
|
+
return `- [m_${String(item.id).slice(-6)}] ${item.sender_type}:${item.sender_id}: ${shown}`
|
|
698
|
+
}).join('\n')
|
|
699
|
+
return `\n\n# Merged messages (queued while this run was waiting, ids are for team_recall):\n${lines}`
|
|
700
|
+
},
|
|
701
|
+
|
|
641
702
|
// 引用行:正文控制在 200 字内;bot 发送者查名字,其余回退 sender_type:sender_id 展示。
|
|
642
703
|
quotedLineFor(chatMessage) {
|
|
643
704
|
if (!chatMessage?.reply_to_id) return ''
|
|
@@ -7,9 +7,10 @@ import { randomUUID } from 'node:crypto'
|
|
|
7
7
|
import { AppError } from '../../errors.js'
|
|
8
8
|
import { id } from '../../util.js'
|
|
9
9
|
import { attachSessionToWorkspace, resolveSessionCwd, workspaceGroupTitle } from '../workspace-groups.js'
|
|
10
|
-
import { effectiveRunLimits, effectiveSessionRolloverTurns, rolloverSummaryKey } from '../../config.js'
|
|
10
|
+
import { effectiveRunLimits, effectiveSessionRolloverTurns, rolloverPendingKey, rolloverSummaryKey } from '../../config.js'
|
|
11
11
|
import { imageContentPartsForMessage } from '../message-images.js'
|
|
12
12
|
import { restoreDefaultModel } from './model-restore.js'
|
|
13
|
+
import { applyBotToolPolicy } from '../../tools.js'
|
|
13
14
|
|
|
14
15
|
export const EFFORT_FALLBACK = (bot) => bot.effort || undefined
|
|
15
16
|
|
|
@@ -33,6 +34,14 @@ export const sessionMethods = {
|
|
|
33
34
|
if (!sessionId) return undefined
|
|
34
35
|
return this.store.get('SELECT * FROM session_bindings WHERE session_id = ?', sessionId)
|
|
35
36
|
},
|
|
37
|
+
// 会话绑定退役(DSHBOTS-256):旧绑定不删,降级为 alias=1 授权别名。
|
|
38
|
+
// 结转(DSHBOTS-145)或宿主失效替换后,仍以旧 session id 运行的宿主 agent
|
|
39
|
+
// 调用 team_* 工具时,ownerContextFor/memberContextFor 仍按同 bot/项目解析到授权;
|
|
40
|
+
// 别名行不参与活跃绑定唯一约束,新会话绑定照常建立。
|
|
41
|
+
retireBinding(sessionId) {
|
|
42
|
+
if (!sessionId) return
|
|
43
|
+
this.store.run('UPDATE session_bindings SET alias = 1 WHERE session_id = ? AND alias = 0', sessionId)
|
|
44
|
+
},
|
|
36
45
|
async catalog(force = false) {
|
|
37
46
|
const age = Date.now() - this.modelsCache.at
|
|
38
47
|
if (!force) {
|
|
@@ -150,7 +159,7 @@ export const sessionMethods = {
|
|
|
150
159
|
await restoreDefaultModel(defaults, before, {
|
|
151
160
|
logger: this.logger,
|
|
152
161
|
hmr: this.ctx.get?.('hmr'),
|
|
153
|
-
audit: (error, meta = {}) => this.store?.audit?.(
|
|
162
|
+
audit: (error, meta = {} ) => this.store?.audit?.(
|
|
154
163
|
'system',
|
|
155
164
|
'system',
|
|
156
165
|
'model_restore_failed',
|
|
@@ -239,17 +248,21 @@ export const sessionMethods = {
|
|
|
239
248
|
)
|
|
240
249
|
return runId
|
|
241
250
|
},
|
|
242
|
-
async ensureSession(bot, project, { run, task, sessionKind, modelOverride } = {}) {
|
|
251
|
+
async ensureSession(bot, project, { run, task, sessionKind, modelOverride } = {} ) {
|
|
252
|
+
// DSHBOTS-238:成员 bot 工具层兜底——隐藏总监专权工具(子代理生成工具由 preset 全局
|
|
253
|
+
// 注册,成员默认可见)。仅作用于项目绑定会话;solo 无项目上下文,本策略自然不触发。
|
|
254
|
+
const isOwner = Boolean(project && bot && project.owner_bot_id === bot.id)
|
|
243
255
|
// 结转摘要运行(DSHBOTS-145):必须回到被结转的旧会话写摘要,且不能参与阈值判定——
|
|
244
256
|
// 否则摘要运行自己又会触发一次结转;solo 摘要运行也没有项目上下文,不查项目。
|
|
245
257
|
if (run?.kind === 'rollover_summary' && run.session_id) {
|
|
246
258
|
const resolved = await this.ctx.sessionController.resolveAgent(run.session_id)
|
|
247
259
|
if (!resolved?.error) {
|
|
248
260
|
this.applyFilePolicy(resolved, bot, run, task)
|
|
261
|
+
applyBotToolPolicy(resolved, { isOwner, logger: this.logger })
|
|
249
262
|
await this.selectModel(run.session_id, bot, modelOverride)
|
|
250
263
|
return run.session_id
|
|
251
264
|
}
|
|
252
|
-
this.
|
|
265
|
+
this.retireBinding(run.session_id)
|
|
253
266
|
}
|
|
254
267
|
// 任务运行使用独立会话,与该项目总监会话互不阻塞;dm 运行用独立私信会话;
|
|
255
268
|
// 单聊运行(solo_chat)没有项目,落在 bot 自己的 _the_bots/<dir> 专属会话;其余运行共用项目会话。
|
|
@@ -263,22 +276,23 @@ export const sessionMethods = {
|
|
|
263
276
|
const solo = kind === 'solo'
|
|
264
277
|
const existing = taskId
|
|
265
278
|
? this.store.get(
|
|
266
|
-
"SELECT * FROM session_bindings WHERE bot_id = ? AND project_id = ? AND kind = 'task' AND task_id = ?",
|
|
279
|
+
"SELECT * FROM session_bindings WHERE bot_id = ? AND project_id = ? AND kind = 'task' AND task_id = ? AND alias = 0",
|
|
267
280
|
bot.id,
|
|
268
281
|
project.id,
|
|
269
282
|
taskId,
|
|
270
283
|
)
|
|
271
284
|
: solo
|
|
272
285
|
? this.store.get(
|
|
273
|
-
"SELECT * FROM session_bindings WHERE bot_id = ? AND kind = 'solo' AND project_id IS NULL AND task_id IS NULL",
|
|
286
|
+
"SELECT * FROM session_bindings WHERE bot_id = ? AND kind = 'solo' AND project_id IS NULL AND task_id IS NULL AND alias = 0",
|
|
274
287
|
bot.id,
|
|
275
288
|
)
|
|
276
289
|
: this.store.get(
|
|
277
|
-
'SELECT * FROM session_bindings WHERE bot_id = ? AND project_id = ? AND kind = ?',
|
|
290
|
+
'SELECT * FROM session_bindings WHERE bot_id = ? AND project_id = ? AND kind = ? AND alias = 0',
|
|
278
291
|
bot.id,
|
|
279
292
|
project.id,
|
|
280
293
|
kind,
|
|
281
294
|
)
|
|
295
|
+
let rolledOver = false
|
|
282
296
|
if (existing) {
|
|
283
297
|
const resolved = await this.ctx.sessionController.resolveAgent(existing.session_id)
|
|
284
298
|
if (!resolved?.error) {
|
|
@@ -288,14 +302,17 @@ export const sessionMethods = {
|
|
|
288
302
|
// 不阻塞对话。
|
|
289
303
|
const rollover = kind !== 'task' && kind !== 'dm'
|
|
290
304
|
&& this.shouldRolloverSession({ bot, project, existing })
|
|
305
|
+
rolledOver = rollover
|
|
291
306
|
if (!rollover) {
|
|
292
307
|
this.applyFilePolicy(resolved, bot, run, task)
|
|
308
|
+
applyBotToolPolicy(resolved, { isOwner, logger: this.logger })
|
|
293
309
|
await this.selectModel(existing.session_id, bot, modelOverride)
|
|
294
310
|
return existing.session_id
|
|
295
311
|
}
|
|
296
312
|
}
|
|
297
|
-
//
|
|
298
|
-
|
|
313
|
+
// 会话已失效(宿主查不到)或结转判定要求开新会话:旧绑定降级为授权别名,
|
|
314
|
+
// 落到下方新建路径(DSHBOTS-256:别名保留旧 session 的 bot/项目归属)。
|
|
315
|
+
this.retireBinding(existing.session_id)
|
|
299
316
|
}
|
|
300
317
|
const key = `${bot.id}:${solo ? 'solo' : project.id}:${kind}:${taskId ?? ''}`
|
|
301
318
|
if (this.sessionCreates.has(key)) return this.sessionCreates.get(key)
|
|
@@ -325,9 +342,10 @@ export const sessionMethods = {
|
|
|
325
342
|
}
|
|
326
343
|
}
|
|
327
344
|
this.applyFilePolicy(agent, bot, run, task)
|
|
345
|
+
applyBotToolPolicy(agent, { isOwner, logger: this.logger })
|
|
328
346
|
this.store.run(
|
|
329
|
-
`INSERT INTO session_bindings(session_id, bot_id, project_id, kind, task_id, created_at)
|
|
330
|
-
VALUES (?, ?, ?, ?, ?,
|
|
347
|
+
`INSERT INTO session_bindings(session_id, bot_id, project_id, kind, task_id, created_at, alias)
|
|
348
|
+
VALUES (?, ?, ?, ?, ?, ?, 0)
|
|
331
349
|
ON CONFLICT(session_id) DO NOTHING`,
|
|
332
350
|
sessionId,
|
|
333
351
|
bot.id,
|
|
@@ -336,6 +354,9 @@ export const sessionMethods = {
|
|
|
336
354
|
taskId,
|
|
337
355
|
new Date().toISOString(),
|
|
338
356
|
)
|
|
357
|
+
// 结转消费闸(DSHBOTS-213):新会话成为摘要的唯一注入目标——否则旧会话在摘要就绪
|
|
358
|
+
// 前后被非结转路径顶替(如宿主重启失效)时,替身会话的普通轮次会把摘要提前消费掉。
|
|
359
|
+
if (rolledOver) this.store.setSetting(rolloverPendingKey(bot.id, solo ? null : project.id), sessionId)
|
|
339
360
|
await this.selectModel(sessionId, bot, modelOverride)
|
|
340
361
|
// 挂到 DSH 原生工作区分组(可选增强):registry 经 ctx.get 读取,宿主未装就整体跳过;
|
|
341
362
|
// 挂载失败只在 workspace-groups 内 warn,绝不影响会话返回与运行。
|
|
@@ -356,7 +377,7 @@ export const sessionMethods = {
|
|
|
356
377
|
this.sessionCreates.delete(key)
|
|
357
378
|
}
|
|
358
379
|
},
|
|
359
|
-
async startRun({ run, bot, project, task, chatMessage, sessionKind }) {
|
|
380
|
+
async startRun({ run, bot, project, task, chatMessage, extraMessages, sessionKind } ) {
|
|
360
381
|
if (!this.ctx?.sessionController) throw new AppError('DSH_UNAVAILABLE', 'DSH Session 服务不可用')
|
|
361
382
|
// 备用模型覆盖:派生运行在 runs 行里带 model_* 三列,指明这条运行改用备用模型下发。
|
|
362
383
|
// 不带 override 的运行照旧走 Bot 主模型——「运行结束自动回退」就靠这条默认路径实现。
|
|
@@ -366,17 +387,20 @@ export const sessionMethods = {
|
|
|
366
387
|
? { ...bot, provider: modelOverride.provider, model: modelOverride.model, effort: modelOverride.effort ?? null }
|
|
367
388
|
: bot
|
|
368
389
|
const sessionId = await this.ensureSession(bot, project, { run, task, sessionKind, modelOverride })
|
|
369
|
-
let prompt = this.promptFor({ run, bot, project, task, chatMessage, sessionId })
|
|
390
|
+
let prompt = this.promptFor({ run, bot, project, task, chatMessage, extraMessages, sessionId })
|
|
370
391
|
// recovery note(DSHBOTS-135):恢复标记已被上面的首条提示词消费,即刻清零——
|
|
371
392
|
// 恢复提醒只对「重排队后的第一次执行」注入一次,后续运行回到标准提示词。
|
|
372
393
|
if (Number(run.recovery) === 1) {
|
|
373
394
|
this.store.run('UPDATE runs SET recovery = 0 WHERE id = ?', run.id)
|
|
374
395
|
}
|
|
375
|
-
const pending
|
|
396
|
+
const pending = {
|
|
376
397
|
runId: run.id,
|
|
377
398
|
sessionId,
|
|
378
399
|
bot: effectiveBot,
|
|
379
400
|
projectId: project?.id ?? null,
|
|
401
|
+
// 任务归因(DSHBOTS-212):记账时透传到 usage_events.task_id;
|
|
402
|
+
// 非任务运行为 null,沿用既有「无任务归因」口径。
|
|
403
|
+
taskId: run.task_id ?? null,
|
|
380
404
|
started: false,
|
|
381
405
|
texts: [],
|
|
382
406
|
lastText: '',
|