@lmzhen/dsh-evolution-activity 0.44.0 → 0.46.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/lib/feedback/index.js +690 -0
- package/lib/index.js +23 -18
- package/lib/learning-graph/index.js +538 -0
- package/lib/replay/index.js +286 -0
- package/lib/threat/index.js +70 -0
- package/lib/types/feedback/index.d.ts +179 -0
- package/lib/types/feedback/index.js +899 -0
- package/lib/types/index.js +335 -0
- package/lib/types/learning-graph/index.d.ts +178 -0
- package/lib/types/learning-graph/index.js +712 -0
- package/lib/types/replay/index.d.ts +182 -0
- package/lib/types/replay/index.js +404 -0
- package/lib/types/threat/index.d.ts +35 -0
- package/lib/types/threat/index.js +119 -0
- package/locale/feedback/de.json +6 -0
- package/locale/feedback/en.json +6 -0
- package/locale/feedback/es.json +6 -0
- package/locale/feedback/fr.json +6 -0
- package/locale/feedback/ja.json +6 -0
- package/locale/feedback/pt.json +6 -0
- package/locale/feedback/ru.json +6 -0
- package/locale/feedback/zh.json +6 -0
- package/locale/learning-graph/de.json +6 -0
- package/locale/learning-graph/en.json +6 -0
- package/locale/learning-graph/es.json +6 -0
- package/locale/learning-graph/fr.json +6 -0
- package/locale/learning-graph/ja.json +6 -0
- package/locale/learning-graph/pt.json +6 -0
- package/locale/learning-graph/ru.json +6 -0
- package/locale/learning-graph/zh.json +6 -0
- package/locale/replay/de.json +6 -0
- package/locale/replay/en.json +6 -0
- package/locale/replay/es.json +6 -0
- package/locale/replay/fr.json +6 -0
- package/locale/replay/ja.json +6 -0
- package/locale/replay/pt.json +6 -0
- package/locale/replay/ru.json +6 -0
- package/locale/replay/zh.json +6 -0
- package/locale/threat/de.json +6 -0
- package/locale/threat/en.json +6 -0
- package/locale/threat/es.json +6 -0
- package/locale/threat/fr.json +6 -0
- package/locale/threat/ja.json +6 -0
- package/locale/threat/pt.json +6 -0
- package/locale/threat/ru.json +6 -0
- package/locale/threat/zh.json +6 -0
- package/package.json +30 -8
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write-time threat guard for evolution tools.
|
|
3
|
+
* @module @lmzhen/dsh-evolution-threat
|
|
4
|
+
*/
|
|
5
|
+
import { asRecord } from '@lmzhen/dsh-evolution-core';
|
|
6
|
+
import z from '@deepseek-ai/schemastery';
|
|
7
|
+
import { DEFAULT_THREAT_MAX_SCAN_CHARS, EVOLUTION_WRITE_TOOLS, PATTERN_OVERLAP, scanContentThreats, scanMemoryThreats, clampedNumber } from '@lmzhen/dsh-evolution-core';
|
|
8
|
+
import { toolsPort } from '@lmzhen/dsh-evolution-core/platform';
|
|
9
|
+
export const name = 'evolution-threat';
|
|
10
|
+
export const Config = z.object({
|
|
11
|
+
enabled: z.boolean().default(true),
|
|
12
|
+
// V6-05 (0.3.35): the legal range is [PATTERN_OVERLAP + 1, ∞) — a window
|
|
13
|
+
// below the overlap floor cannot guarantee full-coverage scanning (see
|
|
14
|
+
// evolution-core PATTERN_OVERLAP), so the schema rejects it at load and the
|
|
15
|
+
// assembly clamp falls back to the default.
|
|
16
|
+
maxScanChars: z.number().min(PATTERN_OVERLAP + 1).default(DEFAULT_THREAT_MAX_SCAN_CHARS),
|
|
17
|
+
threatExemptLabels: z.array(z.string()).default([]),
|
|
18
|
+
});
|
|
19
|
+
/** Scan one tool invocation for threat-shaped payload text. Exported so the
|
|
20
|
+
* guard contract is testable directly (0.3.17). `options.excludeLabels` carries
|
|
21
|
+
* the deployment's benign-label allowlist so this channel agrees with the
|
|
22
|
+
* SkillLibrary/MemoryStore write gates (P2-4, v14). */
|
|
23
|
+
export function scanToolArgs(toolName, args, maxScanChars, options = {}) {
|
|
24
|
+
// 0.3.20 (N-5): the write-tool set is the core single source — the local
|
|
25
|
+
// hardcoded pair drifted into the S3.10 dead-constant trap.
|
|
26
|
+
if (!EVOLUTION_WRITE_TOOLS.includes(toolName))
|
|
27
|
+
return null;
|
|
28
|
+
const record = asRecord(args);
|
|
29
|
+
// `asRecord` answers `undefined` for anything that is not a plain mapping: there is nothing to
|
|
30
|
+
// scan then, and saying so once removes the index-safety noise below (the CI build line proved it).
|
|
31
|
+
if (record === undefined)
|
|
32
|
+
return null;
|
|
33
|
+
if (toolName === 'memory') {
|
|
34
|
+
for (const text of [record.facts, record.content]) {
|
|
35
|
+
if (typeof text === 'string') {
|
|
36
|
+
const hit = scanMemoryThreats(text, maxScanChars, options);
|
|
37
|
+
if (hit)
|
|
38
|
+
return hit;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(record.operations)) {
|
|
42
|
+
for (const op of record.operations) {
|
|
43
|
+
// 0.3.17 (E-28a): `facts ?? content` let a truthy non-string `facts`
|
|
44
|
+
// shadow a string `content` — scan BOTH (union), scanning a value
|
|
45
|
+
// twice is cheap and safe.
|
|
46
|
+
const inner = asRecord(op);
|
|
47
|
+
if (inner === undefined)
|
|
48
|
+
continue;
|
|
49
|
+
for (const text of [inner.facts, inner.content]) {
|
|
50
|
+
if (typeof text === 'string') {
|
|
51
|
+
const hit = scanMemoryThreats(text, maxScanChars, options);
|
|
52
|
+
if (hit)
|
|
53
|
+
return hit;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
for (const text of [record.content, record.file_content, record.new_string]) {
|
|
61
|
+
if (typeof text === 'string') {
|
|
62
|
+
const hit = scanContentThreats(text, maxScanChars, options);
|
|
63
|
+
if (hit)
|
|
64
|
+
return hit;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/** Resolve the effective `maxScanChars`, clamping invalid values to the
|
|
70
|
+
* default (G3.1: 0/negative/NaN/±Infinity → DEFAULT_THREAT_MAX_SCAN_CHARS; V6-05: a value below
|
|
71
|
+
* PATTERN_OVERLAP + 1 is out of the coverage-guarantee domain → default).
|
|
72
|
+
* Exported so the clamp is directly testable; `apply` warns when a
|
|
73
|
+
* user-supplied value was corrected. */
|
|
74
|
+
export function resolveMaxScanChars(config) {
|
|
75
|
+
return clampedNumber(config.maxScanChars ?? DEFAULT_THREAT_MAX_SCAN_CHARS, DEFAULT_THREAT_MAX_SCAN_CHARS, { min: PATTERN_OVERLAP + 1 });
|
|
76
|
+
}
|
|
77
|
+
export function apply(ctx, rawConfig = {}) {
|
|
78
|
+
if (!(rawConfig.enabled ?? true))
|
|
79
|
+
return;
|
|
80
|
+
// V6-05 (0.3.35): the clamp floor is PATTERN_OVERLAP+1 (=4097) so the
|
|
81
|
+
// proportional step never leaves a match span uncovered — a 0 would silently
|
|
82
|
+
// disable scanning and NaN/±Infinity (the number schema lets them through)
|
|
83
|
+
// would corrupt the scan window; the schema `.min(PATTERN_OVERLAP + 1)` and
|
|
84
|
+
// this clamp were both raised to the overlap floor in V6-05.
|
|
85
|
+
const maxScanChars = resolveMaxScanChars(rawConfig);
|
|
86
|
+
if (maxScanChars !== (rawConfig.maxScanChars ?? DEFAULT_THREAT_MAX_SCAN_CHARS)) {
|
|
87
|
+
ctx.logger.warn(`evolution-threat: maxScanChars=${String(rawConfig.maxScanChars)} is invalid; falling back to the default ${DEFAULT_THREAT_MAX_SCAN_CHARS}`);
|
|
88
|
+
}
|
|
89
|
+
// P2-4 (v14): the store gates already honored `threatExemptLabels`; the guard
|
|
90
|
+
// channel did not, so an exempted payload was still denied here and the deny
|
|
91
|
+
// message pointed at an option this row could not read.
|
|
92
|
+
const scanOptions = { excludeLabels: rawConfig.threatExemptLabels ?? [] };
|
|
93
|
+
// V10-12 (P2-8): the deny decision moved from a `tools/pre-execute`
|
|
94
|
+
// waterfall listener to the monotonic `tools.guard()` channel (the same
|
|
95
|
+
// channel evolution-policy uses). The pre-execute waterfall is extensible
|
|
96
|
+
// and any earlier listener may short-circuit it by returning a decision
|
|
97
|
+
// without calling `next()` — which silently skipped the threat scan. A
|
|
98
|
+
// guard runs for every ALLOWED execution (upstream evaluates guards on the
|
|
99
|
+
// allow path of the pre-execute gate) and cannot be force-allowed or
|
|
100
|
+
// bypassed by listener ordering; a short-circuiting DENIAL still denies the
|
|
101
|
+
// call, so both outcomes keep the payload scanned-or-denied.
|
|
102
|
+
// The former listener is REMOVED rather than kept as a logging observer:
|
|
103
|
+
// guards and listeners receive the same arguments, so keeping both would
|
|
104
|
+
// double-scan every write-tool call on the hot path.
|
|
105
|
+
ctx.inject(['tools'], (toolCtx) => {
|
|
106
|
+
// P2-13 (v15): the REAL upstream guard type — an upstream signature drift
|
|
107
|
+
// now fails `tsc` at the mirror instead of surfacing at runtime after an
|
|
108
|
+
// upgrade. (The hand-written shape was
|
|
109
|
+
// { guard(guard: (exec: { name; arguments }) => string | undefined): () => void }.)
|
|
110
|
+
const tools = toolsPort(toolCtx);
|
|
111
|
+
if (tools === undefined)
|
|
112
|
+
return;
|
|
113
|
+
toolCtx.effect(() => tools.guard((exec) => {
|
|
114
|
+
const hit = scanToolArgs(exec.name, exec.arguments, maxScanChars, scanOptions);
|
|
115
|
+
return hit ?? undefined;
|
|
116
|
+
}), 'evolution-threat.tools-guard');
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-activity",
|
|
3
3
|
"description": "Durable activity store for self-evolution plan outcomes (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.46.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -19,26 +19,48 @@
|
|
|
19
19
|
"default": "./lib/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./package.json": "./package.json",
|
|
22
|
-
"./locale/*.json": "./locale/*.json"
|
|
22
|
+
"./locale/*.json": "./locale/*.json",
|
|
23
|
+
"./feedback": {
|
|
24
|
+
"types": "./lib/types/feedback/index.d.ts",
|
|
25
|
+
"default": "./lib/feedback/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./feedback/locale/*.json": "./locale/feedback/*.json",
|
|
28
|
+
"./replay": {
|
|
29
|
+
"types": "./lib/types/replay/index.d.ts",
|
|
30
|
+
"default": "./lib/replay/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./replay/locale/*.json": "./locale/replay/*.json",
|
|
33
|
+
"./learning-graph": {
|
|
34
|
+
"types": "./lib/types/learning-graph/index.d.ts",
|
|
35
|
+
"default": "./lib/learning-graph/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./learning-graph/locale/*.json": "./locale/learning-graph/*.json",
|
|
38
|
+
"./threat": {
|
|
39
|
+
"types": "./lib/types/threat/index.d.ts",
|
|
40
|
+
"default": "./lib/threat/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./threat/locale/*.json": "./locale/threat/*.json"
|
|
23
43
|
},
|
|
24
44
|
"files": [
|
|
25
|
-
"
|
|
45
|
+
"lib/**/*.js",
|
|
26
46
|
"lib/*.js",
|
|
27
|
-
"lib/types/**/*.d.ts"
|
|
47
|
+
"lib/types/**/*.d.ts",
|
|
48
|
+
"locale/**/*.json",
|
|
49
|
+
"locale/*.json"
|
|
28
50
|
],
|
|
29
51
|
"license": "MIT",
|
|
30
52
|
"dependencies": {
|
|
31
53
|
"@deepseek-ai/schemastery": "^3.18.5",
|
|
32
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
54
|
+
"@lmzhen/dsh-evolution-core": "^0.46.0",
|
|
55
|
+
"@lmzhen/dsh-evolution-skill-discovery": "^0.46.0",
|
|
56
|
+
"@lmzhen/dsh-evolution-approval": "^0.46.0"
|
|
33
57
|
},
|
|
34
58
|
"peerDependencies": {
|
|
35
59
|
"@deepseek-ai/cordis": "^4.0.5"
|
|
36
60
|
},
|
|
37
61
|
"devDependencies": {
|
|
38
62
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
39
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
40
|
-
"@lmzhen/dsh-evolution-io": "^0.44.0",
|
|
41
|
-
"@lmzhen/dsh-evolution-io-node": "^0.44.0"
|
|
63
|
+
"@lmzhen/dsh-evolution-core": "^0.46.0"
|
|
42
64
|
},
|
|
43
65
|
"engines": {
|
|
44
66
|
"dsh": ">=0.2.2-rc.0 <0.2.3-0"
|