Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3f6fdf2
docs(approval): record confirmed Bot template policy
DoodleBears Nov 15, 2026
4c56775
Merge remote-tracking branch 'origin/main' into t3/bot-auto-approval-…
DoodleBears Nov 15, 2026
2b48ec7
Merge remote-tracking branch 'origin/main' into t3/bot-auto-approval-…
DoodleBears Nov 15, 2026
c78ea5c
Add effective approval-template selection and versioned Human fallback
DoodleBears Nov 15, 2026
d9bbf19
Keep an unreadable global selection visibly unknown
DoodleBears Nov 15, 2026
bb6a5f9
Report unreadable approval selection with a dedicated refusal
DoodleBears Nov 15, 2026
7a28885
fix(approval): preserve management fences and truthful fallback UI
DoodleBears Nov 15, 2026
73aae1f
merge main after E1 tool-effect approval decisions
DoodleBears Nov 15, 2026
0b29008
fix(approval): expose global selection failures and read-only recovery
DoodleBears Nov 15, 2026
0c86d1f
fix(approval): use direct recovery copy in template settings
DoodleBears Nov 15, 2026
250a240
fix(approval): preserve mobile global inheritance selection
DoodleBears Nov 15, 2026
b4fb9ce
fix(permissions): bound template reads and reuse request selection
DoodleBears Nov 15, 2026
28153fa
test(permissions): guard actual template read volume and cleanup
DoodleBears Nov 15, 2026
b4b3fc2
fix(approval): retain full Human cards and record Reviewer handoffs
Nov 15, 2026
8ceb7e0
fix(approval): keep original risk warning on decided cards
Nov 15, 2026
ddd3e45
Clear retained mobile approval details when message content is purged
Nov 15, 2026
c1b7e80
Merge remote-tracking branch 'origin/main' into t3/approval-template-…
Nov 15, 2026
e40ae19
fix: align approval history and search with retained cards
Nov 15, 2026
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
40 changes: 26 additions & 14 deletions .agents/skills/verify-deepseekbot/features/approval-templates.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
# Approval Templates and auto approval

A Human writes Approval Templates, a PersonaBot selects one, and the Approval Reviewer answers that Bot's operation approvals by the template's text before any card is posted (ADR-0207).
A Bot inherits the optional global default, selects one complete shared template, or disables its Reviewer (ADR-0342). Deterministic authorization runs first; Reviewer outcomes are allow for this call or ask-human.

## Sub-features

- `library` is Bot settings → Auto approval: every template with `Built-in` or its file name, its description and the Bots that use it. `New` creates one; `View` opens a built-in read-only with `Copy`; `Edit` opens a Human template with `Save` and `Delete`.
- `cli` is `deepseekbot approval-template list|show|create|edit|delete` and `approval-template-set <bot> <name|off>`. Files live in `$DSH_HOME/botharness/approval-templates/<name>.md`.
- `select` is the Bot's channel settings → Auto approval page, or the composer workspace panel.
- `reviewer` leaves a folded `Auto-approved by <template>` or `Auto-rejected by <template>` system line in the Channel.
- `guard` turns a Bot Shell call that selects a template, or edits or deletes a template some Bot uses, into a Human card that the reviewer and saved rules never answer. Creating a template, or editing one no Bot uses, runs without a card.
- `library`: Bot settings → Auto approval → Global default template (DSH Select), existing template library and Reviewer model. No global default means inherited review is off. Read failures remain errors.
- `cli`: `approval-template list --bot <bot>`, `approval-template-global-set <name|off>`, `approval-template-set <bot> <inherit|name|off>`; library create/edit commands retain existing Markdown contents.
- `select`: Channel settings → Auto approval, or composer Workspace Grants panel → Auto approval, uses the same DSH Select. Inheritance shows its effective global source. Specific selection replaces global; Off retains deterministic rules.
- `mobile`: Bot profile → Settings → Permissions → Workspace grants → Auto approval template, inside the existing iOS sheet / Android `ModalBottomSheet`. Inherit global shows the resolved global template (or Off); selecting Off then Inherit global writes null then @global through the same Host owner. Legacy Hosts without a global-selection field retain their supported choices.
- `reviewer`: a covered call leaves an auto-approved record with template identity/version; an uncovered or failed review posts a Human card with the reason and captured version when available. No new model rejection or rejection pause occurs.
- `guard`: effective template/global/Bot policy changes bypass Full Access and model review, retaining Human or explicit management-scope authorization and execution fences (ADR-0249).

