tencent-claw-shield 0.1.0-beta.4
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 +319 -0
- package/dist/contracts/core.d.ts +277 -0
- package/dist/contracts/events.d.ts +35 -0
- package/dist/contracts/host.d.ts +239 -0
- package/dist/contracts/index.d.ts +6 -0
- package/dist/contracts/operator.d.ts +112 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1 -0
- package/dist/runtime-core/sync-remote-worker.js +1 -0
- package/dist/types.d.ts +224 -0
- package/dist/version.d.ts +1 -0
- package/openclaw.plugin.json +76 -0
- package/package.json +69 -0
- package/remote-guard-config.example.json +30 -0
- package/remote-guard-config.json +30 -0
- package/scripts/claw-shieldctl.mjs +1663 -0
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# Claw Shield — AI Agent Runtime Security Plugin
|
|
2
|
+
|
|
3
|
+
[English](#english) | [中文](#中文)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<a id="中文"></a>
|
|
8
|
+
|
|
9
|
+
**Claw Shield** 是由腾讯安全 WAF 团队打造的 **AI Agent 运行时安全防护插件**,为 [OpenClaw](https://docs.openclaw.ai) Agent 提供全生命周期的安全治理能力。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
### 核心防护能力
|
|
14
|
+
|
|
15
|
+
Claw Shield 在 Agent 运行时的关键节点自动拦截并执行安全检测,覆盖以下防护场景:
|
|
16
|
+
|
|
17
|
+
#### 输入安全防护
|
|
18
|
+
|
|
19
|
+
- **提示词注入检测** — 识别并拦截恶意 Prompt Injection 攻击
|
|
20
|
+
- **敏感内容过滤** — 对用户输入中的违规、有害内容进行实时检测
|
|
21
|
+
|
|
22
|
+
#### 工具调用防护
|
|
23
|
+
|
|
24
|
+
- **危险工具拦截** — 对高风险工具调用(如文件操作、命令执行)进行实时阻断
|
|
25
|
+
- **参数合规校验** — 检测工具调用参数中的越权、注入等安全风险
|
|
26
|
+
- **Skill 安全审计** — 自动收集并上报 Agent 已安装的 Skill 信息,支持远端检测与策略管控
|
|
27
|
+
|
|
28
|
+
#### 输出安全防护
|
|
29
|
+
|
|
30
|
+
- **内容脱敏** — 对 Agent 输出中的敏感信息(如密钥、个人隐私)进行自动脱敏
|
|
31
|
+
- **外发内容审查** — 在消息发送前进行安全检查,防止敏感信息泄露
|
|
32
|
+
|
|
33
|
+
#### 模型交互防护
|
|
34
|
+
|
|
35
|
+
- **LLM 请求审计** — 记录并检测发送给大模型的请求内容
|
|
36
|
+
- **响应内容检测** — 对模型返回结果进行安全合规检查
|
|
37
|
+
|
|
38
|
+
#### 安全运营
|
|
39
|
+
|
|
40
|
+
- **安全事件留痕** — 自动记录所有安全检测事件,支持查询与审计
|
|
41
|
+
- **实时遥测上报** — 基于 WebSocket 长连接的心跳与数据上报,实现集中化安全态势感知
|
|
42
|
+
- **远端策略管控** — 所有防护策略由远端安全服务统一下发,支持动态调整,无需重启 Agent
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### 技术特性
|
|
47
|
+
|
|
48
|
+
- **零侵入集成** — 作为 OpenClaw 标准插件运行,无需修改 Agent 业务代码
|
|
49
|
+
- **同步 + 异步双路径** — 关键路径(如工具调用阻断)采用同步检测确保实时拦截;非关键路径采用异步检测降低延迟影响
|
|
50
|
+
- **高可用容错** — 远端服务不可达时自动 fallback 放行,不影响 Agent 正常运行
|
|
51
|
+
- **闭源加密交付** — 核心代码经混淆加密处理,安全可控
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 环境要求
|
|
56
|
+
|
|
57
|
+
- **Node.js >= 20**(LTS 版本,推荐 20.x 或 22.x)
|
|
58
|
+
- [OpenClaw](https://docs.openclaw.ai) Agent 运行环境
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### 快速安装
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx -y tencent-claw-shield install --global
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
安装过程中会依次提示配置:
|
|
69
|
+
|
|
70
|
+
1. **API Key** — 用于远端安全服务认证
|
|
71
|
+
2. **Server 地址** — 远端安全检测服务的 IP 和端口
|
|
72
|
+
3. **WebSocket 地址** — 遥测上报服务的 IP 和端口
|
|
73
|
+
|
|
74
|
+
也支持非交互式安装:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx -y tencent-claw-shield install --global \
|
|
78
|
+
--api-key '<your-api-key>' \
|
|
79
|
+
--server-address <[http|https://]ip:port> \
|
|
80
|
+
--ws-address <[ws|wss://]ip:port>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> Server 地址支持 `http://` 和 `https://` 协议前缀(如 `https://203.0.113.1:443`),不填默认为 `http`。
|
|
84
|
+
> WebSocket 地址支持 `ws://` 和 `wss://` 协议前缀(如 `wss://203.0.113.1:8081`),不填默认为 `ws`。
|
|
85
|
+
> HTTPS / WSS 模式下均会自动跳过证书校验。
|
|
86
|
+
|
|
87
|
+
#### 其他常用命令
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# 更新插件
|
|
91
|
+
npx -y tencent-claw-shield update --global
|
|
92
|
+
|
|
93
|
+
# 一次性修改 API Key + Server + WebSocket 地址(交互式依次提示)
|
|
94
|
+
npx -y tencent-claw-shield set-config
|
|
95
|
+
|
|
96
|
+
# 也可通过参数直接传入(非交互式)
|
|
97
|
+
npx -y tencent-claw-shield set-config --api-key '<key>' --server-address <ip:port> --ws-address <ip:port>
|
|
98
|
+
|
|
99
|
+
# 单独修改 API Key
|
|
100
|
+
npx -y tencent-claw-shield set-api-key --global
|
|
101
|
+
|
|
102
|
+
# 单独修改 Server 地址(支持 https 协议前缀)
|
|
103
|
+
npx -y tencent-claw-shield set-server --server-address <ip:port>
|
|
104
|
+
npx -y tencent-claw-shield set-server --server-address https://203.0.113.1:443
|
|
105
|
+
|
|
106
|
+
# 单独修改 WebSocket 地址(支持 wss 协议前缀)
|
|
107
|
+
npx -y tencent-claw-shield set-websocket --ws-address <ip:port>
|
|
108
|
+
npx -y tencent-claw-shield set-websocket --ws-address wss://203.0.113.1:8081
|
|
109
|
+
|
|
110
|
+
# 热刷新配置
|
|
111
|
+
npx -y tencent-claw-shield reload
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### 卸载
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# 一键卸载(保留认证文件,方便重新安装时复用)
|
|
118
|
+
npx -y tencent-claw-shield uninstall --global
|
|
119
|
+
|
|
120
|
+
# 完全卸载(同时删除认证文件)
|
|
121
|
+
npx -y tencent-claw-shield uninstall --global --purge
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### 临时关闭 / 恢复防护
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# 一键关闭所有防护(安全检测、遥测上报、Skills 上报全部暂停)
|
|
128
|
+
npx -y tencent-claw-shield bypass
|
|
129
|
+
|
|
130
|
+
# 恢复所有防护
|
|
131
|
+
npx -y tencent-claw-shield resume
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
> Bypass 模式下插件仍然加载在 OpenClaw 中,但所有 Hook 会直接放行,不会调用远端检测服务。执行 `resume` 后立即恢复全部防护能力,无需重启 Gateway。
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### 接入说明
|
|
139
|
+
|
|
140
|
+
Claw Shield 的安全检测能力依赖**远端防护策略服务**。您需要在远端平台完成安全策略配置后,插件才能正常提供防护。
|
|
141
|
+
|
|
142
|
+
当前版本以 OpenClaw Agent 为首要集成目标,后续计划支持更多 AI Agent 框架接入。
|
|
143
|
+
|
|
144
|
+
#### 咨询与接入
|
|
145
|
+
|
|
146
|
+
如果您希望了解更多产品信息或接入使用,请联系:
|
|
147
|
+
|
|
148
|
+
**邮箱:lukayi@tencent.com**
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
### 关于我们
|
|
153
|
+
|
|
154
|
+
Claw Shield 由**腾讯安全 WAF 团队**研发,致力于为 AI Agent 生态提供专业的运行时安全防护方案。
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### License
|
|
159
|
+
|
|
160
|
+
UNLICENSED — 本软件为闭源商业软件,未经授权不得复制、修改或分发。
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
<a id="english"></a>
|
|
165
|
+
|
|
166
|
+
[English](#english) | [中文](#中文)
|
|
167
|
+
|
|
168
|
+
**Claw Shield** is an **AI Agent runtime security plugin** built by the **Tencent Security WAF Team**, providing full-lifecycle security governance for [OpenClaw](https://docs.openclaw.ai) Agents.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### Core Security Capabilities
|
|
173
|
+
|
|
174
|
+
Claw Shield automatically intercepts and performs security checks at critical points during Agent runtime, covering the following scenarios:
|
|
175
|
+
|
|
176
|
+
#### Input Protection
|
|
177
|
+
|
|
178
|
+
- **Prompt Injection Detection** — Identifies and blocks malicious Prompt Injection attacks
|
|
179
|
+
- **Sensitive Content Filtering** — Real-time detection of harmful or non-compliant content in user input
|
|
180
|
+
|
|
181
|
+
#### Tool Call Protection
|
|
182
|
+
|
|
183
|
+
- **Dangerous Tool Blocking** — Real-time blocking of high-risk tool calls (e.g., file operations, command execution)
|
|
184
|
+
- **Parameter Compliance Validation** — Detects privilege escalation, injection, and other security risks in tool call parameters
|
|
185
|
+
- **Skill Security Audit** — Automatically collects and reports installed Skill information for remote detection and policy enforcement
|
|
186
|
+
|
|
187
|
+
#### Output Protection
|
|
188
|
+
|
|
189
|
+
- **Content Redaction** — Automatically redacts sensitive information (e.g., secrets, personal data) in Agent output
|
|
190
|
+
- **Outbound Content Review** — Security checks before message delivery to prevent sensitive data leakage
|
|
191
|
+
|
|
192
|
+
#### Model Interaction Protection
|
|
193
|
+
|
|
194
|
+
- **LLM Request Audit** — Records and inspects content sent to large language models
|
|
195
|
+
- **Response Content Detection** — Security compliance checks on model responses
|
|
196
|
+
|
|
197
|
+
#### Security Operations
|
|
198
|
+
|
|
199
|
+
- **Security Event Logging** — Automatically records all security detection events with full query and audit support
|
|
200
|
+
- **Real-time Telemetry** — Heartbeat and data reporting via WebSocket for centralized security posture awareness
|
|
201
|
+
- **Remote Policy Management** — All security policies are centrally managed and dynamically pushed from the remote security service, with no Agent restart required
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### Technical Highlights
|
|
206
|
+
|
|
207
|
+
- **Zero-intrusion Integration** — Runs as a standard OpenClaw plugin with no changes to Agent business code
|
|
208
|
+
- **Sync + Async Dual Path** — Critical paths (e.g., tool call blocking) use synchronous detection for real-time enforcement; non-critical paths use async detection to minimize latency impact
|
|
209
|
+
- **High Availability & Fault Tolerance** — Automatically falls back to allow when the remote service is unreachable, ensuring uninterrupted Agent operation
|
|
210
|
+
- **Closed-source Encrypted Delivery** — Core code is obfuscated and encrypted for security
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### Requirements
|
|
215
|
+
|
|
216
|
+
- **Node.js >= 20** (LTS version, recommended 20.x or 22.x)
|
|
217
|
+
- [OpenClaw](https://docs.openclaw.ai) Agent runtime environment
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### Quick Install
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
npx -y tencent-claw-shield install --global
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The installer will prompt you to configure the following in sequence:
|
|
228
|
+
|
|
229
|
+
1. **API Key** — For remote security service authentication
|
|
230
|
+
2. **Server Address** — IP and port of the remote security detection service
|
|
231
|
+
3. **WebSocket Address** — IP and port of the telemetry reporting service
|
|
232
|
+
|
|
233
|
+
Non-interactive installation is also supported:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
npx -y tencent-claw-shield install --global \
|
|
237
|
+
--api-key '<your-api-key>' \
|
|
238
|
+
--server-address <[http|https://]ip:port> \
|
|
239
|
+
--ws-address <[ws|wss://]ip:port>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
> Server addresses support `http://` and `https://` protocol prefixes (e.g., `https://203.0.113.1:443`). Defaults to `http` if omitted.
|
|
243
|
+
> WebSocket addresses support `ws://` and `wss://` protocol prefixes (e.g., `wss://203.0.113.1:8081`). Defaults to `ws` if omitted.
|
|
244
|
+
> Certificate verification is automatically skipped in HTTPS / WSS mode.
|
|
245
|
+
|
|
246
|
+
#### Common Commands
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
# Update plugin
|
|
250
|
+
npx -y tencent-claw-shield update --global
|
|
251
|
+
|
|
252
|
+
# Configure API Key + Server + WebSocket at once (interactive prompts)
|
|
253
|
+
npx -y tencent-claw-shield set-config
|
|
254
|
+
|
|
255
|
+
# Or pass all parameters directly (non-interactive)
|
|
256
|
+
npx -y tencent-claw-shield set-config --api-key '<key>' --server-address <ip:port> --ws-address <ip:port>
|
|
257
|
+
|
|
258
|
+
# Modify API Key only
|
|
259
|
+
npx -y tencent-claw-shield set-api-key --global
|
|
260
|
+
|
|
261
|
+
# Modify Server address only (supports https:// prefix)
|
|
262
|
+
npx -y tencent-claw-shield set-server --server-address <ip:port>
|
|
263
|
+
npx -y tencent-claw-shield set-server --server-address https://203.0.113.1:443
|
|
264
|
+
|
|
265
|
+
# Modify WebSocket address only (supports wss:// prefix)
|
|
266
|
+
npx -y tencent-claw-shield set-websocket --ws-address <ip:port>
|
|
267
|
+
npx -y tencent-claw-shield set-websocket --ws-address wss://203.0.113.1:8081
|
|
268
|
+
|
|
269
|
+
# Hot-reload configuration
|
|
270
|
+
npx -y tencent-claw-shield reload
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### Uninstall
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Uninstall (keeps auth files for easy reinstallation)
|
|
277
|
+
npx -y tencent-claw-shield uninstall --global
|
|
278
|
+
|
|
279
|
+
# Full uninstall (also removes auth files)
|
|
280
|
+
npx -y tencent-claw-shield uninstall --global --purge
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
#### Temporarily Disable / Restore Protection
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# Disable all protection (security checks, telemetry, Skills reporting all paused)
|
|
287
|
+
npx -y tencent-claw-shield bypass
|
|
288
|
+
|
|
289
|
+
# Restore all protection
|
|
290
|
+
npx -y tencent-claw-shield resume
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
> In bypass mode, the plugin remains loaded in OpenClaw but all Hooks pass through directly without calling the remote detection service. Running `resume` immediately restores full protection — no Gateway restart required.
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### Integration Guide
|
|
298
|
+
|
|
299
|
+
Claw Shield's security detection capabilities rely on a **remote security policy service**. You need to complete security policy configuration on the remote platform before the plugin can provide protection.
|
|
300
|
+
|
|
301
|
+
The current version primarily targets OpenClaw Agent integration, with plans to support additional AI Agent frameworks in the future.
|
|
302
|
+
|
|
303
|
+
#### Contact & Onboarding
|
|
304
|
+
|
|
305
|
+
For more product information or to get started, please contact:
|
|
306
|
+
|
|
307
|
+
**Email: lukayi@tencent.com**
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
### About Us
|
|
312
|
+
|
|
313
|
+
Claw Shield is developed by the **Tencent Security WAF Team**, dedicated to providing professional runtime security solutions for the AI Agent ecosystem.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
### License
|
|
318
|
+
|
|
319
|
+
UNLICENSED — This is closed-source commercial software. Unauthorized copying, modification, or distribution is prohibited.
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import type { ShieldApprovalCategory, ShieldFailMode, ShieldSeverity, ShieldStage, ShieldSurface } from "../types";
|
|
2
|
+
/** 统一钩子名称枚举:对应 Agent 生命周期中的各个检测点 */
|
|
3
|
+
export type ShieldCanonicalHookName = "message_received" | "before_llm_request" | "before_tool_call" | "message_sending" | "before_message_write" | "tool_result_persist";
|
|
4
|
+
/**
|
|
5
|
+
* 兼容别名:历史代码使用 ShieldHookName,等价于统一钩子名
|
|
6
|
+
* 后续建议优先使用 ShieldCanonicalHookName
|
|
7
|
+
*/
|
|
8
|
+
export type ShieldHookName = ShieldCanonicalHookName;
|
|
9
|
+
/** 宿主类型 */
|
|
10
|
+
export type HostType = "openclaw" | "langchain" | "custom";
|
|
11
|
+
/** 宿主信息(用于跨宿主接入时标识来源) */
|
|
12
|
+
export type HostInfo = {
|
|
13
|
+
hostType: HostType;
|
|
14
|
+
hostVersion?: string;
|
|
15
|
+
};
|
|
16
|
+
/** 钩子信封基础类型:所有钩子事件的公共字段 */
|
|
17
|
+
export type HookEnvelopeBase = {
|
|
18
|
+
/** 统一钩子名:评估引擎优先依赖该字段 */
|
|
19
|
+
canonicalHook: ShieldCanonicalHookName;
|
|
20
|
+
/** 宿主原始钩子名(不同宿主可不一致) */
|
|
21
|
+
hostHookName: string;
|
|
22
|
+
surface: ShieldSurface;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
agentId?: string;
|
|
25
|
+
runId?: string;
|
|
26
|
+
sessionId?: string;
|
|
27
|
+
sessionKey?: string;
|
|
28
|
+
hostInfo?: HostInfo;
|
|
29
|
+
/** 宿主平台传递的上下文信息 */
|
|
30
|
+
hostContext: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
/** 入口钩子信封:用户消息到达时触发 */
|
|
33
|
+
export type IngressEnvelope = HookEnvelopeBase & {
|
|
34
|
+
canonicalHook: "message_received";
|
|
35
|
+
hostHookName: "message_received" | "before_prompt_build";
|
|
36
|
+
surface: "ingress";
|
|
37
|
+
payload: {
|
|
38
|
+
message: unknown;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/** LLM 请求钩子信封:向大模型发送请求前触发 */
|
|
42
|
+
export type LlmRequestEnvelope = HookEnvelopeBase & {
|
|
43
|
+
canonicalHook: "before_llm_request";
|
|
44
|
+
hostHookName: "llm_input";
|
|
45
|
+
surface: "llm";
|
|
46
|
+
payload: {
|
|
47
|
+
provider: string;
|
|
48
|
+
model: string;
|
|
49
|
+
prompt: string;
|
|
50
|
+
systemPrompt?: string;
|
|
51
|
+
historyMessages: unknown[];
|
|
52
|
+
skillNames?: string[];
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/** 工具调用钩子信封:执行工具调用前触发 */
|
|
56
|
+
export type ToolCallEnvelope = HookEnvelopeBase & {
|
|
57
|
+
canonicalHook: "before_tool_call";
|
|
58
|
+
hostHookName: "before_tool_call";
|
|
59
|
+
surface: "tool";
|
|
60
|
+
payload: {
|
|
61
|
+
toolName: string;
|
|
62
|
+
toolParams: Record<string, unknown>;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** 出口钩子信封:向用户发送消息前触发 */
|
|
66
|
+
export type EgressEnvelope = HookEnvelopeBase & {
|
|
67
|
+
canonicalHook: "message_sending";
|
|
68
|
+
hostHookName: "message_sending";
|
|
69
|
+
surface: "egress";
|
|
70
|
+
payload: {
|
|
71
|
+
message: unknown;
|
|
72
|
+
channel?: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/** 持久化钩子信封:写入消息或工具结果前触发 */
|
|
76
|
+
export type PersistEnvelope = HookEnvelopeBase & {
|
|
77
|
+
canonicalHook: "before_message_write" | "tool_result_persist";
|
|
78
|
+
hostHookName: "before_message_write" | "tool_result_persist";
|
|
79
|
+
surface: "persist";
|
|
80
|
+
payload: {
|
|
81
|
+
message?: unknown;
|
|
82
|
+
toolName?: string;
|
|
83
|
+
toolResult?: unknown;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/** 钩子信封联合类型:所有钩子信封的联合 */
|
|
87
|
+
export type HookEnvelope = IngressEnvelope | LlmRequestEnvelope | ToolCallEnvelope | EgressEnvelope | PersistEnvelope;
|
|
88
|
+
/** 原因代码:标识安全问题的分类 */
|
|
89
|
+
export type ReasonCode = "prompt_injection" | "retrieval_poisoning" | "sensitive_action" | "egress_exfiltration" | "mcp_allowlist_violation" | "model_governance_violation" | "approval_required" | "unknown";
|
|
90
|
+
/** 标准化的检测发现:将各种来源的发现统一为标准格式 */
|
|
91
|
+
export type NormalizedFinding = {
|
|
92
|
+
findingId: string;
|
|
93
|
+
detector: string;
|
|
94
|
+
reasonCode: ReasonCode;
|
|
95
|
+
severity: ShieldSeverity;
|
|
96
|
+
summary: string;
|
|
97
|
+
tags: string[];
|
|
98
|
+
evidence?: Record<string, unknown>;
|
|
99
|
+
matchedRuleIds?: string[];
|
|
100
|
+
};
|
|
101
|
+
/** 审批工单草案:创建审批请求时的初始数据 */
|
|
102
|
+
export type ApprovalTicketDraft = {
|
|
103
|
+
category: ShieldApprovalCategory;
|
|
104
|
+
reason: string;
|
|
105
|
+
severity: ShieldSeverity;
|
|
106
|
+
tags?: string[];
|
|
107
|
+
agentId?: string;
|
|
108
|
+
runId?: string;
|
|
109
|
+
sessionId?: string;
|
|
110
|
+
toolName?: string;
|
|
111
|
+
/** 审批来源绑定(关联外部审批系统) */
|
|
112
|
+
sourceBinding?: {
|
|
113
|
+
source: string;
|
|
114
|
+
externalApprovalId?: string;
|
|
115
|
+
};
|
|
116
|
+
/** 相关资源信息 */
|
|
117
|
+
resource?: {
|
|
118
|
+
toolName?: string;
|
|
119
|
+
provider?: string;
|
|
120
|
+
model?: string;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
/** 运行暂停草案:创建运行暂停时的初始数据 */
|
|
124
|
+
export type RunHoldDraft = {
|
|
125
|
+
toolName: string;
|
|
126
|
+
toolParams?: Record<string, unknown>;
|
|
127
|
+
/** 暂停时所处的护盾阶段 */
|
|
128
|
+
stageAtHold: ShieldStage;
|
|
129
|
+
/** 暂停时的失败模式 */
|
|
130
|
+
failModeAtHold: ShieldFailMode;
|
|
131
|
+
category?: ShieldApprovalCategory;
|
|
132
|
+
severity?: ShieldSeverity;
|
|
133
|
+
reason?: string;
|
|
134
|
+
agentId?: string;
|
|
135
|
+
runId?: string;
|
|
136
|
+
sessionId?: string;
|
|
137
|
+
};
|
|
138
|
+
/** 执行计划草案:描述即将执行的操作类型和要求 */
|
|
139
|
+
export type ExecutionPlanDraft = {
|
|
140
|
+
/** 操作类型:llm_request=LLM请求 | tool_call=工具调用 | message_send=消息发送 */
|
|
141
|
+
actionType: "llm_request" | "tool_call" | "message_send";
|
|
142
|
+
/** 要求的后端环境 */
|
|
143
|
+
requiredBackend?: "local" | "sandbox" | "remote_controlled";
|
|
144
|
+
/** 沙箱配置 */
|
|
145
|
+
sandboxProfile?: string;
|
|
146
|
+
/** 审批模式 */
|
|
147
|
+
approvalMode?: "none" | "required" | "already_bound";
|
|
148
|
+
/** 预算配置 */
|
|
149
|
+
budgetProfile?: string;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* 决策效果联合类型:描述护栏决策产生的各种效果
|
|
153
|
+
* - allow: 放行
|
|
154
|
+
* - redact: 脱敏(指定字段和替换值)
|
|
155
|
+
* - block: 拦截(附带原因)
|
|
156
|
+
* - queue_approval: 排队等待审批
|
|
157
|
+
* - create_run_hold: 暂停运行
|
|
158
|
+
* - require_model_profile: 要求使用指定模型配置
|
|
159
|
+
* - restrict_model: 限制可用的模型/提供商
|
|
160
|
+
* - route_execution: 路由到指定执行计划
|
|
161
|
+
* - emit_audit: 发出审计事件
|
|
162
|
+
*/
|
|
163
|
+
export type DecisionEffect = {
|
|
164
|
+
type: "allow";
|
|
165
|
+
} | {
|
|
166
|
+
type: "redact";
|
|
167
|
+
targets: Array<{
|
|
168
|
+
field: string;
|
|
169
|
+
replacement: string;
|
|
170
|
+
ruleId?: string;
|
|
171
|
+
value?: unknown;
|
|
172
|
+
}>;
|
|
173
|
+
} | {
|
|
174
|
+
type: "block";
|
|
175
|
+
reason: string;
|
|
176
|
+
} | {
|
|
177
|
+
type: "queue_approval";
|
|
178
|
+
ticket: ApprovalTicketDraft;
|
|
179
|
+
} | {
|
|
180
|
+
type: "create_run_hold";
|
|
181
|
+
hold: RunHoldDraft;
|
|
182
|
+
} | {
|
|
183
|
+
type: "require_model_profile";
|
|
184
|
+
profileId: string;
|
|
185
|
+
} | {
|
|
186
|
+
type: "restrict_model";
|
|
187
|
+
allowedProviderIds?: string[];
|
|
188
|
+
allowedModelIds?: string[];
|
|
189
|
+
} | {
|
|
190
|
+
type: "route_execution";
|
|
191
|
+
plan: ExecutionPlanDraft;
|
|
192
|
+
} | {
|
|
193
|
+
type: "emit_audit";
|
|
194
|
+
eventType: string;
|
|
195
|
+
};
|
|
196
|
+
/** 护栏决策:一次完整的安全评估决策结果 */
|
|
197
|
+
export type GuardrailDecision = {
|
|
198
|
+
decisionId: string;
|
|
199
|
+
/** 触发决策的钩子信封引用 */
|
|
200
|
+
envelopeRef: {
|
|
201
|
+
/** 统一钩子名 */
|
|
202
|
+
canonicalHook: ShieldCanonicalHookName;
|
|
203
|
+
/** 宿主原始钩子名(可选,跨宿主时可能与 canonicalHook 不同) */
|
|
204
|
+
hostHookName?: string;
|
|
205
|
+
surface: ShieldSurface;
|
|
206
|
+
agentId?: string;
|
|
207
|
+
runId?: string;
|
|
208
|
+
sessionId?: string;
|
|
209
|
+
};
|
|
210
|
+
/** 当前护盾阶段 */
|
|
211
|
+
stage: ShieldStage;
|
|
212
|
+
severity: ShieldSeverity;
|
|
213
|
+
/** 标准化检测发现列表 */
|
|
214
|
+
findings: NormalizedFinding[];
|
|
215
|
+
/** 决策产生的效果列表 */
|
|
216
|
+
effects: DecisionEffect[];
|
|
217
|
+
/** 原因代码列表 */
|
|
218
|
+
reasonCodes: ReasonCode[];
|
|
219
|
+
tags: string[];
|
|
220
|
+
/** 是否为模拟模式 */
|
|
221
|
+
simulated: boolean;
|
|
222
|
+
/** 评估耗时(毫秒) */
|
|
223
|
+
durationMs: number;
|
|
224
|
+
};
|
|
225
|
+
/** 审批状态 */
|
|
226
|
+
export type ApprovalStatus = "pending" | "approved" | "rejected" | "expired" | "cancelled";
|
|
227
|
+
/** 审批工单(完整版):在草案基础上增加了 ID、状态和时间戳等运行时字段 */
|
|
228
|
+
export type ApprovalTicket = ApprovalTicketDraft & {
|
|
229
|
+
approvalId: string;
|
|
230
|
+
incidentId?: string;
|
|
231
|
+
status: ApprovalStatus;
|
|
232
|
+
createdAt: number;
|
|
233
|
+
resolvedAt?: number;
|
|
234
|
+
resolvedBy?: string;
|
|
235
|
+
note?: string;
|
|
236
|
+
};
|
|
237
|
+
/** 运行暂停状态 */
|
|
238
|
+
export type RunHoldStatus = "pending" | "approved_waiting_resume" | "resumed" | "rejected" | "expired" | "cancelled";
|
|
239
|
+
/** 运行暂停工单(完整版):在草案基础上增加了 ID、状态和时间戳 */
|
|
240
|
+
export type RunHoldTicket = RunHoldDraft & {
|
|
241
|
+
holdId: string;
|
|
242
|
+
approvalId: string;
|
|
243
|
+
status: RunHoldStatus;
|
|
244
|
+
createdAt: number;
|
|
245
|
+
resumedAt?: number;
|
|
246
|
+
cancelledAt?: number;
|
|
247
|
+
};
|
|
248
|
+
/** 执行计划(完整版):在草案基础上增加了模型限制和出口策略等 */
|
|
249
|
+
export type ExecutionPlan = ExecutionPlanDraft & {
|
|
250
|
+
planId: string;
|
|
251
|
+
allowedProviderIds?: string[];
|
|
252
|
+
allowedModelIds?: string[];
|
|
253
|
+
requiredModelProfile?: string;
|
|
254
|
+
/** 出口策略:限制目标地址和渠道 */
|
|
255
|
+
egressPolicy?: {
|
|
256
|
+
destinationAllowlist?: string[];
|
|
257
|
+
channelAllowlist?: string[];
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
/** 审计事件类型枚举 */
|
|
261
|
+
export type AuditEventType = "decision.made" | "decision.blocked" | "approval.queued" | "approval.resolved" | "run_hold.created" | "run_hold.resumed" | "hitl.deadletter.queued" | "hitl.deadletter.resolved";
|
|
262
|
+
/** 审计事件:记录系统中发生的每一个重要安全事件 */
|
|
263
|
+
export type AuditEvent = {
|
|
264
|
+
eventId: string;
|
|
265
|
+
eventType: AuditEventType;
|
|
266
|
+
timestamp: number;
|
|
267
|
+
decisionId?: string;
|
|
268
|
+
approvalId?: string;
|
|
269
|
+
holdId?: string;
|
|
270
|
+
agentId?: string;
|
|
271
|
+
runId?: string;
|
|
272
|
+
sessionId?: string;
|
|
273
|
+
/** 事件的详细数据 */
|
|
274
|
+
payload: Record<string, unknown>;
|
|
275
|
+
/** Schema 版本号 */
|
|
276
|
+
schemaVersion: 1;
|
|
277
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** 护盾网关事件常量:定义所有可以通过网关发布的事件名称 */
|
|
2
|
+
export declare const SHIELD_GATEWAY_EVENTS: {
|
|
3
|
+
readonly decision: "shield.decision";
|
|
4
|
+
readonly blocked: "shield.blocked";
|
|
5
|
+
readonly stageChanged: "shield.stage.changed";
|
|
6
|
+
readonly approvalQueued: "shield.approval.queued";
|
|
7
|
+
readonly approvalResolved: "shield.approval.resolved";
|
|
8
|
+
readonly hitlDeadLetterQueued: "shield.hitl.deadletter.queued";
|
|
9
|
+
readonly hitlDeadLetterResolved: "shield.hitl.deadletter.resolved";
|
|
10
|
+
};
|
|
11
|
+
/** 网关事件的通用包装类型 */
|
|
12
|
+
export type GatewayEvent<T = unknown> = {
|
|
13
|
+
eventName: string;
|
|
14
|
+
data: T;
|
|
15
|
+
};
|
|
16
|
+
/** 决策事件数据:决策做出时附带的信息 */
|
|
17
|
+
export type DecisionEventData = {
|
|
18
|
+
decisionId: string;
|
|
19
|
+
hook: string;
|
|
20
|
+
surface: string;
|
|
21
|
+
stage: string;
|
|
22
|
+
severity: string;
|
|
23
|
+
effects: unknown[];
|
|
24
|
+
reasonCodes: string[];
|
|
25
|
+
simulated: boolean;
|
|
26
|
+
durationMs: number;
|
|
27
|
+
};
|
|
28
|
+
/** 拦截事件数据:请求被拦截时附带的信息 */
|
|
29
|
+
export type BlockedEventData = {
|
|
30
|
+
decisionId: string;
|
|
31
|
+
hook: string;
|
|
32
|
+
surface: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
findings: unknown[];
|
|
35
|
+
};
|