dsh-team-bots 0.3.80 → 0.3.105
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/cordis.patch.yml +100 -0
- package/index.js +5 -2
- package/package.json +1 -1
- package/src/api.js +5 -1
- package/src/db-migrations.js +5 -1
- package/src/db.js +52 -0
- package/src/feishu/channel.js +15 -11
- package/src/feishu/format.js +37 -1
- package/src/runtime.js +13 -1
- package/src/service.js +5 -0
- package/src/services/approvals.js +7 -2
- package/src/services/bots.js +8 -1
- package/src/services/chat-stores.js +564 -0
- package/src/services/chat.js +60 -28
- package/src/services/core.js +33 -12
- package/src/services/feishu.js +1 -1
- package/src/services/memory.js +14 -12
- package/src/services/model-fallback.js +3 -1
- package/src/services/notify.js +18 -8
- package/src/services/projects.js +25 -19
- package/src/services/questions.js +37 -12
- package/src/services/review-watchdog.js +31 -12
- package/src/services/run-finish.js +21 -14
- package/src/services/runs.js +29 -41
- package/src/services/runtime/context-window.js +6 -4
- package/src/services/runtime/lifecycle.js +1 -0
- package/src/services/runtime/prompt.js +21 -9
- package/src/services/runtime/sandbox-policy.js +1 -1
- package/src/services/runtime/session.js +27 -15
- package/src/services/runtime/trajectory.js +3 -1
- package/src/services/scheduler.js +48 -49
- package/src/services/system.js +9 -7
- package/src/services/task-review.js +27 -19
- package/src/services/task-runs.js +40 -21
- package/src/services/tasks.js +18 -10
- package/src/services/terminal.js +25 -14
- package/src/services/vision-proxy.js +67 -9
- package/src/services/wechat.js +24 -8
- package/src/subagent-ledger.js +23 -6
- package/src/usage-reconcile.js +93 -32
- package/src/usage.js +125 -50
- package/src/util.js +17 -0
- package/src/wechat/channel.js +3 -1
- package/src/wechat/commands.js +13 -1
- package/ui/modules/events-click.js +14 -1
- package/ui/modules/file-preview.js +22 -10
- package/ui/modules/markdown.js +10 -8
- package/ui/modules/tasks.js +1 -1
- package/ui/styles/cards.css +13 -0
- package/ui/styles/modal.css +4 -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
|
-
|
|
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
|
-
|
|
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
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 轮询。
|
package/src/db-migrations.js
CHANGED
|
@@ -40,7 +40,8 @@ export const RUNS_DDL = `
|
|
|
40
40
|
usage_output INTEGER NOT NULL DEFAULT 0,
|
|
41
41
|
usage_cost REAL,
|
|
42
42
|
cancel_requested INTEGER NOT NULL DEFAULT 0,
|
|
43
|
-
merged_messages TEXT
|
|
43
|
+
merged_messages TEXT,
|
|
44
|
+
image_offload INTEGER NOT NULL DEFAULT 0
|
|
44
45
|
`
|
|
45
46
|
|
|
46
47
|
export const RUNS_INDEXES = `
|
|
@@ -209,6 +210,9 @@ function migrateRuns(db) {
|
|
|
209
210
|
addColumn(db, 'runs', 'model_effort', 'TEXT')
|
|
210
211
|
// 入站消息合批(DSHBOTS-231):领取时同通道排队消息被合并进来,存被合并消息的 id 列表(JSON)。
|
|
211
212
|
addColumn(db, 'runs', 'merged_messages', 'TEXT')
|
|
213
|
+
// 续答运行(DSHBOTS-112 闭环):转写写回后同消息再排一次 chat/solo_chat,
|
|
214
|
+
// 不下发二进制图(首轮已因主模型无视觉失败),转写正文由提示词近期窗口带入。
|
|
215
|
+
addColumn(db, 'runs', 'image_offload', "INTEGER NOT NULL DEFAULT 0")
|
|
212
216
|
db.exec(`UPDATE runs SET mode = 'read' WHERE kind IN ('chat', 'review', 'handle') AND mode = 'write'`)
|
|
213
217
|
}
|
|
214
218
|
|
package/src/db.js
CHANGED
|
@@ -327,6 +327,44 @@ CREATE TABLE IF NOT EXISTS usage_reconciliation (
|
|
|
327
327
|
UNIQUE(run_id)
|
|
328
328
|
);
|
|
329
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
|
+
|
|
330
368
|
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
331
369
|
name TEXT PRIMARY KEY,
|
|
332
370
|
applied_at TEXT NOT NULL
|
|
@@ -510,6 +548,7 @@ export function openDatabase(path) {
|
|
|
510
548
|
export class Store {
|
|
511
549
|
// 同连接事务深度(transaction 嵌套时内层加入外层,见 transaction 实现)。
|
|
512
550
|
|
|
551
|
+
|
|
513
552
|
// 预编译语句缓存:热路径(调度 tick、UI 轮询、消息尾窗)反复执行同一批语句,
|
|
514
553
|
// 按语句文本缓存 StatementSync,免去每次调用的 SQL 解析;语句系于本连接,随 Store 一起丢弃。
|
|
515
554
|
// 值类型保持 any:精确标注 StatementSync 会让 all/get 摆脱 any 推断,
|
|
@@ -568,18 +607,31 @@ export class Store {
|
|
|
568
607
|
if (this.txDepth > 0) return fn()
|
|
569
608
|
this.db.exec('BEGIN IMMEDIATE')
|
|
570
609
|
this.txDepth = 1
|
|
610
|
+
this.txHooks = []
|
|
571
611
|
try {
|
|
572
612
|
const result = fn()
|
|
573
613
|
this.db.exec('COMMIT')
|
|
574
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()
|
|
575
620
|
return result
|
|
576
621
|
} catch (error) {
|
|
577
622
|
this.txDepth = 0
|
|
623
|
+
this.txHooks = null
|
|
578
624
|
try { this.db.exec('ROLLBACK') } catch {}
|
|
579
625
|
throw error
|
|
580
626
|
}
|
|
581
627
|
}
|
|
582
628
|
|
|
629
|
+
// 事务内登记「提交后执行」的跨库写;事务外直接执行。
|
|
630
|
+
afterCommit(fn) {
|
|
631
|
+
if (this.txDepth > 0 && this.txHooks) this.txHooks.push(fn)
|
|
632
|
+
else fn()
|
|
633
|
+
}
|
|
634
|
+
|
|
583
635
|
close() {
|
|
584
636
|
this.db.close()
|
|
585
637
|
}
|
package/src/feishu/channel.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { outboundChunks, failureText, welcomeAdmin } from './format.js'
|
|
2
2
|
import { handleCommand, NON_OWNER_NOTICE } from './commands.js'
|
|
3
|
+
import { stripCarriageReturns } from '../util.js'
|
|
3
4
|
|
|
4
5
|
/** 出站最大尝试次数(含首次):达到上限废弃,永不补发(与微信通道同治理口径)。 */
|
|
5
6
|
const OUTBOX_MAX_ATTEMPTS = 3
|
|
@@ -131,17 +132,19 @@ function sdkLogger(log , secret ) {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
/**
|
|
136
|
+
* 出站载荷:一律走交互卡片的富文本(markdown)组件,卡片用 JSON 2.0 结构。
|
|
137
|
+
* 2.0 才支持标题、引用、表格等标准 markdown——1.0 里 "# 标题" 会原样显示成井号文本,
|
|
138
|
+
* 表格也是一串竖线。width_mode=fill 等同 1.0 的 wide_screen_mode(撑满聊天窗口)。
|
|
139
|
+
* 客户端需 7.20 及以上(更低版本会显示升级提示兜底文案)。
|
|
140
|
+
*/
|
|
141
|
+
export function outboundPayload(text) {
|
|
142
|
+
const card = {
|
|
143
|
+
schema: '2.0',
|
|
144
|
+
config: { width_mode: 'fill' },
|
|
145
|
+
body: { elements: [{ tag: 'markdown', content: String(text ?? '') }] },
|
|
143
146
|
}
|
|
144
|
-
return { msgType: '
|
|
147
|
+
return { msgType: 'interactive', content: JSON.stringify(card) }
|
|
145
148
|
}
|
|
146
149
|
|
|
147
150
|
/** SDK 抛出的错误归一:尽量取出飞书业务错误码(axios 响应体 code / 错误文案里的 code),
|
|
@@ -395,7 +398,8 @@ export class FeishuChannel {
|
|
|
395
398
|
async sendFeishu(messageId, text, idempotencyKey) {
|
|
396
399
|
if (!messageId) throw new Error('缺少飞书回复目标消息 id')
|
|
397
400
|
if (!idempotencyKey) throw new Error('缺少幂等键(应为 outbox 行 id)')
|
|
398
|
-
|
|
401
|
+
// 出站边界去 CR:模型文本偶发带 CR,飞书按行尾渲染会把一句话劈成多段。
|
|
402
|
+
const chunks = outboundChunks(stripCarriageReturns(text))
|
|
399
403
|
for (let index = 0; index < chunks.length; index++) {
|
|
400
404
|
const key = index > 0 ? `${idempotencyKey}#${index}` : idempotencyKey
|
|
401
405
|
for (let attempt = 1; ; attempt++) {
|
package/src/feishu/format.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/feishu/format.ts —— 飞书出站消息排版层(markdown 文本,DSHBOTS-323 卡①)
|
|
2
2
|
// 角色对齐 src/wechat/format.ts:通道全部回程/回执文案在此集中格式化。
|
|
3
|
-
// 飞书原生支持 markdown
|
|
3
|
+
// 飞书原生支持 markdown:出站一律走交互卡片的富文本(markdown)组件——卡片里单个 \n 即换行,
|
|
4
|
+
// 纯文本消息的 \n 是段落间距(版面松);加粗、列表、分割线也都原生渲染。
|
|
4
5
|
// 不做微信式的 markdown 噪点过滤,只负责长文分块(飞书单条文本有长度上限)与固定文案。
|
|
5
6
|
|
|
6
7
|
/** markdown 分隔线:区分消息头与正文。 */
|
|
@@ -45,6 +46,41 @@ export function outboundChunks(text, maxChars = CHUNK_MAX_CHARS) {
|
|
|
45
46
|
return chunks
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* 提问卡片(markdown):题头加粗、选项列表化。
|
|
51
|
+
* 信息口径与微信纯文本镜像一致,但排版按 markdown 给——飞书直接渲染,不必再降成纯文本。
|
|
52
|
+
*/
|
|
53
|
+
export function questionCard(projectName, botName, items, token) {
|
|
54
|
+
const lines = [`**【提问】${botName}(${projectName})**`]
|
|
55
|
+
for (const [index, item] of (items ?? []).entries()) {
|
|
56
|
+
// 题块之间空行分段:markdown 里列表/段落靠空行断开,否则下一题会被吞进上一题的列表。
|
|
57
|
+
lines.push('')
|
|
58
|
+
lines.push(`**Q${index + 1}: ${item.question}**`)
|
|
59
|
+
if (item.detail) lines.push(item.detail)
|
|
60
|
+
for (const [optionIndex, option] of (item.options ?? []).entries()) {
|
|
61
|
+
const description = option.description ? ` — ${option.description}` : ''
|
|
62
|
+
// 用「1:」不用「- 1.」:markdown 列表标记会被飞书重新编号(整卡编成 a./b./c.…),
|
|
63
|
+
// 「1:」既不是列表标记,又和回复格式「1:选项一」同口径。
|
|
64
|
+
lines.push(`${optionIndex + 1}: ${option.label}${description}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
lines.push('')
|
|
68
|
+
lines.push(`回复「答 ${token} 选项号或文字」`)
|
|
69
|
+
if ((items ?? []).length > 1) lines.push(`多个问题用「;」分隔,如:答 ${token} 1:选项一;2:补充说明`)
|
|
70
|
+
return lines.join('\n')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 审批卡片(markdown):与提问卡同版式。 */
|
|
74
|
+
export function approvalCard(projectName, botName, toolName, reason, token) {
|
|
75
|
+
return [
|
|
76
|
+
`**【审批】${botName}(${projectName})**`,
|
|
77
|
+
`工具:${toolName}`,
|
|
78
|
+
`原因:${reason}`,
|
|
79
|
+
'',
|
|
80
|
+
`回复「批 ${token} 允许」或「批 ${token} 拒绝」`,
|
|
81
|
+
].join('\n')
|
|
82
|
+
}
|
|
83
|
+
|
|
48
84
|
/** 管理员绑定欢迎(入站另卡接线时使用)。 */
|
|
49
85
|
export function welcomeAdmin() {
|
|
50
86
|
return '已绑定为本团队管理员\n发送 /? 查看指令'
|
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
|
-
|
|
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
|
-
|
|
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,
|
package/src/services/bots.js
CHANGED
|
@@ -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
|
|
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),
|