dsh-team-bots 0.2.289 → 0.2.347
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 +60 -122
- package/docs/README.zh.md +61 -123
- 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 +14 -5
- package/src/services/approvals.js +109 -24
- package/src/services/backoff.js +34 -0
- 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 +169 -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 +186 -17
- 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 +146 -19
- package/src/services/secrets.js +1 -1
- package/src/services/system.js +23 -6
- package/src/services/task-dispatch.js +315 -0
- package/src/services/task-notify.js +55 -11
- package/src/services/task-runs.js +179 -0
- package/src/services/task-stage.js +4 -0
- package/src/services/tasks.js +51 -399
- 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 +57 -53
- package/ui/i18n/en/chat.js +140 -0
- package/ui/i18n/en/common.js +187 -0
- package/ui/i18n/en/nav.js +89 -0
- package/ui/i18n/en/settings.js +352 -0
- package/ui/i18n/en/tasks.js +229 -0
- package/ui/i18n/en/usage.js +141 -0
- package/ui/i18n/en/wechat.js +23 -0
- package/ui/i18n/en.js +17 -237
- package/ui/i18n/zh/chat.js +140 -0
- package/ui/i18n/zh/common.js +187 -0
- package/ui/i18n/zh/nav.js +89 -0
- package/ui/i18n/zh/settings.js +352 -0
- package/ui/i18n/zh/tasks.js +229 -0
- package/ui/i18n/zh/usage.js +141 -0
- package/ui/i18n/zh/wechat.js +23 -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 +125 -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 +196 -203
- 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 +167 -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 +56 -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
package/src/services/wechat.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { createRequire } from 'node:module'
|
|
7
7
|
import { AppError, conflict } from '../errors.js'
|
|
8
8
|
import { WechatIlinkError } from '../wechat/commands.js'
|
|
9
|
+
import { jsonParse, parseMentions } from '../util.js'
|
|
10
|
+
import { answerFailed, answerReceipt, approvalCard, questionCard, wechatToken } from '../wechat/format.js'
|
|
9
11
|
|
|
10
12
|
// 微信登录二维码:服务端直接出 SVG,UI 注入即可,无需前端 QR 库(vendor/qrcode,MIT)。
|
|
11
13
|
// 依赖按需加载:二维码库缺失只影响扫码,不应让整个插件加载失败。
|
|
@@ -17,6 +19,9 @@ export function wechatQrSvg(url) {
|
|
|
17
19
|
return qr.createSvgTag({ cellSize: 4, margin: 2 })
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
/** 项目外导演通道的正文来源标记(DSHBOTS-258):让 director 一眼看出该消息来自微信管理员。 */
|
|
23
|
+
const WECHAT_SOLO_SOURCE_MARK = '[微信管理员] '
|
|
24
|
+
|
|
20
25
|
/** channel.js 的状态守卫文案全集(未启用/已登录等,抛的都是裸 Error)。 */
|
|
21
26
|
const CHANNEL_GUARD_MESSAGES = new Set([
|
|
22
27
|
'微信通道未启用(DSH_TEAM_WECHAT=1)',
|
|
@@ -82,17 +87,233 @@ export const wechatMethods = {
|
|
|
82
87
|
},
|
|
83
88
|
|
|
84
89
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
90
|
+
* 项目外导演通道的目标解析(DSHBOTS-258):微信自由文本的默认且唯一去向是 director
|
|
91
|
+
* bot 的专属工作区单聊。解析规则:active bot 里 name='director'(大小写不敏感)优先于
|
|
92
|
+
* role='director'/'总监';同级多个按 created_at、id 取最旧,保证确定性。不过滤 solo_dir:
|
|
93
|
+
* 目录一律读 bots.solo_dir 既有链路,为空时按 soloPromptFor 现有兜底路径处理,不写死目录。
|
|
94
|
+
* 0 命中返回 null(异常状态防御,走次级回退避免消息黑洞)。
|
|
95
|
+
*/
|
|
96
|
+
wechatDirectorBot() {
|
|
97
|
+
const rows = this.store.all(
|
|
98
|
+
`SELECT * FROM bots
|
|
99
|
+
WHERE status = 'active' AND (lower(name) = 'director' OR role IN ('director', '总监'))
|
|
100
|
+
ORDER BY CASE WHEN lower(name) = 'director' THEN 0 ELSE 1 END, created_at, id`,
|
|
101
|
+
)
|
|
102
|
+
return rows[0] ?? null
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 项目外导演通道投递(DSHBOTS-258):消息落 director 的 solo_messages 并触发
|
|
107
|
+
* solo_chat 运行,不进任何项目群聊。身份用微信 admin 的 peer id(不以 localUserId
|
|
108
|
+
* 冒充工作台用户);正文前缀 [微信管理员] 让 director 能看出消息来自微信通道。
|
|
109
|
+
* firstContact:该管理员此前没在这个专属工作区说过话(首触回执依据,见 commands)。
|
|
110
|
+
*/
|
|
111
|
+
async wechatDirectorChat(director, body) {
|
|
112
|
+
const adminPeerId = this.wechat?.status?.()?.adminPeerId ?? null
|
|
113
|
+
const actor = { type: 'user', id: adminPeerId ?? 'user:wechat' }
|
|
114
|
+
const firstContact = !this.store.get(
|
|
115
|
+
"SELECT id FROM solo_messages WHERE bot_id = ? AND sender_type = 'user' AND sender_id = ? LIMIT 1",
|
|
116
|
+
director.id,
|
|
117
|
+
actor.id,
|
|
118
|
+
)
|
|
119
|
+
const result = await this.sendSoloMessage(
|
|
120
|
+
director.id,
|
|
121
|
+
`${WECHAT_SOLO_SOURCE_MARK}${body}`,
|
|
122
|
+
actor,
|
|
123
|
+
[],
|
|
124
|
+
{ origin: 'wechat' },
|
|
125
|
+
)
|
|
126
|
+
return { director, messageId: result?.messageId ?? null, firstContact }
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 微信直达对话(DSHBOTS-208 起,258 四次拍板后收敛为绝对二值路由):
|
|
131
|
+
* /tr 显式转发(key 非空)→ 消息以工作台用户身份插入项目群聊并触发 chat 运行,
|
|
132
|
+
* 运行结束的 bot 回复由 run-finish 按 trigger_type='wechat' 推回微信管理员;
|
|
133
|
+
* 自由文本(key 为空)→ 一律投项目外 director 专属工作区单聊(不随 direct_project_key
|
|
134
|
+
* 绑定、active 项目数变化,路由层无绑定/项目数判断分支),返回
|
|
135
|
+
* { director, messageId, firstContact };解析不到 director(通道异常)→ { error: 'no_director' }。
|
|
136
|
+
* 项目无可定向 Bot(无 mention 且总监不可用)→ { error: 'no_owner', project };
|
|
137
|
+
* 群聊直达成功 → { project, messageId, runBots };显式 key 未命中 → null。
|
|
88
138
|
*/
|
|
89
|
-
async
|
|
139
|
+
async wechatChat(key, body) {
|
|
140
|
+
let project = null
|
|
141
|
+
if (key) {
|
|
142
|
+
project = this.store.get(
|
|
143
|
+
"SELECT * FROM projects WHERE key = ? COLLATE NOCASE AND status = 'active'",
|
|
144
|
+
String(key ?? '').trim(),
|
|
145
|
+
)
|
|
146
|
+
if (!project) return null
|
|
147
|
+
} else {
|
|
148
|
+
// DSHBOTS-258 绝对口径:自由文本永远走 director 专属工作区,用户不直接进群。
|
|
149
|
+
// 路由层不出现 direct_project_key 绑定判断,也不出现 active 项目数量判断——
|
|
150
|
+
// 唯一分流条件是 /tr 显式转发(key 非空)。解析不到 director 属通道异常,
|
|
151
|
+
// 独立 no_director 出口(不复用 no_target:那是「需要用户选项目」的语义链)。
|
|
152
|
+
const director = this.wechatDirectorBot()
|
|
153
|
+
if (director) return this.wechatDirectorChat(director, String(body ?? ''))
|
|
154
|
+
return { error: 'no_director' }
|
|
155
|
+
}
|
|
156
|
+
const members = this.membersOf(project.id).filter(bot => bot.status === 'active')
|
|
157
|
+
const text = String(body ?? '')
|
|
158
|
+
// 无 mention 时 sendMessage 兜底定向 owner_bot_id:总监必须可用,否则消息发出无人接。
|
|
159
|
+
if (parseMentions(text, members).length === 0
|
|
160
|
+
&& !members.some(bot => bot.id === project.owner_bot_id)) {
|
|
161
|
+
return { error: 'no_owner', project }
|
|
162
|
+
}
|
|
163
|
+
const result = await this.sendMessage(project.id, text, { type: 'user', id: this.localUserId }, null, [], { origin: 'wechat' })
|
|
164
|
+
return { project, ...result }
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 微信 /bots 指令(DSHBOTS-249):按项目 key 列当前项目机器人清单。
|
|
169
|
+
* 数据源与工作台项目成员表同源(membersOf),只读;key 未命中返回空表。
|
|
170
|
+
*/
|
|
171
|
+
wechatProjectBots(key) {
|
|
90
172
|
const project = this.store.get(
|
|
91
173
|
"SELECT * FROM projects WHERE key = ? COLLATE NOCASE AND status = 'active'",
|
|
92
174
|
String(key ?? '').trim(),
|
|
93
175
|
)
|
|
94
|
-
if (!project) return
|
|
95
|
-
|
|
96
|
-
return project
|
|
176
|
+
if (!project) return []
|
|
177
|
+
return this.membersOf(project.id)
|
|
97
178
|
},
|
|
179
|
+
|
|
180
|
+
// ===== DSHBOTS-215:微信问答回路 =====
|
|
181
|
+
// 群聊提问/审批转发微信:只推纯文本镜像,状态仍由工作台卡片与群消息承载;
|
|
182
|
+
// 管理员在微信的答复经 commands 的「答/批 <token> …」路由回原条目(见 wechatAnswerQuestion /
|
|
183
|
+
// wechatDecideApproval)。转发失败只告警,不阻塞提问主流程。
|
|
184
|
+
|
|
185
|
+
/** 提问转发微信(只推文本;token 取问题 id 末 6 位)。 */
|
|
186
|
+
wechatQuestion(project, row, items) {
|
|
187
|
+
if (!this.wechat || typeof this.wechat.notify !== 'function') return false
|
|
188
|
+
try {
|
|
189
|
+
this.wechat.notify(questionCard(project.name || project.key, row.bot_name ?? 'Bot', items, wechatToken(row.id)))
|
|
190
|
+
return true
|
|
191
|
+
} catch (error ) {
|
|
192
|
+
this.logger.warn?.('dsh-team: 微信提问转发失败: %s', error?.message ?? error)
|
|
193
|
+
return false
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
/** 审批转发微信(只推文本;token 取审批 id 末 6 位)。 */
|
|
198
|
+
wechatApproval(project, row) {
|
|
199
|
+
if (!this.wechat || typeof this.wechat.notify !== 'function') return false
|
|
200
|
+
try {
|
|
201
|
+
this.wechat.notify(approvalCard(project.name || project.key, row.bot_name ?? 'Bot', row.tool_name, row.reason, wechatToken(row.id)))
|
|
202
|
+
return true
|
|
203
|
+
} catch (error ) {
|
|
204
|
+
this.logger.warn?.('dsh-team: 微信审批转发失败: %s', error?.message ?? error)
|
|
205
|
+
return false
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
/** 按 token + 绑定项目定位 pending 条目(questions / approvals 共用)。 */
|
|
210
|
+
pendingWechatRow(table, token, fallbackKey = null) {
|
|
211
|
+
const rows = this.store.all(
|
|
212
|
+
`SELECT ${table}.*, p.key AS project_key FROM ${table}
|
|
213
|
+
LEFT JOIN projects p ON p.id = ${table}.project_id
|
|
214
|
+
WHERE ${table}.status = 'pending' AND lower(substr(${table}.id, -6)) = ?`,
|
|
215
|
+
String(token ?? '').toLowerCase(),
|
|
216
|
+
)
|
|
217
|
+
if (!rows.length) return null
|
|
218
|
+
if (fallbackKey) {
|
|
219
|
+
const key = String(fallbackKey).toUpperCase()
|
|
220
|
+
return rows.find(row => String(row.project_key ?? '').toUpperCase() === key) ?? null
|
|
221
|
+
}
|
|
222
|
+
return rows[0]
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 微信答复路由(DSHBOTS-215):把管理员的「答 <token> <内容>」落成对应提问的宿主应答。
|
|
227
|
+
* 来源标识为 user:wechat,与工作台作答(user:<actorId>)区分,审计单独记 question.answer_wechat。
|
|
228
|
+
*/
|
|
229
|
+
async wechatAnswerQuestion(token, body, fallbackKey = null) {
|
|
230
|
+
const row = this.pendingWechatRow('questions', token, fallbackKey)
|
|
231
|
+
if (!row) return answerFailed(token, '没有匹配的待答提问(可能已作答或已过期)')
|
|
232
|
+
const items = jsonParse(row.questions, [])
|
|
233
|
+
const parsed = parseWechatAnswers(items, body)
|
|
234
|
+
if (parsed.error) return answerFailed(token, parsed.error)
|
|
235
|
+
this.settleQuestion(row.id, 'answered', { answers: parsed.answers }, 'user:wechat')
|
|
236
|
+
this.audit({ type: 'user', id: 'user_wechat' }, 'question.answer_wechat', 'question', row.id, {
|
|
237
|
+
token,
|
|
238
|
+
answers: parsed.answers,
|
|
239
|
+
})
|
|
240
|
+
return answerReceipt(wechatToken(row.id), parsed.summary)
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
/** 微信审批路由(DSHBOTS-215):把「批 <token> 允许|拒绝」落成对应审批的宿主应答。 */
|
|
244
|
+
async wechatDecideApproval(token, decision, fallbackKey = null) {
|
|
245
|
+
const row = this.pendingWechatRow('approvals', token, fallbackKey)
|
|
246
|
+
if (!row) return answerFailed(token, '没有匹配的待审批请求(可能已处理或已过期)')
|
|
247
|
+
if (!['allow', 'reject'].includes(decision)) return answerFailed(token, '只能回复「允许」或「拒绝」')
|
|
248
|
+
this.settleApproval(
|
|
249
|
+
row.id,
|
|
250
|
+
decision === 'allow' ? 'allowed' : 'rejected',
|
|
251
|
+
decision === 'allow' ? 'allowed-once' : 'rejected',
|
|
252
|
+
'user:wechat',
|
|
253
|
+
)
|
|
254
|
+
this.audit({ type: 'user', id: 'user_wechat' }, `approval.${decision}_wechat`, 'approval', row.id, {
|
|
255
|
+
token,
|
|
256
|
+
toolName: row.tool_name,
|
|
257
|
+
})
|
|
258
|
+
return answerReceipt(wechatToken(row.id), `${row.tool_name} 已${decision === 'allow' ? '允许' : '拒绝'}`)
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** 选项匹配:序号(1 起)或选项文字精确命中(大小写不敏感)。 */
|
|
263
|
+
function matchWechatOptions(options, raw) {
|
|
264
|
+
const value = String(raw ?? '').trim().toLowerCase()
|
|
265
|
+
if (!value) return []
|
|
266
|
+
const numeric = /^(\d+)$/.exec(value)
|
|
267
|
+
if (numeric) {
|
|
268
|
+
const index = Number(numeric[1])
|
|
269
|
+
return index >= 1 && index <= options.length ? [options[index - 1].label] : []
|
|
270
|
+
}
|
|
271
|
+
const hit = options.find(option => String(option.label ?? '').trim().toLowerCase() === value)
|
|
272
|
+
return hit ? [hit.label] : []
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 微信答复解析:支持「1:选项一;2:补充说明」的按题作答,也支持单题直接回选项/文字。
|
|
277
|
+
* 带序前缀的段按序号指派,其余段按顺序补到未指派题;选项题必须命中选项,否则整单拒绝。
|
|
278
|
+
*/
|
|
279
|
+
function parseWechatAnswers(items, body) {
|
|
280
|
+
if (!Array.isArray(items) || items.length === 0) return { error: '提问内容缺失' }
|
|
281
|
+
const segments = String(body ?? '').split(/[;;]/).map(segment => segment.trim()).filter(Boolean)
|
|
282
|
+
const assigned = new Map()
|
|
283
|
+
const rest = []
|
|
284
|
+
for (const segment of segments) {
|
|
285
|
+
const indexed = /^(\d+)\s*[::]\s*([\s\S]*)$/.exec(segment)
|
|
286
|
+
if (indexed && Number(indexed[1]) >= 1 && Number(indexed[1]) <= items.length) {
|
|
287
|
+
assigned.set(Number(indexed[1]) - 1, indexed[2].trim())
|
|
288
|
+
} else {
|
|
289
|
+
rest.push(segment)
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
let cursor = 0
|
|
293
|
+
for (let i = 0; i < items.length; i++) {
|
|
294
|
+
if (assigned.has(i)) continue
|
|
295
|
+
if (rest.length === 0) break
|
|
296
|
+
if (rest.length === 1 && items.length === 1) {
|
|
297
|
+
assigned.set(i, rest[0])
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
if (cursor < rest.length) assigned.set(i, rest[cursor++])
|
|
301
|
+
}
|
|
302
|
+
const answers = []
|
|
303
|
+
const parts = []
|
|
304
|
+
for (let i = 0; i < items.length; i++) {
|
|
305
|
+
const item = items[i]
|
|
306
|
+
const raw = String(assigned.get(i) ?? '').trim()
|
|
307
|
+
const options = Array.isArray(item.options) ? item.options : []
|
|
308
|
+
if (options.length > 0) {
|
|
309
|
+
const selected = matchWechatOptions(options, raw)
|
|
310
|
+
if (selected.length === 0) return { error: `Q${i + 1} 无法解析,请回复选项文字或序号(如 1)` }
|
|
311
|
+
answers.push({ id: String(item.id), selected })
|
|
312
|
+
parts.push(`Q${i + 1}: ${selected.join('、')}`)
|
|
313
|
+
} else {
|
|
314
|
+
answers.push({ id: String(item.id), selected: [], ...(raw ? { custom: raw } : {}) })
|
|
315
|
+
parts.push(`Q${i + 1}: ${raw || '(未填)'}`)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return { answers, summary: parts.join('\n') }
|
|
98
319
|
}
|
|
@@ -41,7 +41,7 @@ export async function attachSessionToWorkspace(registry, { cwd, title, sessionId
|
|
|
41
41
|
const entity = await ensureWorkspaceForCwd(registry, { cwd, title })
|
|
42
42
|
await entity.attachSession(sessionId)
|
|
43
43
|
return true
|
|
44
|
-
} catch (error) {
|
|
44
|
+
} catch (error ) {
|
|
45
45
|
logger.warn?.(`dsh-team: 会话挂工作区分组失败(不影响会话运行): ${error?.message ?? error}`)
|
|
46
46
|
return false
|
|
47
47
|
}
|
|
@@ -61,7 +61,8 @@ export async function backfillWorkspaceGroupBindings(service) {
|
|
|
61
61
|
bt.solo_dir, bt.name AS bot_name
|
|
62
62
|
FROM session_bindings b
|
|
63
63
|
LEFT JOIN projects p ON p.id = b.project_id
|
|
64
|
-
LEFT JOIN bots bt ON bt.id = b.bot_id
|
|
64
|
+
LEFT JOIN bots bt ON bt.id = b.bot_id
|
|
65
|
+
WHERE b.alias = 0`)
|
|
65
66
|
const groups = new Map()
|
|
66
67
|
for (const row of rows) {
|
|
67
68
|
const bot = { name: row.bot_name, solo_dir: row.solo_dir }
|
|
@@ -74,7 +75,7 @@ export async function backfillWorkspaceGroupBindings(service) {
|
|
|
74
75
|
}
|
|
75
76
|
group.sessionIds.push(row.session_id)
|
|
76
77
|
groups.set(cwd, group)
|
|
77
|
-
} catch (error) {
|
|
78
|
+
} catch (error ) {
|
|
78
79
|
// 项目/单聊目录已不可推导(如记录残留)时只跳过该条会话。
|
|
79
80
|
service.logger.warn?.(`dsh-team: 回填跳过会话 ${row.session_id}(工作区路径不可用): ${error?.message ?? error}`)
|
|
80
81
|
}
|
package/src/skill-parse.js
CHANGED
|
@@ -3,7 +3,7 @@ import { basename, dirname } from 'node:path'
|
|
|
3
3
|
// 技能包(SKILL.md)解析:frontmatter 优先,缺失时回退到目录名与正文首段。
|
|
4
4
|
export function parseSkill(raw, locator) {
|
|
5
5
|
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(raw)
|
|
6
|
-
const metadata
|
|
6
|
+
const metadata = {}
|
|
7
7
|
if (frontmatter?.[1]) {
|
|
8
8
|
for (const line of frontmatter[1].split('\n')) {
|
|
9
9
|
const match = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line.trim())
|
package/src/skills.js
CHANGED
|
@@ -144,7 +144,7 @@ export function syncSkills(store, skillRoot) {
|
|
|
144
144
|
|
|
145
145
|
// 技能 provider:共享技能池 + 当前会话所在项目的项目技能池。
|
|
146
146
|
// 项目技能按 .agents > .claude > .codex 优先级去重,且优先于同名共享技能。
|
|
147
|
-
export function skillProvider(skillRoot, options = {}) {
|
|
147
|
+
export function skillProvider(skillRoot, options = {} ) {
|
|
148
148
|
const resolveProjectDir = options.resolveProjectDir ?? (() => null)
|
|
149
149
|
const list = (cwd) => {
|
|
150
150
|
const candidates = []
|
package/src/tools.js
CHANGED
|
@@ -3,25 +3,87 @@ const stringOutput = {
|
|
|
3
3
|
render: (_args, value) => [{ type: 'text', text: String(value ?? '') }],
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
// DSHBOTS-238:子代理/智能体团队能力全员化。
|
|
7
|
+
// 「生成子代理/组建临时团队」能力由宿主 preset 注册(subagent/subagent_fork/workflow 与
|
|
8
|
+
// spawn_teammate 等团队工具),插件侧只声明其可用清单与门控,不重复注册。
|
|
9
|
+
// DSHBOTS-237:共享板建卡废弃——宿主共享板的建卡工具(task-N 无项目编号卡)
|
|
10
|
+
// 不再作为成员能力宣告,新建卡一律走项目编号(team_assign_task 派单链,KEY-N);
|
|
11
|
+
// 存量共享板卡可读不可新建,list/get/update 保留读取与流转能力。
|
|
12
|
+
export const SUBAGENT_GENERATION_TOOLS = [
|
|
13
|
+
'subagent',
|
|
14
|
+
'subagent_fork',
|
|
15
|
+
'workflow',
|
|
16
|
+
'spawn_teammate',
|
|
17
|
+
'send_message',
|
|
18
|
+
'list_agents',
|
|
19
|
+
'wait_agent',
|
|
20
|
+
'interrupt_agent',
|
|
21
|
+
'team_task_list',
|
|
22
|
+
'team_task_get',
|
|
23
|
+
'team_task_update',
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
// 总监专权工具:服务层 ownerContextFor 已做权威校验,本清单用于工具层兜底与守门测试。
|
|
27
|
+
// team_block_task(DSHBOTS-232)与派单/验收同款总监专属:强制受阻停运行是不可逆控制面操作。
|
|
28
|
+
// team_list_bots / team_add_member / team_create_bot(DSHBOTS-229)是团队编制入口:
|
|
29
|
+
// 池查询含未入群 bot,加人与建 bot 会改动项目成员或全局 bot 档案。
|
|
30
|
+
// team_memory_list / team_memory_write / team_memory_cleanup(DSHBOTS-239)是记忆巡检面:
|
|
31
|
+
// 枚举、同名覆盖写与批量终态化清理都只归总监。
|
|
32
|
+
export const DIRECTOR_ONLY_TOOLS = [
|
|
33
|
+
'team_assign_task',
|
|
34
|
+
'team_review_task',
|
|
35
|
+
'team_block_task',
|
|
36
|
+
'team_list_bots',
|
|
37
|
+
'team_add_member',
|
|
38
|
+
'team_create_bot',
|
|
39
|
+
'team_memory_list',
|
|
40
|
+
'team_memory_write',
|
|
41
|
+
'team_memory_cleanup',
|
|
42
|
+
'team_release_bot_quota',
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
// 门控:agentTeam 开启且 bot 类型支持(项目内 active bot,成员与总监均可用)。
|
|
46
|
+
export function subagentCapabilityEnabledFor(bot, config) {
|
|
47
|
+
return Boolean(config?.agentTeam) && Boolean(bot?.id) && bot.status !== 'removed'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 工具层兜底(DSHBOTS-238):成员 bot 隐藏总监专权工具,避免「误调被拒后才知情」;
|
|
51
|
+
// 子代理生成工具由 preset 全局注册,成员 bot 默认可见,无需额外放行。
|
|
52
|
+
// DSHBOTS-247:调用点形状不一——session.ts 的结转/复用路径传 resolveAgent 的
|
|
53
|
+
// `{ agent }` 包装,新建会话路径传裸 agent。这里归一为句柄后取 restrict,两种形状都生效;
|
|
54
|
+
// 旧实现只认包装形状时,裸形状会静默跳过(策略从未生效)或旧构建抛 "reading 'ctx'"。
|
|
55
|
+
export function applyBotToolPolicy(resolved, { isOwner, logger } ) {
|
|
56
|
+
if (isOwner) return
|
|
57
|
+
const handle = resolved?.agent ?? resolved
|
|
58
|
+
const restrict = handle?.ctx?.tools?.restrict
|
|
59
|
+
if (typeof restrict !== 'function') return
|
|
60
|
+
try {
|
|
61
|
+
restrict({ deny: [...DIRECTOR_ONLY_TOOLS] })
|
|
62
|
+
} catch (error ) {
|
|
63
|
+
// 工具层兜底失败不阻断会话:服务层 ownerContextFor 仍是权威闸门。
|
|
64
|
+
logger?.warn?.(`dsh-team: 应用成员 bot 工具策略失败:${error?.message ?? error}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
6
68
|
export function installTeamTools(ctx, service) {
|
|
7
69
|
if (!ctx.tools?.register) return
|
|
8
70
|
|
|
9
71
|
ctx.tools.register({
|
|
10
72
|
name: 'team_assign_task',
|
|
11
|
-
description: 'Assign a task to a project bot. Only the project owner bot may use this. With `task` it re-dispatches that existing task (retry to the same bot, or hand it to a different bot);
|
|
73
|
+
description: 'Assign a task to a project bot. Only the project owner bot may use this. With `task` it re-dispatches that existing task (retry to the same bot, or hand it to a different bot); passing title/description/priority alongside `task` amends the card — the assignee is immediately notified to correct course per the new card. Without `task`, creates a new task that starts automatically. A new task whose write scopes exactly match an unfinished task in the same project is rejected as a duplicate dispatch; merge the cards into the existing task instead, or pass force_duplicate to override (audited). Consolidate before dispatch: one requirement goes into one card — amend and re-dispatch the existing card (or add subtask cards with parent_task_id for genuinely independent parts) instead of opening several sibling cards for the same need.',
|
|
12
74
|
parameters: {
|
|
13
75
|
type: 'object',
|
|
14
76
|
properties: {
|
|
15
77
|
assignee: { type: 'string', description: 'Exact bot name from the project member list' },
|
|
16
|
-
title: { type: 'string', description: 'Short actionable task title (new tasks
|
|
17
|
-
description: { type: 'string', description: 'Self-contained instructions, constraints and acceptance criteria (new tasks
|
|
18
|
-
priority: { type: 'string', enum: ['urgent', 'high', 'medium', 'low', 'none'], description: 'Task priority' },
|
|
78
|
+
title: { type: 'string', description: 'Short actionable task title (new tasks; on re-dispatch it amends the card)' },
|
|
79
|
+
description: { type: 'string', description: 'Self-contained instructions, constraints and acceptance criteria (new tasks; on re-dispatch it amends the card and the assignee is notified to correct course)' },
|
|
80
|
+
priority: { type: 'string', enum: ['urgent', 'high', 'medium', 'low', 'none'], description: 'Task priority (new tasks and card amendment on re-dispatch)' },
|
|
19
81
|
write_scopes: { type: 'array', items: { type: 'string' }, description: 'Workspace-relative paths this task will modify (new tasks only); the scheduler runs tasks with disjoint scopes in parallel. Omit to parse a `写范围:`/`write_scopes:` line from the description instead' },
|
|
20
82
|
force_duplicate: { type: 'boolean', description: 'Escape hatch (new tasks only): skip the same-write-scope duplicate check when an unfinished task in this project already declares identical write scopes. Use only when a second task on the same paths is intentional; every use is audited as dispatch_force_duplicate' },
|
|
21
83
|
time_budget_minutes: { type: 'integer', description: 'Required delivery time limit in minutes (new tasks only, 1-10080): injected into the task prompt, and the run is aborted when the budget expires. The effective timeout is the smaller of this budget and the global run timeout. Omit to take the default budget (env DSH_TEAM_TASK_TIME_BUDGET_MINUTES > stall-watchdog minutes > fallback 20 minutes)' },
|
|
22
|
-
parent_task_id: { type: 'string', description: 'Nest the new task as a subtask under this main task id (new tasks only): pass it when the main item cannot be finished in this run or a new closing condition emerged, so follow-up work lands as a product-grade card instead of a verbal note. Must reference an existing task in the same project; self-reference is rejected. The backend validates' },
|
|
84
|
+
parent_task_id: { type: 'string', description: 'Nest the new task as a subtask under this main task id (new tasks only): pass it when the main item cannot be finished in this run or a new closing condition emerged, so follow-up work lands as a product-grade card instead of a verbal note; also pass it to split a large task into parallel subtask cards for speed (independent parts, disjoint write_scopes, so the cards run concurrently). Must reference an existing task in the same project; self-reference is rejected. The backend validates' },
|
|
23
85
|
task: { type: 'string', description: 'Existing task to re-dispatch, as KEY-N (for example DEMO-3). Omit to create a new task' },
|
|
24
|
-
sandbox: { type: 'string', enum: ['inherit', 'workspace-write', 'read-only'], description: '
|
|
86
|
+
sandbox: { type: 'string', enum: ['inherit', 'workspace-write', 'read-only'], default: 'inherit', description: 'Sandbox tier for this task\'s runs (new tasks and re-dispatch); default inherit = follow the assignee bot\'s configured file policy, so a development task is never tightened to read-only unless the card says so. inherit also clears any stored override on re-dispatch. workspace-write/read-only must not be wider than that configuration (tighten-only; every run of the task starts under the effective tier, recorded as a sandbox_mode run event). Use read-only to run a development task in review mode' },
|
|
25
87
|
},
|
|
26
88
|
required: ['assignee'],
|
|
27
89
|
additionalProperties: false,
|
|
@@ -37,6 +99,25 @@ export function installTeamTools(ctx, service) {
|
|
|
37
99
|
},
|
|
38
100
|
})
|
|
39
101
|
|
|
102
|
+
ctx.tools.register({
|
|
103
|
+
name: 'team_block_task',
|
|
104
|
+
description: 'Force-move an in-progress task to blocked and abort its queued/running runs. Only the project owner bot may use this. The stop rides the existing abort chain and is audited as task.force_blocked (run error code TASK_FORCE_BLOCKED). Use it to stop a runaway or wrong-headed execution; typically followed by re-dispatching the same task with an amended card.',
|
|
105
|
+
parameters: {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
task: { type: 'string', description: 'Task to force-block, as KEY-N (for example DEMO-3)' },
|
|
109
|
+
},
|
|
110
|
+
required: ['task'],
|
|
111
|
+
additionalProperties: false,
|
|
112
|
+
},
|
|
113
|
+
output: stringOutput,
|
|
114
|
+
async execute(args, exec) {
|
|
115
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
116
|
+
const task = await service.forceBlockFromBot(sessionId, args)
|
|
117
|
+
return `Force-blocked ${task.identifier} (status: ${task.status}); its queued/running runs were aborted.`
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
|
|
40
121
|
ctx.tools.register({
|
|
41
122
|
name: 'team_review_task',
|
|
42
123
|
description: 'Accept or return a delivered task that is waiting for owner review. Only the project owner bot may use this. `accept` marks the task done; `return` sends it back to the assignee for rework (a reason is required).',
|
|
@@ -58,6 +139,80 @@ export function installTeamTools(ctx, service) {
|
|
|
58
139
|
},
|
|
59
140
|
})
|
|
60
141
|
|
|
142
|
+
// DSHBOTS-229:成员查询——项目群内任意成员可查本项目名单/角色/状态。
|
|
143
|
+
ctx.tools.register({
|
|
144
|
+
name: 'team_list_members',
|
|
145
|
+
description: 'List the bots in this project group with their project role, job role and status. Any bot in the project group may use this. The result is limited to this project\'s members; it never exposes other projects\' data.',
|
|
146
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
147
|
+
output: stringOutput,
|
|
148
|
+
async execute(args, exec) {
|
|
149
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
150
|
+
return service.listMembersFromBot(sessionId)
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
// DSHBOTS-229:bots 池查询——总监可见含未入群的 bot;成员调用被服务层拒绝。
|
|
155
|
+
ctx.tools.register({
|
|
156
|
+
name: 'team_list_bots',
|
|
157
|
+
description: 'List the team bot pool for this project, including bots that are not in the project group yet, with their status and whether they already belong to this project. Only the project owner bot may use this. It shows each bot\'s own profile and this project\'s membership only; it never exposes other projects\' data.',
|
|
158
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
159
|
+
output: stringOutput,
|
|
160
|
+
async execute(args, exec) {
|
|
161
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
162
|
+
return service.listBotsPoolFromBot(sessionId)
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
// DSHBOTS-229:加人申请——复用 addProjectMember 的校验、审计与入群通知。
|
|
167
|
+
ctx.tools.register({
|
|
168
|
+
name: 'team_add_member',
|
|
169
|
+
description: 'Invite an existing bot into this project group by its exact name. Only the project owner bot may use this. The invite rides the normal membership path: the bot must be active and cannot already be a member, the join is audited, and the other members are announced in the group automatically.',
|
|
170
|
+
parameters: {
|
|
171
|
+
type: 'object',
|
|
172
|
+
properties: {
|
|
173
|
+
bot: { type: 'string', description: 'Exact bot name from the team bot pool' },
|
|
174
|
+
},
|
|
175
|
+
required: ['bot'],
|
|
176
|
+
additionalProperties: false,
|
|
177
|
+
},
|
|
178
|
+
output: stringOutput,
|
|
179
|
+
async execute(args, exec) {
|
|
180
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
181
|
+
const result = await service.addMemberFromBot(sessionId, args)
|
|
182
|
+
return `Added ${result.member.name} to ${result.project.key} as ${result.member.member_role}.`
|
|
183
|
+
},
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
// DSHBOTS-229:建 bot 申请——仅申请入口,复用 createBot 的全部校验与审计。
|
|
187
|
+
ctx.tools.register({
|
|
188
|
+
name: 'team_create_bot',
|
|
189
|
+
description: 'Request a brand-new bot for the team. Only the project owner bot may use this. The request goes through the normal bot creation path, so name format/uniqueness and provider/model validation still apply, and the audit records you as the requester. The new bot is not added to this project automatically; invite it with team_add_member.',
|
|
190
|
+
parameters: {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
name: { type: 'string', description: 'Bot name (Chinese/letters/digits/underscore/hyphen, up to 24 chars)' },
|
|
194
|
+
role: { type: 'string', description: 'Short job role, for example 开发 or 设计' },
|
|
195
|
+
instructions: { type: 'string', description: 'Standing instructions for the new bot' },
|
|
196
|
+
provider: { type: 'string', description: 'Model provider (must pair with model)' },
|
|
197
|
+
model: { type: 'string', description: 'Model id (must pair with provider)' },
|
|
198
|
+
effort: { type: 'string', description: 'Optional reasoning effort' },
|
|
199
|
+
fallbackProvider: { type: 'string', description: 'Optional fallback model provider (must pair with fallbackModel)' },
|
|
200
|
+
fallbackModel: { type: 'string', description: 'Optional fallback model id' },
|
|
201
|
+
fallbackEffort: { type: 'string', description: 'Optional fallback reasoning effort' },
|
|
202
|
+
color: { type: 'string', description: 'Avatar color: blue/teal/violet/amber/coral/pink/green/gray' },
|
|
203
|
+
filePolicy: { type: 'string', enum: ['workspace-write', 'read-only', 'danger-full-access'], description: 'File sandbox tier for the new bot; omit to use the default workspace-write' },
|
|
204
|
+
},
|
|
205
|
+
required: ['name'],
|
|
206
|
+
additionalProperties: false,
|
|
207
|
+
},
|
|
208
|
+
output: stringOutput,
|
|
209
|
+
async execute(args, exec) {
|
|
210
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
211
|
+
const bot = await service.createBotFromBot(sessionId, args)
|
|
212
|
+
return `Created bot ${bot.name} (status: ${bot.status}). Invite it to a project with team_add_member.`
|
|
213
|
+
},
|
|
214
|
+
})
|
|
215
|
+
|
|
61
216
|
ctx.tools.register({
|
|
62
217
|
name: 'team_recall',
|
|
63
218
|
description: 'Expand one truncated context item by its reference id. Accepts a message id (m_xxxxxx), a task comment id (c_xxxxxx), a run id (run_xxxxxx), or a task number such as DEMO-7. Returns the full stored text for that project only.',
|
|
@@ -97,6 +252,95 @@ export function installTeamTools(ctx, service) {
|
|
|
97
252
|
},
|
|
98
253
|
})
|
|
99
254
|
|
|
255
|
+
// ── 总监记忆管理工具集(DSHBOTS-239):list / 同名覆盖写 / 批量清理 ──
|
|
256
|
+
// 服务层 ownerContextFor 权威鉴权;此处注册形态与 DIRECTOR_ONLY_TOOLS 兜底同源。
|
|
257
|
+
|
|
258
|
+
ctx.tools.register({
|
|
259
|
+
name: 'team_memory_list',
|
|
260
|
+
description: 'List existing long-term memories in one scope (bot / project / team) for hygiene inspection: entries with short id, topic, updated time and a content preview, optionally filtered by topic substring. Director-only.',
|
|
261
|
+
parameters: {
|
|
262
|
+
type: 'object',
|
|
263
|
+
properties: {
|
|
264
|
+
scope: { type: 'string', enum: ['bot', 'project', 'team'], description: 'Which memory scope to enumerate: bot = your own memories, project = this project, team = whole team. Default project' },
|
|
265
|
+
topic: { type: 'string', description: 'Optional substring filter on the topic label' },
|
|
266
|
+
limit: { type: 'integer', description: 'Max entries to return (1-200, default 50)' },
|
|
267
|
+
},
|
|
268
|
+
additionalProperties: false,
|
|
269
|
+
},
|
|
270
|
+
output: stringOutput,
|
|
271
|
+
async execute(args, exec) {
|
|
272
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
273
|
+
const rows = service.memoryListFromBot(sessionId, args)
|
|
274
|
+
if (!rows.length) return 'No active memories in this scope.'
|
|
275
|
+
return rows
|
|
276
|
+
.map(row => `- [${row.id.slice(-6)}] ${row.topic} (${row.scope_type}, updated ${row.updated_at})\n ${String(row.content).replace(/\s+/g, ' ').slice(0, 240)}`)
|
|
277
|
+
.join('\n')
|
|
278
|
+
},
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
ctx.tools.register({
|
|
282
|
+
name: 'team_memory_write',
|
|
283
|
+
description: 'Write a durable memory with same-name overwrite: an active memory with the same scope+topic is updated in place (revision bumps, event trail kept) instead of appending a duplicate entry; otherwise a new memory is created. Use it to refresh a wording to the latest final state instead of piling up near-duplicates. Scope rules: bot = your own, project = this project, team = whole team. Never store secrets or credentials. Director-only.',
|
|
284
|
+
parameters: {
|
|
285
|
+
type: 'object',
|
|
286
|
+
properties: {
|
|
287
|
+
scope: { type: 'string', enum: ['bot', 'project', 'team'], description: 'bot: only you remember it; project: every project bot can use it; team: shared by the whole team (owner bots only)' },
|
|
288
|
+
topic: { type: 'string', description: 'Short topic label; same topic in the same scope is overwritten in place' },
|
|
289
|
+
content: { type: 'string', description: 'The durable memory, with enough context to be useful later' },
|
|
290
|
+
},
|
|
291
|
+
required: ['scope', 'topic', 'content'],
|
|
292
|
+
additionalProperties: false,
|
|
293
|
+
},
|
|
294
|
+
output: stringOutput,
|
|
295
|
+
async execute(args, exec) {
|
|
296
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
297
|
+
const { memory, overwritten } = service.memoryWriteFromBot(sessionId, args)
|
|
298
|
+
return `${overwritten ? 'Overwrote' : 'Saved'} ${memory.scope_type} memory "${memory.topic}" (rev ${memory.revision}).`
|
|
299
|
+
},
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
ctx.tools.register({
|
|
303
|
+
name: 'team_memory_cleanup',
|
|
304
|
+
description: 'Batch-deprecate stale memories in one scope: matched entries are archived (terminal — excluded from recall), each keeps its memory_events trail, and the batch is audited as memory.cleanup with the cleaned entries listed. Two criteria, combinable: `task` archives a closed card\'s process records (its 任务 KEY-N / KEY-N 交付记录 topics; the task must already be done or canceled); `topics` archives the explicitly listed topics — use it for older wordings that conflict with a newer final decision. Do not archive entries recording the user\'s explicit decisions. Director-only.',
|
|
305
|
+
parameters: {
|
|
306
|
+
type: 'object',
|
|
307
|
+
properties: {
|
|
308
|
+
scope: { type: 'string', enum: ['bot', 'project', 'team'], description: 'Which memory scope to clean: bot = your own, project = this project, team = whole team' },
|
|
309
|
+
topics: { type: 'array', items: { type: 'string' }, description: 'Exact topic labels to archive in this scope' },
|
|
310
|
+
task: { type: 'string', description: 'Closed card (KEY-N) whose process-record memories should be archived; rejected unless the task is done or canceled' },
|
|
311
|
+
},
|
|
312
|
+
required: ['scope'],
|
|
313
|
+
additionalProperties: false,
|
|
314
|
+
},
|
|
315
|
+
output: stringOutput,
|
|
316
|
+
async execute(args, exec) {
|
|
317
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
318
|
+
const result = service.memoryCleanupFromBot(sessionId, args)
|
|
319
|
+
const cleaned = result.cleaned.map(item => `"${item.topic}"`).join(', ') || 'none'
|
|
320
|
+
const missed = result.missed.length ? ` Not found (skipped): ${result.missed.map(topic => `"${topic}"`).join(', ')}.` : ''
|
|
321
|
+
return `Archived ${result.archived} ${result.archived === 1 ? 'entry' : 'entries'}: ${cleaned}.${missed}`
|
|
322
|
+
},
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
ctx.tools.register({
|
|
326
|
+
name: 'team_release_bot_quota',
|
|
327
|
+
description: 'Clear a bot\'s provider quota-exhausted state immediately so its queued task runs dispatch again now, instead of waiting for the provider\'s reset time. Use when the provider says the quota already reset, or the bot must work before the recorded reset time. Idempotent: releasing an already-clear bot is a no-op. Director-only; the human owner can do the same from the bot detail panel.',
|
|
328
|
+
parameters: {
|
|
329
|
+
type: 'object',
|
|
330
|
+
properties: {
|
|
331
|
+
bot: { type: 'string', description: 'Bot id or exact bot name whose quota state should be cleared' },
|
|
332
|
+
},
|
|
333
|
+
required: ['bot'],
|
|
334
|
+
additionalProperties: false,
|
|
335
|
+
},
|
|
336
|
+
output: stringOutput,
|
|
337
|
+
async execute(args, exec) {
|
|
338
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
339
|
+
const view = service.releaseBotQuotaFromBot(sessionId, args.bot)
|
|
340
|
+
return `Cleared quota state for ${view.name ?? args.bot}.`
|
|
341
|
+
},
|
|
342
|
+
})
|
|
343
|
+
|
|
100
344
|
ctx.tools.register({
|
|
101
345
|
name: 'team_propose_evolution',
|
|
102
346
|
description: 'Propose a versioned change to your own instructions or to the shared skill library. A human must review and approve it; this tool never applies the change.',
|
|
@@ -185,4 +429,29 @@ export function installTeamTools(ctx, service) {
|
|
|
185
429
|
return `Secret request ${request.requestId.slice(-6)} for ${request.name} is pending human approval.`
|
|
186
430
|
},
|
|
187
431
|
})
|
|
432
|
+
|
|
433
|
+
// DSHBOTS-243:通知通道产品化——成员通知 / 任务提醒,项目内任意成员可用。
|
|
434
|
+
// 投递面是宿主会话通道(runtime.steer),插件 messages 落库为准绳;跨项目目标一律拒绝。
|
|
435
|
+
ctx.tools.register({
|
|
436
|
+
name: 'team_notify',
|
|
437
|
+
description: 'Send a notification inside this project. Any project member may use this. `target=member` notifies another member bot of this project: the host session channel delivers it immediately when reachable, and the notification is always recorded in the group chat (sender = you, mention = the target). `target=task` reminds a task of this project: if the task has an active run, the reminder is steered into that run session (re-read the card and act on it); otherwise it lands as a task-thread message the owner can see on the review panel. Only members and tasks of this project are addressable; cross-project targets are rejected. A channel failure only warns and never blocks the other channel.',
|
|
438
|
+
parameters: {
|
|
439
|
+
type: 'object',
|
|
440
|
+
properties: {
|
|
441
|
+
target: { type: 'string', enum: ['member', 'task'], description: 'member = notify another project member bot; task = remind a task of this project' },
|
|
442
|
+
member: { type: 'string', description: 'Exact bot name from the project member list (required when target=member)' },
|
|
443
|
+
task: { type: 'string', description: 'Task to remind, as KEY-N (required when target=task)' },
|
|
444
|
+
message: { type: 'string', description: 'Self-contained notification body' },
|
|
445
|
+
},
|
|
446
|
+
required: ['target', 'message'],
|
|
447
|
+
additionalProperties: false,
|
|
448
|
+
},
|
|
449
|
+
output: stringOutput,
|
|
450
|
+
async execute(args, exec) {
|
|
451
|
+
const sessionId = exec?.agent?.id ?? exec?.agent?.session?.id
|
|
452
|
+
if (args.target === 'member' && !args.member) throw new Error('target=member 需要 member(目标 bot 名称)')
|
|
453
|
+
if (args.target === 'task' && !args.task) throw new Error('target=task 需要 task(KEY-N 任务编号)')
|
|
454
|
+
return service.notifyFromBot(sessionId, args)
|
|
455
|
+
},
|
|
456
|
+
})
|
|
188
457
|
}
|