@lmzhen/dsh-evolution-activity 0.30.28 → 0.30.30
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 +60 -4
- package/lib/types/index.d.ts +26 -2
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -47,14 +47,37 @@ function applyActivityEvent(items, event, maxItems, at = Date.now()) {
|
|
|
47
47
|
const cap = Number.isFinite(maxItems) ? Math.max(1, maxItems) : 200;
|
|
48
48
|
return [...items, record].slice(-cap);
|
|
49
49
|
}
|
|
50
|
+
/** Fold one review-completed payload into a bounded review list (pure). */
|
|
51
|
+
function applyReviewActivityEvent(reviews, event, maxItems, at = Date.now()) {
|
|
52
|
+
const record = {
|
|
53
|
+
reviewId: event.reviewId,
|
|
54
|
+
sessionId: event.sessionId,
|
|
55
|
+
...event.branchSessionId === void 0 ? {} : { branchSessionId: event.branchSessionId },
|
|
56
|
+
kind: event.kind,
|
|
57
|
+
status: event.status,
|
|
58
|
+
trigger: event.trigger,
|
|
59
|
+
finalText: event.finalText,
|
|
60
|
+
actions: event.actions,
|
|
61
|
+
...event.usage === void 0 ? {} : { usage: event.usage },
|
|
62
|
+
startedAt: event.startedAt,
|
|
63
|
+
finishedAt: event.finishedAt,
|
|
64
|
+
...event.model === void 0 ? {} : { model: event.model },
|
|
65
|
+
...event.promptVersion === void 0 ? {} : { promptVersion: event.promptVersion },
|
|
66
|
+
...event.error === void 0 ? {} : { error: event.error },
|
|
67
|
+
at
|
|
68
|
+
};
|
|
69
|
+
const cap = Number.isFinite(maxItems) ? Math.max(1, maxItems) : 200;
|
|
70
|
+
return [...reviews, record].slice(-cap);
|
|
71
|
+
}
|
|
50
72
|
/** Single-source activity sidecar serialization (F-304): the `apply()`
|
|
51
73
|
* listener emits the versioned envelope through this one function, so a
|
|
52
74
|
* format change cannot drift across hand-written writers.
|
|
53
75
|
* `parseActivityContent` is the matching single reader. */
|
|
54
|
-
function serializeActivity(items) {
|
|
76
|
+
function serializeActivity(items, reviews = []) {
|
|
55
77
|
return JSON.stringify({
|
|
56
78
|
version: 2,
|
|
57
|
-
items
|
|
79
|
+
items,
|
|
80
|
+
...reviews.length === 0 ? {} : { reviews }
|
|
58
81
|
}, null, 2);
|
|
59
82
|
}
|
|
60
83
|
function parseActivityContent(raw) {
|
|
@@ -69,6 +92,16 @@ function parseActivityContent(raw) {
|
|
|
69
92
|
return [];
|
|
70
93
|
}
|
|
71
94
|
}
|
|
95
|
+
/** Parse the review history sidecar array; malformed entries are dropped. */
|
|
96
|
+
function parseActivityReviews(raw) {
|
|
97
|
+
if (raw === null) return [];
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(raw);
|
|
100
|
+
return (typeof parsed === "object" && parsed !== null && Array.isArray(parsed.reviews) ? parsed.reviews : []).filter((item) => typeof item === "object" && item !== null && typeof item.reviewId === "string" && typeof item.sessionId === "string" && typeof item.finalText === "string" && typeof item.at === "number" && Number.isFinite(item.at));
|
|
101
|
+
} catch {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
72
105
|
/**
|
|
73
106
|
* One parse, one verdict — every reader-facing answer above is derived from this one call.
|
|
74
107
|
* @param raw - the sidecar bytes, or null when the file is absent.
|
|
@@ -115,6 +148,10 @@ async function loadActivityState(root, io) {
|
|
|
115
148
|
async function loadActivity(root, io) {
|
|
116
149
|
return (await loadActivityState(root, io)).records;
|
|
117
150
|
}
|
|
151
|
+
/** Read durable review history without a plan-record read. */
|
|
152
|
+
async function loadReviewActivity(root, io) {
|
|
153
|
+
return parseActivityReviews(await io.readText(activityFile(root)));
|
|
154
|
+
}
|
|
118
155
|
/**
|
|
119
156
|
* The WRITE side's quarantine predicate: should these bytes be preserved under `.corrupt` before a
|
|
120
157
|
* current-version file replaces them?
|
|
@@ -160,7 +197,26 @@ function apply(ctx, rawConfig = {}) {
|
|
|
160
197
|
}
|
|
161
198
|
ioCtx.logger.warn(`evolution-activity: ${file} is unreadable (unparsable JSON or wrong top-level shape); the original bytes were copied to ${file}.corrupt and the store restarts from the readable entries`);
|
|
162
199
|
}
|
|
163
|
-
return serializeActivity(applyActivityEvent(parseActivityContent(current), event, maxItems));
|
|
200
|
+
return serializeActivity(applyActivityEvent(parseActivityContent(current), event, maxItems), parseActivityReviews(current));
|
|
201
|
+
}));
|
|
202
|
+
chain = run.then(() => void 0, () => void 0);
|
|
203
|
+
run.catch((error) => {
|
|
204
|
+
ioCtx.logger.warn(error instanceof Error ? error : String(error));
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
ioCtx.effect(() => () => chain, "evolution-activity.flush");
|
|
208
|
+
ioCtx.on("evolution/review-completed", (event) => {
|
|
209
|
+
const run = chain.then(() => transactIo(io, activityFile(root), async (current) => {
|
|
210
|
+
const file = activityFile(root);
|
|
211
|
+
if (isCorruptActivity(current)) {
|
|
212
|
+
if (!await io.writeText(`${file}.corrupt`, current).then(() => true, () => false)) {
|
|
213
|
+
ioCtx.logger.warn(`evolution-activity: ${file} is unreadable; the .corrupt copy could not be written — refusing this write so the original bytes stay recoverable`);
|
|
214
|
+
return current;
|
|
215
|
+
}
|
|
216
|
+
ioCtx.logger.warn(`evolution-activity: ${file} is unreadable; the original bytes were copied to ${file}.corrupt and the store restarts from the readable entries`);
|
|
217
|
+
}
|
|
218
|
+
const reviews = applyReviewActivityEvent(parseActivityReviews(current), event, maxItems);
|
|
219
|
+
return serializeActivity(parseActivityContent(current), reviews);
|
|
164
220
|
}));
|
|
165
221
|
chain = run.then(() => void 0, () => void 0);
|
|
166
222
|
run.catch((error) => {
|
|
@@ -170,4 +226,4 @@ function apply(ctx, rawConfig = {}) {
|
|
|
170
226
|
});
|
|
171
227
|
}
|
|
172
228
|
//#endregion
|
|
173
|
-
export { ACTIVITY_FILE_VERSION, Config, DEFAULT_MAX_ITEMS, activityFile, apply, applyActivityEvent, isCorruptActivity, loadActivity, loadActivityState, name, parseActivityContent, serializeActivity };
|
|
229
|
+
export { ACTIVITY_FILE_VERSION, Config, DEFAULT_MAX_ITEMS, activityFile, apply, applyActivityEvent, applyReviewActivityEvent, isCorruptActivity, loadActivity, loadActivityState, loadReviewActivity, name, parseActivityContent, parseActivityReviews, serializeActivity };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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 { EvolutionIoLike, EvolutionPlanAppliedEvent } from '@lmzhen/dsh-evolution-core';
|
|
20
|
+
import type { EvolutionIoLike, EvolutionPlanAppliedEvent, EvolutionReviewCompletedEvent } from '@lmzhen/dsh-evolution-core';
|
|
21
21
|
/** One persisted plan outcome (payload v2 of `evolution/plan-applied`). */
|
|
22
22
|
export interface EvolutionActivityRecord {
|
|
23
23
|
sessionId: string;
|
|
@@ -42,6 +42,24 @@ export interface EvolutionActivityRecord {
|
|
|
42
42
|
evidenceClassReports?: number | undefined;
|
|
43
43
|
at: number;
|
|
44
44
|
}
|
|
45
|
+
/** One durable review outcome folded into the activity sidecar. */
|
|
46
|
+
export interface EvolutionReviewActivityRecord {
|
|
47
|
+
reviewId: string;
|
|
48
|
+
sessionId: string;
|
|
49
|
+
branchSessionId?: string | undefined;
|
|
50
|
+
kind: EvolutionReviewCompletedEvent['kind'];
|
|
51
|
+
status: EvolutionReviewCompletedEvent['status'];
|
|
52
|
+
trigger: EvolutionReviewCompletedEvent['trigger'];
|
|
53
|
+
finalText: string;
|
|
54
|
+
actions: EvolutionReviewCompletedEvent['actions'];
|
|
55
|
+
usage?: EvolutionReviewCompletedEvent['usage'];
|
|
56
|
+
startedAt: number;
|
|
57
|
+
finishedAt: number;
|
|
58
|
+
model?: EvolutionReviewCompletedEvent['model'];
|
|
59
|
+
promptVersion?: string | undefined;
|
|
60
|
+
error?: string | undefined;
|
|
61
|
+
at: number;
|
|
62
|
+
}
|
|
45
63
|
/** Version of the `activity.json` shape; writers always emit the current one. */
|
|
46
64
|
export declare const ACTIVITY_FILE_VERSION = 2;
|
|
47
65
|
/** Default bound on the retained sidecar (S6.4: also the fallback for a
|
|
@@ -50,12 +68,16 @@ export declare const DEFAULT_MAX_ITEMS = 200;
|
|
|
50
68
|
export declare function activityFile(root: string): string;
|
|
51
69
|
/** Fold one plan-applied payload into a bounded record list (pure). */
|
|
52
70
|
export declare function applyActivityEvent(items: EvolutionActivityRecord[], event: EvolutionPlanAppliedEvent, maxItems: number, at?: number): EvolutionActivityRecord[];
|
|
71
|
+
/** Fold one review-completed payload into a bounded review list (pure). */
|
|
72
|
+
export declare function applyReviewActivityEvent(reviews: EvolutionReviewActivityRecord[], event: EvolutionReviewCompletedEvent, maxItems: number, at?: number): EvolutionReviewActivityRecord[];
|
|
53
73
|
/** Single-source activity sidecar serialization (F-304): the `apply()`
|
|
54
74
|
* listener emits the versioned envelope through this one function, so a
|
|
55
75
|
* format change cannot drift across hand-written writers.
|
|
56
76
|
* `parseActivityContent` is the matching single reader. */
|
|
57
|
-
export declare function serializeActivity(items: EvolutionActivityRecord[]): string;
|
|
77
|
+
export declare function serializeActivity(items: EvolutionActivityRecord[], reviews?: EvolutionReviewActivityRecord[]): string;
|
|
58
78
|
export declare function parseActivityContent(raw: string | null): EvolutionActivityRecord[];
|
|
79
|
+
/** Parse the review history sidecar array; malformed entries are dropped. */
|
|
80
|
+
export declare function parseActivityReviews(raw: string | null): EvolutionReviewActivityRecord[];
|
|
59
81
|
/**
|
|
60
82
|
* FLOW6-6 (v43, the read side of H-3) + T4-08/A50: the sidecar's records PLUS two independent
|
|
61
83
|
* verdicts, because two different things were being folded into one word.
|
|
@@ -103,6 +125,8 @@ export declare function loadActivityState(root: string, io: EvolutionIoLike): Pr
|
|
|
103
125
|
* sidecar as "no history" use {@link loadActivityState}.
|
|
104
126
|
*/
|
|
105
127
|
export declare function loadActivity(root: string, io: EvolutionIoLike): Promise<EvolutionActivityRecord[]>;
|
|
128
|
+
/** Read durable review history without a plan-record read. */
|
|
129
|
+
export declare function loadReviewActivity(root: string, io: EvolutionIoLike): Promise<EvolutionReviewActivityRecord[]>;
|
|
106
130
|
/**
|
|
107
131
|
* The WRITE side's quarantine predicate: should these bytes be preserved under `.corrupt` before a
|
|
108
132
|
* current-version file replaces them?
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-activity",
|
|
3
3
|
"description": "Durable activity store for self-evolution plan outcomes (community build)",
|
|
4
|
-
"version": "0.30.
|
|
4
|
+
"version": "0.30.30",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@deepseek-ai/schemastery": "^3.18.5",
|
|
30
|
-
"@lmzhen/dsh-evolution-core": "^0.30.
|
|
30
|
+
"@lmzhen/dsh-evolution-core": "^0.30.30"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@deepseek-ai/cordis": "^4.0.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
37
|
-
"@lmzhen/dsh-evolution-core": "^0.30.
|
|
38
|
-
"@lmzhen/dsh-evolution-io": "^0.30.
|
|
39
|
-
"@lmzhen/dsh-evolution-io-node": "^0.30.
|
|
37
|
+
"@lmzhen/dsh-evolution-core": "^0.30.30",
|
|
38
|
+
"@lmzhen/dsh-evolution-io": "^0.30.30",
|
|
39
|
+
"@lmzhen/dsh-evolution-io-node": "^0.30.30"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"dsh": ">=0.2.1-rc.2 <0.2.2-0"
|