## How to get to it (user POV)

- Bot mode → `Bot settings` → `Auto approval`.
Bot mode → Bot settings → Auto approval for global default; open a Bot DM → Channel settings → Auto approval for its selection.

## Driving it with verify-app

Preconditions: `launch` reported a model credential and `doctor` passes. Point the CLI at the instance with `--host <origin>` and `--token-file <file holding the launcher token>`.
Use an isolated Host and its own authenticated CLI. Confirm health and Client console/DOM before each journey. Use the actual CLI Host origin and a private token file; never put tokens in screenshots or args.

- **Library.** `shot <label> --bot-mode --click "Bot settings" --click "Auto approval" --wait-text "Get the work done"`. Then `--click "Edit"` on a Human template or `--click-text "View"` on a built-in, and `--click "Copy"` then `--click-text "New"` to save the copy. Proof: the file appears under `approval-templates/`.
- **Reviewer follows the text.** Create a template that rejects files named `secret-plan` with a fixed reason, select it, and DM the Bot to write `/root/bh-1824/secret-plan.txt` and ask to leave the sandbox. Proof: `rpc botharness/channelMessages` holds a system entry with `toolAutoApproval.outcome: "rejected"` and that reason, and the file does not exist.
- **Guard.** Copy the launcher token to a file the Bot's Shell can read and give the Bot the full CLI command. `create` returns with no card. `edit` of a template another Bot uses posts a `toolApprovalRequest` entry; `tool-approval-decide <channel> --message-id <id> --outcome rejected` leaves the file's hash unchanged.
1. Capture light/dark global and Bot selection before/after at the same viewport and locale.
2. Set global cautious with the CLI, select inherit through the Client, and read back list --bot: selected @global, source global, effective cautious. Change global to get-work-done: inheritance follows. Select cautious specifically, change global or clear it: the Bot remains cautious. Select Off: effective null, source off.
3. New Bot creation reads back @global; a retained legacy missing field remains Off. Restart verifies persistence without schema changes.
4. Trigger an existing approval through the native tool path. A deterministic saved rule makes zero Reviewer calls. An uncovered call uses the effective template and leaves either the versioned auto-approved record or Human card; answer that card through the normal owner.
5. Edit/switch during an injected Reviewer wait at the Channel Tool Approval seam: this Review retains the old identity/version, the next uses the new one. Missing/unreadable template or model timeout/malformed response posts Human with a reason, even if diagnostics fail. Check canonical Channel records and developer logs.
6. Exercise a policy-management approval under Full Access; Reviewer calls remain zero and only Human or an explicit management rule can authorize effects. Revoke the rule before execution and verify refusal.

## Native mobile qualification

Use the shared device QA lane and T3 device tools. The same synthetic Bot and isolated QA Host must be used for before/after, with the current PR/source/build identities recorded. In Bot profile → Settings → Permissions → Workspace grants, verify the inherited row is checked and names the global template or Off. Choose Off, return to Inherit global, then choose one specific template; read back each selection using the authenticated CLI. A global switch updates the inherited row after refresh while a specific choice remains specific. Read failures stay visible failures. Capture default/intermediate/maximum system text in light/dark, keep the last choice reachable, and distinguish Android, iOS and Human acceptance. Web screenshots do not qualify this journey.

## Gotchas

- `/tmp` is writable inside the Bot sandbox, so a write there never reaches the reviewer. Use a path outside it.
- The model tends to refuse to edit the template it is itself bound by. Exercise the guard with a template another Bot uses.
- The default Bot only exists after the Web Client first loads; run one `shot` before CLI calls that need its id.
- `/tmp` may already be writable; an ordinary file write there need not reach an approval gate.
- Three-part editing, card-rule table and confirmed bulk deletion fallback are separate issues; this journey does not qualify them.
- Browser screenshots establish Web behavior only. Preserve failed drives and observe before retrying.

