agent-moss 0.2.0__tar.gz

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.
Files changed (62) hide show
  1. agent_moss-0.2.0/LICENSE +21 -0
  2. agent_moss-0.2.0/MANIFEST.in +4 -0
  3. agent_moss-0.2.0/PKG-INFO +432 -0
  4. agent_moss-0.2.0/README.md +414 -0
  5. agent_moss-0.2.0/agent_moss/__init__.py +3 -0
  6. agent_moss-0.2.0/agent_moss/__version__.py +1 -0
  7. agent_moss-0.2.0/agent_moss/adapters/__init__.py +7 -0
  8. agent_moss-0.2.0/agent_moss/adapters/observable.py +104 -0
  9. agent_moss-0.2.0/agent_moss/cli.py +130 -0
  10. agent_moss-0.2.0/agent_moss/engine/__init__.py +18 -0
  11. agent_moss-0.2.0/agent_moss/engine/analyzer.py +288 -0
  12. agent_moss-0.2.0/agent_moss/engine/coordinator.py +261 -0
  13. agent_moss-0.2.0/agent_moss/engine/heuristic.py +213 -0
  14. agent_moss-0.2.0/agent_moss/engine/llm_analyzer.py +250 -0
  15. agent_moss-0.2.0/agent_moss/engine/logic_rules.py +219 -0
  16. agent_moss-0.2.0/agent_moss/engine/script_analyzer.py +347 -0
  17. agent_moss-0.2.0/agent_moss/engine/skill_engine.py +195 -0
  18. agent_moss-0.2.0/agent_moss/engine/types.py +48 -0
  19. agent_moss-0.2.0/agent_moss/infra/__init__.py +0 -0
  20. agent_moss-0.2.0/agent_moss/infra/config.json +31 -0
  21. agent_moss-0.2.0/agent_moss/infra/config.py +372 -0
  22. agent_moss-0.2.0/agent_moss/infra/llm_client.py +215 -0
  23. agent_moss-0.2.0/agent_moss/infra/logging.py +95 -0
  24. agent_moss-0.2.0/agent_moss/infra/parsers.py +249 -0
  25. agent_moss-0.2.0/agent_moss/infra/policy_cache.py +175 -0
  26. agent_moss-0.2.0/agent_moss/infra/prompt_templates.py +130 -0
  27. agent_moss-0.2.0/agent_moss/profiles/__init__.py +52 -0
  28. agent_moss-0.2.0/agent_moss/profiles/base.py +106 -0
  29. agent_moss-0.2.0/agent_moss/profiles/linux.py +339 -0
  30. agent_moss-0.2.0/agent_moss/profiles/windows.py +258 -0
  31. agent_moss-0.2.0/agent_moss/rules/user_rules.json +77 -0
  32. agent_moss-0.2.0/agent_moss/server/__init__.py +1 -0
  33. agent_moss-0.2.0/agent_moss/server/app.py +55 -0
  34. agent_moss-0.2.0/agent_moss/server/middleware.py +32 -0
  35. agent_moss-0.2.0/agent_moss/server/models.py +50 -0
  36. agent_moss-0.2.0/agent_moss/server/routes.py +83 -0
  37. agent_moss-0.2.0/agent_moss/server/socket_server.py +40 -0
  38. agent_moss-0.2.0/agent_moss/skills/browser_web_access_guard.md +31 -0
  39. agent_moss-0.2.0/agent_moss/skills/data_exfiltration_guard.md +33 -0
  40. agent_moss-0.2.0/agent_moss/skills/email_operation_guard.md +30 -0
  41. agent_moss-0.2.0/agent_moss/skills/file_access_guard.md +33 -0
  42. agent_moss-0.2.0/agent_moss/skills/general_tool_risk_guard.md +33 -0
  43. agent_moss-0.2.0/agent_moss/skills/intent_deviation_guard.md +39 -0
  44. agent_moss-0.2.0/agent_moss/skills/lateral_movement_guard.md +31 -0
  45. agent_moss-0.2.0/agent_moss/skills/persistence_backdoor_guard.md +32 -0
  46. agent_moss-0.2.0/agent_moss/skills/resource_exhaustion_guard.md +32 -0
  47. agent_moss-0.2.0/agent_moss/skills/script_execution_guard.md +37 -0
  48. agent_moss-0.2.0/agent_moss/skills/skill_installation_guard.md +30 -0
  49. agent_moss-0.2.0/agent_moss/skills/supply_chain_guard.md +31 -0
  50. agent_moss-0.2.0/agent_moss/templates/policy_mapping.md +87 -0
  51. agent_moss-0.2.0/agent_moss/templates/prompt1_template.txt +62 -0
  52. agent_moss-0.2.0/agent_moss/templates/prompt2_template.txt +45 -0
  53. agent_moss-0.2.0/agent_moss/templates/security_judge_template.txt +71 -0
  54. agent_moss-0.2.0/agent_moss.egg-info/PKG-INFO +432 -0
  55. agent_moss-0.2.0/agent_moss.egg-info/SOURCES.txt +60 -0
  56. agent_moss-0.2.0/agent_moss.egg-info/dependency_links.txt +1 -0
  57. agent_moss-0.2.0/agent_moss.egg-info/entry_points.txt +2 -0
  58. agent_moss-0.2.0/agent_moss.egg-info/requires.txt +11 -0
  59. agent_moss-0.2.0/agent_moss.egg-info/top_level.txt +1 -0
  60. agent_moss-0.2.0/pyproject.toml +30 -0
  61. agent_moss-0.2.0/setup.cfg +4 -0
  62. agent_moss-0.2.0/tests/test_all_cases.py +400 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentMoss Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ recursive-include agent_moss/templates *
