@sofagent/rules 1.3.0 → 1.3.2
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/dist/approval-mode.d.ts +24 -0
- package/dist/approval-mode.js +51 -0
- package/dist/engine.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -3
- package/dist/rules/index.js +1 -1
- package/dist/rules/tool-injection.js +1 -1
- package/dist/rules/tool-secret-leak.js +2 -2
- package/dist/rules/tool-sensitive-file.js +1 -1
- package/dist/should-allow.js +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** 工具审批四模式 */
|
|
2
|
+
export type ApprovalMode = 'allow-with-audit' | 'deny-all' | 'read-only' | 'always-ask';
|
|
3
|
+
/** 审批判定结果 */
|
|
4
|
+
export interface ApprovalResult {
|
|
5
|
+
/** 是否放行(false 时调用方应走人工确认或拒绝) */
|
|
6
|
+
allow: boolean;
|
|
7
|
+
/** 人类可读判定理由(写审计日志) */
|
|
8
|
+
reason: string;
|
|
9
|
+
/** 本次判定所用的模式 */
|
|
10
|
+
mode: ApprovalMode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 按审批模式 + 工具权限判定是否放行。
|
|
14
|
+
*
|
|
15
|
+
* 注意:本函数只做「模式级」判定——read-only 遇 rw 工具、always-ask 遇任何工具
|
|
16
|
+
* 返回 allow:false + reason='待人工确认',实际人工确认由 middleware 层
|
|
17
|
+
*(approvalCallback)执行;无回调时由 middleware 按保守默认拒绝处理。
|
|
18
|
+
*
|
|
19
|
+
* @param mode 审批模式
|
|
20
|
+
* @param permission 工具权限标记('r' 只读 / 'rw' 读写)
|
|
21
|
+
* @returns ApprovalResult
|
|
22
|
+
*/
|
|
23
|
+
export declare function shouldApprove(mode: ApprovalMode, permission: 'r' | 'rw'): ApprovalResult;
|
|
24
|
+
//# sourceMappingURL=approval-mode.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// approval-mode.ts · 工具审批四模式(v1.3.2 交付 10)
|
|
4
|
+
//
|
|
5
|
+
// 设计来源:PenguinHarness CLI --approve 四模式
|
|
6
|
+
//(allow-all / deny-all / read-only / always-ask)。
|
|
7
|
+
//
|
|
8
|
+
// 四种模式行为:
|
|
9
|
+
// allow-with-audit 全部放行 + 写审计日志(默认模式 = v1.3.2 行为,不破坏既有)
|
|
10
|
+
// deny-all 全部拦截(调试/安全演练)
|
|
11
|
+
// read-only 只读工具(permission='r')自动放行,读写需人工确认(Benchmark 评测)
|
|
12
|
+
// always-ask 每次工具调用都问人(危险操作密集场景)
|
|
13
|
+
//
|
|
14
|
+
// 保守默认拒绝(安全铁律 #7):需要人工确认的场景(read-only 遇 rw /
|
|
15
|
+
// always-ask)若 SDK 未提供审批回调 → 默认拒绝一切,不是放行。
|
|
16
|
+
// ============================================================
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.shouldApprove = shouldApprove;
|
|
19
|
+
/**
|
|
20
|
+
* 按审批模式 + 工具权限判定是否放行。
|
|
21
|
+
*
|
|
22
|
+
* 注意:本函数只做「模式级」判定——read-only 遇 rw 工具、always-ask 遇任何工具
|
|
23
|
+
* 返回 allow:false + reason='待人工确认',实际人工确认由 middleware 层
|
|
24
|
+
*(approvalCallback)执行;无回调时由 middleware 按保守默认拒绝处理。
|
|
25
|
+
*
|
|
26
|
+
* @param mode 审批模式
|
|
27
|
+
* @param permission 工具权限标记('r' 只读 / 'rw' 读写)
|
|
28
|
+
* @returns ApprovalResult
|
|
29
|
+
*/
|
|
30
|
+
function shouldApprove(mode, permission) {
|
|
31
|
+
switch (mode) {
|
|
32
|
+
case 'allow-with-audit':
|
|
33
|
+
return { allow: true, reason: '放行(审计日志已写)', mode };
|
|
34
|
+
case 'deny-all':
|
|
35
|
+
return { allow: false, reason: 'deny-all 模式拦截', mode };
|
|
36
|
+
case 'read-only':
|
|
37
|
+
if (permission === 'r') {
|
|
38
|
+
return { allow: true, reason: 'read-only 放行只读', mode };
|
|
39
|
+
}
|
|
40
|
+
return { allow: false, reason: 'read-only 拦截读写(待人工确认)', mode };
|
|
41
|
+
case 'always-ask':
|
|
42
|
+
// 需人工确认——交给 HITL 回调(middleware 层)
|
|
43
|
+
return { allow: false, reason: 'always-ask 待人工确认', mode };
|
|
44
|
+
default: {
|
|
45
|
+
// 未知模式 → 保守默认拒绝(安全铁律:宁可错杀不可放行)
|
|
46
|
+
const exhaustive = mode;
|
|
47
|
+
return { allow: false, reason: `未知审批模式 ${String(exhaustive)} → 保守拒绝`, mode };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=approval-mode.js.map
|
package/dist/engine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// engine.ts · RulesEngine 纯函数入口
|
|
4
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:P3 编排引擎内嵌——规则引擎核心
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.RulesEngine = void 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export type { ToolRule, ToolCallContext, InterceptVerdict, RuleStatus, RuleClass
|
|
|
3
3
|
export { defaultToolRules } from './rules';
|
|
4
4
|
export { shouldAllow } from './should-allow';
|
|
5
5
|
export type { ShouldAllowResult } from './should-allow';
|
|
6
|
+
export { shouldApprove } from './approval-mode';
|
|
7
|
+
export type { ApprovalMode, ApprovalResult } from './approval-mode';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// index.ts · @sofagent/rules barrel export
|
|
4
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:只导出 5 个公开符号,内部实现不外露
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.shouldAllow = exports.defaultToolRules = exports.RulesEngine = void 0;
|
|
7
|
+
exports.shouldApprove = exports.shouldAllow = exports.defaultToolRules = exports.RulesEngine = void 0;
|
|
8
8
|
var engine_1 = require("./engine");
|
|
9
9
|
Object.defineProperty(exports, "RulesEngine", { enumerable: true, get: function () { return engine_1.RulesEngine; } });
|
|
10
10
|
var rules_1 = require("./rules");
|
|
11
11
|
Object.defineProperty(exports, "defaultToolRules", { enumerable: true, get: function () { return rules_1.defaultToolRules; } });
|
|
12
|
-
// v1.3.
|
|
12
|
+
// v1.3.2 (交付 2):tool-gate 便捷判定 API
|
|
13
13
|
var should_allow_1 = require("./should-allow");
|
|
14
14
|
Object.defineProperty(exports, "shouldAllow", { enumerable: true, get: function () { return should_allow_1.shouldAllow; } });
|
|
15
|
+
// v1.3.2 (交付 10):工具审批四模式
|
|
16
|
+
var approval_mode_1 = require("./approval-mode");
|
|
17
|
+
Object.defineProperty(exports, "shouldApprove", { enumerable: true, get: function () { return approval_mode_1.shouldApprove; } });
|
|
15
18
|
//# sourceMappingURL=index.js.map
|
package/dist/rules/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// rules/index.ts · 默认规则注册表
|
|
4
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:P3 编排引擎内嵌——默认 tool 规则集合
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.defaultToolRules = void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// tool-injection.ts · 移植 audit rule-a9(prompt injection 检测)
|
|
4
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:tool 视角——扫 args 里的 prompt injection 模式
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.toolInjection = void 0;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// tool-secret-leak.ts · 移植 audit rule-a2(密钥泄漏检测)
|
|
4
|
-
// v1.3.
|
|
5
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:tool 视角——扫 args 字面量里的密钥模式
|
|
5
|
+
// v1.3.2 SECRET_PATTERNS 抽到 @sofagent/core 共享——此前本文件用严格
|
|
6
6
|
// 48 位 sk- 模式导致 32-47 位密钥被 ToolGate 放行(与 A2 漂移互补成洞)。
|
|
7
7
|
// ============================================================
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// tool-sensitive-file.ts · 移植 audit rule-a1(敏感文件保护)
|
|
4
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:tool 视角——校验 args 里的文件路径
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.toolSensitiveFile = void 0;
|
package/dist/should-allow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
|
-
// should-allow.ts · tool-gate 便捷 API(v1.3.
|
|
3
|
+
// should-allow.ts · tool-gate 便捷 API(v1.3.2 交付 2)
|
|
4
4
|
//
|
|
5
5
|
// shouldAllow()——编排层/运行时 wrapper 判定「本次工具调用是否放行」。
|
|
6
6
|
// 聚合 RulesEngine.check + aggregate,并额外暴露 requireApproval:
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// types.ts · P3 编排引擎内嵌——tool call 拦截器类型定义
|
|
4
|
-
// v1.3.
|
|
4
|
+
// v1.3.2:从 audit 规则抽出为纯函数,零 fs/git 依赖
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sofagent/rules",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "sofagent 规则引擎纯函数包——从 audit 抽出,零 fs/git 依赖,供编排引擎 tool call 事前拦截",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@sofagent/core": "1.3.
|
|
31
|
+
"@sofagent/core": "1.3.2"
|
|
32
32
|
}
|
|
33
33
|
}
|