@lmzhen/dsh-evolution-replay 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-replay
2
+
3
+ Replay/A-B evaluation primitives for evolution plans
4
+
5
+ ## Model Experience
6
+
7
+ ### Indirect model surface
8
+
9
+ #### What the model sees
10
+
11
+ `@deepseek-ai/dsh-evolution-replay` 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,103 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ //#region lib/types/index.js
3
+ /**
4
+ * Replay/A-B evaluation for evolution plans.
5
+ *
6
+ * The pure scoring functions remain deterministic and runtime-free. The DSH
7
+ * driver records every `evolution/plan-applied` session event into an
8
+ * in-memory leaderboard and exposes `/evolution replay` for comparison, so a
9
+ * human can A/B review policy/prompt changes against real plan outcomes.
10
+ * @module @lmzhen/dsh-evolution-replay
11
+ */
12
+ const DEFAULT_WEIGHTS = {
13
+ accepted: 10,
14
+ rejectedPenalty: 15,
15
+ evidence: 2,
16
+ cost: .001
17
+ };
18
+ const Config = z.object({
19
+ maxPlans: z.number().default(50),
20
+ weights: z.object({
21
+ accepted: z.number().default(10),
22
+ rejectedPenalty: z.number().default(15),
23
+ evidence: z.number().default(2),
24
+ cost: z.number().default(.001)
25
+ }).default(DEFAULT_WEIGHTS)
26
+ });
27
+ function scorePlan(plan, weights = DEFAULT_WEIGHTS) {
28
+ return plan.acceptedOps * weights.accepted - plan.rejectedOps * weights.rejectedPenalty + plan.evidenceQuotes * weights.evidence - plan.estimatedInputChars * weights.cost;
29
+ }
30
+ function comparePlans(plans, weights = DEFAULT_WEIGHTS) {
31
+ if (plans.length === 0) return {
32
+ winner: null,
33
+ margin: 0,
34
+ plans,
35
+ report: "No plans to compare."
36
+ };
37
+ const scored = plans.map((plan) => ({
38
+ plan,
39
+ score: scorePlan(plan, weights)
40
+ })).sort((a, b) => b.score - a.score);
41
+ const winner = scored[0];
42
+ if (!winner) return {
43
+ winner: null,
44
+ margin: 0,
45
+ plans,
46
+ report: "No plans to compare."
47
+ };
48
+ const runnerUp = scored[1];
49
+ const margin = runnerUp ? winner.score - runnerUp.score : winner.score;
50
+ return {
51
+ winner: winner.plan.policyId,
52
+ margin,
53
+ plans,
54
+ report: scored.map(({ plan, score }) => `${plan.policyId}: ${score.toFixed(1)} (${plan.acceptedOps} accepted, ${plan.rejectedOps} rejected)`).join("\n")
55
+ };
56
+ }
57
+ var EvolutionReplayDriver = class {
58
+ plans = [];
59
+ maxPlans;
60
+ weights;
61
+ constructor(config = {}) {
62
+ this.maxPlans = config.maxPlans ?? 50;
63
+ this.weights = config.weights ?? DEFAULT_WEIGHTS;
64
+ }
65
+ record(event) {
66
+ if (event.type !== "evolution/plan-applied") return;
67
+ const data = event.data;
68
+ this.plans.push({
69
+ policyId: typeof data.policyFingerprint === "string" ? data.policyFingerprint : data.planId,
70
+ acceptedOps: data.memoryApplied + data.skillApplied,
71
+ rejectedOps: data.rejectedOps,
72
+ memoryOps: data.memoryApplied,
73
+ skillOps: data.skillApplied,
74
+ evidenceQuotes: typeof data.evidenceQuotes === "number" ? data.evidenceQuotes : data.memoryApplied + data.skillApplied,
75
+ estimatedInputChars: typeof data.estimatedInputChars === "number" ? data.estimatedInputChars : 0
76
+ });
77
+ if (this.plans.length > this.maxPlans) this.plans.shift();
78
+ }
79
+ plansSnapshot() {
80
+ return [...this.plans];
81
+ }
82
+ compare(weights = this.weights) {
83
+ return comparePlans(this.plans, weights);
84
+ }
85
+ };
86
+ const name = "evolution-replay";
87
+ function apply(ctx, rawConfig = {}) {
88
+ const driver = new EvolutionReplayDriver(rawConfig);
89
+ ctx.provide("evolutionReplay", driver);
90
+ ctx.on("session/event", (_session, event) => {
91
+ if (event.type === "evolution/plan-applied") driver.record(event);
92
+ });
93
+ ctx.inject(["commands"], (commandCtx) => {
94
+ commandCtx.commands.register({
95
+ name: "evolution replay",
96
+ description: "Compare recent evolution plan outcomes",
97
+ recordInput: false,
98
+ handler: () => ({ text: driver.compare().report })
99
+ });
100
+ });
101
+ }
102
+ //#endregion
103
+ export { Config, DEFAULT_WEIGHTS, EvolutionReplayDriver, EvolutionReplayDriver as default, apply, comparePlans, name, scorePlan };
@@ -0,0 +1,8 @@
1
+ //#region lib/types/invariant.js
2
+ const PACKAGE_NAME = "@deepseek-ai/dsh-evolution-replay";
3
+ const name = "evolution-replay-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,69 @@
1
+ /**
2
+ * Replay/A-B evaluation for evolution plans.
3
+ *
4
+ * The pure scoring functions remain deterministic and runtime-free. The DSH
5
+ * driver records every `evolution/plan-applied` session event into an
6
+ * in-memory leaderboard and exposes `/evolution replay` for comparison, so a
7
+ * human can A/B review policy/prompt changes against real plan outcomes.
8
+ * @module @deepseek-ai/dsh-evolution-replay
9
+ */
10
+ import type { Context } from '@deepseek-ai/cordis';
11
+ import z from '@deepseek-ai/schemastery';
12
+ export interface ReplayPlan {
13
+ policyId: string;
14
+ acceptedOps: number;
15
+ rejectedOps: number;
16
+ memoryOps: number;
17
+ skillOps: number;
18
+ evidenceQuotes: number;
19
+ estimatedInputChars: number;
20
+ }
21
+ export interface ReplayResult {
22
+ winner: string | null;
23
+ margin: number;
24
+ plans: ReplayPlan[];
25
+ report: string;
26
+ }
27
+ export interface ReplayWeights {
28
+ accepted: number;
29
+ rejectedPenalty: number;
30
+ evidence: number;
31
+ cost: number;
32
+ }
33
+ export declare const DEFAULT_WEIGHTS: ReplayWeights;
34
+ export interface Config {
35
+ maxPlans?: number;
36
+ weights?: ReplayWeights;
37
+ }
38
+ export declare const Config: z<Config>;
39
+ export declare function scorePlan(plan: ReplayPlan, weights?: ReplayWeights): number;
40
+ export declare function comparePlans(plans: ReplayPlan[], weights?: ReplayWeights): ReplayResult;
41
+ declare module '@deepseek-ai/cordis' {
42
+ interface Context {
43
+ evolutionReplay: EvolutionReplayDriver;
44
+ }
45
+ }
46
+ export declare class EvolutionReplayDriver {
47
+ private readonly plans;
48
+ private readonly maxPlans;
49
+ private readonly weights;
50
+ constructor(config?: Config);
51
+ record(event: {
52
+ type: string;
53
+ data: {
54
+ planId: string;
55
+ policyFingerprint?: string | undefined;
56
+ memoryApplied: number;
57
+ skillApplied: number;
58
+ rejectedOps: number;
59
+ evidenceQuotes?: number | undefined;
60
+ estimatedInputChars?: number | undefined;
61
+ };
62
+ }): void;
63
+ plansSnapshot(): ReplayPlan[];
64
+ compare(weights?: ReplayWeights): ReplayResult;
65
+ }
66
+ export declare const name = "evolution-replay";
67
+ export declare function apply(ctx: Context, rawConfig?: Config): void;
68
+ export default EvolutionReplayDriver;
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ export declare const name = "evolution-replay-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,48 @@
1
+ {
2
+ "name": "@lmzhen/dsh-evolution-replay",
3
+ "description": "Replay/A-B evaluation primitives for evolution plans (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-replay"
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-session": "^0.1.0-rc.6"
42
+ },
43
+ "devDependencies": {
44
+ "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
45
+ "@deepseek-ai/dsh-session": "^0.1.0-rc.6",
46
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.1"
47
+ }
48
+ }