@lmzhen/dsh-evolution-activity 0.1.0-rc.41 → 0.1.0-rc.43

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,54 +1,84 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
- import { z as z$1 } from "zod";
2
+ import { evolutionHome } from "@lmzhen/dsh-evolution-core";
3
+ import { join } from "node:path";
3
4
  //#region lib/types/index.js
4
5
  /**
5
- * Session projection for self-evolution activity.
6
+ * Durable activity store for self-evolution plan outcomes.
7
+ *
8
+ * Adjudication (rc.42, A-line P0-1): plan outcomes are process events on the
9
+ * cordis bus (a session log carrying `evolution/*` types is refused wholesale
10
+ * at resume), so the retired session projection is replaced by this driver:
11
+ * it subscribes to `evolution/plan-applied` (payload v2, with sessionId) and
12
+ * persists every outcome to `$DSH_HOME/evolution/activity.json` through the
13
+ * evolution IO seam — the same best-effort sidecar posture as
14
+ * `feedback.json` and the curator reports. A storage-domain table is deferred
15
+ * until a consumer needs domain routing (the domain spec version-gates its
16
+ * media, so adding a table is not a free schema addition).
17
+ *
18
+ * The sidecar is append-merge (load → fold → save under an in-process queue),
19
+ * so records survive host restarts and are readable without a session.
6
20
  * @module @lmzhen/dsh-evolution-activity
7
21
  */
