Skip to content

Commit 99a02bf

Browse files
authored
feat(approvals): typed approval scope summaries on channel cards (#130116)
* feat(approvals): typed approval scope summaries on channel cards Approval owners can attach a closed ApprovalScope union (message-send, payment, external-post) describing an action's blast radius. The gateway sanitizes it once at the producer boundary, the core view model renders a Scope metadata row so Slack/Discord/Google Chat cards show it unchanged, shared text builders cover Telegram/WhatsApp/Signal/iMessage/Matrix, and the durable presentation carries it additively for operator surfaces. Scope is display-only, never authorization; missing scope keeps today's cards. * fix(approvals): emit native ApprovalScope union and clamp recipient previews Name the three scope variants as registered protocol schemas so the Swift generator emits the ApprovalScope discriminated union the presentation structs reference, and commit the regenerated GatewayModels.swift. Clamp recipient previews to the declared recipientCount at the sanitize boundary so a count of 1 with 2 previews can no longer render inconsistently. Addresses both ClawSweeper findings on #130116. * refactor(approvals): extract text sanitizer to break the exec-approvals import cycle check:architecture flagged approval-scope joining the exec-approvals SCC through exec-approval-command-display. Move the self-contained display sanitizer into a leaf module (exec-approval-text-sanitize) with no exec-approvals imports and migrate all sanitize importers; command-display keeps only the payload-typed command/preview resolver. * chore(plugin-sdk): ratchet public surface budgets down after sanitizer extraction The approval display sanitizers left the publicly reachable SDK graph when they moved to the exec-approval-text-sanitize leaf: exports 4343 -> 4338, callable exports 2582 -> 2578. Shrink-only budget pin.
1 parent 8a101ed commit 99a02bf

44 files changed

Lines changed: 945 additions & 223 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17619,6 +17619,71 @@ public struct TerminalExitEvent: Codable, Sendable {
1761917619
}
1762017620
}
1762117621

