@lmzhen/dsh-evolution-threat 0.1.0-rc.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.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @deepseek-ai/dsh-evolution-threat
2
+
3
+ Write-time threat guard for evolution tools
4
+
5
+ ## Model Experience
6
+
7
+ ### Indirect model surface
8
+
9
+ #### What the model sees
10
+
11
+ `@deepseek-ai/dsh-evolution-threat` registers no direct prompt or tool schema itself. Model-visible effects are owned by the packages that consume this service.
12
+
13
+ #### Token effect
14
+
15
+ Zero direct token effect from this package; consumers add any model-visible tokens.
16
+
17
+ #### KV Cache effect
18
+
19
+ Independent of request-prefix construction. This package does not alter the assembled prompt or tool list.
20
+
21
+ ## Known Limitations and Deferred Work
22
+
23
+
24
+ - No known durable consumer gaps at this time. Runtime contracts are covered by package and boundary tests.
package/lib/index.js ADDED
@@ -0,0 +1,57 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { scanContentThreats, scanMemoryThreats } from "@lmzhen/dsh-evolution-core";
3
+ //#region lib/types/index.js
4
+ /**
5
+ * Write-time threat guard for evolution tools.
6
+ * @module @lmzhen/dsh-evolution-threat
7
+ */
8
+ const name = "evolution-threat";
9
+ const inject = ["tools"];
10
+ const Config = z.object({
11
+ enabled: z.boolean().default(true),
12
+ maxScanChars: z.number().default(65536)
13
+ });
14
+ function asRecord(value) {
15
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
16
+ }
17
+ function scanArgs(toolName, args, maxScanChars) {
18
+ if (toolName !== "memory" && toolName !== "skill_manage") return null;
19
+ const record = asRecord(args);
20
+ if (toolName === "memory") {
21
+ for (const text of [record.facts, record.content]) if (typeof text === "string") {
22
+ const hit = scanMemoryThreats(text, maxScanChars);
23
+ if (hit) return hit;
24
+ }
25
+ if (Array.isArray(record.operations)) for (const op of record.operations) {
26
+ const text = asRecord(op).facts ?? asRecord(op).content;
27
+ if (typeof text === "string") {
28
+ const hit = scanMemoryThreats(text, maxScanChars);
29
+ if (hit) return hit;
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ for (const text of [
35
+ record.content,
36
+ record.file_content,
37
+ record.new_string
38
+ ]) if (typeof text === "string") {
39
+ const hit = scanContentThreats(text, maxScanChars);
40
+ if (hit) return hit;
41
+ }
42
+ return null;
43
+ }
44
+ function apply(ctx, rawConfig = {}) {
45
+ if (!(rawConfig.enabled ?? true)) return;
46
+ const maxScanChars = rawConfig.maxScanChars ?? 65536;
47
+ ctx.on("tools/pre-execute", async (exec, next) => {
48
+ const hit = scanArgs(exec.name, exec.arguments, maxScanChars);
49
+ if (hit) return {
50
+ kind: "deny",
51
+ reason: hit
52
+ };
53
+ return next();
54
+ });
55
+ }
56
+ //#endregion
57
+ export { Config, apply, inject, name };
@@ -0,0 +1,8 @@
1
+ //#region lib/types/invariant.js
2
+ const PACKAGE_NAME = "@deepseek-ai/dsh-evolution-threat";
3
+ const name = "evolution-threat-invariant";
4
+ const inject = ["invariants"];
5
+ const install = () => {};
6
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
7
+ //#endregion
8
+ export { apply, inject, name };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Write-time threat guard for evolution tools.
3
+ * @module @deepseek-ai/dsh-evolution-threat
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ import z from '@deepseek-ai/schemastery';
7
+ export declare const name = "evolution-threat";
8
+ export declare const inject: string[];
9
+ export interface Config {
10
+ enabled?: boolean;
11
+ /** Maximum normalized characters scanned per write field. */
12
+ maxScanChars?: number;
13
+ }
14
+ export declare const Config: z<Config>;
15
+ export declare function apply(ctx: Context, rawConfig?: Config): void;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ export declare const name = "evolution-threat-invariant";
3
+ export declare const inject: string[];
4
+ export declare const apply: (ctx: Context) => Promise<() => void>;
5
+ //# sourceMappingURL=invariant.d.ts.map
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@lmzhen/dsh-evolution-threat",
3
+ "description": "Write-time threat guard for evolution tools (community build)",
4
+ "version": "0.1.0-rc.1",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/lmzhen/dsh-evolution.git",
11
+ "directory": "packages/dsh-evolution-threat"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "lib/index.js",
29
+ "lib/invariant.js",
30
+ "lib/types/**/*.d.ts",
31
+ "lib/types/invariant.d.ts"
32
+ ],
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "@deepseek-ai/schemastery": "^3.18.1",
36
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.1"
37
+ },
38
+ "peerDependencies": {
39
+ "@deepseek-ai/cordis": "^4.0.1",
40
+ "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
41
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.6"
42
+ },
43
+ "devDependencies": {
44
+ "@deepseek-ai/dsh-agent-loop-testkit": "^0.1.0-rc.6",
45
+ "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
46
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
47
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.1"
48
+ }
49
+ }