2
+ recursive-include agent_moss/skills *.md
3
+ recursive-include agent_moss/rules *.json
4
+ include agent_moss/infra/config.json
@@ -0,0 +1,432 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-moss
3
+ Version: 0.2.0
4
+ Summary: Multi-layer security analysis engine for AI agents
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: openai>=1.0
9
+ Requires-Dist: httpx>=0.25
10
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
11
+ Requires-Dist: pydantic>=2.0
12
+ Requires-Dist: tenacity>=8.0
13
+ Requires-Dist: loguru>=0.7
14
+ Requires-Dist: fastapi>=0.100
15
+ Requires-Dist: uvicorn[standard]>=0.20
16
+ Requires-Dist: pyyaml>=6.0
17
+ Dynamic: license-file
18
+
19
+ # AgentMoss
20
+
21
+ AgentMoss 是一个**可被任意 AI Agent 调用的独立通用安全分析服务**。基于 OS Profile 机制,自动适配 Linux/Windows 的 syscall 检测模式,提供三层防御安全分析(启发式 → 逻辑规则 → LLM 语义分析)。
22
+
23
+ > v2 更新:新增 OS Profile 系统(Linux/Windows 自适应)、Unix Domain Socket 支持、标准化 API 契约。
24
+
25
+ ## 目录
26
+
27
+ - [架构](#架构)
28
+ - [快速开始](#快速开始)
29
+ - [LLM 配置](#llm-配置)
30
+ - [openEuler 部署](#openeuler-部署)
31
+ - [API 参考](#api-参考)
32
+ - [配置](#配置)
33
+ - [项目结构](#项目结构)
34
+ - [测试](#测试)
35
+
36
+ ## 架构
37
+
38
+ ```
39
+ ┌───────────────────────────────────────────┐
40
+ │ 调用入口 (HTTP / Unix Socket) │
41
+ │ POST /api/v1/analyze │
42
+ │ GET /api/v1/health │
43
+ ├───────────────────────────────────────────┤
44
+ │ ObservableAdapter │
45
+ │ AgentOS 可观测服务 syscall → 标准格式 │
46
+ ├───────────────────────────────────────────┤
47
+ │ OS Profile 选择 │
48
+ │ ┌──────────┐ ┌──────────┐ │
49
+ │ │ Linux │ │ Windows │ │
50
+ │ │ Profile │ │ Profile │ │
51
+ │ └──────────┘ └──────────┘ │
52
+ ├───────────────────────────────────────────┤
53
+ │ 安全分析引擎 (三层防御) │
54
+ │ │
55
+ │ 层1: 启发式静态检测 (毫秒级) │
56
+ │ ├── 用户规则匹配 │
57
+ │ ├── 危险命令正则 (OS Profile 驱动) │
58
+ │ └── Prompt 注入检测 │
59
+ │ │
60
+ │ 层2: 逻辑规则检测 (毫秒级) │
61
+ │ ├── read_before_write 原则 │
62
+ │ ├── 意图一致性检测 │
63
+ │ ├── 敏感路径访问 (OS Profile 驱动) │
64
+ │ └── 危险操作模式 │
65
+ │ │
66
+ │ 层3: LLM + Skill 深度分析 │
67
+ │ ├── Skill 规则匹配 (12 个 Skill) │
68
+ │ ├── 脚本内容预扫描 │
69
+ │ └── LLM 语义安全判断 │
70
+ └───────────────────────────────────────────┘
71
+ ```
72
+
73
+ ### 设计原则
74
+
75
+ - **适配在 OS 层,不在 Agent 层** — 不同 Agent 最终都会调用操作系统的 syscall,这是确定性的
76
+ - **标准化 I/O 契约** — 任何 Agent 遵循 API 格式即可接入,无需关心内部实现
77
+ - **fail-closed 安全原则** — 不确定时默认拒绝
78
+
79
+ ## 快速开始
80
+
81
+ ### 安装(开发环境)
82
+
83
+ ```bash
84
+ pip install -e .
85
+ ```
86
+
87
+ ### CLI 使用
88
+
89
+ ```bash
90
+ # 生成输入模板 (v2: 含 os_type 和 cwd 字段)
91
+ agent-moss init -o input.json
92
+
93
+ # 运行安全分析
94
+ agent-moss analyze input.json
95
+
96
+ # 启动 HTTP 服务 (TCP)
97
+ agent-moss server --port 9090
98
+
99
+ # 启动 Unix Domain Socket 服务(同机部署推荐)
100
+ agent-moss server --mode socket --socket /var/run/agent_moss/agent_moss.sock
101
+
102
+ # 指定配置文件
103
+ agent-moss server --mode socket --config /etc/agent_moss/agent_moss.yaml
104
+ ```
105
+
106
+ ### API 调用
107
+
108
+ **HTTP TCP 方式:**
109
+
110
+ ```bash
111
+ curl -X POST http://127.0.0.1:9090/api/v1/analyze \
112
+ -H 'Content-Type: application/json' \
113
+ -d '{
114
+ "session_id": "test-001",
115
+ "prompt_session": "列出系统文件",
116
+ "action_history": [],
117
+ "a_next": {
118
+ "action_type": "bash",
119
+ "action_detail": "ls -la /tmp"
120
+ },
121
+ "reason": "查看临时目录",
122
+ "os_type": "",
123
+ "cwd": "/home/user"
124
+ }'
125
+ ```
126
+
127
+ **Unix Domain Socket 方式(同机低延迟):**
128
+
129
+ ```bash
130
+ curl --unix-socket /var/run/agent_moss/agent_moss.sock \
131
+ -X POST http://localhost/api/v1/analyze \
132
+ -H 'Content-Type: application/json' \
133
+ -d '{
134
+ "session_id": "test-001",
135
+ "a_next": {
136
+ "action_type": "bash",
137
+ "action_detail": "ls -la /tmp"
138
+ }
139
+ }'
140
+ ```
141
+
142
+ **响应示例 (Allow)**:
143
+
144
+ ```json
145
+ {
146
+ "decision": "Allow",
147
+ "risk_level": "low",
148
+ "risk_type": "",
149
+ "violated_layers": [],
150
+ "confidence": 100,
151
+ "analysis_duration_ms": 10.8
152
+ }
153
+ ```
154
+
155
+ **响应示例 (Deny)**:
156
+
157
+ ```json
158
+ {
159
+ "decision": "Deny",
160
+ "reason": "检测到递归强制删除关键路径 (rm -rf /...)",
161
+ "risk_level": "critical",
162
+ "risk_type": "script_execution",
163
+ "violated_layers": ["1.1"],
164
+ "confidence": 95,
165
+ "analysis_duration_ms": 1.2
166
+ }
167
+ ```
168
+
169
+ ## LLM 配置
170
+
171
+ AgentMoss 的三层防御中,层3(LLM 语义分析)是可选的。层1+层2 的静态规则可以独立运行。
172
+
173
+ ### 启用 LLM
174
+
175
+ **方式 1:环境变量(推荐)**
176
+
177
+ ```bash
178
+ export AGENT_MOSS_LLM_API_KEY="sk-your-key"
179
+ # 可选:自定义模型和 API 端点
180
+ export AGENT_MOSS_LLM_MODEL="glm-5.0"
181
+ export AGENT_MOSS_LLM_BASE_URL="https://api.nextapi.store/v1"
182
+ ```
183
+
184
+ **方式 2:YAML 配置文件**
185
+
186
+ 编辑 `config/agent_moss.yaml`:
187
+
188
+ ```yaml
189
+ llm:
190
+ provider: "zhipu"
191
+ model: "glm-5.0"
192
+ base_url: "https://api.nextapi.store/v1"
193
+ api_key_env: "AGENT_MOSS_LLM_API_KEY"
194
+ temperature: 0.1
195
+ max_tokens: 4096
196
+
197
+ security:
198
+ llm_analysis:
199
+ enabled: true
200
+ ```
201
+
202
+ ### 禁用 LLM(仅静态规则)
203
+
204
+ ```bash
205
+ export AGENT_MOSS_DISABLE_LLM=1
206
+ ```
207
+
208
+ ### 支持的 LLM Provider
209
+
210
+ | Provider | 说明 |
211
+ |----------|------|
212
+ | OpenAI | api.openai.com |
213
+ | DeepSeek | api.deepseek.com |
214
+ | 智谱 (GLM) | open.bigmodel.cn |
215
+ | OpenRouter | openrouter.ai |
216
+ | Groq | api.groq.com |
217
+ | 任何 OpenAI 兼容 API | 设置 `base_url` 即可 |
218
+
219
+ ## openEuler 部署
220
+
221
+ ### 前提
222
+
223
+ - openEuler 22.03 LTS+
224
+ - Python 3.10+
225
+ - root 权限
226
+
227
+ ### 一键安装
228
+
229
+ ```bash
230
+ sudo dnf install -y python3 python3-pip python3-devel
231
+ git clone <repo-url> agent_moss
232
+ cd agent_moss
233
+ sudo bash scripts/install.sh
234
+ ```
235
+
236
+ ### 配置 LLM(生产环境)
237
+
238
+ ```bash
239
+ # 写入 API Key(文件权限 600)
240
+ echo "AGENT_MOSS_LLM_API_KEY=sk-your-key" | sudo tee /etc/agent_moss/agent_moss.env
241
+ sudo chmod 600 /etc/agent_moss/agent_moss.env
242
+
243
+ # 编辑 LLM model / base_url
244
+ sudo vim /etc/agent_moss/agent_moss.yaml
245
+ ```
246
+
247
+ ### 启动方式
248
+
249
+ ```bash
250
+ # HTTP TCP 模式(默认,适合跨机/调试)
251
+ sudo systemctl enable --now agent_moss
252
+
253
+ # Unix Socket 模式(同机部署推荐,更低延迟)
254
+ # 编辑 /etc/agent_moss/agent_moss.yaml 中 server.mode: "socket"
255
+ # 或修改 /etc/systemd/system/agent_moss.service 中的 ExecStart
256
+ ```
257
+
258
+ ### 启动与验证
259
+
260
+ ```bash
261
+ sudo systemctl enable --now agent_moss
262
+
263
+ # HTTP 模式验证
264
+ curl http://127.0.0.1:9090/api/v1/health
265
+ # {"status":"healthy","version":"0.1.0"}
266
+
267
+ # Socket 模式验证
268
+ curl --unix-socket /var/run/agent_moss/agent_moss.sock \
269
+ http://localhost/api/v1/health
270
+ ```
271
+
272
+ ### 管理命令
273
+
274
+ | 命令 | 说明 |
275
+ |------|------|
276
+ | `systemctl start agent_moss` | 启动 |
277
+ | `systemctl stop agent_moss` | 停止 |
278
+ | `systemctl restart agent_moss` | 重启 |
279
+ | `systemctl status agent_moss` | 查看状态 |
280
+ | `journalctl -u agent_moss -f` | 查看日志 |
281
+ | `systemctl disable agent_moss` | 取消开机启动 |
282
+
283
+ ### 防火墙(HTTP 模式需要)
284
+
285
+ ```bash
286
+ sudo firewall-cmd --add-port=9090/tcp --permanent
287
+ sudo firewall-cmd --reload
288
+ ```
289
+
290
+ ## API 参考
291
+
292
+ | 方法 | 路径 | 说明 |
293
+ |------|------|------|
294
+ | `GET` | `/api/v1/health` | 健康检查 |
295
+ | `POST` | `/api/v1/analyze` | 安全分析 |
296
+
297
+ ### POST /api/v1/analyze
298
+
299
+ **请求体 (v2)**:
300
+
301
+ ```json
302
+ {
303
+ "session_id": "会话ID (必填)",
304
+ "prompt_session": "原始任务描述 (可选)",
305
+ "action_history": [{"action_type": "...", "action_detail": "..."}],
306
+ "a_next": {
307
+ "action_type": "bash",
308
+ "action_detail": "cat /etc/passwd"
309
+ },
310
+ "reason": "执行理由 (可选)",
311
+ "os_type": "",
312
+ "cwd": "/home/user/project",
313
+ "metadata": {"agent_id": "...", "sandbox_id": "..."}
314
+ }
315
+ ```
316
+
317
+ | 字段 | 类型 | 必填 | 说明 |
318
+ |------|------|------|------|
319
+ | `session_id` | string | 是 | 会话唯一标识 |
320
+ | `prompt_session` | string | 否 | 原始任务描述 |
321
+ | `action_history` | array | 否 | 历史动作序列 |
322
+ | `a_next.action_type` | string | 是 | 动作类型 (bash/file_read/file_write 等) |
323
+ | `a_next.action_detail` | string | 是 | 命令/动作详情 |
324
+ | `reason` | string | 否 | 执行理由 |
325
+ | `os_type` | string | 否 | **v2 新增** — `"linux"` / `"windows"`,留空自动检测 |
326
+ | `cwd` | string | 否 | **v2 新增** — 当前工作目录 |
327
+ | `metadata` | object | 否 | 扩展元数据 |
328
+
329
+ **响应字段**:
330
+
331
+ | 字段 | 类型 | 说明 |
332
+ |------|------|------|
333
+ | `decision` | string | `Allow` / `Deny` |
334
+ | `reason` | string | 决策原因 |
335
+ | `risk_level` | string | `low` / `medium` / `high` / `critical` |
336
+ | `risk_type` | string | 风险类别 (file_access, script_execution, data_exfiltration, ...) |
337
+ | `violated_layers` | array | 触发的检测层,如 `["1.1", "1.2"]` |
338
+ | `violated_policy` | string | 违反的具体条款 (Deny 时) |
339
+ | `policy` | string | Cerberus TOML 策略 (Allow 时) |
340
+ | `confidence` | int | 置信度 0-100 |
341
+ | `analysis_duration_ms` | float | 分析耗时(毫秒) |
342
+
343
+ ## 配置
344
+
345
+ 优先级:环境变量 > YAML 配置文件 > 内置默认值
346
+
347
+ ### 环境变量
348
+
349
+ | 变量 | 说明 | 默认值 |
350
+ |------|------|--------|
351
+ | `AGENT_MOSS_DISABLE_LLM` | 设为 `1` 禁用层3 LLM | 未设置 |
352
+ | `AGENT_MOSS_LLM_API_KEY` | LLM API Key | 未设置 |
353
+ | `AGENT_MOSS_LLM_MODEL` | LLM 模型名称 | `gpt-4o` |
354
+ | `AGENT_MOSS_LLM_BASE_URL` | LLM API 端点 | `https://api.openai.com/v1` |
355
+ | `AGENT_MOSS_LLM_TIMEOUT` | LLM 超时(秒) | `300` |
356
+ | `AGENT_MOSS_ENABLE_POLICY_GEN` | 启用 Policy 生成 | 未设置 |
357
+ | `AGENT_MOSS_CONFIG_PATH` | 配置文件路径 | 内置默认 |
358
+
359
+ ### 配置文件
360
+
361
+ 参考 `config/agent_moss.yaml`。
362
+
363
+ ### v2 新增配置
364
+
365
+ ```yaml
366
+ # OS Profile 自动选择
367
+ os_profile:
368
+ type: "" # 留空自动检测,可手动指定 linux / windows
369
+
370
+ # 服务调用模式
371
+ server:
372
+ mode: "http" # "http" (TCP) 或 "socket" (Unix Domain Socket)
373
+ socket_path: "/var/run/agent_moss/agent_moss.sock"
374
+ ```
375
+
376
+ ## 项目结构
377
+
378
+ ```
379
+ agent_moss/
380
+ ├── profiles/ # [v2 新增] OS Profile 系统
381
+ │ ├── base.py # OSProfile 抽象基类
382
+ │ ├── linux.py # LinuxProfile
383
+ │ └── windows.py # WindowsProfile
384
+ ├── engine/ # 安全分析引擎
385
+ │ ├── analyzer.py # 主入口 analyze()
386
+ │ ├── coordinator.py # AgentMossBot 三层协调器
387
+ │ ├── heuristic.py # 层1: 启发式检测 (OS Profile 驱动)
388
+ │ ├── logic_rules.py # 层2: 逻辑规则检测 (OS Profile 驱动)
389
+ │ ├── llm_analyzer.py # 层3: LLM + Skill 深度分析
390
+ │ ├── skill_engine.py # Skill 匹配引擎
391
+ │ ├── script_analyzer.py # 脚本内容扫描
392
+ │ └── types.py # 类型定义
393
+ ├── server/ # HTTP API 服务层
394
+ │ ├── app.py # FastAPI 应用 + 多模式启动
395
+ │ ├── socket_server.py # [v2 新增] Unix Domain Socket
396
+ │ ├── routes.py # API 路由
397
+ │ └── models.py # Pydantic 请求/响应模型
398
+ ├── adapters/ # 适配器层
399
+ │ └── observable.py # AgentOS 可观测服务数据适配器
400
+ ├── infra/ # 基础设施
401
+ │ ├── config.py # 配置管理
402
+ │ ├── llm_client.py # LLM 客户端 (OpenAI SDK)
403
+ │ └── ...
404
+ ├── skills/ # 安全 Skill 规则 (12 个 Markdown)
405
+ ├── rules/ # 用户自定义规则
406
+ ├── templates/ # Prompt 模板
407
+ └── cli.py # 命令行工具
408
+ config/
409
+ └── agent_moss.yaml # YAML 配置模板
410
+ docs/
411
+ ├── design.md # 基础架构设计
412
+ ├── agent_moss_adapter_design_v2.md # v2 适配方案设计
413
+ └── agent_collector_design_v1.md # Agent 数据采集服务设计
414
+ tests/
415
+ ├── conftest.py # 共享 fixtures
416
+ ├── test_all_cases.py # 全量测试 (48 个用例)
417
+ └── cases/ # 测试用例 JSON
418
+ ```
419
+
420
+ ## 测试
421
+
422
+ ```bash
423
+ # 前两层测试(不依赖 LLM)
424
+ python3 -m pytest tests/ -v --no-header
425
+
426
+ # 包含 LLM 层(需 API Key)
427
+ AGENT_MOSS_LLM_API_KEY="sk-xxx" python3 -m pytest tests/ -v
428
+
429
+ # 仅运行特定测试
430
+ python3 -m pytest tests/ -k "deny" -v
431
+ python3 -m pytest tests/ -k "profile" -v
432
+ ```