dsh-team-bots 0.3.79 → 0.3.98

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.
Files changed (46) hide show
  1. package/cordis.patch.yml +100 -0
  2. package/index.js +5 -2
  3. package/package.json +1 -1
  4. package/src/api.js +5 -1
  5. package/src/db-migrations.js +3 -0
  6. package/src/db.js +53 -0
  7. package/src/runtime.js +13 -1
  8. package/src/service.js +5 -0
  9. package/src/services/approvals.js +7 -2
  10. package/src/services/bots.js +8 -1
  11. package/src/services/chat-stores.js +564 -0
  12. package/src/services/chat.js +60 -28
  13. package/src/services/core.js +30 -10
  14. package/src/services/feishu.js +1 -1
  15. package/src/services/memory.js +14 -12
  16. package/src/services/model-fallback.js +3 -1
  17. package/src/services/notify.js +18 -8
  18. package/src/services/projects.js +25 -19
  19. package/src/services/questions.js +2 -1
  20. package/src/services/review-watchdog.js +31 -12
  21. package/src/services/run-finish.js +17 -13
  22. package/src/services/runs.js +29 -41
  23. package/src/services/runtime/context-window.js +6 -4
  24. package/src/services/runtime/lifecycle.js +1 -0
  25. package/src/services/runtime/prompt.js +21 -9
  26. package/src/services/runtime/sandbox-policy.js +1 -1
  27. package/src/services/runtime/session.js +22 -13
  28. package/src/services/runtime/trajectory.js +3 -1
  29. package/src/services/scheduler.js +63 -54
  30. package/src/services/system.js +9 -7
  31. package/src/services/task-dispatch.js +28 -21
  32. package/src/services/task-review.js +34 -25
  33. package/src/services/task-runs.js +40 -21
  34. package/src/services/tasks.js +34 -18
  35. package/src/services/terminal.js +25 -14
  36. package/src/services/vision-proxy.js +9 -6
  37. package/src/services/wechat.js +1 -1
  38. package/src/subagent-ledger.js +23 -6
  39. package/src/usage-reconcile.js +93 -32
  40. package/src/usage.js +125 -50
  41. package/ui/i18n/en/settings.js +1 -0
  42. package/ui/i18n/zh/settings.js +1 -0
  43. package/ui/modules/modal-forms.js +8 -8
  44. package/ui/modules/tasks.js +1 -1
  45. package/ui/styles/cards.css +13 -0
  46. package/ui/styles/modal.css +2 -0
package/cordis.patch.yml CHANGED
@@ -1,3 +1,103 @@
1
1
  - insert:
2
2
  - id: dsh-team-bots
3
3
  name: dsh-team-bots
