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
|
@@ -16,8 +16,9 @@ import { runReviewWatchdog } from './review-watchdog.js'
|
|
|
16
16
|
const PLAN_RETRY_MAX_LATE_SECONDS = 24 * 3600
|
|
17
17
|
|
|
18
18
|
// DSHBOTS-43 人的消息保底槽:人触发的运行判定。
|
|
19
|
-
// 现有字段口径:chat/solo_chat 的 trigger_type 是 'mention'
|
|
20
|
-
//
|
|
19
|
+
// 现有字段口径:chat/solo_chat 的 trigger_type 是 'mention'(微信直达为 'wechat',DSHBOTS-208;
|
|
20
|
+
// DSHBOTS-258 起项目外 director 专属工作区的 solo 直达同为 'wechat'),dm 是 'dm',dm_reply 是
|
|
21
|
+
// 'dm_reply';用 kind 判定最稳(solo_chat 也命中),以现有字段为准不新增列。
|
|
21
22
|
const HUMAN_RUN_KINDS = new Set(['chat', 'solo_chat', 'dm', 'dm_reply'])
|
|
22
23
|
function isHumanRun(run) {
|
|
23
24
|
return HUMAN_RUN_KINDS.has(run.kind)
|
|
@@ -29,7 +30,7 @@ function isHumanRun(run) {
|
|
|
29
30
|
// - 只读运行(mode ≠ 'write')不占写槽。
|
|
30
31
|
// - 非任务运行(chat/dm/dm_reply 等)不绑任务,按运行自身判定,照旧占槽。
|
|
31
32
|
// - 任务运行(kind = 'task')只有任务 status = 'in_progress' 时才占槽;任务不在进行中即视为已释放。
|
|
32
|
-
export function runHoldsWriteLock({ kind, mode, taskStatus } = {}) {
|
|
33
|
+
export function runHoldsWriteLock({ kind, mode, taskStatus } = {} ) {
|
|
33
34
|
if (mode !== 'write') return false
|
|
34
35
|
if (kind !== 'task') return true
|
|
35
36
|
return taskStatus === 'in_progress'
|
|
@@ -44,6 +45,14 @@ export function runHoldsWriteLock({ kind, mode, taskStatus } = {}) {
|
|
|
44
45
|
// task_run 的先写者赢是防重复派生闸,同样保持默认(先写者赢)不动。
|
|
45
46
|
const OUTBOX_COALESCE_KINDS = new Set(['review_delegate_auto'])
|
|
46
47
|
|
|
48
|
+
// 入站消息合批(DSHBOTS-231):只合并「人发的消息运行」——同一条绑定道内、仍在排队的
|
|
49
|
+
// chat / solo_chat 运行。任务运行、派生运行(review/handle/memory_review/vision)与私信
|
|
50
|
+
// (dm/dm_reply,各自有按消息的回信契约)都不参与:合并它们会破坏既有的投递语义。
|
|
51
|
+
const RUN_COALESCE_KINDS = new Set(['chat', 'solo_chat'])
|
|
52
|
+
// 默认保守上限:一次运行最多合并 5 条消息、且只合并入队时间相差 30 秒内的排队消息。
|
|
53
|
+
const COALESCE_MAX_MESSAGES_DEFAULT = 5
|
|
54
|
+
const COALESCE_WINDOW_MS_DEFAULT = 30_000
|
|
55
|
+
|
|
47
56
|
export const schedulerMethods = {
|
|
48
57
|
|
|
49
58
|
// outbox:把「状态变更 → 建运行」这一跳变成可重放的持久交接。
|
|
@@ -95,7 +104,7 @@ export const schedulerMethods = {
|
|
|
95
104
|
nowIso(), row.id,
|
|
96
105
|
)
|
|
97
106
|
return result
|
|
98
|
-
} catch (error) {
|
|
107
|
+
} catch (error ) {
|
|
99
108
|
if (error?.defer === true) {
|
|
100
109
|
this.store.run(
|
|
101
110
|
`UPDATE outbox SET status = 'pending', available_at = ?, last_error = ? WHERE id = ?`,
|
|
@@ -157,7 +166,7 @@ export const schedulerMethods = {
|
|
|
157
166
|
const project = this.store.get('SELECT * FROM projects WHERE id = ?', payload.projectId)
|
|
158
167
|
const bot = this.store.get('SELECT * FROM bots WHERE id = ?', payload.botId)
|
|
159
168
|
if (!project || !bot || project.status !== 'active' || bot.status !== 'active') return null
|
|
160
|
-
return this.enqueueChatRun(project, bot, payload.messageId)
|
|
169
|
+
return this.enqueueChatRun(project, bot, payload.messageId, payload.origin)
|
|
161
170
|
}
|
|
162
171
|
if (row.kind === 'task_run') {
|
|
163
172
|
const task = this.store.get('SELECT * FROM tasks WHERE id = ?', payload.taskId)
|
|
@@ -183,7 +192,7 @@ export const schedulerMethods = {
|
|
|
183
192
|
if (!task || task.status !== 'in_review') return null
|
|
184
193
|
try {
|
|
185
194
|
return this.spawnReviewDelegate(task, { actor: { type: 'system', id: 'system' }, origin: 'auto' }).runId
|
|
186
|
-
} catch (error) {
|
|
195
|
+
} catch (error ) {
|
|
187
196
|
const exhausted = Number(row.attempts ?? 0) >= 3
|
|
188
197
|
this.audit({ type: 'system', id: 'system' }, 'review.auto_delegate_retry', 'task', task.id, {
|
|
189
198
|
attempt: Number(row.attempts ?? 0) + 1,
|
|
@@ -230,7 +239,11 @@ export const schedulerMethods = {
|
|
|
230
239
|
if (row.kind === 'solo_chat_run') {
|
|
231
240
|
const bot = this.store.get('SELECT * FROM bots WHERE id = ?', payload.botId)
|
|
232
241
|
if (!bot || bot.status !== 'active') return null
|
|
233
|
-
|
|
242
|
+
// payload.origin='wechat'(DSHBOTS-258):微信通道投的项目外 director 单聊,
|
|
243
|
+
// solo 运行打 wechat 标记,运行收尾的回复据此推回微信;普通 UI 单聊保持 mention。
|
|
244
|
+
return this.enqueueSoloChatRun(bot, payload.messageId, {
|
|
245
|
+
triggerType: payload.origin === 'wechat' ? 'wechat' : 'mention',
|
|
246
|
+
})
|
|
234
247
|
}
|
|
235
248
|
if (row.kind === 'dm_run') {
|
|
236
249
|
const message = this.store.get('SELECT * FROM bot_messages WHERE id = ?', payload.messageId)
|
|
@@ -255,9 +268,90 @@ export const schedulerMethods = {
|
|
|
255
268
|
throw error
|
|
256
269
|
},
|
|
257
270
|
|
|
258
|
-
//
|
|
271
|
+
// 同一条会话上的运行必须串行(原注释意图);DSHBOTS-219 分身模型:串行键从「bot」
|
|
272
|
+
// 放细到「会话绑定维度」(= 一条分身通道)——单聊/各项目群聊/私信互不阻塞,
|
|
273
|
+
// 一路 pending(如单聊提权审批)不再挡死同一 bot 的其它通道。
|
|
274
|
+
// 键与 ensureSession 的绑定元组一一对应,同一会话的两条运行必得同键,串行不失效。
|
|
259
275
|
claimKey(run) {
|
|
260
|
-
|
|
276
|
+
if (run.kind === 'task' && run.task_id) return `task:${run.task_id}`
|
|
277
|
+
return this.sessionLaneKey(run)
|
|
278
|
+
},
|
|
279
|
+
// 会话绑定的通道键(纯查库推导,无副作用):task / solo / dm / project 四类绑定各归各道。
|
|
280
|
+
bindingLaneKey(binding) {
|
|
281
|
+
if (binding.kind === 'task' && binding.task_id) return `task:${binding.task_id}`
|
|
282
|
+
if (binding.kind === 'solo') return `solo:${binding.bot_id}`
|
|
283
|
+
if (binding.kind === 'dm') return `dm:${binding.bot_id}:${binding.project_id}`
|
|
284
|
+
return `project:${binding.bot_id}:${binding.project_id}`
|
|
285
|
+
},
|
|
286
|
+
// 非任务运行的通道键:按该运行实际会落到的会话推导(与 ensureSession 的 kind0 同一套映射)。
|
|
287
|
+
// solo_chat 与无项目 vision 落 solo 会话;chat/review/handle/memory_review 与带项目 vision
|
|
288
|
+
// 落项目会话;dm 落私信会话;dm_reply 按来信 origin 回对应会话(task_id 留空躲唯一索引,
|
|
289
|
+
// 任务通道只能从 bot_messages 解);rollover_summary 复用指定旧会话,按该会话当前绑定
|
|
290
|
+
// 的通道键对齐(防与复用同一会话的群聊并发——runtime 的 pending 按会话一对一)。
|
|
291
|
+
sessionLaneKey(run) {
|
|
292
|
+
if (run.kind === 'solo_chat' || (run.kind === 'vision' && !run.project_id)) return `solo:${run.bot_id}`
|
|
293
|
+
if (run.kind === 'rollover_summary') {
|
|
294
|
+
if (!run.session_id) return `bot:${run.bot_id}`
|
|
295
|
+
const binding = this.store.get('SELECT * FROM session_bindings WHERE session_id = ?', run.session_id)
|
|
296
|
+
return binding ? this.bindingLaneKey(binding) : `session:${run.session_id}`
|
|
297
|
+
}
|
|
298
|
+
if (run.kind === 'dm_reply') {
|
|
299
|
+
const message = run.trigger_ref
|
|
300
|
+
? this.store.get('SELECT origin_kind, origin_task_id FROM bot_messages WHERE id = ?', run.trigger_ref)
|
|
301
|
+
: null
|
|
302
|
+
if (message?.origin_kind === 'task' && message.origin_task_id) return `task:${message.origin_task_id}`
|
|
303
|
+
if (message?.origin_kind === 'dm') return `dm:${run.bot_id}:${run.project_id}`
|
|
304
|
+
return `project:${run.bot_id}:${run.project_id}`
|
|
305
|
+
}
|
|
306
|
+
if (run.kind === 'dm') return `dm:${run.bot_id}:${run.project_id}`
|
|
307
|
+
return `project:${run.bot_id}:${run.project_id}`
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
// 入站消息合批(DSHBOTS-231):领取一条运行后,把同一条绑定道内仍在排队的消息运行合并
|
|
311
|
+
// 进来——被合并的运行置 canceled(error_code='MERGED'),消息 id 记入本运行的
|
|
312
|
+
// merged_messages,executeRun 据此把多条消息一次性注入同一轮上下文,不再一条消息一次运行。
|
|
313
|
+
// 只在 claimKey 相同的通道内合并,D-219 的四道解耦语义不变;合并窗口与条数上限走 settings。
|
|
314
|
+
// 并发安全:被合并的运行用「queued → canceled」原子更新抢占,抢不到(另一拍已领取)就跳过。
|
|
315
|
+
coalesceQueuedRuns(run) {
|
|
316
|
+
if (!RUN_COALESCE_KINDS.has(run.kind)) return []
|
|
317
|
+
const max = Number(this.store.setting('coalesce_max_messages', String(COALESCE_MAX_MESSAGES_DEFAULT)))
|
|
318
|
+
if (!Number.isFinite(max) || max <= 1) return []
|
|
319
|
+
const windowMs = Number(this.store.setting('coalesce_window_ms', String(COALESCE_WINDOW_MS_DEFAULT)))
|
|
320
|
+
const claimedQueuedAt = Date.parse(run.queued_at)
|
|
321
|
+
const laneKey = this.claimKey(run)
|
|
322
|
+
const candidates = this.store.all(
|
|
323
|
+
`SELECT * FROM runs WHERE status = 'queued' AND id != ? AND kind = ?
|
|
324
|
+
ORDER BY queued_at LIMIT 100`,
|
|
325
|
+
run.id, run.kind,
|
|
326
|
+
)
|
|
327
|
+
const mergedIds = []
|
|
328
|
+
const mergedRuns = []
|
|
329
|
+
for (const candidate of candidates) {
|
|
330
|
+
if (mergedIds.length >= max - 1) break
|
|
331
|
+
if (!candidate.trigger_ref) continue
|
|
332
|
+
if (this.claimKey(candidate) !== laneKey) continue
|
|
333
|
+
const queuedAt = Date.parse(candidate.queued_at)
|
|
334
|
+
if (!Number.isFinite(queuedAt) || !Number.isFinite(claimedQueuedAt)) continue
|
|
335
|
+
if (queuedAt < claimedQueuedAt || queuedAt - claimedQueuedAt > windowMs) continue
|
|
336
|
+
const changed = this.store.run(
|
|
337
|
+
`UPDATE runs SET status = 'canceled', ended_at = ?, error_code = 'MERGED', error_message = ?
|
|
338
|
+
WHERE id = ? AND status = 'queued'`,
|
|
339
|
+
nowIso(), `消息已合并进运行 ${run.id},不再单独执行`, candidate.id,
|
|
340
|
+
)
|
|
341
|
+
if (Number(changed?.changes ?? 0) !== 1) continue
|
|
342
|
+
mergedIds.push(candidate.trigger_ref)
|
|
343
|
+
mergedRuns.push(candidate)
|
|
344
|
+
}
|
|
345
|
+
if (!mergedIds.length) return []
|
|
346
|
+
this.store.run('UPDATE runs SET merged_messages = ? WHERE id = ?', JSON.stringify(mergedIds), run.id)
|
|
347
|
+
this.insertRunEvent(
|
|
348
|
+
run.id, 'runs_merged',
|
|
349
|
+
`同通道 ${mergedIds.length} 条排队消息合并进本次运行:${mergedIds.map(item => item.slice(-6)).join('、')}`,
|
|
350
|
+
)
|
|
351
|
+
for (const candidate of mergedRuns) {
|
|
352
|
+
this.insertRunEvent(candidate.id, 'merged_into', `排队消息已合并进运行 ${run.id}`)
|
|
353
|
+
}
|
|
354
|
+
return mergedRuns
|
|
261
355
|
},
|
|
262
356
|
|
|
263
357
|
// 运行超时由 runtime 的定时器负责;这里补充“还活着但没有任何进展”的判定。
|
|
@@ -270,20 +364,26 @@ export const schedulerMethods = {
|
|
|
270
364
|
// 存在 run_id 匹配且未过 expires_at 的 pending 提问时豁免;豁免期被提问窗口
|
|
271
365
|
// (questionTimeoutMs,默认 180s)自然封顶:窗口一过(提问置 timeout/answered 或残留
|
|
272
366
|
// pending 的 expires_at 已过)超龄 run 下一拍照常回收,泄漏 pending 不可能永久豁免。
|
|
367
|
+
// DSHBOTS-222:审批与提问同口径——等待审批中的 run 同样没有进展事件,pending 审批
|
|
368
|
+
// 未过 expires_at 时一并豁免;豁免期被审批窗口(approvalTimeoutMs)自然封顶。
|
|
273
369
|
const stalled = this.store.all(
|
|
274
370
|
`SELECT id, kind, started_at, last_progress_at FROM runs
|
|
275
371
|
WHERE status = 'running' AND COALESCE(last_progress_at, started_at) < ?
|
|
276
372
|
AND NOT EXISTS(
|
|
277
373
|
SELECT 1 FROM questions q
|
|
278
374
|
WHERE q.run_id = runs.id AND q.status = 'pending' AND q.expires_at > ?
|
|
375
|
+
)
|
|
376
|
+
AND NOT EXISTS(
|
|
377
|
+
SELECT 1 FROM approvals a
|
|
378
|
+
WHERE a.run_id = runs.id AND a.status = 'pending' AND a.expires_at > ?
|
|
279
379
|
)`,
|
|
280
|
-
cutoff, nowIso(),
|
|
380
|
+
cutoff, nowIso(), nowIso(),
|
|
281
381
|
)
|
|
282
382
|
for (const run of stalled) {
|
|
283
383
|
this.logger.warn?.('dsh-team: run %s made no progress since %s', run.id, run.last_progress_at ?? run.started_at)
|
|
284
384
|
try {
|
|
285
385
|
await this.runtime?.cancelRun?.(run.id)
|
|
286
|
-
} catch (error) {
|
|
386
|
+
} catch (error ) {
|
|
287
387
|
this.logger.warn?.('dsh-team: cancel stalled run %s failed: %s', run.id, error)
|
|
288
388
|
}
|
|
289
389
|
await this.finishRun({
|
|
@@ -349,7 +449,7 @@ export const schedulerMethods = {
|
|
|
349
449
|
id('evt'), run.id, 'plan_retry',
|
|
350
450
|
`限流重试到期,派生新运行 ${runId}(attempt ${(run.attempt ?? 1) + 1})`, createdAt,
|
|
351
451
|
)
|
|
352
|
-
} catch (error) {
|
|
452
|
+
} catch (error ) {
|
|
353
453
|
// idempotency_key UNIQUE 撞车 = 另一个 tick 已派生过,跳过即可。
|
|
354
454
|
if (String(error).includes('UNIQUE')) continue
|
|
355
455
|
throw error
|
|
@@ -416,7 +516,10 @@ export const schedulerMethods = {
|
|
|
416
516
|
// 写占用只看「进行中」的任务(DSHBOTS-73,用户口径):join tasks 取任务当前状态,
|
|
417
517
|
// 任务不在 in_progress 的写运行不再占槽——离开进行中即释放占用/锁定。
|
|
418
518
|
// 非任务运行 LEFT JOIN 出的 task_status 为空,按运行自身判定,不受这条闸门影响。
|
|
519
|
+
// trigger_ref/session_id 供 claimKey 通道推导(dm_reply 按来信 origin、rollover_summary
|
|
520
|
+
// 按旧会话绑定)——在跑侧与候选侧必须算出同一个键,串行才不失效(DSHBOTS-219)。
|
|
419
521
|
`SELECT r.bot_id, r.kind, r.task_id, r.project_id, r.mode, r.write_scopes, r.trigger_type,
|
|
522
|
+
r.trigger_ref, r.session_id,
|
|
420
523
|
t.status AS task_status
|
|
421
524
|
FROM runs r LEFT JOIN tasks t ON t.id = r.task_id
|
|
422
525
|
WHERE r.status = 'running'`,
|
|
@@ -490,6 +593,26 @@ export const schedulerMethods = {
|
|
|
490
593
|
await this.finishRun({ runId: run.id, status: 'failed', output: '', error: { code: 'UNAVAILABLE', message: '项目或 Bot 不可用' } })
|
|
491
594
|
continue
|
|
492
595
|
}
|
|
596
|
+
// DSHBOTS-241 额度闸门:主 provider 仍在耗尽期、且本次没走备用模型的任务运行不领取——
|
|
597
|
+
// 留 queued,恢复时间过后下一拍自动回主模型(避免每拍撞同一堵墙)。
|
|
598
|
+
// 走备用的运行(model_provider 非空)不受此闸影响,主备两套额度各自独立。
|
|
599
|
+
if (run.kind === 'task' && !run.model_provider) {
|
|
600
|
+
const quota = this.botQuotaState(run.bot_id, bot.provider)
|
|
601
|
+
if (quota?.exhausted) {
|
|
602
|
+
const alreadyNoted = this.store.get(
|
|
603
|
+
"SELECT 1 AS ok FROM run_events WHERE run_id = ? AND type = 'quota_wait'",
|
|
604
|
+
run.id,
|
|
605
|
+
)
|
|
606
|
+
if (!alreadyNoted) {
|
|
607
|
+
this.insertRunEvent(
|
|
608
|
+
run.id,
|
|
609
|
+
'quota_wait',
|
|
610
|
+
`额度耗尽(${quota.provider}),恢复时间 ${quota.resetAt ?? '未知'} 前暂缓领取`,
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
continue
|
|
614
|
+
}
|
|
615
|
+
}
|
|
493
616
|
const budgetError = this.budgetError(needsProject ? project : null)
|
|
494
617
|
if (budgetError) {
|
|
495
618
|
await this.finishRun({ runId: run.id, status: 'failed', output: '', error: { code: 'BUDGET_EXCEEDED', message: budgetError } })
|
|
@@ -524,6 +647,9 @@ export const schedulerMethods = {
|
|
|
524
647
|
nowIso(), nowIso(), run.id,
|
|
525
648
|
)
|
|
526
649
|
if (Number(claimed.changes) !== 1) continue
|
|
650
|
+
// 入站消息合批(DSHBOTS-231):领取后把同通道仍在排队的消息并进本次运行,
|
|
651
|
+
// 被合并的运行置 canceled/MERGED,消息 id 落到 merged_messages 供 executeRun 注入。
|
|
652
|
+
this.coalesceQueuedRuns(run)
|
|
527
653
|
// 借用了人的消息保底槽(超出并发上限放行):记事件并占住额外槽,下一次归还前不再放第二条。
|
|
528
654
|
if (human && activeTotal >= maxRuns) {
|
|
529
655
|
humanSlotTaken = true
|
|
@@ -558,7 +684,7 @@ export const schedulerMethods = {
|
|
|
558
684
|
}
|
|
559
685
|
void this.executeRun(run.id)
|
|
560
686
|
}
|
|
561
|
-
} catch (error) {
|
|
687
|
+
} catch (error ) {
|
|
562
688
|
this.logger.error?.('dsh-team: scheduler tick failed: %s', error)
|
|
563
689
|
} finally {
|
|
564
690
|
this.ticking = false
|
package/src/services/secrets.js
CHANGED
|
@@ -127,7 +127,7 @@ export const secretsMethods = {
|
|
|
127
127
|
try {
|
|
128
128
|
if (!existsSync(filePath)) return false
|
|
129
129
|
rmSync(filePath, { force: true })
|
|
130
|
-
} catch (error) {
|
|
130
|
+
} catch (error ) {
|
|
131
131
|
this.logger.warn?.('dsh-team: 焚毁项目 %s 运行时密钥失败:%s', projectId, error?.message ?? error)
|
|
132
132
|
return false
|
|
133
133
|
}
|
package/src/services/system.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { createRequire } from 'node:module'
|
|
7
7
|
import { AppError, badRequest, conflict, hotUpgradeUnsupported } from '../errors.js'
|
|
8
8
|
import { usageSnapshot } from '../usage.js'
|
|
9
|
-
import { latestDshVersion, latestTeamBotsVersion, compareVersions, validTargetVersion, detectDshRuntimeVersion } from '../updater.js'
|
|
9
|
+
import { latestDshVersion, latestTeamBotsVersion, compareVersions, validTargetVersion, detectDshRuntimeVersion, detectHostDshVersionFromPlugin, displayDshVersion } from '../updater.js'
|
|
10
10
|
import { skillSnapshot } from '../skills.js'
|
|
11
11
|
import { projectSkillRoots } from '../project-skills.js'
|
|
12
12
|
import { resolveUiLanguage } from './locale.js'
|
|
@@ -71,7 +71,8 @@ export const systemMethods = {
|
|
|
71
71
|
const unreadCounts = this.unreadChatCounts()
|
|
72
72
|
let project = projectId ? this.store.get('SELECT * FROM projects WHERE id = ?', projectId) : undefined
|
|
73
73
|
if (!project) project = this.store.get("SELECT * FROM projects WHERE status = 'active' ORDER BY updated_at DESC LIMIT 1")
|
|
74
|
-
const
|
|
74
|
+
const capabilityInfo = this.runtime?.capabilityInfo?.() ?? {}
|
|
75
|
+
const view = {
|
|
75
76
|
me: this.store.get('SELECT id, name FROM users WHERE id = ?', this.localUserId),
|
|
76
77
|
models: await this.runtime?.catalog() ?? [],
|
|
77
78
|
bots: bots.map(bot => this.botView(bot)),
|
|
@@ -116,9 +117,12 @@ export const systemMethods = {
|
|
|
116
117
|
},
|
|
117
118
|
dsh: {
|
|
118
119
|
native: true,
|
|
119
|
-
profile:
|
|
120
|
+
profile: process.env.DSH_PROFILE ?? 'team-bots',
|
|
120
121
|
home: this.config.dshHome,
|
|
121
|
-
...
|
|
122
|
+
...capabilityInfo,
|
|
123
|
+
// 当前版本尽力取真值(DSHBOTS-253):capability 链(env→argv)取不到时,从插件
|
|
124
|
+
// 部署位置再探宿主包;仍拿不到为 '',UI 据此整行隐藏「dsh 当前版本」。
|
|
125
|
+
version: displayDshVersion(capabilityInfo.version) || detectHostDshVersionFromPlugin(),
|
|
122
126
|
},
|
|
123
127
|
// 本插件(dsh-team-bots)部署生效版:与 health().version 同源。
|
|
124
128
|
pluginVersion: PLUGIN_VERSION,
|
|
@@ -197,6 +201,10 @@ export const systemMethods = {
|
|
|
197
201
|
})
|
|
198
202
|
const soloTotal = Number(this.store.get('SELECT COUNT(*) AS count FROM solo_messages WHERE bot_id = ?', soloBot.id)?.count ?? 0)
|
|
199
203
|
const archivedCount = Math.max(0, soloTotal - soloWindow.length)
|
|
204
|
+
// 单聊卡片条目(DSHBOTS-218):提问/审批在单聊会话里发起时落 solo_messages 卡片锚点,
|
|
205
|
+
// 状态查 questions/approvals 表(project_id 为空的那批)。
|
|
206
|
+
const soloQuestions = this.questionsForBot(soloBot.id)
|
|
207
|
+
const soloApprovals = this.approvalsForBot(soloBot.id)
|
|
200
208
|
view.solo = {
|
|
201
209
|
bot: this.botView(soloBot),
|
|
202
210
|
// 默认视图走归档窗口(DSHBOTS-171):只留「最近 dmKeepRecent 条 且 dmArchiveDays
|
|
@@ -207,7 +215,13 @@ export const systemMethods = {
|
|
|
207
215
|
"SELECT * FROM runs WHERE bot_id = ? AND project_id IS NULL ORDER BY queued_at DESC LIMIT 30",
|
|
208
216
|
soloBot.id,
|
|
209
217
|
).map(run => this.runView(run)),
|
|
218
|
+
questions: soloQuestions,
|
|
219
|
+
approvals: soloApprovals,
|
|
210
220
|
}
|
|
221
|
+
// 卡片渲染与点击处理统一读 state.data.questions/approvals(群聊/单聊共用同一条 renderMessage),
|
|
222
|
+
// 这里把单聊条目并进同一份列表,单聊里的卡片才查得到状态、不退化成纯文本。
|
|
223
|
+
view.questions = [...(view.questions ?? []), ...soloQuestions]
|
|
224
|
+
view.approvals = [...(view.approvals ?? []), ...soloApprovals]
|
|
211
225
|
// 单聊上下文口径(DSHBOTS-5 收敛):记忆只看该 bot 自己的(不含团队);运行只看该 bot 的项目外运行;
|
|
212
226
|
// 提案保持全量(渲染层按 bot 过滤,逐个审批)。
|
|
213
227
|
view.proposals = this.store.all('SELECT * FROM proposals ORDER BY created_at DESC LIMIT 100').map(item => this.proposalView(item))
|
|
@@ -357,7 +371,10 @@ export const systemMethods = {
|
|
|
357
371
|
},
|
|
358
372
|
async dshUpdateInfo() {
|
|
359
373
|
// 探测链(DSHBOTS-146):env → argv[1] 向上找宿主 package.json → unknown。
|
|
360
|
-
|
|
374
|
+
// argv 链 miss 时(插件作为宿主子进程,argv[1] 指不到宿主包)从插件部署位置再探
|
|
375
|
+
// 宿主包(DSHBOTS-253);仍拿不到保持 'unknown',updateAvailable 的 unknown 语义不变。
|
|
376
|
+
const detected = detectDshRuntimeVersion(process.env, process.argv[1])
|
|
377
|
+
const current = detected !== 'unknown' ? detected : detectHostDshVersionFromPlugin() || 'unknown'
|
|
361
378
|
let latest
|
|
362
379
|
let pluginLatest
|
|
363
380
|
try {
|
|
@@ -365,7 +382,7 @@ export const systemMethods = {
|
|
|
365
382
|
latestDshVersion({ force: true }),
|
|
366
383
|
latestTeamBotsVersion({ force: true }),
|
|
367
384
|
])
|
|
368
|
-
} catch (error) {
|
|
385
|
+
} catch (error ) {
|
|
369
386
|
throw new AppError('DSH_REGISTRY_UNAVAILABLE', `无法查询最新版本:${error.message}`, 502)
|
|
370
387
|
}
|
|
371
388
|
return {
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
// 通知失败不能把已落库的变更打挂。
|
|
7
7
|
// notifyTaskStarted(DSHBOTS-100)是群内开工通知+运行入队(非微信推送),
|
|
8
8
|
// 与两个微信锚点同属任务通知域,一并落在本文件。
|
|
9
|
+
// 微信推送文案排版集中在 src/wechat/format.js(DSHBOTS-211)。
|
|
10
|
+
|
|
11
|
+
import { taskCreated, taskDone } from '../wechat/format.js'
|
|
9
12
|
|
|
10
13
|
export const taskNotifyMethods = {
|
|
11
14
|
// 「任务进入进行中」的唯一落点。
|
|
@@ -42,7 +45,7 @@ export const taskNotifyMethods = {
|
|
|
42
45
|
body: `任务 ${identifier} 已开始(${bot.name})。`,
|
|
43
46
|
mentions: [assigneeId],
|
|
44
47
|
})
|
|
45
|
-
} catch (error) {
|
|
48
|
+
} catch (error ) {
|
|
46
49
|
// 状态变更已经落库,通知/开工失败不能反过来把整次 update_task 打挂(用户会看到报错但状态已变)。
|
|
47
50
|
this.logger.warn?.('dsh-team: 任务开始通知失败 %s: %s', identifier, error?.message ?? error)
|
|
48
51
|
return null
|
|
@@ -50,13 +53,54 @@ export const taskNotifyMethods = {
|
|
|
50
53
|
void this.tick()
|
|
51
54
|
return { taskId: task.id, triggerType }
|
|
52
55
|
},
|
|
56
|
+
// 任务卡修正闭环(DSHBOTS-232 ①):已派单卡的卡面(标题/描述/优先级/写范围)变更时,
|
|
57
|
+
// 群内发系统消息点名负责人「按新卡面修正」;负责人名下该任务有正在执行的运行时,
|
|
58
|
+
// 再向其会话注入一条修正提示(复用 steer 通道,与评论直通同机制)。
|
|
59
|
+
// 通知失败不回滚已落库的卡面变更(与 notifyTaskStarted 同口径)。
|
|
60
|
+
async notifyTaskCardChanged(task) {
|
|
61
|
+
const assigneeId = task.assignee_bot_id
|
|
62
|
+
if (!assigneeId) return null
|
|
63
|
+
const bot = this.store.get('SELECT name FROM bots WHERE id = ?', assigneeId)
|
|
64
|
+
if (!bot) return null
|
|
65
|
+
const project = this.projectRow(task.project_id)
|
|
66
|
+
const identifier = `${project.key}-${task.number}`
|
|
67
|
+
try {
|
|
68
|
+
this.insertMessage({
|
|
69
|
+
projectId: task.project_id,
|
|
70
|
+
senderType: 'system',
|
|
71
|
+
senderId: 'system',
|
|
72
|
+
taskId: task.id,
|
|
73
|
+
body: `任务 ${identifier} 卡面已变更,请按新卡面修正。`,
|
|
74
|
+
mentions: [assigneeId],
|
|
75
|
+
})
|
|
76
|
+
} catch (error ) {
|
|
77
|
+
this.logger.warn?.('dsh-team: 卡面变更通知失败 %s: %s', identifier, error?.message ?? error)
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
const run = this.store.get(
|
|
81
|
+
"SELECT id, session_id FROM runs WHERE task_id = ? AND status = 'running' AND session_id IS NOT NULL ORDER BY started_at DESC LIMIT 1",
|
|
82
|
+
task.id,
|
|
83
|
+
)
|
|
84
|
+
if (run && this.runtime?.steer) {
|
|
85
|
+
try {
|
|
86
|
+
await this.runtime.steer(
|
|
87
|
+
run.session_id,
|
|
88
|
+
`Task card ${identifier} has just been amended by the owner. Re-read the latest card (title/description/priority/write scopes) and correct the work in progress accordingly; mention the amendment in the delivery report.`,
|
|
89
|
+
)
|
|
90
|
+
this.insertRunEvent(run.id, 'card_changed', `卡面变更修正提示已注入(${identifier})`)
|
|
91
|
+
} catch (error ) {
|
|
92
|
+
this.logger.warn?.('dsh-team: 卡面变更修正提示注入失败 %s: %s', identifier, error?.message ?? error)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { taskId: task.id, steered: Boolean(run) }
|
|
96
|
+
},
|
|
53
97
|
// 任务完成微信推送(DSHBOTS-182):锚定 →done 转换,触发点在 updateTask。
|
|
54
98
|
notifyTaskDone(task) {
|
|
55
99
|
const project = this.projectRow(task.project_id)
|
|
56
100
|
const identifier = `${project.key}-${task.number}`
|
|
57
101
|
try {
|
|
58
|
-
this.wechat?.notify(
|
|
59
|
-
} catch (error) {
|
|
102
|
+
this.wechat?.notify(taskDone(identifier, task.title))
|
|
103
|
+
} catch (error ) {
|
|
60
104
|
this.logger.warn?.('dsh-team: 任务完成微信通知失败 %s: %s', identifier, error?.message ?? error)
|
|
61
105
|
}
|
|
62
106
|
},
|
|
@@ -67,10 +111,8 @@ export const taskNotifyMethods = {
|
|
|
67
111
|
const identifier = `${project.key}-${task.number}`
|
|
68
112
|
const assignee = task.assignee_bot_id ? this.botRow(task.assignee_bot_id)?.name : null
|
|
69
113
|
try {
|
|
70
|
-
this.wechat?.notify(
|
|
71
|
-
|
|
72
|
-
)
|
|
73
|
-
} catch (error) {
|
|
114
|
+
this.wechat?.notify(taskCreated(identifier, task.title, assignee))
|
|
115
|
+
} catch (error ) {
|
|
74
116
|
this.logger.warn?.('dsh-team: 任务创建微信通知失败 %s: %s', identifier, error?.message ?? error)
|
|
75
117
|
}
|
|
76
118
|
},
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
// 终态(done/canceled)一律 ended、不渲染任何徽标——即使任务上还挂着遗留运行
|
|
14
14
|
// (回归锁:「已完成」列出现过「已取消/运行中」标签的历史 bug)。
|
|
15
15
|
|
|
16
|
+
// attention 在多数调用点不传(无待答提问),标记为可选;用重载签名而非行内注解,
|
|
17
|
+
// 保证擦除产物里实现行仍是 `export function taskStage(task, latestRun, attention) {`
|
|
18
|
+
// (tests/task-stage.test.ts 对该行做逐字源码断言)。
|
|
19
|
+
|
|
16
20
|
export function taskStage(task, latestRun, attention) {
|
|
17
21
|
if (task?.status === 'done' || task?.status === 'canceled') return { stage: 'ended' }
|
|
18
22
|
// 有待回答的结构化提问:无论任务处于哪个状态,先在等人回答。
|