@lmzhen/dsh-evolution-replay 0.3.22 → 0.3.24

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,4 +1,5 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
+ import { clampedNumber } from "@lmzhen/dsh-evolution-core";
2
3
  //#region lib/types/index.js
3
4
  /**
4
5
  * Replay/A-B evaluation for evolution plans.
@@ -19,14 +20,29 @@ const DEFAULT_WEIGHTS = {
19
20
  cost: .001
20
21
  };
21
22
  const Config = z.object({
22
- maxPlans: z.number().default(50),
23
+ maxPlans: z.number().min(1).default(50),
23
24
  weights: z.object({
24
- accepted: z.number().default(10),
25
- rejectedPenalty: z.number().default(15),
26
- evidence: z.number().default(2),
27
- cost: z.number().default(.001)
25
+ accepted: z.number().min(1).default(10),
26
+ rejectedPenalty: z.number().min(1).default(15),
27
+ evidence: z.number().min(1).default(2),
28
+ cost: z.number().min(0).default(.001)
28
29
  }).default(DEFAULT_WEIGHTS)
29
30
  });
31
+ /**
32
+ * Clamp a weights object to its per-field domain (G3.1). `accepted`,
33
+ * `rejectedPenalty` and `evidence` are positive multipliers (min 1 — a zero or
34
+ * negative weight would silently drop a scoring term or reverse its sign);
35
+ * `cost` may be 0 (0 means "no cost penalty"), so its min is 0. NaN, ±Infinity
36
+ * and out-of-range values fall back to the default for that field.
37
+ */
38
+ function clampReplayWeights(weights, fallback = DEFAULT_WEIGHTS) {
39
+ return {
40
+ accepted: clampedNumber(weights?.accepted, fallback.accepted, { min: 1 }),
41
+ rejectedPenalty: clampedNumber(weights?.rejectedPenalty, fallback.rejectedPenalty, { min: 1 }),
42
+ evidence: clampedNumber(weights?.evidence, fallback.evidence, { min: 1 }),
43
+ cost: clampedNumber(weights?.cost, fallback.cost, { min: 0 })
44
+ };
45
+ }
30
46
  function scorePlan(plan, weights = DEFAULT_WEIGHTS) {
31
47
  return plan.acceptedOps * weights.accepted - plan.rejectedOps * weights.rejectedPenalty + plan.evidenceQuotes * weights.evidence - plan.estimatedInputChars * weights.cost;
32
48
  }
@@ -61,9 +77,11 @@ var EvolutionReplayDriver = class {
61
77
  plans = [];
62
78
  maxPlans;
63
79
  weights;
64
- constructor(config = {}) {
65
- this.maxPlans = config.maxPlans ?? 50;
66
- this.weights = config.weights ?? DEFAULT_WEIGHTS;
80
+ constructor(config = {}, warn = () => {}) {
81
+ const maxPlans = clampedNumber(config.maxPlans ?? 50, 50, { min: 1 });
82
+ this.maxPlans = maxPlans;
83
+ if (config.maxPlans !== void 0 && maxPlans !== config.maxPlans) warn(`evolution-replay: maxPlans=${String(config.maxPlans)} is invalid; falling back to the default 50`);
84
+ this.weights = clampReplayWeights(config.weights);
67
85
  }
68
86
  record(plan) {
69
87
  this.plans.push({
@@ -86,11 +104,13 @@ var EvolutionReplayDriver = class {
86
104
  };
87
105
  const name = "evolution-replay";
88
106
  function apply(ctx, rawConfig = {}) {
89
- const driver = new EvolutionReplayDriver(rawConfig);
107
+ const driver = new EvolutionReplayDriver(rawConfig, (message) => {
108
+ ctx.logger.warn(message);
109
+ });
90
110
  ctx.provide("evolutionReplay", driver);
91
111
  ctx.on("evolution/plan-applied", (event) => {
92
112
  driver.record(event);
93
113
  });
94
114
  }
95
115
  //#endregion
96
- export { Config, DEFAULT_WEIGHTS, EvolutionReplayDriver, apply, comparePlans, name };
116
+ export { Config, DEFAULT_WEIGHTS, EvolutionReplayDriver, apply, clampReplayWeights, comparePlans, name };
@@ -40,6 +40,14 @@ export interface Config {
40
40
  weights?: ReplayWeights;
41
41
  }
42
42
  export declare const Config: z<Config>;
43
+ /**
44
+ * Clamp a weights object to its per-field domain (G3.1). `accepted`,
45
+ * `rejectedPenalty` and `evidence` are positive multipliers (min 1 — a zero or
46
+ * negative weight would silently drop a scoring term or reverse its sign);
47
+ * `cost` may be 0 (0 means "no cost penalty"), so its min is 0. NaN, ±Infinity
48
+ * and out-of-range values fall back to the default for that field.
49
+ */
50
+ export declare function clampReplayWeights(weights: ReplayWeights | undefined, fallback?: ReplayWeights): ReplayWeights;
43
51
  export declare function comparePlans(plans: ReplayPlan[], weights?: ReplayWeights): ReplayResult;
44
52
  declare module '@deepseek-ai/cordis' {
45
53
  interface Context {
@@ -50,7 +58,7 @@ export declare class EvolutionReplayDriver {
50
58
  private readonly plans;
51
59
  private readonly maxPlans;
52
60
  private readonly weights;
53
- constructor(config?: Config);
61
+ constructor(config?: Config, warn?: (message: string) => void);
54
62
  record(plan: EvolutionPlanAppliedEvent): void;
55
63
  plansSnapshot(): ReplayPlan[];
56
64
  compare(weights?: ReplayWeights): ReplayResult;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-replay",
3
3
  "description": "Replay/A-B evaluation primitives for evolution plans (community build)",
4
- "version": "0.3.22",
4
+ "version": "0.3.24",
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.22"
34
+ "@lmzhen/dsh-evolution-core": "^0.3.24"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@deepseek-ai/cordis": "^4.0.1",
@@ -40,6 +40,6 @@
40
40
  "devDependencies": {
41
41
  "@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
42
42
  "@deepseek-ai/dsh-session": "^0.1.1-rc.2",
43
- "@lmzhen/dsh-evolution-core": "^0.3.22"
43
+ "@lmzhen/dsh-evolution-core": "^0.3.24"
44
44
  }
45
45
  }