@lmzhen/dsh-evolution-activity 0.44.0 → 0.45.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.
Files changed (47) hide show
  1. package/lib/feedback/index.js +690 -0
  2. package/lib/index.js +23 -18
  3. package/lib/learning-graph/index.js +538 -0
  4. package/lib/replay/index.js +286 -0
  5. package/lib/threat/index.js +70 -0
  6. package/lib/types/feedback/index.d.ts +179 -0
  7. package/lib/types/feedback/index.js +899 -0
  8. package/lib/types/index.js +335 -0
  9. package/lib/types/learning-graph/index.d.ts +178 -0
  10. package/lib/types/learning-graph/index.js +712 -0
  11. package/lib/types/replay/index.d.ts +182 -0
  12. package/lib/types/replay/index.js +404 -0
  13. package/lib/types/threat/index.d.ts +35 -0
  14. package/lib/types/threat/index.js +119 -0
  15. package/locale/feedback/de.json +6 -0
  16. package/locale/feedback/en.json +6 -0
  17. package/locale/feedback/es.json +6 -0
  18. package/locale/feedback/fr.json +6 -0
  19. package/locale/feedback/ja.json +6 -0
  20. package/locale/feedback/pt.json +6 -0
  21. package/locale/feedback/ru.json +6 -0
  22. package/locale/feedback/zh.json +6 -0
  23. package/locale/learning-graph/de.json +6 -0
  24. package/locale/learning-graph/en.json +6 -0
  25. package/locale/learning-graph/es.json +6 -0
  26. package/locale/learning-graph/fr.json +6 -0
  27. package/locale/learning-graph/ja.json +6 -0
  28. package/locale/learning-graph/pt.json +6 -0
  29. package/locale/learning-graph/ru.json +6 -0
  30. package/locale/learning-graph/zh.json +6 -0
  31. package/locale/replay/de.json +6 -0
  32. package/locale/replay/en.json +6 -0
  33. package/locale/replay/es.json +6 -0
  34. package/locale/replay/fr.json +6 -0
  35. package/locale/replay/ja.json +6 -0
  36. package/locale/replay/pt.json +6 -0
  37. package/locale/replay/ru.json +6 -0
  38. package/locale/replay/zh.json +6 -0
  39. package/locale/threat/de.json +6 -0
  40. package/locale/threat/en.json +6 -0
  41. package/locale/threat/es.json +6 -0
  42. package/locale/threat/fr.json +6 -0
  43. package/locale/threat/ja.json +6 -0
  44. package/locale/threat/pt.json +6 -0
  45. package/locale/threat/ru.json +6 -0
  46. package/locale/threat/zh.json +6 -0
  47. 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
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Qualitätswert",
4
+ "description": "Macht aus Bewertungen einen Qualitätswert; die Bewertungen muss eine andere Quelle liefern."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Feedback scoring",
4
+ "description": "Turns skill ratings into a quality score; needs another source to supply the ratings."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Nota de calidad",
4
+ "description": "Convierte en nota de calidad las valoraciones de skills que aporta otra fuente."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Note des retours",
4
+ "description": "Transforme les notes des skills en score de qualité ; une autre source doit fournir ces notes."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "評価の点数化",
4
+ "description": "スキルの評価を品質スコアに変えるが、評価を渡してくれる機能が別に要る。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Nota de qualidade",
4
+ "description": "Dá uma nota de qualidade às skills a partir de avaliações que vêm de outra fonte."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Оценка отзывов",
4
+ "description": "Превращает оценки навыков в общий балл качества; ставить оценки должен другой источник."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "反馈评分",
4
+ "description": "把技能收到的评分算成一个质量分;评分得由别的地方提供。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Wissensverbindungen",
4
+ "description": "Verbindet Skills und gemerkte Fakten, damit zusammengehöriges Wissen verknüpft bleibt."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Knowledge links",
4
+ "description": "Links skills and remembered facts so related knowledge stays connected."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Enlaces de conocimiento",
4
+ "description": "Une skills y datos recordados para que el conocimiento relacionado siga conectado."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Liens entre les savoirs",
4
+ "description": "Relie les skills et les faits retenus pour que les savoirs proches restent regroupés."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "知識のつながり",
4
+ "description": "スキルと覚えた知識をつなぎ、関係する知識をたどりやすくする。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Conexões de conhecimento",
4
+ "description": "Liga skills e fatos lembrados para o conhecimento relacionado continuar conectado."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Связи знаний",
4
+ "description": "Связывает навыки и запомненные факты, чтобы близкое знание было рядом."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "知识关联",
4
+ "description": "把技能和记住的事连起来,相关的内容不会散着。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Pläne vergleichen",
4
+ "description": "Vergleicht frühere Pläne und bewertet, wie sie gelaufen sind; führt sie nie erneut aus."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Plan compare",
4
+ "description": "Compares past plans and scores how they went; never re-runs them."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Comparación de planes",
4
+ "description": "Compara planes anteriores, puntúa cómo salieron y nunca los repite."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Comparaison de plans",
4
+ "description": "Compare les plans passés et note comment ils se sont déroulés ; il ne les relance jamais."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "計画の比較",
4
+ "description": "過去の計画を比べて結果を採点するだけで、同じ計画をやり直すことはない。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Comparação de planos",
4
+ "description": "Compara planos anteriores, dá uma nota a como saíram e nunca os executa de novo."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Сравнение планов",
4
+ "description": "Сравнивает прошлые планы и оценивает, чем закончились; ничего не запускает заново."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "计划对比",
4
+ "description": "把过去的计划放在一起比,给它们的结果打分;不会重跑。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Sicherheitsprüfung",
4
+ "description": "Prüft Änderungen an Gedächtnis und Skills auf unsichere Inhalte."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Safety scan",
4
+ "description": "Checks the agent's memory and skill changes for unsafe content."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Análisis de seguridad",
4
+ "description": "Comprueba si los cambios de memoria y de skills traen contenido peligroso."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Contrôle de sécurité",
4
+ "description": "Vérifie que les changements de mémoire et de skills ne contiennent rien de dangereux."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "安全確認",
4
+ "description": "メモリとスキルの変更に、危険な内容がないか確かめる。"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Verificação de segurança",
4
+ "description": "Confere se as mudanças de memória e de skills trazem conteúdo inseguro."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Проверка безопасности",
4
+ "description": "Ищет небезопасное содержимое в изменениях памяти и навыков."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "安全扫描",
4
+ "description": "改记忆、改技能时,先查一遍有没有不安全的内容。"
5
+ }
6
+ }
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.44.0",
4
+ "version": "0.45.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
- "locale/*.json",
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.44.0"
54
+ "@lmzhen/dsh-evolution-core": "^0.45.0",
55
+ "@lmzhen/dsh-evolution-skill-discovery": "^0.45.0",
56
+ "@lmzhen/dsh-evolution-approval": "^0.45.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.44.0",
40
- "@lmzhen/dsh-evolution-io": "^0.44.0",
41
- "@lmzhen/dsh-evolution-io-node": "^0.44.0"
63
+ "@lmzhen/dsh-evolution-core": "^0.45.0"
42
64
  },
43
65
  "engines": {
44
66
  "dsh": ">=0.2.2-rc.0 <0.2.3-0"