@lmzhen/dsh-evolution-activity 0.3.24 → 0.3.26
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 +14 -10
- package/lib/types/index.d.ts +5 -0
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -44,6 +44,16 @@ function applyActivityEvent(items, event, maxItems, at = Date.now()) {
|
|
|
44
44
|
return [...items, record].slice(-cap);
|
|
45
45
|
}
|
|
46
46
|
/** Parse a raw sidecar into records; malformed content reads as empty (best-effort telemetry). */
|
|
47
|
+
/** Single-source activity sidecar serialization (F-304): both `saveActivity`
|
|
48
|
+
* and the `apply()` listener emit the versioned envelope through this one
|
|
49
|
+
* function, so a format change cannot drift across two hand-written writers.
|
|
50
|
+
* `parseActivityContent` is the matching single reader. */
|
|
51
|
+
function serializeActivity(items) {
|
|
52
|
+
return JSON.stringify({
|
|
53
|
+
version: 2,
|
|
54
|
+
items
|
|
55
|
+
}, null, 2);
|
|
56
|
+
}
|
|
47
57
|
function parseActivityContent(raw) {
|
|
48
58
|
if (raw === null) return [];
|
|
49
59
|
try {
|
|
@@ -57,13 +67,10 @@ async function loadActivity(root, io) {
|
|
|
57
67
|
return parseActivityContent(await io.readText(activityFile(root)));
|
|
58
68
|
}
|
|
59
69
|
async function saveActivity(root, items, io) {
|
|
60
|
-
await io.writeText(activityFile(root),
|
|
61
|
-
version: 2,
|
|
62
|
-
items
|
|
63
|
-
}, null, 2));
|
|
70
|
+
await io.writeText(activityFile(root), serializeActivity(items));
|
|
64
71
|
}
|
|
65
72
|
const name = "evolution-activity";
|
|
66
|
-
const Config = z.object({ maxItems: z.number().default(200) });
|
|
73
|
+
const Config = z.object({ maxItems: z.number().min(1).default(200) });
|
|
67
74
|
function apply(ctx, rawConfig = {}) {
|
|
68
75
|
const configuredMaxItems = rawConfig.maxItems ?? 200;
|
|
69
76
|
const maxItems = Number.isFinite(configuredMaxItems) ? configuredMaxItems : 200;
|
|
@@ -76,10 +83,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
76
83
|
ioCtx.on("evolution/plan-applied", (event) => {
|
|
77
84
|
const run = chain.then(() => transactIo(io, activityFile(root), (current) => {
|
|
78
85
|
const items = applyActivityEvent(parseActivityContent(current), event, maxItems);
|
|
79
|
-
return Promise.resolve(
|
|
80
|
-
version: 2,
|
|
81
|
-
items
|
|
82
|
-
}, null, 2));
|
|
86
|
+
return Promise.resolve(serializeActivity(items));
|
|
83
87
|
}));
|
|
84
88
|
chain = run.then(() => void 0, () => void 0);
|
|
85
89
|
run.catch((error) => {
|
|
@@ -89,4 +93,4 @@ function apply(ctx, rawConfig = {}) {
|
|
|
89
93
|
});
|
|
90
94
|
}
|
|
91
95
|
//#endregion
|
|
92
|
-
export { ACTIVITY_FILE_VERSION, Config, DEFAULT_MAX_ITEMS, activityFile, apply, applyActivityEvent, loadActivity, name, parseActivityContent, saveActivity };
|
|
96
|
+
export { ACTIVITY_FILE_VERSION, Config, DEFAULT_MAX_ITEMS, activityFile, apply, applyActivityEvent, loadActivity, name, parseActivityContent, saveActivity, serializeActivity };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ export declare function activityFile(root: string): string;
|
|
|
39
39
|
/** Fold one plan-applied payload into a bounded record list (pure). */
|
|
40
40
|
export declare function applyActivityEvent(items: EvolutionActivityRecord[], event: EvolutionPlanAppliedEvent, maxItems: number, at?: number): EvolutionActivityRecord[];
|
|
41
41
|
/** Parse a raw sidecar into records; malformed content reads as empty (best-effort telemetry). */
|
|
42
|
+
/** Single-source activity sidecar serialization (F-304): both `saveActivity`
|
|
43
|
+
* and the `apply()` listener emit the versioned envelope through this one
|
|
44
|
+
* function, so a format change cannot drift across two hand-written writers.
|
|
45
|
+
* `parseActivityContent` is the matching single reader. */
|
|
46
|
+
export declare function serializeActivity(items: EvolutionActivityRecord[]): string;
|
|
42
47
|
export declare function parseActivityContent(raw: string | null): EvolutionActivityRecord[];
|
|
43
48
|
export declare function loadActivity(root: string, io: EvolutionIoLike): Promise<EvolutionActivityRecord[]>;
|
|
44
49
|
export declare function saveActivity(root: string, items: EvolutionActivityRecord[], io: EvolutionIoLike): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-activity",
|
|
3
3
|
"description": "Session projection for self-evolution activity (community build)",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.26",
|
|
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.
|
|
34
|
+
"@lmzhen/dsh-evolution-core": "^0.3.26"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
42
42
|
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
|
|
43
|
-
"@lmzhen/dsh-evolution-core": "^0.3.
|
|
44
|
-
"@lmzhen/dsh-evolution-io": "^0.3.
|
|
45
|
-
"@lmzhen/dsh-evolution-io-node": "^0.3.
|
|
43
|
+
"@lmzhen/dsh-evolution-core": "^0.3.26",
|
|
44
|
+
"@lmzhen/dsh-evolution-io": "^0.3.26",
|
|
45
|
+
"@lmzhen/dsh-evolution-io-node": "^0.3.26"
|
|
46
46
|
}
|
|
47
47
|
}
|