17622+
public struct MessageSendApprovalScope: Codable, Sendable {
17623+
public let kind: String
17624+
public let target: String
17625+
public let recipientcount: Int
17626+
public let recipients: [String]?
17627+
public let audience: AnyCodable?
17628+
17629+
public init(
17630+
kind: String,
17631+
target: String,
17632+
recipientcount: Int,
17633+
recipients: [String]? = nil,
17634+
audience: AnyCodable? = nil)
17635+
{
17636+
self.kind = kind
17637+
self.target = target
17638+
self.recipientcount = recipientcount
17639+
self.recipients = recipients
17640+
self.audience = audience
17641+
}
17642+
17643+
private enum CodingKeys: String, CodingKey {
17644+
case kind
17645+
case target
17646+
case recipientcount = "recipientCount"
17647+
case recipients
17648+
case audience
17649+
}
17650+
}
17651+
17652+
public struct PaymentApprovalScope: Codable, Sendable {
17653+
public let kind: String
17654+
public let amount: String
17655+
public let currency: String
17656+
public let target: String
17657+
17658+
public init(
17659+
kind: String,
17660+
amount: String,
17661+
currency: String,
17662+
target: String)
17663+
{
17664+
self.kind = kind
17665+
self.amount = amount
17666+
self.currency = currency
17667+
self.target = target
17668+
}
17669+
}
17670+
17671+
public struct ExternalPostApprovalScope: Codable, Sendable {
17672+
public let kind: String
17673+
public let target: String
17674+
public let visibility: AnyCodable
17675+
17676+
public init(
17677+
kind: String,
17678+
target: String,
17679+
visibility: AnyCodable)
17680+
{
17681+
self.kind = kind
17682+
self.target = target
17683+
self.visibility = visibility
17684+
}
17685+
}
17686+
1762217687
public struct ExecApprovalPresentation: Codable, Sendable {
1762317688
public let kind: String
1762417689
public let commandtext: String
@@ -17627,6 +17692,7 @@ public struct ExecApprovalPresentation: Codable, Sendable {
1762717692
public let host: AnyCodable?
1762817693
public let nodeid: AnyCodable?
1762917694
public let agentid: AnyCodable?
17695+
public let scope: ApprovalScope?
1763017696
public let alloweddecisions: [ApprovalDecision]
1763117697

1763217698
public init(
@@ -17637,6 +17703,7 @@ public struct ExecApprovalPresentation: Codable, Sendable {
1763717703
host: AnyCodable? = nil,
1763817704
nodeid: AnyCodable? = nil,
1763917705
agentid: AnyCodable? = nil,
17706+
scope: ApprovalScope? = nil,
1764017707
alloweddecisions: [ApprovalDecision])
1764117708
{
1764217709
self.kind = kind
@@ -17646,6 +17713,7 @@ public struct ExecApprovalPresentation: Codable, Sendable {
1764617713
self.host = host
1764717714
self.nodeid = nodeid
1764817715
self.agentid = agentid
17716+
self.scope = scope
1764917717
self.alloweddecisions = alloweddecisions
1765017718
}
1765117719

@@ -17657,6 +17725,7 @@ public struct ExecApprovalPresentation: Codable, Sendable {
1765717725
case host
1765817726
case nodeid = "nodeId"
1765917727
case agentid = "agentId"
17728+
case scope
1766017729
case alloweddecisions = "allowedDecisions"
1766117730
}
1766217731
}
@@ -17670,6 +17739,7 @@ public struct PluginApprovalPresentation: Codable, Sendable {
1767017739
public let pluginid: AnyCodable?
1767117740
public let toolname: AnyCodable?
1767217741
public let agentid: AnyCodable?
17742+
public let scope: ApprovalScope?
1767317743
public let alloweddecisions: [ApprovalDecision]
1767417744

1767517745
public init(
@@ -17681,6 +17751,7 @@ public struct PluginApprovalPresentation: Codable, Sendable {
1768117751
pluginid: AnyCodable? = nil,
1768217752
toolname: AnyCodable? = nil,
1768317753
agentid: AnyCodable? = nil,
17754+
scope: ApprovalScope? = nil,
1768417755
alloweddecisions: [ApprovalDecision])
1768517756
{
1768617757
self.kind = kind
@@ -17691,6 +17762,7 @@ public struct PluginApprovalPresentation: Codable, Sendable {
1769117762
self.pluginid = pluginid
1769217763
self.toolname = toolname
1769317764
self.agentid = agentid
17765+
self.scope = scope
1769417766
self.alloweddecisions = alloweddecisions
1769517767
}
1769617768

@@ -17703,6 +17775,7 @@ public struct PluginApprovalPresentation: Codable, Sendable {
1770317775
case pluginid = "pluginId"
1770417776
case toolname = "toolName"
1770517777
case agentid = "agentId"
17778+
case scope
1770617779
case alloweddecisions = "allowedDecisions"
1770717780
}
1770817781
}
@@ -18321,6 +18394,7 @@ public struct ExecApprovalRequestParams: Codable, Sendable {
1832118394
public let security: AnyCodable?
1832218395
public let ask: AnyCodable?
1832318396
public let warningtext: AnyCodable?
18397+
public let scope: ApprovalScope?
1832418398
public let unavailabledecisions: [String]?
1832518399
public let commandspans: [[String: AnyCodable]]?
1832618400
public let agentid: AnyCodable?
@@ -18352,6 +18426,7 @@ public struct ExecApprovalRequestParams: Codable, Sendable {
1835218426
security: AnyCodable? = nil,
1835318427
ask: AnyCodable? = nil,
1835418428
warningtext: AnyCodable? = nil,
18429+
scope: ApprovalScope? = nil,
1835518430
unavailabledecisions: [String]? = nil,
1835618431
commandspans: [[String: AnyCodable]]? = nil,
1835718432
agentid: AnyCodable? = nil,
@@ -18382,6 +18457,7 @@ public struct ExecApprovalRequestParams: Codable, Sendable {
1838218457
self.security = security
1838318458
self.ask = ask
1838418459
self.warningtext = warningtext
18460+
self.scope = scope
1838518461
self.unavailabledecisions = unavailabledecisions
1838618462
self.commandspans = commandspans
1838718463
self.agentid = agentid
@@ -18414,6 +18490,7 @@ public struct ExecApprovalRequestParams: Codable, Sendable {
1841418490
case security
1841518491
case ask
1841618492
case warningtext = "warningText"
18493+
case scope
1841718494
case unavailabledecisions = "unavailableDecisions"
1841818495
case commandspans = "commandSpans"
1841918496
case agentid = "agentId"
@@ -18778,6 +18855,7 @@ public struct PluginApprovalRequestParams: Codable, Sendable {
1877818855
public let description: String
1877918856
public let detail: String?
1878018857
public let severity: String?
18858+
public let scope: ApprovalScope?
1878118859
public let toolname: String?
1878218860
public let toolcallid: String?
1878318861
public let alloweddecisions: [String]?
@@ -18797,6 +18875,7 @@ public struct PluginApprovalRequestParams: Codable, Sendable {
1879718875
description: String,
1879818876
detail: String? = nil,
1879918877
severity: String? = nil,
18878+
scope: ApprovalScope? = nil,
1880018879
toolname: String? = nil,
1880118880
toolcallid: String? = nil,
1880218881
alloweddecisions: [String]? = nil,
@@ -18815,6 +18894,7 @@ public struct PluginApprovalRequestParams: Codable, Sendable {
1881518894
self.description = description
1881618895
self.detail = detail
1881718896
self.severity = severity
18897+
self.scope = scope
1881818898
self.toolname = toolname
1881918899
self.toolcallid = toolcallid
1882018900
self.alloweddecisions = alloweddecisions
@@ -18835,6 +18915,7 @@ public struct PluginApprovalRequestParams: Codable, Sendable {
1883518915
case description
1883618916
case detail
1883718917
case severity
18918+
case scope
1883818919
case toolname = "toolName"
1883918920
case toolcallid = "toolCallId"
1884018921
case alloweddecisions = "allowedDecisions"
@@ -21655,6 +21736,40 @@ public enum ToolsGitHubAuthorizePollResult: Codable, Sendable {
2165521736
}
2165621737
}
2165721738

21739+
public enum ApprovalScope: Codable, Sendable {
21740+
case messageSend(MessageSendApprovalScope)
21741+
case payment(PaymentApprovalScope)
21742+
case externalPost(ExternalPostApprovalScope)
21743+
21744+
private enum CodingKeys: String, CodingKey {
21745+
case discriminator = "kind"
21746+
}
21747+
21748+
public init(from decoder: Decoder) throws {
21749+
let container = try decoder.container(keyedBy: CodingKeys.self)
21750+
let discriminator = try container.decode(String.self, forKey: .discriminator)
21751+
switch discriminator {
21752+
case "message-send": self = try .messageSend(MessageSendApprovalScope(from: decoder))
21753+
case "payment": self = try .payment(PaymentApprovalScope(from: decoder))
21754+
case "external-post": self = try .externalPost(ExternalPostApprovalScope(from: decoder))
21755+
default:
21756+
throw DecodingError.dataCorruptedError(
21757+
forKey: .discriminator,
21758+
in: container,
21759+
debugDescription: "Unknown ApprovalScope discriminator value"
21760+
)
21761+
}
21762+
}
21763+
21764+
public func encode(to encoder: Encoder) throws {
21765+
switch self {
21766+
case .messageSend(let value): try value.encode(to: encoder)
21767+
case .payment(let value): try value.encode(to: encoder)
21768+
case .externalPost(let value): try value.encode(to: encoder)
21769+
}
21770+
}
21771+
}
21772+
2165821773
public enum ApprovalPresentation: Codable, Sendable {
2165921774
case exec(ExecApprovalPresentation)
2166021775
case plugin(PluginApprovalPresentation)

‎docs/plugins/plugin-permission-requests.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,65 @@ Write prompt text for the person who will approve the action:
8888
- `timeoutMs` defaults to 120000 (2 minutes) and is capped at 600000 (10
8989
minutes) regardless of the requested value.
9090

91+
## Declare approval scope
92+
93+
Set `requireApproval.scope` when your plugin knows the consequences of an
94+
operation. Scope is typed, optional, and display-only: it helps reviewers
95+
understand the action but never grants permission or changes the approval
96+
decision. The plugin declaring the approval supplies these facts; channels never
97+
infer scope from commands, titles, or message text.
98+
99+
For an email to three external recipients, include the destination, total
100+
recipient count, an optional preview, and the audience:
101+
102+
```typescript
103+
requireApproval: {
104+
title: "Send customer update",
105+
scope: {
106+
kind: "message-send",
107+
target: "email",
108+
recipientCount: 3,
109+
110+
audience: "external",
111+
},
112+
}
113+
```
114+
115+
For a payment, provide the exact decimal amount as a string, its currency, and
116+
the payee or payment system:
117+
118+
```typescript
119+
requireApproval: {
120+
title: "Pay invoice",
121+
scope: {
122+
kind: "payment",
123+
amount: "49.99",
124+
currency: "EUR",
125+
target: "Stripe",
126+
},
127+
}
128+
```
129+
130+
For an external post, identify its destination and declare its visibility:
131+
132+
```typescript
133+
requireApproval: {
134+
title: "Publish announcement",
135+
scope: {
136+
kind: "external-post",
137+
target: "github",
138+
visibility: "public",
139+
},
140+
}
141+
```
142+
143+
Message audiences can be `internal` or `external`; external-post visibility can
144+
be `public` or `restricted`. Recipient previews contain at most five identities.
145+
All strings are sanitized and bounded before display: targets and recipient
146+
identities are limited to 128 characters, payment amounts to 40, and currencies
147+
to 12. If sanitization would exceed a bound, OpenClaw omits the scope while
148+
preserving the normal approval prompt.
149+
91150
## Decision behavior
92151

93152
OpenClaw creates a pending approval with a `plugin:` ID, delivers it to the

‎docs/tools/exec-approvals.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,23 @@ context when forwarding approved `system.run` requests:
511511
- Once approved, the final forwarded `system.run` call reuses the stored plan instead of trusting later caller edits.
512512
- If the caller changes `command`, `rawCommand`, `cwd`, `agentId`, or `sessionKey` after the approval request was created, the gateway rejects the forwarded run as an approval mismatch.
513513

514+
## Approval scope summaries
515+
516+
An approval owner can attach a typed, display-only scope describing the action's
517+
blast radius. OpenClaw renders the sanitized summary on channel approval cards
518+
and includes the bounded scope in the safe approval presentation available to
519+
Control UI clients. Scope never grants authorization or changes approval policy.
520+
521+
- `message-send`: destination, recipient count, optional recipient preview, and
522+
whether the audience is internal or external.
523+
- `payment`: exact decimal amount, currency, and payee or payment system.
524+
- `external-post`: destination and whether the post is public or restricted.
525+
526+
For example, an email approval might show `Send to 3 recipients via email
527+
(external): [email protected], [email protected], +1 more`. Owners supply these
528+
facts; channels never infer them from commands or message text. Without a
529+
declared scope, approval cards render exactly as before.
530+
514531
## System events and denials
515532

516533
Exec lifecycle posts an `Exec finished` system message to the agent's

‎extensions/imessage/src/approval-native.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ function buildIMessageExecPendingPayload(params: { request: ExecApprovalRequest;
225225
cwd: params.request.request.cwd ?? undefined,
226226
host: params.request.request.host === "node" ? "node" : "gateway",
227227
nodeId: params.request.request.nodeId ?? undefined,
228+
scope: params.request.request.scope ?? undefined,
228229
sessionKey: params.request.request.sessionKey ?? null,
229230
expiresAtMs: params.request.expiresAtMs,
230231
nowMs: params.nowMs,

‎extensions/matrix/src/approval-handler.runtime.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ function buildPendingApprovalContent(params: {
308308
toolName: params.view.toolName ?? undefined,
309309
pluginId: params.view.pluginId ?? undefined,
310310
agentId: params.view.agentId ?? undefined,
311+
scope: params.view.scope ?? undefined,
311312
},
312313
createdAtMs: 0,
313314
expiresAtMs: params.view.expiresAtMs,
@@ -326,6 +327,7 @@ function buildPendingApprovalContent(params: {
326327
cwd: params.view.cwd ?? undefined,
327328
host: params.view.host === "node" ? "node" : "gateway",
328329
nodeId: params.view.nodeId ?? undefined,
330+
scope: params.view.scope ?? undefined,
329331
sessionKey: params.view.sessionKey ?? undefined,
330332
expiresAtMs: params.view.expiresAtMs,
331333
nowMs: params.nowMs,

‎extensions/slack/src/approval-handler.runtime.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ describe("slackApprovalNativeRuntime", () => {
394394
metadata: [
395395
{ label: "Severity", value: "Warning" },
396396
{ label: "Plugin", value: "computer-use" },
397+
{
398+
label: "Scope",
399+
value: "Send to 3 recipients via email (external): [email protected], +2 more",
400+
},
397401
],
398402
decisions: ["allow-once", "allow-always", "deny"],
399403
});
@@ -404,6 +408,12 @@ describe("slackApprovalNativeRuntime", () => {
404408
);
405409
expect(payload.text).toContain("Share screen with Computer Use");
406410
expect(payload.text).toContain("*Approval ID:* plugin:req-1");
411+
expect(payload.text).toContain(
412+
"*Scope:* Send to 3 recipients via email (external): [email protected], +2 more",
413+
);
414+
expect(readMrkdwnTexts(payload.blocks)).toContain(
415+
"*Scope:* Send to 3 recipients via email (external): [email protected], +2 more",
416+
);
407417
expect(payload.text).not.toContain("*Command*");
408418
const actionsBlock = findSlackActionsBlock(
409419
payload.blocks as Array<{ type?: string; elements?: unknown[] }>,

0 commit comments

Comments
 (0)