@lmzhen/dsh-evolution-activity 0.1.0-rc.57 → 0.1.0-rc.59

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
- import { evolutionHome } from "@lmzhen/dsh-evolution-core";
2
+ import { evolutionHome, evolutionIoAdapter, transactIo } from "@lmzhen/dsh-evolution-core";
3
3
  import { join } from "node:path";
4
4
  //#region lib/types/index.js
5
5
  /**
@@ -40,8 +40,8 @@ function applyActivityEvent(items, event, maxItems, at = Date.now()) {
40
40
  const cap = Math.max(1, maxItems);
41
41
  return [...items, record].slice(-cap);
42
42
  }
43
- async function loadActivity(root, io) {
44
- const raw = await io.readText(activityFile(root));
43
+ /** Parse a raw sidecar into records; malformed content reads as empty (best-effort telemetry). */
44
+ function parseActivityContent(raw) {
45
45
  if (raw === null) return [];
46
46
  try {
47
47
  const parsed = JSON.parse(raw);
@@ -50,6 +50,9 @@ async function loadActivity(root, io) {
50
50
  return [];
51
51
  }
52
52
  }
53
+ async function loadActivity(root, io) {
54
+ return parseActivityContent(await io.readText(activityFile(root)));
55
+ }
53
56
  async function saveActivity(root, items, io) {
54
57
  await io.writeText(activityFile(root), JSON.stringify({
55
58
  version: 2,
@@ -65,16 +68,17 @@ function apply(ctx, rawConfig = {}) {
65
68
  ctx.logger.warn("evolution-activity: no evolution IO provider mounted; plan outcomes will not be persisted");
66
69
  return;
67
70
  }
68
- const io = {
69
- readText: (path) => ioRegistry.provider().readText(path),
70
- writeText: (path, content) => ioRegistry.provider().writeText(path, content)
71
- };
71
+ const io = evolutionIoAdapter(() => ioRegistry.provider());
72
72
  const root = evolutionHome();
73
73
  let chain = Promise.resolve();
74
74
  ctx.on("evolution/plan-applied", (event) => {
75
- const run = chain.then(async () => {
76
- await saveActivity(root, applyActivityEvent(await loadActivity(root, io), event, maxItems), io);
77
- });
75
+ const run = chain.then(() => transactIo(io, activityFile(root), (current) => {
76
+ const items = applyActivityEvent(parseActivityContent(current), event, maxItems);
77
+ return Promise.resolve(JSON.stringify({
78
+ version: 2,
79
+ items
80
+ }, null, 2));
81
+ }));
78
82
  chain = run.then(() => void 0, () => void 0);
79
83
  run.catch((error) => {
80
84
  ctx.logger.warn(error instanceof Error ? error : String(error));
@@ -82,4 +86,4 @@ function apply(ctx, rawConfig = {}) {
82
86
  });
83
87
  }
84
88
  //#endregion
85
- export { ACTIVITY_FILE_VERSION, Config, activityFile, apply, applyActivityEvent, loadActivity, name, saveActivity };
89
+ export { ACTIVITY_FILE_VERSION, Config, activityFile, apply, applyActivityEvent, loadActivity, name, parseActivityContent, saveActivity };
@@ -17,7 +17,7 @@
17
17
  */
18
18
  import type { Context } from '@deepseek-ai/cordis';
19
19
  import z from '@deepseek-ai/schemastery';
20
- import type { EvolutionPlanAppliedEvent } from '@deepseek-ai/dsh-evolution-core';
20
+ import type { EvolutionIoLike, EvolutionPlanAppliedEvent } from '@deepseek-ai/dsh-evolution-core';
21
21
  /** One persisted plan outcome (payload v2 of `evolution/plan-applied`). */
22
22
  export interface EvolutionActivityRecord {
23
23
  sessionId: string;
@@ -33,15 +33,12 @@ export interface EvolutionActivityRecord {
33
33
  /** Version of the `activity.json` shape; writers always emit the current one. */
34
34
  export declare const ACTIVITY_FILE_VERSION = 2;
35
35
  export declare function activityFile(root: string): string;
36
- /** Minimal IO surface the driver needs (subset of `EvolutionIoLike`). */
37
- export interface ActivityIoLike {
38
- readText(path: string): Promise<string | null>;
39
- writeText(path: string, content: string): Promise<void>;
40
- }
41
36
  /** Fold one plan-applied payload into a bounded record list (pure). */
42
37
  export declare function applyActivityEvent(items: EvolutionActivityRecord[], event: EvolutionPlanAppliedEvent, maxItems: number, at?: number): EvolutionActivityRecord[];
43
- export declare function loadActivity(root: string, io: ActivityIoLike): Promise<EvolutionActivityRecord[]>;
44
- export declare function saveActivity(root: string, items: EvolutionActivityRecord[], io: ActivityIoLike): Promise<void>;
38
+ /** Parse a raw sidecar into records; malformed content reads as empty (best-effort telemetry). */
39
+ export declare function parseActivityContent(raw: string | null): EvolutionActivityRecord[];
40
+ export declare function loadActivity(root: string, io: EvolutionIoLike): Promise<EvolutionActivityRecord[]>;
41
+ export declare function saveActivity(root: string, items: EvolutionActivityRecord[], io: EvolutionIoLike): Promise<void>;
45
42
  export declare const name = "evolution-activity";
46
43
  export interface Config {
47
44
  /** Bounded sidecar: how many recent outcomes are kept. */
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.1.0-rc.57",
4
+ "version": "0.1.0-rc.59",
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.1.0-rc.57"
36
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.59"
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.1.0-rc.57",
46
- "@lmzhen/dsh-evolution-io": "^0.1.0-rc.57",
47
- "@lmzhen/dsh-evolution-io-node": "^0.1.0-rc.57"
45
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.59",
46
+ "@lmzhen/dsh-evolution-io": "^0.1.0-rc.59",
47
+ "@lmzhen/dsh-evolution-io-node": "^0.1.0-rc.59"
48
48
  }
49
49
  }