4
+ - id: preset-team-bots
5
+ name: '@deepseek-ai/dsh-agent-preset'
6
+ config:
7
+ id: team-bots
8
+ name: Team Bot
9
+ description: Team-work preset shipped with dsh-team-bots for all projects using the plugin.
10
+ order: 5
11
+ plugins:
12
+ - id: persona
13
+ name: '@deepseek-ai/dsh-persona'
14
+ config:
15
+ prefix: |-
16
+ You are a member agent of a dsh-team-bots team workspace: every
17
+ project is a group chat, work flows through the task board with
18
+ write scopes and parallel scheduling, and memory and skills are
19
+ shared across the team. Honor the team contract: declare write
20
+ scopes truthfully before working and update the declaration when
21
+ the actual changes exceed it; runs marked read-only modify nothing
22
+ in the workspace; commit your own changes selectively, never
23
+ git add -A. Never assume or invent symptoms: reproduce a problem
24
+ before fixing it, and do not over-test — no test suites built
25
+ alongside feature work, no new engine stubs. Avoid defensive
26
+ programming and over-delivered verification: never bundle
27
+ verification logic into a feature delivery. Report deliverables by
28
+ path so reviewers read the files.
29
+ - id: agent-instructions
30
+ name: '@deepseek-ai/dsh-agent-instructions'
31
+ config:
32
+ maxBytes: 65536
33
+ - id: time-context
34
+ name: '@deepseek-ai/dsh-time-context'
35
+ - id: tool-fs
36
+ name: '@deepseek-ai/dsh-tool-fs'
37
+ config:
38
+ applyPatch: false
39
+ - id: tool-fs-search
40
+ name: '@deepseek-ai/dsh-tool-fs-search'
41
+ config:
42
+ sampleOverCapGlobResults: false
43
+ - id: skill-filesystem
44
+ name: '@deepseek-ai/dsh-skill-filesystem'
45
+ - id: tool-skill
46
+ name: '@deepseek-ai/dsh-tool-skill'
47
+ - id: delegation
48
+ name: cordis:group
49
+ group: true
50
+ isolate:
51
+ workflowEngine: true
52
+ config:
53
+ - id: tool-subagent-control
54
+ name: '@deepseek-ai/dsh-tool-subagent-control'
55
+ config:
56
+ interrupt: false
57
+ - id: tool-subagent
58
+ name: '@deepseek-ai/dsh-tool-subagent'
59
+ config:
60
+ provider: spawn
61
+ toolName: subagent
62
+ modelSelection: true
63
+ modelDiscovery: true
64
+ - id: tool-subagent-fork
65
+ name: '@deepseek-ai/dsh-tool-subagent'
66
+ config:
67
+ provider: fork
68
+ toolName: subagent_fork
69
+ - id: workflow-ptc
70
+ name: '@deepseek-ai/dsh-workflow-ptc'
71
+ config:
72
+ provider: spawn
73
+ - id: tool-workflow
74
+ name: '@deepseek-ai/dsh-tool-workflow'
75
+ - id: tool-ask-user
76
+ name: '@deepseek-ai/dsh-tool-ask-user'
77
+ - id: tool-todo
78
+ name: '@deepseek-ai/dsh-tool-todo'
79
+ config:
80
+ allowParallelInProgress: true
81
+ - id: compaction
82
+ name: cordis:group
83
+ group: true
84
+ isolate:
85
+ compaction: true
86
+ toolResultPruner: true
87
+ config:
88
+ - id: compaction-basic
89
+ name: '@deepseek-ai/dsh-compaction-basic'
90
+ - id: command-compact
91
+ name: '@deepseek-ai/dsh-command-compact'
92
+ - id: tool-result-pruner
93
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
94
+ config:
95
+ thresholdChars: 8192
96
+ headChars: 4096
97
+ tailChars: 1024
98
+ - id: tool-bash
99
+ name: '@deepseek-ai/dsh-tool-bash'
100
+ disabled: !!js process.platform === 'win32'
101
+ - id: tool-pwsh
102
+ name: '@deepseek-ai/dsh-tool-pwsh'
103
+ disabled: !!js process.platform !== 'win32'
package/index.js CHANGED
@@ -27,11 +27,14 @@ export function apply(ctx, config = {}) {
27
27
  const logger = createLogger()
28
28
  const store = openDatabase(resolved.dbPath)
29
29
  const service = new TeamService({ store, config: resolved, logger })
30
- const runtime = new DshRuntime({ ctx, config: resolved, store, logger })
30
+ // 聊天分库(chat-db-split Phase 1):运行时按运行归属路由正文读写到对应聊天库;
31
+ // 注入解析器而非库本身,懒打开与 LRU 都收敛在 service 侧。
32
+ const runtime = new DshRuntime({ ctx, config: resolved, store, logger, chatStores: { forRun: (run ) => (service ).runChatStore(run) } })
31
33
  service.attachRuntime(runtime)
32
34
  runtime.attach()
33
35
  installTeamTools(ctx, service)
34
- installSubagentLedger(ctx, store, logger)
36
+ // Phase 3:账本事件住运行归属聊天库,与 DshRuntime 同款路由器。
37
+ installSubagentLedger(ctx, store, logger, { forRun: (run ) => (service ).runChatStore(run) })
35
38
  installSkillProvider(ctx, resolved, logger, store)
36
39
  installHttp(ctx, service, logger)
37
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-team-bots",
3
- "version": "0.3.79",
3
+ "version": "0.3.98",
4
4
  "description": "Project spaces, group chats, task boards, memory and usage for teams of DSH bots",
5
5
  "repository": {
6
6
  "type": "git",
package/src/api.js CHANGED
@@ -217,7 +217,11 @@ export async function handleAction(service, action , payload
217
217
  soloBotId: payload.soloBotId ?? null,
218
218
  days: payload.days ?? 30,
219
219
  window: payload.window ?? null,
220
- }),
220
+ }, payload.projectId
221
+ ? [service.groupChatStore(payload.projectId)]
222
+ : payload.soloBotId
223
+ ? [service.soloChatStore(payload.soloBotId)]
224
+ : service.allChatStores()),
221
225
  }