## Human result retention (#4211)

After Reviewer asks the Human, verify a compact sent-to-Human row precedes the real request. Open request details, then Allow once, Always allow or Reject: command/tool/folder/input remain, opened details stay open, and the chosen disabled control is identifiable. Reload history and verify the full request remains readable with no resubmission. Mobile uses the existing validated message projection for decided history without one timeline/status RPC per card; malformed/purged content stays unavailable. Historical Reviewer rejection rows remain readable; new ask-human rows cannot be overridden as rejections. Use the public online CLI synthetic missing-secret path on Windows; do not run the native-pwsh journey under the Human no-PowerShell constraint.
2 changes: 1 addition & 1 deletion apps/mobile/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ The two-tab shell follows [ADR-0211](../../docs/adr/0211-the-mobile-app-has-two-
- **Workspace** opens a sheet titled "Workspace · {Bot}" with three sections, the same actions as the Web composer's workspace panel:
1. **Folders**: each granted folder as a row (name, then "Can edit" or "Read only" and its path) with a × that removes access, then **Add folder**. Add folder turns the sheet into a folder browser of the computer: folders registered on the computer, the path as tappable crumbs, and the subfolders; **Authorize this folder** resolves the current folder and asks for a scoped confirmation ("Confirm authorization for {Bot}" with the resolved path) before granting it.
2. **Access**: a **Full access** switch. Turning it on first shows the danger confirmation in place, in an inset box with a red "I understand, enable" button and Cancel; once on, a warning callout and a **Scope of full access** group (Chat and new Assignments, or New Assignments only) follow.
3. **Auto approval template**: Off, Cautious and Get the work done (plus any other template on the Host), each with its one-line hint, the current one checked.
3. **Auto approval template**: Inherit global (with the current global template or Off), Off, Cautious and Get the work done (plus any other template on the Host), each with its one-line hint, the current choice checked. Inheritance is offered only when the Host returns its global selection; legacy Hosts keep Off and named choices. Unreadable inherited selection stays a failed read, never an implicit Off.
- The mic dictates with the phone's speech recognizer, and the words fill the field so the Human edits them before sending. On iOS it is a native SwiftUI button: tap to start, then tap **■** to stop; the **×** that replaces **+** cancels and clears the text. Its SF Symbol is centered in the full button frame, with native press and accessibility activation. There is no iOS hold, drag or lock mode. Android retains hold-to-talk/release-to-stop, slide-left cancel, slide-up lock and tap-to-lock. Dictation stays in the same row, and its status shows as the field's placeholder. A refused microphone or speech permission shows a notice and leaves the mic in place. This is speech-to-text, not an audio-message sender; permissions, native recognition events and cleanup stay owned by the speech adapter.
- A group Channel opens the same chat screen, with these differences:
- The header is the same native header. Its title holds the group's photo (or a round `#` mark), the Channel name and its member count; it opens the **Group profile**. The native three-dot Profile button is the trailing item.
Expand Down
10 changes: 10 additions & 0 deletions apps/mobile/src/host/bot-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ export interface ApprovalTemplate {
description: string;
}

export const INHERIT_APPROVAL_TEMPLATE = '@global';

export interface ApprovalTemplates {
templates: ApprovalTemplate[];
selected: string | null;
globalDefault?: string | null;
}

export class HostAnswerInvalid extends Error {}
Expand Down Expand Up @@ -544,6 +547,12 @@ export async function loadApprovalTemplates(
): Promise<ApprovalTemplates> {
const value = record(await client.call<unknown>('approvalTemplates', { slug }));
const selected = value?.['selected'];
const globalDefault = value?.['globalDefault'];
if (
(globalDefault !== undefined && globalDefault !== null && !text(globalDefault)) ||
(selected === INHERIT_APPROVAL_TEMPLATE && globalDefault === undefined)
)
throw new HostAnswerInvalid('approvalTemplates returned no readable global selection.');
if (!Array.isArray(value?.['templates']) || (selected !== null && !text(selected)))
throw new HostAnswerInvalid('approvalTemplates returned no templates.');
return {
Expand All @@ -554,6 +563,7 @@ export async function loadApprovalTemplates(
: undefined;
}),
selected,
...(globalDefault === undefined ? {} : { globalDefault }),
};
}

