@lmzhen/dsh-evolution-activity 0.3.17 → 0.3.18
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 +25 -22
- package/lib/types/index.d.ts +3 -0
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -21,6 +21,9 @@ import { join } from "node:path";
|
|
|
21
21
|
*/
|
|
22
22
|
/** Version of the `activity.json` shape; writers always emit the current one. */
|
|
23
23
|
const ACTIVITY_FILE_VERSION = 2;
|
|
24
|
+
/** Default bound on the retained sidecar (S6.4: also the fallback for a
|
|
25
|
+
* non-finite `maxItems`). */
|
|
26
|
+
const DEFAULT_MAX_ITEMS = 200;
|
|
24
27
|
function activityFile(root) {
|
|
25
28
|
return join(root, "activity.json");
|
|
26
29
|
}
|
|
@@ -37,7 +40,7 @@ function applyActivityEvent(items, event, maxItems, at = Date.now()) {
|
|
|
37
40
|
estimatedInputChars: event.estimatedInputChars,
|
|
38
41
|
at
|
|
39
42
|
};
|
|
40
|
-
const cap = Math.max(1, maxItems);
|
|
43
|
+
const cap = Number.isFinite(maxItems) ? Math.max(1, maxItems) : 200;
|
|
41
44
|
return [...items, record].slice(-cap);
|
|
42
45
|
}
|
|
43
46
|
/** Parse a raw sidecar into records; malformed content reads as empty (best-effort telemetry). */
|
|
@@ -62,28 +65,28 @@ async function saveActivity(root, items, io) {
|
|
|
62
65
|
const name = "evolution-activity";
|
|
63
66
|
const Config = z.object({ maxItems: z.number().default(200) });
|
|
64
67
|
function apply(ctx, rawConfig = {}) {
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
const configuredMaxItems = rawConfig.maxItems ?? 200;
|
|
69
|
+
const maxItems = Number.isFinite(configuredMaxItems) ? configuredMaxItems : 200;
|
|
70
|
+
if (!Number.isFinite(configuredMaxItems)) ctx.logger.warn(`evolution-activity: maxItems is not a finite number; falling back to the default 200`);
|
|
71
|
+
ctx.inject(["evolutionIo"], (ioCtx) => {
|
|
72
|
+
const ioRegistry = ioCtx.evolutionIo;
|
|
73
|
+
const io = evolutionIoAdapter(() => ioRegistry.provider());
|
|
74
|
+
const root = evolutionHome();
|
|
75
|
+
let chain = Promise.resolve();
|
|
76
|
+
ioCtx.on("evolution/plan-applied", (event) => {
|
|
77
|
+
const run = chain.then(() => transactIo(io, activityFile(root), (current) => {
|
|
78
|
+
const items = applyActivityEvent(parseActivityContent(current), event, maxItems);
|
|
79
|
+
return Promise.resolve(JSON.stringify({
|
|
80
|
+
version: 2,
|
|
81
|
+
items
|
|
82
|
+
}, null, 2));
|
|
83
|
+
}));
|
|
84
|
+
chain = run.then(() => void 0, () => void 0);
|
|
85
|
+
run.catch((error) => {
|
|
86
|
+
ioCtx.logger.warn(error instanceof Error ? error : String(error));
|
|
87
|
+
});
|
|
85
88
|
});
|
|
86
89
|
});
|
|
87
90
|
}
|
|
88
91
|
//#endregion
|
|
89
|
-
export { ACTIVITY_FILE_VERSION, Config, activityFile, apply, applyActivityEvent, loadActivity, name, parseActivityContent, saveActivity };
|
|
92
|
+
export { ACTIVITY_FILE_VERSION, Config, DEFAULT_MAX_ITEMS, activityFile, apply, applyActivityEvent, loadActivity, name, parseActivityContent, saveActivity };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export interface EvolutionActivityRecord {
|
|
|
32
32
|
}
|
|
33
33
|
/** Version of the `activity.json` shape; writers always emit the current one. */
|
|
34
34
|
export declare const ACTIVITY_FILE_VERSION = 2;
|
|
35
|
+
/** Default bound on the retained sidecar (S6.4: also the fallback for a
|
|
36
|
+
* non-finite `maxItems`). */
|
|
37
|
+
export declare const DEFAULT_MAX_ITEMS = 200;
|
|
35
38
|
export declare function activityFile(root: string): string;
|
|
36
39
|
/** Fold one plan-applied payload into a bounded record list (pure). */
|
|
37
40
|
export declare function applyActivityEvent(items: EvolutionActivityRecord[], event: EvolutionPlanAppliedEvent, maxItems: number, at?: number): EvolutionActivityRecord[];
|
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.18",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@deepseek-ai/schemastery": "^3.18.1",
|
|
36
|
-
"@lmzhen/dsh-evolution-core": "^0.3.
|
|
36
|
+
"@lmzhen/dsh-evolution-core": "^0.3.18"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
44
44
|
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
|
|
45
|
-
"@lmzhen/dsh-evolution-core": "^0.3.
|
|
46
|
-
"@lmzhen/dsh-evolution-io": "^0.3.
|
|
47
|
-
"@lmzhen/dsh-evolution-io-node": "^0.3.
|
|
45
|
+
"@lmzhen/dsh-evolution-core": "^0.3.18",
|
|
46
|
+
"@lmzhen/dsh-evolution-io": "^0.3.18",
|
|
47
|
+
"@lmzhen/dsh-evolution-io-node": "^0.3.18"
|
|
48
48
|
}
|
|
49
49
|
}
|