@hddz/plugin-harness 0.1.19 → 0.2.1
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.
Potentially problematic release.
This version of @hddz/plugin-harness might be problematic. Click here for more details.
- package/README.md +97 -114
- package/dist/core/auditors/index.d.ts +2 -0
- package/dist/core/auditors/index.js +7 -0
- package/dist/core/auditors/skill-auditor.d.ts +72 -0
- package/dist/core/auditors/skill-auditor.js +488 -0
- package/dist/core/index.d.ts +22 -0
- package/dist/core/index.js +47 -0
- package/dist/core/loggers/config-logger.d.ts +25 -0
- package/dist/core/loggers/config-logger.js +139 -0
- package/dist/core/loggers/index.d.ts +4 -0
- package/dist/core/loggers/index.js +9 -0
- package/dist/core/loggers/operation-logger.d.ts +23 -0
- package/dist/core/loggers/operation-logger.js +125 -0
- package/dist/core/middleware/context-injector.d.ts +25 -0
- package/dist/core/middleware/context-injector.js +174 -0
- package/dist/core/middleware/index.d.ts +5 -0
- package/dist/core/middleware/index.js +11 -0
- package/dist/core/middleware/loop-detector.d.ts +18 -0
- package/dist/core/middleware/loop-detector.js +125 -0
- package/dist/core/middleware/trace-logger.d.ts +34 -0
- package/dist/core/middleware/trace-logger.js +141 -0
- package/dist/core/utils/file.d.ts +28 -0
- package/dist/core/utils/file.js +104 -0
- package/dist/core/utils/format.d.ts +16 -0
- package/dist/core/utils/format.js +60 -0
- package/dist/core/utils/index.d.ts +2 -0
- package/dist/core/utils/index.js +14 -0
- package/dist/core/validators/config-validator.d.ts +25 -0
- package/dist/core/validators/config-validator.js +235 -0
- package/dist/core/validators/index.d.ts +2 -0
- package/dist/core/validators/index.js +7 -0
- package/dist/file-watcher.d.ts +37 -0
- package/dist/file-watcher.js +151 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +166 -106
- package/dist/src/file-watcher.d.ts +37 -0
- package/dist/src/file-watcher.js +151 -0
- package/dist/src/index.d.ts +70 -0
- package/dist/src/index.js +192 -0
- package/package.json +4 -12
- package/openclaw.plugin.json +0 -39
package/README.md
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
1
|
# @hddz/plugin-harness
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
> **许可**: MIT
|
|
3
|
+
> OpenClaw Harness Engineering 插件 - 为 AI Agent 构建约束、反馈与控制系统
|
|
4
|
+
|
|
5
|
+
**最新版本**: v0.2.0 (2026-03-24)
|
|
7
6
|
|
|
8
7
|
---
|
|
9
8
|
|
|
10
|
-
## 🎯
|
|
9
|
+
## 🎯 功能
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
| **Trace 追踪** | 完整的工具调用链路追踪 | ✅ |
|
|
11
|
+
- ✅ **配置验证**:修改 `openclaw.json` 前自动验证
|
|
12
|
+
- ✅ **Skill 审核**:安装 Skill 前自动安全扫描
|
|
13
|
+
- ✅ **循环检测**:防止 AI 反复修改同一文件
|
|
14
|
+
- ✅ **文件保护**:保护关键文件(SOUL.md 等)不被误删
|
|
15
|
+
- ✅ **操作审计**:记录所有关键操作
|
|
16
|
+
- ✅ **Trace 追踪**:完整的工具调用链路
|
|
17
|
+
- ✅ **文件监听器** (v0.2.0 新增):实时监听配置文件变化,用户手动编辑也能触发验证
|
|
20
18
|
|
|
21
19
|
---
|
|
22
20
|
|
|
23
21
|
## 🚀 快速开始
|
|
24
22
|
|
|
25
|
-
###
|
|
23
|
+
### 安装
|
|
26
24
|
|
|
27
25
|
```bash
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
# 重启 Gateway
|
|
32
|
-
openclaw gateway restart
|
|
26
|
+
# 从 npm 安装(推荐)
|
|
27
|
+
npm install @hddz/plugin-harness@0.2.0
|
|
33
28
|
|
|
34
|
-
#
|
|
35
|
-
openclaw
|
|
29
|
+
# 本地开发版
|
|
30
|
+
cd /Users/hzl/.openclaw/extensions/harness
|
|
31
|
+
npm link
|
|
36
32
|
```
|
|
37
33
|
|
|
38
|
-
|
|
34
|
+
### 配置
|
|
35
|
+
|
|
36
|
+
编辑 `~/.openclaw/openclaw.json`:
|
|
39
37
|
|
|
40
38
|
```json
|
|
41
39
|
{
|
|
42
40
|
"plugins": {
|
|
41
|
+
"installs": [
|
|
42
|
+
"@hddz/plugin-harness@0.2.0"
|
|
43
|
+
],
|
|
43
44
|
"entries": {
|
|
44
45
|
"harness": {
|
|
45
46
|
"enabled": true,
|
|
@@ -55,7 +56,7 @@ openclaw plugins list
|
|
|
55
56
|
"MEMORY.md",
|
|
56
57
|
"openclaw.json"
|
|
57
58
|
],
|
|
58
|
-
"logsDir": "
|
|
59
|
+
"logsDir": "logs/harness"
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -63,13 +64,9 @@ openclaw plugins list
|
|
|
63
64
|
}
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
然后重启 gateway:
|
|
67
68
|
|
|
68
69
|
```bash
|
|
69
|
-
# 链接本地插件目录
|
|
70
|
-
openclaw plugins install -l /Users/hzl/.openclaw/workspace/harness-plugin
|
|
71
|
-
|
|
72
|
-
# 重启 Gateway
|
|
73
70
|
openclaw gateway restart
|
|
74
71
|
```
|
|
75
72
|
|
|
@@ -79,17 +76,35 @@ openclaw gateway restart
|
|
|
79
76
|
|
|
80
77
|
| 选项 | 类型 | 默认值 | 说明 |
|
|
81
78
|
|------|------|--------|------|
|
|
82
|
-
| `autoValidateConfig` | boolean |
|
|
83
|
-
| `autoAuditSkill` | boolean |
|
|
84
|
-
| `loopDetectionEnabled` | boolean |
|
|
85
|
-
| `protectedFiles` | string[] |
|
|
86
|
-
| `logsDir` | string |
|
|
79
|
+
| `autoValidateConfig` | boolean | true | 配置修改前自动验证 |
|
|
80
|
+
| `autoAuditSkill` | boolean | true | Skill 安装前自动审核 |
|
|
81
|
+
| `loopDetectionEnabled` | boolean | true | 启用循环检测 |
|
|
82
|
+
| `protectedFiles` | string[] | 见上文 | 受保护的文件列表 |
|
|
83
|
+
| `logsDir` | string | logs/harness | 日志目录 |
|
|
87
84
|
|
|
88
85
|
---
|
|
89
86
|
|
|
90
|
-
##
|
|
87
|
+
## 🔍 使用示例
|
|
88
|
+
|
|
89
|
+
### 配置验证(自动)
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// 修改 openclaw.json 时自动触发
|
|
93
|
+
const result = await plugin.onConfigChange(newConfig);
|
|
94
|
+
// 如果验证失败,会抛出异常阻止修改
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Skill 审核(自动)
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// 安装 Skill 时自动触发
|
|
101
|
+
const auditResult = await plugin.onSkillInstall('/path/to/skill');
|
|
102
|
+
if (!auditResult.passed) {
|
|
103
|
+
throw new Error(`Skill 审核未通过:${auditResult.riskLevel}`);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
91
106
|
|
|
92
|
-
|
|
107
|
+
### 手动查询
|
|
93
108
|
|
|
94
109
|
```bash
|
|
95
110
|
# 查看最近的配置变更
|
|
@@ -97,112 +112,80 @@ harness get-config-changes -l 10
|
|
|
97
112
|
|
|
98
113
|
# 查看操作日志
|
|
99
114
|
harness get-operations -l 20
|
|
115
|
+
|
|
116
|
+
# 查看循环检测统计
|
|
117
|
+
harness loop-stats
|
|
100
118
|
```
|
|
101
119
|
|
|
102
120
|
---
|
|
103
121
|
|
|
104
|
-
##
|
|
122
|
+
## 🛡️ 安全机制
|
|
105
123
|
|
|
106
|
-
###
|
|
124
|
+
### 保护文件
|
|
107
125
|
|
|
108
|
-
|
|
109
|
-
|------|----------|------|
|
|
110
|
-
| `onConfigChange` | 修改 `openclaw.json` 前 | 验证配置有效性 |
|
|
111
|
-
| `onSkillInstall` | 安装 Skill 前 | 扫描安全风险 |
|
|
112
|
-
| `onFileEdit` | 编辑文件时 | 循环检测 + 保护文件监控 |
|
|
113
|
-
| `onFileDelete` | 删除文件前 | 拦截保护文件删除 |
|
|
114
|
-
| `onExecCommand` | 执行命令前 | 记录审计日志 |
|
|
126
|
+
以下文件默认受保护,修改/删除前会告警:
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
- `SOUL.md` - 身份定义
|
|
129
|
+
- `USER.md` - 用户信息
|
|
130
|
+
- `AGENTS.md` - Agent 指南
|
|
131
|
+
- `TOOLS.md` - 工具配置
|
|
132
|
+
- `MEMORY.md` - 长期记忆
|
|
133
|
+
- `openclaw.json` - 核心配置
|
|
117
134
|
|
|
118
|
-
|
|
119
|
-
harness-plugin/
|
|
120
|
-
├── src/
|
|
121
|
-
│ └── index.ts # 插件核心逻辑
|
|
122
|
-
├── dist/ # 编译输出
|
|
123
|
-
├── docs/ # 文档
|
|
124
|
-
├── openclaw.plugin.json # OpenClaw 插件元数据
|
|
125
|
-
├── package.json # NPM 配置
|
|
126
|
-
├── tsconfig.json # TypeScript 配置
|
|
127
|
-
└── README.md # 本文件
|
|
128
|
-
```
|
|
135
|
+
### 风险等级
|
|
129
136
|
|
|
130
|
-
|
|
137
|
+
| 等级 | 标识 | 处理 |
|
|
138
|
+
|------|------|------|
|
|
139
|
+
| LOW | 🟢 | 允许 |
|
|
140
|
+
| MEDIUM | 🟡 | 警告,但允许 |
|
|
141
|
+
| HIGH | 🟠 | 阻止,需人工确认 |
|
|
142
|
+
| CRITICAL | 🔴 | 阻止,禁止操作 |
|
|
131
143
|
|
|
132
|
-
|
|
144
|
+
---
|
|
133
145
|
|
|
134
|
-
|
|
146
|
+
## 📚 文档
|
|
135
147
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
3. 确认 `openclaw.json` 配置了 `plugins.entries.harness`
|
|
140
|
-
4. 检查 manifest:`cat ~/.openclaw/extensions/harness/openclaw.plugin.json`
|
|
148
|
+
- [使用指南](./docs/使用指南.md)
|
|
149
|
+
- [开发文档](./docs/开发文档.md)
|
|
150
|
+
- [API 参考](./docs/API.md)
|
|
141
151
|
|
|
142
|
-
|
|
152
|
+
---
|
|
143
153
|
|
|
144
|
-
|
|
145
|
-
```json
|
|
146
|
-
{
|
|
147
|
-
"plugins": {
|
|
148
|
-
"entries": {
|
|
149
|
-
"harness": {
|
|
150
|
-
"enabled": true,
|
|
151
|
-
"config": {
|
|
152
|
-
"autoValidateConfig": true
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
```
|
|
154
|
+
## 🔧 开发
|
|
159
155
|
|
|
160
|
-
|
|
156
|
+
```bash
|
|
157
|
+
# 安装依赖
|
|
158
|
+
npm install
|
|
161
159
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
{
|
|
165
|
-
"plugins": {
|
|
166
|
-
"entries": {
|
|
167
|
-
"harness": {
|
|
168
|
-
"config": {
|
|
169
|
-
"autoValidateConfig": false,
|
|
170
|
-
"loopDetectionEnabled": false
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
```
|
|
160
|
+
# 构建
|
|
161
|
+
npm run build
|
|
177
162
|
|
|
178
|
-
|
|
163
|
+
# 测试
|
|
164
|
+
npm test
|
|
179
165
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
openclaw plugins uninstall harness
|
|
183
|
-
openclaw gateway restart
|
|
166
|
+
# 链接到 OpenClaw
|
|
167
|
+
npm link
|
|
184
168
|
```
|
|
185
169
|
|
|
186
170
|
---
|
|
187
171
|
|
|
188
|
-
##
|
|
172
|
+
## 📝 变更日志
|
|
173
|
+
|
|
174
|
+
### v0.1.0 (2026-03-19)
|
|
189
175
|
|
|
190
|
-
-
|
|
191
|
-
-
|
|
176
|
+
- ✅ 初始版本
|
|
177
|
+
- ✅ 配置验证
|
|
178
|
+
- ✅ Skill 审核
|
|
179
|
+
- ✅ 循环检测
|
|
180
|
+
- ✅ 操作日志
|
|
181
|
+
- ✅ Trace 追踪
|
|
192
182
|
|
|
193
183
|
---
|
|
194
184
|
|
|
195
|
-
##
|
|
185
|
+
## 📄 许可证
|
|
196
186
|
|
|
197
|
-
|
|
198
|
-
|------|------|------|
|
|
199
|
-
| 0.1.10 | 2026-03-24 | 添加 `openclaw.plugin.json` manifest,支持 `openclaw plugins install` |
|
|
200
|
-
| 0.1.9 | 2026-03-24 | 提供 `install.sh` 一键安装脚本 |
|
|
201
|
-
| 0.1.8 | 2026-03-24 | 修复 Skill 审核路径问题 |
|
|
202
|
-
| 0.1.7 | 2026-03-23 | 初始发布到 npm |
|
|
187
|
+
MIT
|
|
203
188
|
|
|
204
189
|
---
|
|
205
190
|
|
|
206
|
-
|
|
207
|
-
**仓库**: https://github.com/hddz/plugin-harness
|
|
208
|
-
**npm**: https://www.npmjs.com/package/@hddz/plugin-harness
|
|
191
|
+
_@openclaw/plugin-harness | 蓝山 | 2026-03-19_
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/auditors/index.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SkillAuditor = void 0;
|
|
5
|
+
var skill_auditor_1 = require("./skill-auditor");
|
|
6
|
+
Object.defineProperty(exports, "SkillAuditor", { enumerable: true, get: function () { return skill_auditor_1.SkillAuditor; } });
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29yZS9hdWRpdG9ycy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsd0JBQXdCOzs7QUFFeEIsaURBQStDO0FBQXRDLDZHQUFBLFlBQVksT0FBQSIsInNvdXJjZXNDb250ZW50IjpbIi8vIHNyYy9hdWRpdG9ycy9pbmRleC50c1xuXG5leHBvcnQgeyBTa2lsbEF1ZGl0b3IgfSBmcm9tICcuL3NraWxsLWF1ZGl0b3InO1xuZXhwb3J0IHR5cGUgeyBTa2lsbEF1ZGl0UmVzdWx0LCBXYXJuaW5nLCBTa2lsbE1ldGFkYXRhIH0gZnJvbSAnLi9za2lsbC1hdWRpdG9yJztcbiJdfQ==
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface SkillAuditResult {
|
|
2
|
+
skillName: string;
|
|
3
|
+
skillPath: string;
|
|
4
|
+
source: string;
|
|
5
|
+
riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
6
|
+
passed: boolean;
|
|
7
|
+
warnings: Warning[];
|
|
8
|
+
recommendations: string[];
|
|
9
|
+
metadata: SkillMetadata;
|
|
10
|
+
}
|
|
11
|
+
export interface Warning {
|
|
12
|
+
type: 'dangerous_code' | 'permission' | 'dependency' | 'network' | 'other';
|
|
13
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
14
|
+
message: string;
|
|
15
|
+
file?: string;
|
|
16
|
+
line?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface SkillMetadata {
|
|
19
|
+
hasSkillMd: boolean;
|
|
20
|
+
hasScripts: boolean;
|
|
21
|
+
hasPackageJson: boolean;
|
|
22
|
+
declaredPermissions: string[];
|
|
23
|
+
dependencies: string[];
|
|
24
|
+
devDependencies: string[];
|
|
25
|
+
lastModified?: Date;
|
|
26
|
+
}
|
|
27
|
+
export declare class SkillAuditor {
|
|
28
|
+
private workspacePath;
|
|
29
|
+
constructor(workspacePath: string);
|
|
30
|
+
/**
|
|
31
|
+
* 审核 Skill
|
|
32
|
+
*/
|
|
33
|
+
audit(skillPath: string, source?: string): Promise<SkillAuditResult>;
|
|
34
|
+
/**
|
|
35
|
+
* 检查来源
|
|
36
|
+
*/
|
|
37
|
+
private checkSource;
|
|
38
|
+
/**
|
|
39
|
+
* 检查权限声明
|
|
40
|
+
*/
|
|
41
|
+
private checkPermissions;
|
|
42
|
+
/**
|
|
43
|
+
* 扫描危险代码
|
|
44
|
+
*/
|
|
45
|
+
private scanDangerousCode;
|
|
46
|
+
/**
|
|
47
|
+
* 扫描脚本文件
|
|
48
|
+
*/
|
|
49
|
+
private scanScripts;
|
|
50
|
+
/**
|
|
51
|
+
* 检查依赖
|
|
52
|
+
*/
|
|
53
|
+
private checkDependencies;
|
|
54
|
+
/**
|
|
55
|
+
* 获取 Skill 元数据
|
|
56
|
+
*/
|
|
57
|
+
private getSkillMetadata;
|
|
58
|
+
/**
|
|
59
|
+
* 获取所有 JS 文件
|
|
60
|
+
*/
|
|
61
|
+
private getJsFiles;
|
|
62
|
+
/**
|
|
63
|
+
* 计算风险等级
|
|
64
|
+
*/
|
|
65
|
+
private calculateRiskLevel;
|
|
66
|
+
/**
|
|
67
|
+
* 生成审计报告
|
|
68
|
+
*/
|
|
69
|
+
generateReport(result: SkillAuditResult): string;
|
|
70
|
+
private getRiskEmoji;
|
|
71
|
+
private getSeverityEmoji;
|
|
72
|
+
}
|