@sofagent/rules 1.2.9 → 1.3.0
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/engine.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -2
- package/dist/rules/index.js +1 -1
- package/dist/rules/tool-injection.js +2 -1
- package/dist/rules/tool-secret-leak.js +3 -2
- package/dist/rules/tool-sensitive-file.js +2 -1
- package/dist/should-allow.d.ts +20 -0
- package/dist/should-allow.js +28 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +1 -1
- package/package.json +3 -3
package/dist/engine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// engine.ts · RulesEngine 纯函数入口
|
|
4
|
-
// v1.
|
|
4
|
+
// v1.3.0:P3 编排引擎内嵌——规则引擎核心
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.RulesEngine = void 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { RulesEngine } from './engine';
|
|
2
2
|
export type { ToolRule, ToolCallContext, InterceptVerdict, RuleStatus, RuleClass } from './types';
|
|
3
3
|
export { defaultToolRules } from './rules';
|
|
4
|
+
export { shouldAllow } from './should-allow';
|
|
5
|
+
export type { ShouldAllowResult } from './should-allow';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// index.ts · @sofagent/rules barrel export
|
|
4
|
-
// v1.
|
|
4
|
+
// v1.3.0:只导出 5 个公开符号,内部实现不外露
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.defaultToolRules = exports.RulesEngine = void 0;
|
|
7
|
+
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.0 (交付 2):tool-gate 便捷判定 API
|
|
13
|
+
var should_allow_1 = require("./should-allow");
|
|
14
|
+
Object.defineProperty(exports, "shouldAllow", { enumerable: true, get: function () { return should_allow_1.shouldAllow; } });
|
|
12
15
|
//# 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.
|
|
4
|
+
// v1.3.0: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.
|
|
4
|
+
// v1.3.0:tool 视角——扫 args 里的 prompt injection 模式
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.toolInjection = void 0;
|
|
@@ -55,6 +55,7 @@ exports.toolInjection = {
|
|
|
55
55
|
name: 'tool-injection',
|
|
56
56
|
number: 9,
|
|
57
57
|
ruleClass: '业务底线',
|
|
58
|
+
ruleType: 'tool',
|
|
58
59
|
check(ctx) {
|
|
59
60
|
const allStrings = extractStrings(ctx.args);
|
|
60
61
|
const hits = [];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// tool-secret-leak.ts · 移植 audit rule-a2(密钥泄漏检测)
|
|
4
|
-
// v1.
|
|
5
|
-
// v1.
|
|
4
|
+
// v1.3.0:tool 视角——扫 args 字面量里的密钥模式
|
|
5
|
+
// v1.3.0 SECRET_PATTERNS 抽到 @sofagent/core 共享——此前本文件用严格
|
|
6
6
|
// 48 位 sk- 模式导致 32-47 位密钥被 ToolGate 放行(与 A2 漂移互补成洞)。
|
|
7
7
|
// ============================================================
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -31,6 +31,7 @@ exports.toolSecretLeak = {
|
|
|
31
31
|
name: 'tool-secret-leak',
|
|
32
32
|
number: 2,
|
|
33
33
|
ruleClass: '业务底线',
|
|
34
|
+
ruleType: 'tool',
|
|
34
35
|
check(ctx) {
|
|
35
36
|
const allStrings = extractStrings(ctx.args);
|
|
36
37
|
const detections = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// tool-sensitive-file.ts · 移植 audit rule-a1(敏感文件保护)
|
|
4
|
-
// v1.
|
|
4
|
+
// v1.3.0:tool 视角——校验 args 里的文件路径
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.toolSensitiveFile = void 0;
|
|
@@ -76,6 +76,7 @@ exports.toolSensitiveFile = {
|
|
|
76
76
|
name: 'tool-sensitive-file',
|
|
77
77
|
number: 1,
|
|
78
78
|
ruleClass: '业务底线',
|
|
79
|
+
ruleType: 'tool',
|
|
79
80
|
check(ctx) {
|
|
80
81
|
const filePaths = extractFilePaths(ctx.args);
|
|
81
82
|
const hits = [];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RulesEngine } from './engine';
|
|
2
|
+
import type { ToolCallContext } from './types';
|
|
3
|
+
/** shouldAllow 判定结果 */
|
|
4
|
+
export interface ShouldAllowResult {
|
|
5
|
+
/** 是否放行(FAIL → false;WARN/PASS → true) */
|
|
6
|
+
allow: boolean;
|
|
7
|
+
/** 判定理由(聚合 details) */
|
|
8
|
+
reason: string;
|
|
9
|
+
/** 是否需要人工批准(任一规则 requireApproval=true) */
|
|
10
|
+
requireApproval: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 判定工具调用是否应放行。
|
|
14
|
+
*
|
|
15
|
+
* @param engine 规则引擎实例
|
|
16
|
+
* @param ctx tool call 上下文
|
|
17
|
+
* @returns ShouldAllowResult
|
|
18
|
+
*/
|
|
19
|
+
export declare function shouldAllow(engine: RulesEngine, ctx: ToolCallContext): ShouldAllowResult;
|
|
20
|
+
//# sourceMappingURL=should-allow.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// should-allow.ts · tool-gate 便捷 API(v1.3.0 交付 2)
|
|
4
|
+
//
|
|
5
|
+
// shouldAllow()——编排层/运行时 wrapper 判定「本次工具调用是否放行」。
|
|
6
|
+
// 聚合 RulesEngine.check + aggregate,并额外暴露 requireApproval:
|
|
7
|
+
// 任一规则判定 requireApproval=true 时挂起人工批准(交付 3 HITL 消费)。
|
|
8
|
+
// ============================================================
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.shouldAllow = shouldAllow;
|
|
11
|
+
/**
|
|
12
|
+
* 判定工具调用是否应放行。
|
|
13
|
+
*
|
|
14
|
+
* @param engine 规则引擎实例
|
|
15
|
+
* @param ctx tool call 上下文
|
|
16
|
+
* @returns ShouldAllowResult
|
|
17
|
+
*/
|
|
18
|
+
function shouldAllow(engine, ctx) {
|
|
19
|
+
const verdicts = engine.check(ctx);
|
|
20
|
+
const agg = engine.aggregate(verdicts);
|
|
21
|
+
const needApproval = verdicts.some((v) => v.requireApproval === true);
|
|
22
|
+
return {
|
|
23
|
+
allow: agg.status !== 'FAIL',
|
|
24
|
+
reason: agg.details.join('; '),
|
|
25
|
+
requireApproval: needApproval,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=should-allow.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface InterceptVerdict {
|
|
|
31
31
|
details: string[];
|
|
32
32
|
/** 修复建议 */
|
|
33
33
|
suggestion: string;
|
|
34
|
+
/** v1.3.0 新增:需要人工批准(HITL 挂起,交付 3 消费) */
|
|
35
|
+
requireApproval?: boolean;
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* Tool 视角规则接口
|
|
@@ -43,6 +45,10 @@ export interface ToolRule {
|
|
|
43
45
|
number: number;
|
|
44
46
|
/** 规则等级 */
|
|
45
47
|
ruleClass: RuleClass;
|
|
48
|
+
/** v1.3.0 (交付 7):双规则统一——'tool' = 运行时拦截工具调用 */
|
|
49
|
+
ruleType: 'tool';
|
|
50
|
+
/** v1.3.0 (交付 10 MA7):规则「为什么」记忆 namespace——提取规则触发上下文时按此分组 */
|
|
51
|
+
whyMemoryNamespace?: string;
|
|
46
52
|
/**
|
|
47
53
|
* 检查 tool call 是否违规
|
|
48
54
|
* @param ctx tool call 上下文
|
package/dist/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// ============================================================
|
|
3
3
|
// types.ts · P3 编排引擎内嵌——tool call 拦截器类型定义
|
|
4
|
-
// v1.
|
|
4
|
+
// v1.3.0:从 audit 规则抽出为纯函数,零 fs/git 依赖
|
|
5
5
|
// ============================================================
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sofagent/rules",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "sofagent 规则引擎纯函数包——从 audit 抽出,零 fs/git 依赖,供编排引擎 tool call 事前拦截",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npm run clean && tsc",
|
|
9
|
-
"clean": "
|
|
9
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
10
10
|
"test": "vitest run"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@sofagent/core": "1.
|
|
31
|
+
"@sofagent/core": "1.3.0"
|
|
32
32
|
}
|
|
33
33
|
}
|