@lmzhen/dsh-evolution-policy 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 +24 -0
- package/lib/index.js +96 -0
- package/lib/invariant.js +8 -0
- package/lib/types/index.d.ts +64 -0
- package/lib/types/invariant.d.ts +5 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @deepseek-ai/dsh-evolution-policy
|
|
2
|
+
|
|
3
|
+
Immutable evolution policy service
|
|
4
|
+
|
|
5
|
+
## Model Experience
|
|
6
|
+
|
|
7
|
+
### Indirect model surface
|
|
8
|
+
|
|
9
|
+
#### What the model sees
|
|
10
|
+
|
|
11
|
+
`@deepseek-ai/dsh-evolution-policy` 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,96 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import { join, resolve, sep } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import z from "@deepseek-ai/schemastery";
|
|
5
|
+
//#region lib/types/index.js
|
|
6
|
+
/**
|
|
7
|
+
* Immutable evolution policy service.
|
|
8
|
+
* The policy is the control plane. Model plans may not change it.
|
|
9
|
+
* @module @lmzhen/dsh-evolution-policy
|
|
10
|
+
*/
|
|
11
|
+
const Config = z.object({
|
|
12
|
+
reviewMemoryInterval: z.number().default(10),
|
|
13
|
+
reviewSkillInterval: z.number().default(10),
|
|
14
|
+
substantiveMinToolCalls: z.number().default(3),
|
|
15
|
+
substantiveMinUserChars: z.number().default(200),
|
|
16
|
+
substantiveMinAgentChars: z.number().default(500),
|
|
17
|
+
reviewMode: z.string().default("subagent"),
|
|
18
|
+
memoryReviewModel: z.string().default("deepseek-v4-flash"),
|
|
19
|
+
skillReviewModel: z.string().default("deepseek-v4-pro"),
|
|
20
|
+
curatorModel: z.string().default("deepseek-v4-pro"),
|
|
21
|
+
memoryChars: z.number().default(2200),
|
|
22
|
+
userChars: z.number().default(1375),
|
|
23
|
+
skillContentChars: z.number().default(1e5),
|
|
24
|
+
maxOpsPerPlan: z.number().default(32),
|
|
25
|
+
curatorIntervalHours: z.number().default(168),
|
|
26
|
+
staleAfterDays: z.number().default(30),
|
|
27
|
+
archiveAfterDays: z.number().default(90),
|
|
28
|
+
protectedSkillNames: z.array(z.string()).default([]),
|
|
29
|
+
protectedPaths: z.array(z.string()).default([])
|
|
30
|
+
});
|
|
31
|
+
var EvolutionPolicy = class extends Service {
|
|
32
|
+
static Config = Config;
|
|
33
|
+
snapshot;
|
|
34
|
+
constructor(ctx, config = {}) {
|
|
35
|
+
super(ctx, "evolutionPolicy");
|
|
36
|
+
ctx.inject(["tools"], (toolCtx) => {
|
|
37
|
+
const tools = toolCtx.get("tools");
|
|
38
|
+
toolCtx.effect(() => tools.guard((exec) => this.guardReason(exec.name, exec.arguments)), "evolution-policy.tools-guard");
|
|
39
|
+
});
|
|
40
|
+
const homePolicyPath = resolve(join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), "evolution", "policy.json"));
|
|
41
|
+
this.snapshot = Object.freeze({
|
|
42
|
+
version: 1,
|
|
43
|
+
reviewMemoryInterval: config.reviewMemoryInterval ?? 10,
|
|
44
|
+
reviewSkillInterval: config.reviewSkillInterval ?? 10,
|
|
45
|
+
substantiveMinToolCalls: config.substantiveMinToolCalls ?? 3,
|
|
46
|
+
substantiveMinUserChars: config.substantiveMinUserChars ?? 200,
|
|
47
|
+
substantiveMinAgentChars: config.substantiveMinAgentChars ?? 500,
|
|
48
|
+
reviewMode: config.reviewMode === "inject" ? "inject" : "subagent",
|
|
49
|
+
memoryReviewModel: config.memoryReviewModel ?? "deepseek-v4-flash",
|
|
50
|
+
skillReviewModel: config.skillReviewModel ?? "deepseek-v4-pro",
|
|
51
|
+
curatorModel: config.curatorModel ?? "deepseek-v4-pro",
|
|
52
|
+
memoryChars: config.memoryChars ?? 2200,
|
|
53
|
+
userChars: config.userChars ?? 1375,
|
|
54
|
+
skillContentChars: config.skillContentChars ?? 1e5,
|
|
55
|
+
maxOpsPerPlan: config.maxOpsPerPlan ?? 32,
|
|
56
|
+
curatorIntervalHours: config.curatorIntervalHours ?? 168,
|
|
57
|
+
staleAfterDays: config.staleAfterDays ?? 30,
|
|
58
|
+
archiveAfterDays: config.archiveAfterDays ?? 90,
|
|
59
|
+
protectedSkillNames: Object.freeze([...new Set(["plan", ...config.protectedSkillNames ?? []])]),
|
|
60
|
+
protectedPaths: Object.freeze([...config.protectedPaths ?? [], homePolicyPath])
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
get() {
|
|
64
|
+
return this.snapshot;
|
|
65
|
+
}
|
|
66
|
+
isProtectedPath(path) {
|
|
67
|
+
if (typeof path !== "string") return false;
|
|
68
|
+
const normalized = resolve(path);
|
|
69
|
+
return this.snapshot.protectedPaths.some((prefix) => {
|
|
70
|
+
const resolved = resolve(prefix);
|
|
71
|
+
return normalized === resolved || normalized.startsWith(resolved + sep);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
guardReason(toolName, args) {
|
|
75
|
+
if (toolName === "write" || toolName === "edit" || toolName === "patch" || toolName === "str_replace_editor") {
|
|
76
|
+
const record = asRecord(args);
|
|
77
|
+
const target = record.path ?? record.file_path ?? record.filePath;
|
|
78
|
+
if (this.isProtectedPath(target)) return `evolution-policy: refusing to modify protected policy path ${String(target)}`;
|
|
79
|
+
}
|
|
80
|
+
if (toolName === "memory" || toolName === "skill_manage") {
|
|
81
|
+
const record = asRecord(args);
|
|
82
|
+
for (const forbidden of [
|
|
83
|
+
"policy",
|
|
84
|
+
"threshold",
|
|
85
|
+
"prompt_hash",
|
|
86
|
+
"model_route",
|
|
87
|
+
"evolution_config"
|
|
88
|
+
]) if (forbidden in record) return `evolution-policy: tool call may not mutate ${forbidden}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function asRecord(value) {
|
|
93
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { Config, EvolutionPolicy, EvolutionPolicy as default };
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-evolution-policy";
|
|
3
|
+
const name = "evolution-policy-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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable evolution policy service.
|
|
3
|
+
* The policy is the control plane. Model plans may not change it.
|
|
4
|
+
* @module @deepseek-ai/dsh-evolution-policy
|
|
5
|
+
*/
|
|
6
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
7
|
+
import type Schema from '@deepseek-ai/schemastery';
|
|
8
|
+
declare module '@deepseek-ai/cordis' {
|
|
9
|
+
interface Context {
|
|
10
|
+
evolutionPolicy: EvolutionPolicy;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export interface PolicySnapshot {
|
|
14
|
+
version: 1;
|
|
15
|
+
reviewMemoryInterval: number;
|
|
16
|
+
reviewSkillInterval: number;
|
|
17
|
+
substantiveMinToolCalls: number;
|
|
18
|
+
substantiveMinUserChars: number;
|
|
19
|
+
substantiveMinAgentChars: number;
|
|
20
|
+
reviewMode: 'subagent' | 'inject';
|
|
21
|
+
memoryReviewModel: string;
|
|
22
|
+
skillReviewModel: string;
|
|
23
|
+
curatorModel: string;
|
|
24
|
+
memoryChars: number;
|
|
25
|
+
userChars: number;
|
|
26
|
+
skillContentChars: number;
|
|
27
|
+
maxOpsPerPlan: number;
|
|
28
|
+
curatorIntervalHours: number;
|
|
29
|
+
staleAfterDays: number;
|
|
30
|
+
archiveAfterDays: number;
|
|
31
|
+
protectedSkillNames: readonly string[];
|
|
32
|
+
protectedPaths: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
export interface Config {
|
|
35
|
+
reviewMemoryInterval?: number;
|
|
36
|
+
reviewSkillInterval?: number;
|
|
37
|
+
substantiveMinToolCalls?: number;
|
|
38
|
+
substantiveMinUserChars?: number;
|
|
39
|
+
substantiveMinAgentChars?: number;
|
|
40
|
+
reviewMode?: string;
|
|
41
|
+
memoryReviewModel?: string;
|
|
42
|
+
skillReviewModel?: string;
|
|
43
|
+
curatorModel?: string;
|
|
44
|
+
memoryChars?: number;
|
|
45
|
+
userChars?: number;
|
|
46
|
+
skillContentChars?: number;
|
|
47
|
+
maxOpsPerPlan?: number;
|
|
48
|
+
curatorIntervalHours?: number;
|
|
49
|
+
staleAfterDays?: number;
|
|
50
|
+
archiveAfterDays?: number;
|
|
51
|
+
protectedSkillNames?: string[];
|
|
52
|
+
protectedPaths?: string[];
|
|
53
|
+
}
|
|
54
|
+
export declare const Config: Schema<Config>;
|
|
55
|
+
export declare class EvolutionPolicy extends Service {
|
|
56
|
+
static Config: Schema<Config>;
|
|
57
|
+
readonly snapshot: PolicySnapshot;
|
|
58
|
+
constructor(ctx: Context, config?: Config);
|
|
59
|
+
get(): PolicySnapshot;
|
|
60
|
+
isProtectedPath(path: unknown): boolean;
|
|
61
|
+
guardReason(toolName: string, args: unknown): string | undefined;
|
|
62
|
+
}
|
|
63
|
+
export default EvolutionPolicy;
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lmzhen/dsh-evolution-policy",
|
|
3
|
+
"description": "Immutable evolution policy service (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-policy"
|
|
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
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
|
|
39
|
+
"@deepseek-ai/cordis": "^4.0.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6"
|
|
43
|
+
}
|
|
44
|
+
}
|