222
226
  case 'usage_window':
223
227
  // 用量时间窗快照(DSHBOTS-121):按需取,不进 state 轮询。
@@ -217,8 +217,11 @@ function migrateRuns(db) {
217
217
  // tasks.time_budget_minutes 存发布时的时效要求(分钟,NULL = 未声明不注入提示词)。
218
218
  // tasks.deliverables 存卡面声明的交付物文件路径(JSON 路径数组);核验按路径直接读文件,
219
219
  // 交付报告只引用路径不复述正文(DSHBOTS-345 复盘)。
220
+ // tasks.ignored_write_scopes 存声明中被 .gitignore 命中的「染色」条目(JSON 路径数组):
221
+ // 进卡面展示但不参与并行锁判定(全染色卡不与任何写运行串行,见 scheduler 写范围闸门)。
220
222
  function migrateTasks(db) {
221
223
  addColumn(db, 'tasks', 'write_scopes', "TEXT NOT NULL DEFAULT '[]'")
224
+ addColumn(db, 'tasks', 'ignored_write_scopes', "TEXT NOT NULL DEFAULT '[]'")
222
225
  addColumn(db, 'tasks', 'time_budget_minutes', 'INTEGER')
223
226
  addColumn(db, 'tasks', 'deliverables', "TEXT NOT NULL DEFAULT '[]'")
224
227
  }
package/src/db.js CHANGED
@@ -162,6 +162,7 @@ CREATE TABLE IF NOT EXISTS tasks (
162
162
  estimate REAL,
163
163
  time_budget_minutes INTEGER,
164
164
  write_scopes TEXT NOT NULL DEFAULT '[]',
165
+ ignored_write_scopes TEXT NOT NULL DEFAULT '[]',
165
166
  deliverables TEXT NOT NULL DEFAULT '[]',
166
167
  version INTEGER NOT NULL DEFAULT 1,
167
168
  created_at TEXT NOT NULL,
@@ -326,6 +327,44 @@ CREATE TABLE IF NOT EXISTS usage_reconciliation (
326
327
  UNIQUE(run_id)
327
328
  );
328
329
 
330
+ -- usage_rollup(chat-db-split Phase 2):用量小时汇总,顶库唯一用量账本。
331
+ -- 明细住各聊天库,视图/预算/月度口径全部读这里;project_key 冗余存档,
332
+ -- 项目移除后历史汇总仍可读(承 2026-11-02 拍板:用量是全局历史)。
333
+ -- project_id/bot_id 用空串哨兵(非 NULL)保证复合主键的 upsert 冲突检测命中。
334
+ CREATE TABLE IF NOT EXISTS usage_rollup (
335
+ hour_utc TEXT NOT NULL,
336
+ project_id TEXT NOT NULL DEFAULT '',
337
+ project_key TEXT NOT NULL DEFAULT '',
338
+ bot_id TEXT NOT NULL DEFAULT '',
339
+ provider TEXT NOT NULL DEFAULT '',
340
+ model TEXT NOT NULL DEFAULT '',
341
+ currency TEXT NOT NULL DEFAULT '',
342
+ priced INTEGER NOT NULL DEFAULT 0,
343
+ calls INTEGER NOT NULL DEFAULT 0,
344
+ input_tokens INTEGER NOT NULL DEFAULT 0,
345
+ cache_read_tokens INTEGER NOT NULL DEFAULT 0,
346
+ cache_write_tokens INTEGER NOT NULL DEFAULT 0,
347
+ output_tokens INTEGER NOT NULL DEFAULT 0,
348
+ reasoning_tokens INTEGER NOT NULL DEFAULT 0,
349
+ stored_cost REAL NOT NULL DEFAULT 0,
350
+ PRIMARY KEY (hour_utc, project_id, bot_id, provider, model, currency, priced)
351
+ );
352
+
353
+ CREATE INDEX IF NOT EXISTS usage_rollup_project_idx ON usage_rollup(project_id, hour_utc);
354
+ CREATE INDEX IF NOT EXISTS usage_rollup_bot_idx ON usage_rollup(bot_id, hour_utc);
355
+
356
+ -- 对账摘要(chat-db-split Phase 2):对账明细住各聊天库,顶库只留每轮对账的权威计数,
357
+ -- 由 reconcileUsage 每轮整体覆写;usageSnapshot 的摘要与缓存版本读这里。
358
+ CREATE TABLE IF NOT EXISTS usage_recon_state (
359
+ id INTEGER PRIMARY KEY CHECK (id = 1),
360
+ runs_checked INTEGER NOT NULL DEFAULT 0,
361
+ ok_runs INTEGER NOT NULL DEFAULT 0,
362
+ missing_usage INTEGER NOT NULL DEFAULT 0,
363
+ expired_usage INTEGER NOT NULL DEFAULT 0,
364
+ repaired INTEGER NOT NULL DEFAULT 0,
365
+ checked_at TEXT
366
+ );
367
+
329
368
  CREATE TABLE IF NOT EXISTS schema_migrations (
330
369
  name TEXT PRIMARY KEY,
331
370
  applied_at TEXT NOT NULL
@@ -509,6 +548,7 @@ export function openDatabase(path) {
509
548
  export class Store {
510
549
  // 同连接事务深度(transaction 嵌套时内层加入外层,见 transaction 实现)。
511
550
 
551
+
512
552
  // 预编译语句缓存:热路径(调度 tick、UI 轮询、消息尾窗)反复执行同一批语句,
513
553
  // 按语句文本缓存 StatementSync,免去每次调用的 SQL 解析;语句系于本连接,随 Store 一起丢弃。
514
554
  // 值类型保持 any:精确标注 StatementSync 会让 all/get 摆脱 any 推断,
@@ -567,18 +607,31 @@ export class Store {
567
607
  if (this.txDepth > 0) return fn()
568
608
  this.db.exec('BEGIN IMMEDIATE')
569
609
  this.txDepth = 1
610
+ this.txHooks = []
570
611
  try {
571
612
  const result = fn()
572
613
  this.db.exec('COMMIT')
573
614
  this.txDepth = 0
615
+ // 提交后钩子(Phase 3 跨库写):顶库 COMMIT 成功后才把聊天库侧写真正落库,
616
+ // 外层回滚即丢弃——跨库跟随顶库事务的提交/回滚语义。
617
+ const hooks = this.txHooks
618
+ this.txHooks = null
619
+ for (const hook of hooks) hook()
574
620
  return result
575
621
  } catch (error) {
576
622
  this.txDepth = 0
623
+ this.txHooks = null
577
624
  try { this.db.exec('ROLLBACK') } catch {}
578
625
  throw error
579
626
  }
580
627
  }
581
628
 
629
+ // 事务内登记「提交后执行」的跨库写;事务外直接执行。
630
+ afterCommit(fn) {
631
+ if (this.txDepth > 0 && this.txHooks) this.txHooks.push(fn)
632
+ else fn()
633
+ }
634
+
582
635
  close() {
583
636
  this.db.close()
584
637
  }
package/src/runtime.js CHANGED
@@ -6,7 +6,10 @@ import { trajectoryMethods } from './services/runtime/trajectory.js'
6
6
  import { lifecycleMethods } from './services/runtime/lifecycle.js'
7
7
 
8
8
  export class DshRuntime {
9
- constructor({ ctx, config, store, logger = console , mask = null }) {
9
+ // 聊天分库路由器(chat-db-split Phase 1):{ forRun(run) -> 聊天库 Store },由 index 注入。
10
+ chatStores = null
11
+
12
+ constructor({ ctx, config, store, logger = console , mask = null, chatStores = null }) {
10
13
  this.ctx = ctx
11
14
  // config 存活覆盖视图(与 TeamService 同款):workerPreset/routerPreset 等
12
15
  // 运行参数经全局设置改值后,下一次会话创建即用新值,无需重启。
@@ -25,6 +28,9 @@ export class DshRuntime {
25
28
  })
26
29
  this.store = store
27
30
  this.logger = logger
31
+ // 聊天分库路由(chat-db-split Phase 1):service 注入 { forRun(run) -> 聊天库 Store }。
32
+ // 未注入(独立构造/测试桩)时一律回落顶库,行为与分库前一致。
33
+ this.chatStores = chatStores
28
34
  // 密钥掩码钩子:service 层注入,轨迹等落库内容在写入前先脱敏。
29
35
  this.mask = typeof mask === 'function' ? mask : null
30
36
  this.pending = new Map()
@@ -51,6 +57,12 @@ export class DshRuntime {
51
57
  setMask(fn) {
52
58
  this.mask = typeof fn === 'function' ? fn : null
53
59
  }
60
+
61
+ // 聊天分库路由(chat-db-split Phase 1):按运行归属取正文库(群聊库/单聊库)。
62
+ // 未注入解析器(测试桩/独立构造)时回落顶库,行为与分库前一致。
63
+ chatStoreForRun(run) {
64
+ return this.chatStores?.forRun?.(run) ?? this.store
65
+ }
54
66
  }
55
67
 
56
68
  // 业务域方法按域拆到 src/services/runtime/*.js,这里挂回 DshRuntime 原型:
package/src/service.js CHANGED
@@ -46,6 +46,7 @@ import { feishuMethods } from './services/feishu.js'
46
46
  import { githubSourceMethods } from './services/github-source.js'
47
47
  import { approvalsMethods } from './services/approvals.js'
48
48
  import { questionsMethods } from './services/questions.js'
49
+ import { chatStoreMethods } from './services/chat-stores.js'
49
50
  import { coreMethods } from './services/core.js'
50
51
 
51
52
  export { WRITE_SCOPE_MAX, WRITE_SCOPE_MAX_LEN, parseWriteScopes, readWriteScopes, writeScopePathsOverlap, writeScopesOverlap } from './services/write-scopes.js'
@@ -76,6 +77,9 @@ export class TeamService {
76
77
  this.timer = null
77
78
  this.ticking = false
78
79
  this.started = false
80
+ // 停机标志:插件卸载后实例必须完全静默(库已关闭,任何再触发的写库都是错的)。
81
+ this.stopped = false
82
+ this.bootTimer = null
79
83
  this.ready = null
80
84
  this.rate = {}
81
85
  // 只读运行开始时的项目工作区指纹,用于事后发现“只读会话改了文件”。
@@ -137,5 +141,6 @@ defineMethods(TeamService.prototype, [
137
141
  githubSourceMethods,
138
142
  approvalsMethods,
139
143
  questionsMethods,
144
+ chatStoreMethods,
140
145
  coreMethods,
141
146
  ])
@@ -196,8 +196,12 @@ export function approvalGlobToRegExp(pattern) {
196
196
  }
197
197
  index += 2
198
198
  if (text[index] === '/') {
199
+ // 行首的 **/:前缀边界除「/ 结尾的任意前缀」外还允许「以空白结尾」(或串首)——
200
+ // 命令维度的目标是命令首行(如 `mkdir -p .tmp/bots/x`),相对路径前面是空格不是 /,
201
+ // 旧的 (?:.*/)? 永远吃不到这段前缀,关键词免审规则对相对路径命令整体失明。
202
+ const atPatternStart = index === 2
199
203
  index += 1
200
- out += '(?:.*/)?'
204
+ out += atPatternStart ? '(?:.*?[/\\s])?' : '(?:.*/)?'
201
205
  } else {
202
206
  out += '.*'
203
207
  }
@@ -397,7 +401,8 @@ export const approvalsMethods = {
397
401
  })
398
402
  } else {
399
403
  const group = this.groupOf(project.id)
400
- store.run(
404
+ // 卡片锚点住项目聊天库(chat-db-split Phase 1)。
405
+ this.groupChatStore(project.id).run(
401
406
  `INSERT INTO messages(id, project_id, group_chat_id, sender_type, sender_id, body, mentions_json, kind, approval_id, created_at)
402
407
  VALUES (?, ?, ?, 'system', ?, ?, '[]', 'approval', ?, ?)`,
403
408
  id('msg'), project.id, group?.id ?? null, bot.id, anchorBody, approvalId, createdAt,
@@ -9,6 +9,7 @@ import { badRequest, conflict, notFound } from '../errors.js'
9
9
  import { botWorkspaceDir, botsHome, SLUG_MAX } from '../paths.js'
10
10
  import { id, nowIso, slugify, text } from '../util.js'
11
11
  import { normalizeFilePolicy } from './file-policy.js'
12
+ import { runningSubagentCount } from '../subagent-ledger.js'
12
13
 
13
14
  export const COLORS = ['blue', 'teal', 'violet', 'amber', 'coral', 'pink', 'green', 'gray']
14
15
 
@@ -59,7 +60,7 @@ export const botsMethods = {
59
60
  const color = COLORS.includes(input.color) ? input.color : 'blue'
60
61
  const filePolicy = normalizeFilePolicy(input.filePolicy)
61
62
  // Bot 级 agent preset 覆盖:空 = 跟随全局(DSH_TEAM_WORKER_PRESET 生效链);
62
- // 自由短串,不在此校验存在性——宿主侧 defaultAgentPreset 只选可用 preset,写错回落 standard。
63
+ // 自由短串,不在此校验存在性——宿主侧 defaultAgentPreset 只选可用 preset,写错回落插件自带预设再回落 standard。
63
64
  const agentPreset = input.agentPreset !== undefined ? text(input.agentPreset, 80) : ''
64
65
  // 先建目录再建号:目录建不出来就别留下一个单聊必然失败的 bot 行。
65
66
  // 这里预建的是占位候选;并发同名时权威 solo_dir 在事务内重算,输家目录提交后补建。
@@ -368,6 +369,10 @@ export const botsMethods = {
368
369
  FROM runs WHERE bot_id = ?`,
369
370
  bot.id,
370
371
  )
372
+ const activeRuns = this.store.get(
373
+ "SELECT EXISTS(SELECT 1 FROM runs WHERE bot_id = ? AND status IN ('queued', 'running')) AS n",
374
+ bot.id,
375
+ )?.n ?? 0
371
376
  return {
372
377
  ...bot,
373
378
  agentPreset: bot.agent_preset ?? '',
@@ -379,6 +384,8 @@ export const botsMethods = {
379
384
  soloWorkspace: bot.solo_dir ? join(this.config.workspace, '_the_bots', bot.solo_dir) : null,
380
385
  memoryCount: Number(memoryCount),
381
386
  openTasks: Number(openTasks),
387
+ // 任务中口径:有排队/运行中的 run,或有在跑的子代理(子代理不占 runs 行)。
388
+ busy: activeRuns > 0 || runningSubagentCount(bot.id) > 0,
382
389
  stats: {
383
390
  runs: Number(runs?.total ?? 0),
384
391
  succeeded: Number(runs?.succeeded ?? 0),