Expand Down
20 changes: 19 additions & 1 deletion apps/mobile/src/host/channel-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ChannelMemberDeparture,
ChannelMemoryCommit,
ChannelTurnStop,
ChannelToolAutoApproval,
} from '../../../../packages/core/src/channels/channel';
import { isChannelTurnStopTarget } from '../../../../packages/core/src/channels/turn-stop';
import {
Expand All @@ -13,6 +14,7 @@ import {
import type { ChannelWireMessage } from './wire';

export type ChannelActivity =
| { kind: 'approval-review'; record: ChannelToolAutoApproval }
| ({ kind: 'dm-action' } & BotDmAction)
| { kind: 'channel-post'; channelId: string; messageId: string; preview: string | null }
| { kind: 'memory'; commit: ChannelMemoryCommit; noticeOrigin?: { channelId: string } }
Expand Down Expand Up @@ -58,6 +60,20 @@ function memoryCommit(value: unknown): value is ChannelMemoryCommit {
);
}

function approvalReview(value: unknown): value is ChannelToolAutoApproval {
const review = record(value);
return (
['botSlug', 'sessionId', 'callId', 'toolName', 'template', 'reason'].every((key) =>
text(review[key]),
) &&
typeof review['input'] === 'string' &&
(review['templateVersion'] === undefined || text(review['templateVersion'])) &&
(review['outcome'] === 'allowed' ||
review['outcome'] === 'ask-human' ||
review['outcome'] === 'rejected')
);
}

export function activityOf(message: ChannelWireMessage): ChannelActivity | undefined {
if (message.author.kind === 'bot') {
const dm = record(message.botDmAction);
Expand All @@ -81,7 +97,9 @@ export function activityOf(message: ChannelWireMessage): ChannelActivity | undef
const created = record(message.botCreateAction);
if (message.author.kind === 'bot' && text(created['botSlug']) && text(created['displayName']))
return { kind: 'bot-create', botSlug: created['botSlug'], displayName: created['displayName'] };
if (message.author.kind !== 'system') return undefined;
if (message.author.kind !== 'system' || message.contentPurge !== undefined) return undefined;
if (approvalReview(message.toolAutoApproval))
return { kind: 'approval-review', record: message.toolAutoApproval };
if (isChannelVoiceCallRecord(message.voiceCallRecord))
return { kind: 'voice-call', record: message.voiceCallRecord };
if (memoryCommit(message.memoryCommit)) {
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/host/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { forgetGenuiDocumentViews } from '../genui/view';
import { forgetMedia } from './media-cache';
import { sessionFailure } from './session-failure';
import { activityOf, type ChannelActivity } from './channel-activity';
import { approvalCommand } from './requests';
import { approvalCommand, approvalContent, type ApprovalContent } from './requests';
import { replyPreviewOf } from '../../../../packages/core/src/channels/reply-preview';
import type {
AttachmentRef,
Expand Down Expand Up @@ -33,6 +33,7 @@ export interface MessageCard {
channelId: string;
subject?: string;
command?: string;
approvalContent?: ApprovalContent;
resolved?: true;
takeover?: { target: 'computer' | 'browser'; title: string; expiresAt: string };
}
Expand Down Expand Up @@ -368,13 +369,16 @@ function field(value: unknown, key: string): unknown {

function cardOf(channelId: string, message: ChannelWireMessage): MessageCard | undefined {
if (message.toolApprovalRequest !== undefined) {
if (message.contentPurge !== undefined) return { kind: 'tool-approval', channelId };
const content = approvalContent(message.toolApprovalRequest);
const subject = text(field(message.toolApprovalRequest, 'toolName'));
const input = text(field(message.toolApprovalRequest, 'input'));
const command =
subject === undefined || input === undefined ? undefined : approvalCommand(subject, input);
return {
kind: 'tool-approval',
channelId,
...(content === undefined ? {} : { approvalContent: content }),
...(subject === undefined ? {} : { subject }),
...(command === undefined ? {} : { command }),
};
Expand Down
26 changes: 25 additions & 1 deletion apps/mobile/src/host/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ export interface ApprovalRequest extends RequestRef {
execution?: ApprovalExecution;
}

export type ApprovalContent = Pick<
ApprovalRequest,
'toolName' | 'role' | 'cwd' | 'input' | 'allowAlways'
>;

export function approvalContent(value: unknown): ApprovalContent | undefined {
if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;
if (!('toolName' in value) || typeof value.toolName !== 'string' || !value.toolName.trim())
return undefined;
if (!('role' in value) || (value.role !== 'orchestrator' && value.role !== 'assignment'))
return undefined;
if (!('cwd' in value) || typeof value.cwd !== 'string') return undefined;
if (!('input' in value) || typeof value.input !== 'string') return undefined;
if ('allowAlways' in value && typeof value.allowAlways !== 'boolean') return undefined;
return {
toolName: value.toolName,
role: value.role,
cwd: value.cwd,
input: value.input,
allowAlways: 'allowAlways' in value && value.allowAlways === true,
};
}

export type ApprovalExecution =
| 'waiting-human'
| 'waiting-capacity'
Expand Down Expand Up @@ -99,7 +122,8 @@ export async function loadApproval(client: HostClient, ref: RequestRef): Promise
messageId: ref.messageId,
}),
]);
const card = request.toolApprovalRequest;
const card =
request.contentPurge === undefined ? approvalContent(request.toolApprovalRequest) : undefined;
if (card === undefined) throw new Error('This message is not a Tool approval.');
const decision = later.find(
(entry) => entry.toolApprovalDecision?.requestMessageId === ref.messageId,
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/host/wire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface ChannelWireMessage extends WireMessage {
};
bridgeOrigin?: { sourceEventId: string };
toolApprovalRequest?: unknown;
toolAutoApproval?: unknown;
userQuestionRequest?: unknown;
privateInputRequest?: unknown;
takeoverRequest?: unknown;
Expand Down Expand Up @@ -591,6 +592,7 @@ export interface QuestionAnswer {
}

export interface TimelineMessage {
contentPurge?: unknown;
id: string;
body: string;
toolApprovalRequest?: ToolApprovalRequestCard;
Expand Down
29 changes: 16 additions & 13 deletions apps/mobile/src/ui/chat/activity-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PhoneIcon,
PlusIcon,
StopCircleIcon,
ShieldCheckIcon,
} from '../shell/icons';
import { useStrings } from '../strings';
import { activityPeer, activityText, type ActivityTarget } from './activity-text';
Expand Down Expand Up @@ -59,19 +60,21 @@ export function ActivityRow({
const summary =
dmSlug !== undefined && line.botSlug === dmSlug ? detail : `${line.name} ${detail}`;
const Icon =
activity.kind === 'memory'
? GitCommitIcon
: activity.kind === 'dm-action'
? MessageIcon
: activity.kind === 'channel-post'
? ChatsIcon
: activity.kind === 'bot-create'
? PlusIcon
: activity.kind === 'departure'
? PersonIcon
: activity.kind === 'voice-call'
? PhoneIcon
: StopCircleIcon;
activity.kind === 'approval-review'
? ShieldCheckIcon
: activity.kind === 'memory'
? GitCommitIcon
: activity.kind === 'dm-action'
? MessageIcon
: activity.kind === 'channel-post'
? ChatsIcon
: activity.kind === 'bot-create'
? PlusIcon
: activity.kind === 'departure'
? PersonIcon
: activity.kind === 'voice-call'
? PhoneIcon
: StopCircleIcon;
const size = theme.type.meta.line * theme.fontScale;
const hit = Math.max(0, (theme.touch - size) / 2);
const open = () => {
Expand Down
9 changes: 9 additions & 0 deletions apps/mobile/src/ui/chat/activity-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export function activityText(
return kind === 'memory' ? copy.memoryIn(place) : copy.posted(place, count);
};
switch (activity.kind) {
case 'approval-review': {
const review = activity.record;
return {
botSlug: review.botSlug,
name: botName(review.botSlug),
verb: copy.review[review.outcome](review.template),
detail: review.reason,
};
}
case 'dm-action':
return {
...sender,
Expand Down
Loading
Loading