@lmzhen/dsh-evolution-state-json 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 +26 -0
- package/lib/index.js +132 -0
- package/lib/invariant.js +8 -0
- package/lib/types/index.d.ts +17 -0
- package/lib/types/invariant.d.ts +5 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @deepseek-ai/dsh-evolution-state-json
|
|
2
|
+
|
|
3
|
+
JSON-file evolution state provider over the IO seam
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Model Experience
|
|
7
|
+
|
|
8
|
+
### Indirect model surface
|
|
9
|
+
|
|
10
|
+
#### What the model sees
|
|
11
|
+
|
|
12
|
+
`@deepseek-ai/dsh-evolution-state-json` registers no direct prompt or tool schema itself. Model-visible effects are owned by the packages that consume this service.
|
|
13
|
+
|
|
14
|
+
#### Token effect
|
|
15
|
+
|
|
16
|
+
Zero direct token effect from this package; consumers add any model-visible tokens.
|
|
17
|
+
|
|
18
|
+
#### KV Cache effect
|
|
19
|
+
|
|
20
|
+
Independent of request-prefix construction. This package does not alter the assembled prompt or tool list.
|
|
21
|
+
|
|
22
|
+
## Known Limitations and Deferred Work
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
- JSON provider serializes writers inside one process. Cross-process locking is a DSH storage-layer limitation (`storage-json` documents no cross-process write locking); multi-process deployments should route the evolution domain to a backend with cross-process semantics such as SQLite or remote storage.
|
|
26
|
+
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
//#region lib/types/index.js
|
|
5
|
+
/**
|
|
6
|
+
* JSON-file evolution state provider over the IO seam.
|
|
7
|
+
*
|
|
8
|
+
* This is the portable provider: `ctx.evolutionIo` may be node:fs today and a
|
|
9
|
+
* network/shared medium tomorrow without any state-format changes.
|
|
10
|
+
* @module @lmzhen/dsh-evolution-state-json
|
|
11
|
+
*/
|
|
12
|
+
const name = "evolution-state-json";
|
|
13
|
+
const inject = ["evolutionStateStorage", "evolutionIo"];
|
|
14
|
+
const Config = z.object({ root: z.string().default("") });
|
|
15
|
+
function defaultRoot(env = process.env) {
|
|
16
|
+
return join(env.DSH_HOME ?? join(homedir(), ".dsh"), "evolution");
|
|
17
|
+
}
|
|
18
|
+
function apply(ctx, rawConfig) {
|
|
19
|
+
const root = rawConfig.root || defaultRoot();
|
|
20
|
+
const io = () => ctx.evolutionIo.provider();
|
|
21
|
+
const pathOf = (file) => join(root, file);
|
|
22
|
+
async function readJson(file) {
|
|
23
|
+
const raw = await io().readText(pathOf(file));
|
|
24
|
+
if (raw === null) return null;
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(raw);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function writeJson(file, value) {
|
|
32
|
+
await io().writeText(pathOf(file), JSON.stringify(value, null, 2));
|
|
33
|
+
}
|
|
34
|
+
let chain = Promise.resolve();
|
|
35
|
+
function mutate(task) {
|
|
36
|
+
const run = chain.then(task, task);
|
|
37
|
+
chain = run.then(() => void 0, () => void 0);
|
|
38
|
+
return run;
|
|
39
|
+
}
|
|
40
|
+
async function loadPendingMap() {
|
|
41
|
+
const [current, legacy] = await Promise.all([readJson("pending-state.json"), readJson("pending.json")]);
|
|
42
|
+
return {
|
|
43
|
+
...legacy ?? {},
|
|
44
|
+
...current ?? {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const provider = {
|
|
48
|
+
name: "json",
|
|
49
|
+
async loadReviewState(sessionId) {
|
|
50
|
+
return await mutate(async () => {
|
|
51
|
+
return (await readJson("review-state.json"))?.[sessionId] ?? null;
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
async saveReviewState(sessionId, record) {
|
|
55
|
+
await mutate(async () => {
|
|
56
|
+
const map = await readJson("review-state.json") ?? {};
|
|
57
|
+
map[sessionId] = record;
|
|
58
|
+
await writeJson("review-state.json", map);
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
async loadCuratorState() {
|
|
62
|
+
return await mutate(async () => {
|
|
63
|
+
return (await readJson("curator-state.json"))?.primary ?? null;
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
async saveCuratorState(record) {
|
|
67
|
+
await mutate(async () => {
|
|
68
|
+
const map = await readJson("curator-state.json") ?? {};
|
|
69
|
+
map.primary = record;
|
|
70
|
+
await writeJson("curator-state.json", map);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
async listPending(status = "pending") {
|
|
74
|
+
return await mutate(async () => {
|
|
75
|
+
const map = await loadPendingMap();
|
|
76
|
+
return Object.values(map).filter((record) => record.status === status);
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
async savePending(record) {
|
|
80
|
+
await mutate(async () => {
|
|
81
|
+
const map = await loadPendingMap();
|
|
82
|
+
map[record.id] = record;
|
|
83
|
+
await writeJson("pending-state.json", map);
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
async claimPending(id, claimId) {
|
|
87
|
+
return await mutate(async () => {
|
|
88
|
+
const map = await loadPendingMap();
|
|
89
|
+
const record = map[id] ?? null;
|
|
90
|
+
if (record === null || record.status !== "pending") return null;
|
|
91
|
+
const now = Date.now();
|
|
92
|
+
const claimedAt = typeof record.claimedAt === "string" ? Date.parse(record.claimedAt) : 0;
|
|
93
|
+
if (record.claimedBy !== void 0 && Number.isFinite(claimedAt) && now - claimedAt < 10 * 6e4) return null;
|
|
94
|
+
record.claimedBy = claimId;
|
|
95
|
+
record.claimedAt = new Date(now).toISOString();
|
|
96
|
+
await writeJson("pending-state.json", map);
|
|
97
|
+
return { ...record };
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
async releasePendingClaim(id, claimId) {
|
|
101
|
+
await mutate(async () => {
|
|
102
|
+
const map = await loadPendingMap();
|
|
103
|
+
const record = map[id];
|
|
104
|
+
if (record && record.status === "pending" && record.claimedBy === claimId) {
|
|
105
|
+
delete record.claimedBy;
|
|
106
|
+
delete record.claimedAt;
|
|
107
|
+
await writeJson("pending-state.json", map);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
async tryResolvePending(id, status) {
|
|
112
|
+
return await mutate(async () => {
|
|
113
|
+
const map = await loadPendingMap();
|
|
114
|
+
const record = map[id] ?? null;
|
|
115
|
+
if (record === null || record.status !== "pending") return {
|
|
116
|
+
record,
|
|
117
|
+
applied: false
|
|
118
|
+
};
|
|
119
|
+
record.status = status;
|
|
120
|
+
record.resolvedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
121
|
+
await writeJson("pending-state.json", map);
|
|
122
|
+
return {
|
|
123
|
+
record,
|
|
124
|
+
applied: true
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
ctx.effect(() => ctx.evolutionStateStorage.registerProvider(provider), "evolution-state-json.provider");
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { Config, apply, inject, name };
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-evolution-state-json";
|
|
3
|
+
const name = "evolution-state-json-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,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-file evolution state provider over the IO seam.
|
|
3
|
+
*
|
|
4
|
+
* This is the portable provider: `ctx.evolutionIo` may be node:fs today and a
|
|
5
|
+
* network/shared medium tomorrow without any state-format changes.
|
|
6
|
+
* @module @deepseek-ai/dsh-evolution-state-json
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import z from '@deepseek-ai/schemastery';
|
|
10
|
+
export declare const name = "evolution-state-json";
|
|
11
|
+
export declare const inject: string[];
|
|
12
|
+
export interface Config {
|
|
13
|
+
root?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const Config: z<Config>;
|
|
16
|
+
export declare function apply(ctx: Context, rawConfig: Config): void;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lmzhen/dsh-evolution-state-json",
|
|
3
|
+
"description": "JSON-file evolution state provider over the IO seam (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-state-json"
|
|
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
|
+
"@lmzhen/dsh-evolution-io": "^0.1.0-rc.1",
|
|
41
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.1.0-rc.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
|
|
45
|
+
"@lmzhen/dsh-evolution-io": "^0.1.0-rc.1",
|
|
46
|
+
"@lmzhen/dsh-evolution-state-storage": "^0.1.0-rc.1"
|
|
47
|
+
}
|
|
48
|
+
}
|