@lmzhen/dsh-evolution-threat 0.3.16 → 0.3.18
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/lib/index.js +7 -5
- package/lib/types/index.d.ts +3 -0
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -14,7 +14,9 @@ const Config = z.object({
|
|
|
14
14
|
function asRecord(value) {
|
|
15
15
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
/** Scan one tool invocation for threat-shaped payload text. Exported so the
|
|
18
|
+
* guard contract is testable directly (0.3.17). */
|
|
19
|
+
function scanToolArgs(toolName, args, maxScanChars) {
|
|
18
20
|
if (toolName !== "memory" && toolName !== "skill_manage") return null;
|
|
19
21
|
const record = asRecord(args);
|
|
20
22
|
if (toolName === "memory") {
|
|
@@ -23,8 +25,8 @@ function scanArgs(toolName, args, maxScanChars) {
|
|
|
23
25
|
if (hit) return hit;
|
|
24
26
|
}
|
|
25
27
|
if (Array.isArray(record.operations)) for (const op of record.operations) {
|
|
26
|
-
const
|
|
27
|
-
if (typeof text === "string") {
|
|
28
|
+
const inner = asRecord(op);
|
|
29
|
+
for (const text of [inner.facts, inner.content]) if (typeof text === "string") {
|
|
28
30
|
const hit = scanMemoryThreats(text, maxScanChars);
|
|
29
31
|
if (hit) return hit;
|
|
30
32
|
}
|
|
@@ -45,7 +47,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
45
47
|
if (!(rawConfig.enabled ?? true)) return;
|
|
46
48
|
const maxScanChars = rawConfig.maxScanChars ?? 65536;
|
|
47
49
|
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
48
|
-
const hit =
|
|
50
|
+
const hit = scanToolArgs(exec.name, exec.arguments, maxScanChars);
|
|
49
51
|
if (hit) return {
|
|
50
52
|
kind: "deny",
|
|
51
53
|
reason: hit
|
|
@@ -54,4 +56,4 @@ function apply(ctx, rawConfig = {}) {
|
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
//#endregion
|
|
57
|
-
export { Config, apply, inject, name };
|
|
59
|
+
export { Config, apply, inject, name, scanToolArgs };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -12,5 +12,8 @@ export interface Config {
|
|
|
12
12
|
maxScanChars?: number;
|
|
13
13
|
}
|
|
14
14
|
export declare const Config: z<Config>;
|
|
15
|
+
/** Scan one tool invocation for threat-shaped payload text. Exported so the
|
|
16
|
+
* guard contract is testable directly (0.3.17). */
|
|
17
|
+
export declare function scanToolArgs(toolName: string, args: unknown, maxScanChars: number): string | null;
|
|
15
18
|
export declare function apply(ctx: Context, rawConfig?: Config): void;
|
|
16
19
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-threat",
|
|
3
3
|
"description": "Write-time threat guard for evolution tools (community build)",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.18",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@deepseek-ai/schemastery": "^3.18.1",
|
|
36
|
-
"@lmzhen/dsh-evolution-core": "^0.3.
|
|
36
|
+
"@lmzhen/dsh-evolution-core": "^0.3.18"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"@deepseek-ai/dsh-agent-loop-testkit": "^0.1.1-rc.2",
|
|
45
45
|
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
|
|
46
46
|
"@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
|
|
47
|
-
"@lmzhen/dsh-evolution-core": "^0.3.
|
|
47
|
+
"@lmzhen/dsh-evolution-core": "^0.3.18"
|
|
48
48
|
}
|
|
49
49
|
}
|