@lmzhen/dsh-evolution-threat 0.3.21 → 0.3.23

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
- import { EVOLUTION_WRITE_TOOLS, scanContentThreats, scanMemoryThreats } from "@lmzhen/dsh-evolution-core";
2
+ import { EVOLUTION_WRITE_TOOLS, clampedNumber, scanContentThreats, scanMemoryThreats } from "@lmzhen/dsh-evolution-core";
3
3
  //#region lib/types/index.js
4
4
  /**
5
5
  * Write-time threat guard for evolution tools.
@@ -9,7 +9,7 @@ const name = "evolution-threat";
9
9
  const inject = ["tools"];
10
10
  const Config = z.object({
11
11
  enabled: z.boolean().default(true),
12
- maxScanChars: z.number().default(65536)
12
+ maxScanChars: z.number().min(1).default(65536)
13
13
  });
14
14
  function asRecord(value) {
15
15
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
@@ -43,9 +43,16 @@ function scanToolArgs(toolName, args, maxScanChars) {
43
43
  }
44
44
  return null;
45
45
  }
46
+ /** Resolve the effective `maxScanChars`, clamping invalid values to the
47
+ * default (G3.1: 0/negative/NaN/±Infinity → 65_536). Exported so the clamp is
48
+ * directly testable; `apply` warns when a user-supplied value was corrected. */
49
+ function resolveMaxScanChars(config) {
50
+ return clampedNumber(config.maxScanChars ?? 65536, 65536, { min: 1 });
51
+ }
46
52
  function apply(ctx, rawConfig = {}) {
47
53
  if (!(rawConfig.enabled ?? true)) return;
48
- const maxScanChars = rawConfig.maxScanChars ?? 65536;
54
+ const maxScanChars = resolveMaxScanChars(rawConfig);
55
+ if (maxScanChars !== (rawConfig.maxScanChars ?? 65536)) ctx.logger.warn(`evolution-threat: maxScanChars=${String(rawConfig.maxScanChars)} is invalid; falling back to the default 65_536`);
49
56
  ctx.on("tools/pre-execute", async (exec, next) => {
50
57
  const hit = scanToolArgs(exec.name, exec.arguments, maxScanChars);
51
58
  if (hit) return {
@@ -56,4 +63,4 @@ function apply(ctx, rawConfig = {}) {
56
63
  });
57
64
  }
58
65
  //#endregion
59
- export { Config, apply, inject, name, scanToolArgs };
66
+ export { Config, apply, inject, name, resolveMaxScanChars, scanToolArgs };
@@ -15,5 +15,9 @@ export declare const Config: z<Config>;
15
15
  /** Scan one tool invocation for threat-shaped payload text. Exported so the
16
16
  * guard contract is testable directly (0.3.17). */
17
17
  export declare function scanToolArgs(toolName: string, args: unknown, maxScanChars: number): string | null;
18
+ /** Resolve the effective `maxScanChars`, clamping invalid values to the
19
+ * default (G3.1: 0/negative/NaN/±Infinity → 65_536). Exported so the clamp is
20
+ * directly testable; `apply` warns when a user-supplied value was corrected. */
21
+ export declare function resolveMaxScanChars(config: Config): number;
18
22
  export declare function apply(ctx: Context, rawConfig?: Config): void;
19
23
  //# 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.21",
4
+ "version": "0.3.23",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -31,7 +31,7 @@
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
33
  "@deepseek-ai/schemastery": "^3.18.1",
34
- "@lmzhen/dsh-evolution-core": "^0.3.21"
34
+ "@lmzhen/dsh-evolution-core": "^0.3.23"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@deepseek-ai/cordis": "^4.0.1",
@@ -42,6 +42,6 @@
42
42
  "@deepseek-ai/dsh-agent-loop-testkit": "^0.1.1-rc.2",
43
43
  "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
44
44
  "@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
45
- "@lmzhen/dsh-evolution-core": "^0.3.21"
45
+ "@lmzhen/dsh-evolution-core": "^0.3.23"
46
46
  }
47
47
  }