@lmzhen/dsh-evolution-activity 0.1.0-rc.5 → 0.1.0-rc.51

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 CHANGED
@@ -21,4 +21,5 @@ Independent of request-prefix construction. This package does not alter the asse
21
21
  ## Known Limitations and Deferred Work
22
22
 
23
23
 
24
- - No known durable consumer gaps at this time. Runtime contracts are covered by package and boundary tests.
24
+ - The projection registers BOTH contract generations — `stateSchema` + `wire.viewSchema` (DSH 0.1.1+ session-projection contract) and legacy `schema` + `view` (0.1.0-rc.6 era) — because each registry ignores the fields it does not know. When the legacy fields are removed, drop the old half of the dual registration.
25
+ - On 0.1.1+ hosts the cold-read path (`restore`) calls `stateSchema.parse` on checkpointed rows; a registration missing `stateSchema` would throw on the first cold read, so the new half is load-bearing, not cosmetic.
package/lib/index.js CHANGED
@@ -1,45 +1,85 @@
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
+ const cap = Math.max(1, maxItems);
41
+ return [...items, record].slice(-cap);
42
+ }
43
+ async function loadActivity(root, io) {
44
+ const raw = await io.readText(activityFile(root));
45
+ if (raw === null) return [];
46
+ try {
47
+ const parsed = JSON.parse(raw);
48
+ 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");
49
+ } catch {
50
+ return [];
51
+ }
52
+ }
53
+ async function saveActivity(root, items, io) {
54
+ await io.writeText(activityFile(root), JSON.stringify({
55
+ version: 2,
56
+ items
57
+ }, null, 2));
28
58
  }
29
59
  const name = "evolution-activity";
30
- const Config = z.object({ maxItems: z.number().default(20) });
60
+ const Config = z.object({ maxItems: z.number().default(200) });
31
61
  function apply(ctx, rawConfig = {}) {
32
- const maxItems = rawConfig.maxItems ?? 20;
33
- ctx.inject(["sessionProjections"], (projectionCtx) => {
34
- projectionCtx.sessionProjections.register({
35
- key: "evolution-activity",
36
- schema: activitySchema,
37
- init: () => ({ items: [] }),
38
- apply: (state, event) => applyState(state, event, maxItems),
39
- view: (state) => ({ items: state.items }),
40
- stateVersion: 1
62
+ const maxItems = rawConfig.maxItems ?? 200;
63
+ const ioRegistry = ctx.get("evolutionIo");
64
+ if (!ioRegistry) {
65
+ ctx.logger.warn("evolution-activity: no evolution IO provider mounted; plan outcomes will not be persisted");
66
+ return;
67
+ }
68
+ const io = {
69
+ readText: (path) => ioRegistry.provider().readText(path),
70
+ writeText: (path, content) => ioRegistry.provider().writeText(path, content)
71
+ };
72
+ const root = evolutionHome();
73
+ let chain = Promise.resolve();
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
+ });
78
+ chain = run.then(() => void 0, () => void 0);
79
+ run.catch((error) => {
80
+ ctx.logger.warn(error instanceof Error ? error : String(error));
41
81
  });
42
82
  });
43
83
  }
44
84
  //#endregion
45
- export { Config, apply, applyState, name };
85
+ 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.5",
4
+ "version": "0.1.0-rc.51",
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.51"
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.51",
46
+ "@lmzhen/dsh-evolution-io": "^0.1.0-rc.51",
47
+ "@lmzhen/dsh-evolution-io-node": "^0.1.0-rc.51"
46
48
  }
47
49
  }