Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changes/4334-source-reply-approval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
section: Fixed
---

## en

- Fixed every PersonaBot reply waiting for a Human approval card: a `bot_send_message` reply to its own Source Event is admitted directly again, while proactive sends to another Channel, Human, Bot or external target still need approval ([#4334](https://github.com/BotHarness/DeepSeekBot/pull/4334)).

## zh

- 修复了 PersonaBot 每次回复都要等 Human 审批卡的问题:`bot_send_message` 回复自身 Source Event 时重新直接放行;主动发往其他 Channel、Human、Bot 或外部目标仍需审批([#4334](https://github.com/BotHarness/DeepSeekBot/pull/4334))。
2 changes: 2 additions & 0 deletions docs/architecture/bot-approval-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ The target first uses deterministic code to determine whether the action needs a

Implementation slice #4210 routes trusted irreversible external effects through the common approval owner even under Full Access. Deterministic rules resolve before the Reviewer; approval records capture the declared effects for presentation. Management keeps ADR-0249’s dedicated scope. Full Access does not by itself waive the external-effect approval specified in [E2 #4210](https://github.com/BotHarness/DeepSeekBot/issues/4210). The concrete effect declarations and admission mechanism remain in [E1 #4205](https://github.com/BotHarness/DeepSeekBot/issues/4205), E2 and [E4 #4212](https://github.com/BotHarness/DeepSeekBot/issues/4212). No claim is made that arbitrary behavior can be inferred reliably from a command string.

A `bot_send_message` reply to the Bot's own Source Event, with no other destination, is answering the conversation that asked; it is declared local and admitted without a card. A proactive send naming a Channel, Human, Bot, binding or Grant stays external and keeps approval.

Card-created Tool Approval Rules remain deterministic, Bot-scoped authorizations with their existing role, authority scope and execution checks. The Bot permissions table shows their source such as “From approval card”, role, scope and revoke action. This separate display does not turn them into the template editor's natural-language Always allow rows. They are not written into the shared template, granted to other Bots using it, or included in template copies. A natural-language row cannot override an already matched deterministic rule; the Human must revoke that rule to return those requests to review.

Current ownership, Workspace Grant, device-target and rule-revocation checks remain independent of model permission. Effective policy management skips the model Reviewer and Full Access, but may use an explicitly saved authorization covering that management operation under ADR-0249. Existing ordinary rules do not gain management authority. Management approval identifies affected Bots.
Expand Down
2 changes: 2 additions & 0 deletions docs/architecture/bot-approval-policy.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Profile 有一个可选的全局默认模板,来源是共享 Approval Template

实现切片 #4210 将可信声明的不可撤销外部效果送入统一审批,Full Access 不豁免。确定性授权先于 Reviewer,审批记录保存本次效果供呈现;管理操作继续使用 ADR-0249 的专用显式授权范围。具体效果声明与准入机制见 [E1 #4205](https://github.com/BotHarness/DeepSeekBot/issues/4205)、[E2 #4210](https://github.com/BotHarness/DeepSeekBot/issues/4210) 与 [E4 #4212](https://github.com/BotHarness/DeepSeekBot/issues/4212);不声称能从任意命令文本可靠推断全部行为。

`bot_send_message` 只回复 Bot 自身 Source Event、不指定其他目标时,是在回答发起请求的会话,声明为本地效果,不出审批卡。指定 Channel、Human、Bot、binding 或 Grant 的主动发送仍是外部效果,继续审批。

卡片 Always allow 保存的 Tool Approval Rule 是确定性授权,继续绑定具体 Bot、角色、授权范围及执行检查。Bot 权限表标注“来自卡片”、角色、作用范围及撤销入口;独立展示不会将它们变成模板编辑器中的自然语言 Always allow 行。它不写入共享模板,不授权使用同模板的其他 Bot,也不随模板复制。已经命中确定性规则时,模板中的自然语言不会覆盖它;需要重新审核时,由 Human 撤销该规则。

当前所有权、Workspace Grant、设备目标及授权撤销检查独立于模型判断。生效中的策略管理跳过 Reviewer 与 Full Access,须由 Human 决定,或使用 ADR-0249 独立管理范围中确实覆盖该操作的显式已保存授权。旧普通规则不因此获得管理权限。管理审批展示受影响的 Bot。
Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/workspaces/tool-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ function inputText(args: unknown): string {
}
}

const PROACTIVE_DESTINATIONS = [
'channel_id',
'human_id',
'bot_id',
'binding_id',
'conversation_id',
'grant_id',
] as const;

function repliesToSource(operation: object): boolean {
return (
'source_event_id' in operation &&
typeof operation.source_event_id === 'string' &&
operation.source_event_id.trim() !== '' &&
PROACTIVE_DESTINATIONS.every((key) => !(key in operation))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
);
}

export function toolEffects(name: string, args: unknown): ToolEffects | undefined {
if (name === 'deepseekbot_cli') {
if (
Expand Down Expand Up @@ -181,6 +199,8 @@ export function toolEffects(name: string, args: unknown): ToolEffects | undefine
operation.method.toUpperCase() === 'GET'
)
return { ...effects, changes: 'none' };
if (name === 'bot_send_message' && operation && repliesToSource(operation))
return { ...effects, reach: 'local' };
if (name === 'browser_tabs' && operation && 'action' in operation && operation.action === 'close')
return { ...effects, reach: 'local' };
if (
Expand Down
22 changes: 22 additions & 0 deletions packages/core/test/tool-effects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ describe('public tool effects', () => {
secrets: true,
});
});
it('admits a reply to its own Source Event without a card and keeps proactive sends under approval', () => {
const reply = { source_event_id: 'event-1', body: 'pong', end_turn: true };
expect(toolEffects('bot_send_message', reply)).toEqual({
changes: 'irreversible',
reach: 'local',
personalData: true,
});
expect(toolApprovalRequired('bot_send_message', reply, false)).toBe(false);
for (const destination of [
{ channel_id: 'group-1' },
{ human_id: 'alice' },
{ bot_id: 'bot-2' },
{ binding_id: 'lark-1', conversation_id: 'chat-1' },
{ grant_id: 'grant-1' },
]) {
const proactive = { ...reply, ...destination };
expect(toolEffects('bot_send_message', proactive)?.reach).toBe('external');
expect(toolApprovalRequired('bot_send_message', proactive, false)).toBe(true);
}
for (const missing of [{ body: 'hello' }, { source_event_id: ' ', body: 'hello' }])
expect(toolApprovalRequired('bot_send_message', missing, false)).toBe(true);
});
it('includes request delivery when restoring an Assignment with a message', () => {
expect(toolEffects('unarchive_assignment', { session_id: 'assignment-1' })).toEqual({
changes: 'reversible',
Expand Down
Loading