8
- const activitySchema = z$1.object({ items: z$1.array(z$1.object({
9
- planId: z$1.string(),
10
- kind: z$1.string(),
11
- memoryApplied: z$1.number().min(0),
12
- skillApplied: z$1.number().min(0),
13
- rejectedOps: z$1.number().min(0),
14
- at: z$1.number().min(0)
15
- })) });
16
- function applyState(state, event, maxItems = 20) {
17
- if (event.type !== "evolution/plan-applied") return state;
18
- const data = event.data;
19
- const time = event.time;
20
- return { items: [...state.items, {
21
- planId: data.planId,
22
- kind: "plan",
23
- memoryApplied: data.memoryApplied,
24
- skillApplied: data.skillApplied,
25
- rejectedOps: data.rejectedOps,
26
- at: time
27
- }].slice(-maxItems) };
22
+ /** Version of the `activity.json` shape; writers always emit the current one. */
23
+ const ACTIVITY_FILE_VERSION = 2;
24
+ function activityFile(root) {
25
+ return join(root, "activity.json");
26
+ }
27
+ /** Fold one plan-applied payload into a bounded record list (pure). */
28
+ function applyActivityEvent(items, event, maxItems, at = Date.now()) {
29
+ const record = {
30
+ sessionId: event.sessionId,
31
+ planId: event.planId,
32
+ policyFingerprint: event.policyFingerprint,
33
+ memoryApplied: event.memoryApplied,
34
+ skillApplied: event.skillApplied,
35
+ rejectedOps: event.rejectedOps,
36
+ evidenceQuotes: event.evidenceQuotes,
37
+ estimatedInputChars: event.estimatedInputChars,
38
+ at
39
+ };
40
+ return [...items, record].slice(-maxItems);
41
+ }
42
+ async function loadActivity(root, io) {
43
+ const raw = await io.readText(activityFile(root));
44
+ if (raw === null) return [];
45
+ try {
46
+ const parsed = JSON.parse(raw);
47
+ return (typeof parsed === "object" && parsed !== null && Array.isArray(parsed.items) ? parsed.items : []).filter((item) => typeof item === "object" && item !== null && typeof item.planId === "string" && typeof item.sessionId === "string");
48
+ } catch {
49
+ return [];
50
+ }
51
+ }
52
+ async function saveActivity(root, items, io) {
53
+ await io.writeText(activityFile(root), JSON.stringify({
54
+ version: 2,
55
+ items
56
+ }, null, 2));
28
57
  }
29
58
  const name = "evolution-activity";
30
- const Config = z.object({ maxItems: z.number().default(20) });
59
+ const Config = z.object({ maxItems: z.number().default(200) });
31
60
  function apply(ctx, rawConfig = {}) {
32
- const maxItems = rawConfig.maxItems ?? 20;
33
- ctx.inject(["sessionProjections"], (projectionCtx) => {
34
- const runtime = projectionCtx.sessionProjections;
35
- const init = () => ({ items: [] });
36
- const apply = (state, event) => applyState(state, event, maxItems);
37
- const view = (state) => ({ items: state.items });
38
- runtime.register({
39
- key: "evolution-activity",
40
- stateSchema: activitySchema,
41
- schema: activitySchema,
42
- init,
43
- apply,
44
- wire: {
45
- viewSchema: activitySchema,
46
- view
47
- },
48
- view,
49
- stateVersion: 1
61
+ const maxItems = rawConfig.maxItems ?? 200;
62
+ const ioRegistry = ctx.get("evolutionIo");
63
+ if (!ioRegistry) {
64
+ ctx.logger.warn("evolution-activity: no evolution IO provider mounted; plan outcomes will not be persisted");
65
+ return;
66
+ }
67
+ const io = {
68
+ readText: (path) => ioRegistry.provider().readText(path),
69
+ writeText: (path, content) => ioRegistry.provider().writeText(path, content)
70
+ };
71
+ const root = evolutionHome();
72
+ let chain = Promise.resolve();
73
+ ctx.on("evolution/plan-applied", (event) => {
74
+ const run = chain.then(async () => {
75
+ await saveActivity(root, applyActivityEvent(await loadActivity(root, io), event, maxItems), io);
76
+ });
77
+ chain = run.then(() => void 0, () => void 0);
78
+ run.catch((error) => {
79
+ ctx.logger.warn(error instanceof Error ? error : String(error));
50
80
  });
51
81
  });
52
82
  }
53
83
  //#endregion
54
- export { Config, apply, applyState, name };
84
+ export { ACTIVITY_FILE_VERSION, Config, activityFile, apply, applyActivityEvent, loadActivity, name, saveActivity };
@@ -1,41 +1,52 @@
1
1
  /**
2
- * Session projection for self-evolution activity.
2
+ * Durable activity store for self-evolution plan outcomes.
3
+ *
4
+ * Adjudication (rc.42, A-line P0-1): plan outcomes are process events on the
5
+ * cordis bus (a session log carrying `evolution/*` types is refused wholesale
6
+ * at resume), so the retired session projection is replaced by this driver:
7
+ * it subscribes to `evolution/plan-applied` (payload v2, with sessionId) and
8
+ * persists every outcome to `$DSH_HOME/evolution/activity.json` through the
9
+ * evolution IO seam — the same best-effort sidecar posture as
10
+ * `feedback.json` and the curator reports. A storage-domain table is deferred
11
+ * until a consumer needs domain routing (the domain spec version-gates its
12
+ * media, so adding a table is not a free schema addition).
13
+ *
14
+ * The sidecar is append-merge (load → fold → save under an in-process queue),
15
+ * so records survive host restarts and are readable without a session.
3
16
  * @module @deepseek-ai/dsh-evolution-activity
4
17
  */
5
18
  import type { Context } from '@deepseek-ai/cordis';
6
19
  import z from '@deepseek-ai/schemastery';
7
- export interface EvolutionActivityItem {
20
+ import type { EvolutionPlanAppliedEvent } from '@deepseek-ai/dsh-evolution-core';
21
+ /** One persisted plan outcome (payload v2 of `evolution/plan-applied`). */
22
+ export interface EvolutionActivityRecord {
23
+ sessionId: string;
8
24
  planId: string;
9
- kind: string;
25
+ policyFingerprint?: string | undefined;
10
26
  memoryApplied: number;
11
27
  skillApplied: number;
12
28
  rejectedOps: number;
29
+ evidenceQuotes?: number | undefined;
30
+ estimatedInputChars?: number | undefined;
13
31
  at: number;
14
32
  }
15
- export interface EvolutionActivityProjection {
16
- items: EvolutionActivityItem[];
33
+ /** Version of the `activity.json` shape; writers always emit the current one. */
34
+ export declare const ACTIVITY_FILE_VERSION = 2;
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>;
17
40
  }
18
- export interface State {
19
- items: EvolutionActivityItem[];
20
- }
21
- type SessionEventLike = {
22
- type: 'evolution/plan-applied';
23
- data: {
24
- planId: string;
25
- memoryApplied: number;
26
- skillApplied: number;
27
- rejectedOps: number;
28
- };
29
- time: number;
30
- } | {
31
- type: string;
32
- };
33
- export declare function applyState(state: State, event: SessionEventLike, maxItems?: number): State;
41
+ /** Fold one plan-applied payload into a bounded record list (pure). */
42
+ 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>;
34
45
  export declare const name = "evolution-activity";
35
46
  export interface Config {
47
+ /** Bounded sidecar: how many recent outcomes are kept. */
36
48
  maxItems?: number;
37
49
  }
38
50
  export declare const Config: z<Config>;
39
51
  export declare function apply(ctx: Context, rawConfig?: Config): void;
40
- export {};
41
52
  //# sourceMappingURL=index.d.ts.map
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.41",
4
+ "version": "0.1.0-rc.43",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -33,15 +33,17 @@
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
35
  "@deepseek-ai/schemastery": "^3.18.1",
36
- "zod": "^4.4.3"
36
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.43"
37
37
  },
38
38
  "peerDependencies": {
39
- "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
40
39
  "@deepseek-ai/cordis": "^4.0.1",
41
- "@deepseek-ai/dsh-session-projection": "^0.1.0-rc.6"
40
+ "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6"
42
41
  },
43
42
  "devDependencies": {
43
+ "@deepseek-ai/cordis": "^4.0.1",
44
44
  "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
45
- "@deepseek-ai/dsh-session-projection": "^0.1.0-rc.6"
45
+ "@lmzhen/dsh-evolution-core": "^0.1.0-rc.43",
46
+ "@lmzhen/dsh-evolution-io": "^0.1.0-rc.43",
47
+ "@lmzhen/dsh-evolution-io-node": "^0.1.0-rc.43"
46
48
  }
47
49
  }