@lmzhen/dsh-evolution-review 0.39.2 → 0.40.0
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 +67 -12
- package/lib/types/index.d.ts +1 -1
- package/lib/types/review-executor.d.ts +11 -3
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { BlockAssembler, createToolResultMessage, createUserMessage } from "@
|
|
4
|
-
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
3
|
+
import { BlockAssembler, SessionId, createToolResultMessage, createUserMessage } from "@lmzhen/dsh-evolution-core/platform";
|
|
5
4
|
import { DEFAULT_REVIEW_MEMORY_INTERVAL, DEFAULT_REVIEW_SKILL_INTERVAL, DEFAULT_REVIEW_TIMEOUT_MS, DEFAULT_SKILL_REVIEW_COMPLETION_MIN_TOOL_CALLS, DEFAULT_SKILL_REVIEW_TRIGGER, DEFAULT_SUBSTANTIVE_MIN_AGENT_CHARS, DEFAULT_SUBSTANTIVE_MIN_TOOL_CALLS, DEFAULT_SUBSTANTIVE_MIN_USER_CHARS, INJECT_COMPLETION_SKILL_REVIEW_PROMPT, MAX_TIMER_DELAY_MS, PROMPT_BUNDLE, advanceReview, assertSkillsRootAliasRetired, clampOnce, classifySessionEvent, clearReviewChannel, filterUnreadSkillOps, liveBool, markReviewChannel, paramRowId, pickWithPolicy, readDispatchSignal, registerOwnerSettings, reviewPrompt, sessionAudited, sessionTurnSignals, sweepReviewChannelSessions, unwrapLive, userSetKeys, verifyPromptBundle, withReviewContext } from "@lmzhen/dsh-evolution-core";
|
|
6
5
|
//#region lib/types/review-executor.js
|
|
7
6
|
/**
|
|
@@ -13,6 +12,30 @@ import { DEFAULT_REVIEW_MEMORY_INTERVAL, DEFAULT_REVIEW_SKILL_INTERVAL, DEFAULT_
|
|
|
13
12
|
*
|
|
14
13
|
* @module @lmzhen/dsh-evolution-review/review-executor
|
|
15
14
|
*/
|
|
15
|
+
var ReviewModelError = class extends Error {
|
|
16
|
+
code;
|
|
17
|
+
constructor(message, code) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.name = "ReviewModelError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
async function* streamReviewModel(llm, options, signal) {
|
|
24
|
+
try {
|
|
25
|
+
yield* llm.stream(options);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
const code = signal.aborted ? "cancelled" : error.name === "TimeoutError" ? "timeout" : "transport";
|
|
28
|
+
throw new ReviewModelError(error instanceof Error ? error.message : String(error), code);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var ReviewPartialFailure = class extends Error {
|
|
32
|
+
actions;
|
|
33
|
+
constructor(message, actions = []) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.actions = actions;
|
|
36
|
+
this.name = "ReviewPartialFailure";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
16
39
|
function toolTarget(name, raw) {
|
|
17
40
|
if (raw === "") return name;
|
|
18
41
|
try {
|
|
@@ -62,7 +85,7 @@ async function runReview(input) {
|
|
|
62
85
|
for (let round = 0; round < maxRounds; round += 1) {
|
|
63
86
|
signal.throwIfAborted();
|
|
64
87
|
const assembler = new BlockAssembler();
|
|
65
|
-
const stream = llm
|
|
88
|
+
const stream = streamReviewModel(llm, {
|
|
66
89
|
provider: header.config.provider,
|
|
67
90
|
model: header.config.model,
|
|
68
91
|
...header.config.reasoningEffort === void 0 ? {} : { reasoningEffort: header.config.reasoningEffort },
|
|
@@ -72,7 +95,7 @@ async function runReview(input) {
|
|
|
72
95
|
...header.tools === void 0 ? {} : { tools: [...header.tools] },
|
|
73
96
|
...toolHistory === void 0 ? {} : { toolHistory },
|
|
74
97
|
signal
|
|
75
|
-
});
|
|
98
|
+
}, signal);
|
|
76
99
|
requests += 1;
|
|
77
100
|
for await (const chunk of stream) {
|
|
78
101
|
assembler.push(chunk);
|
|
@@ -124,7 +147,7 @@ async function runReview(input) {
|
|
|
124
147
|
type: actionType(call.name),
|
|
125
148
|
action: call.name,
|
|
126
149
|
target: toolTarget(call.name, call.arguments),
|
|
127
|
-
status: item.result.isError ? "error" : "ok"
|
|
150
|
+
status: item.result.isError ? "error" : item.result.content.some((block) => block.type === "text" && /staged id:|已暂存|pending_id/.test(block.text)) ? "staged" : "ok"
|
|
128
151
|
});
|
|
129
152
|
messages.push(createToolResultMessage({
|
|
130
153
|
callId: item.callId,
|
|
@@ -133,12 +156,12 @@ async function runReview(input) {
|
|
|
133
156
|
}));
|
|
134
157
|
}
|
|
135
158
|
toolCalls += calls.length;
|
|
136
|
-
if (parent.session.seq !== beforeSeq) throw new
|
|
159
|
+
if (parent.session.seq !== beforeSeq) throw new ReviewPartialFailure("review tool mutated the parent Session", actions);
|
|
137
160
|
}
|
|
138
161
|
} finally {
|
|
139
162
|
clearReview();
|
|
140
163
|
}
|
|
141
|
-
if (parent.session.seq !== beforeSeq) throw new
|
|
164
|
+
if (parent.session.seq !== beforeSeq) throw new ReviewPartialFailure("review mutated the parent Session", actions);
|
|
142
165
|
return {
|
|
143
166
|
finalText,
|
|
144
167
|
actions,
|
|
@@ -592,7 +615,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
592
615
|
if (pendingKind !== void 0) {
|
|
593
616
|
pendingCadenceReviews.delete(session.id);
|
|
594
617
|
if (params().reviewMode === "aux") {
|
|
595
|
-
if (!tryAuxReview(session, agent, pendingKind, signal, "cadence")) pendingCadenceReviews.set(session.id, pendingKind);
|
|
618
|
+
if (!await tryAuxReview(session, agent, pendingKind, signal, "cadence")) pendingCadenceReviews.set(session.id, pendingKind);
|
|
596
619
|
return;
|
|
597
620
|
}
|
|
598
621
|
if (params().reviewMode === "inject") {
|
|
@@ -627,7 +650,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
627
650
|
if (!shouldCompletionReview(event.data.reason, cumulative, params().skillReviewCompletionMinToolCalls)) return;
|
|
628
651
|
completionInjected.add(session.id);
|
|
629
652
|
if (params().reviewMode === "aux") {
|
|
630
|
-
if (!tryAuxReview(session, agent, "skill", signal, "completion")) completionInjected.delete(session.id);
|
|
653
|
+
if (!await tryAuxReview(session, agent, "skill", signal, "completion")) completionInjected.delete(session.id);
|
|
631
654
|
return;
|
|
632
655
|
}
|
|
633
656
|
if (!deliverMessage(agent, INJECT_COMPLETION_SKILL_REVIEW_PROMPT, "completion review", true)) {
|
|
@@ -758,7 +781,8 @@ function apply(ctx, rawConfig = {}) {
|
|
|
758
781
|
* Run one plugin-side review over the parent prefix. No child Agent/Session is
|
|
759
782
|
* created; the parent Agent is used only for tool scope/approval, with no log.
|
|
760
783
|
*/
|
|
761
|
-
|
|
784
|
+
let inFlightControllers = /* @__PURE__ */ new Set();
|
|
785
|
+
async function tryAuxReview(session, agent, kind, signal, reason) {
|
|
762
786
|
const running = auxRunning.get(session.id);
|
|
763
787
|
if (running !== void 0) {
|
|
764
788
|
running.rerun = kind;
|
|
@@ -775,16 +799,39 @@ function apply(ctx, rawConfig = {}) {
|
|
|
775
799
|
ctx.logger.warn("dsh-evolution-review: aux review skipped — llm/tools service is not mounted");
|
|
776
800
|
return false;
|
|
777
801
|
}
|
|
802
|
+
const authority = ctx.get("evolutionMutationAuthority");
|
|
803
|
+
let leaseToken;
|
|
804
|
+
if (authority?.lease !== void 0) {
|
|
805
|
+
const lease = await authority.lease.acquire("background_review", "review:" + session.id, Math.max(config.reviewTimeoutMs + 3e4, 6e4)).catch(() => void 0);
|
|
806
|
+
if (lease === void 0) {
|
|
807
|
+
ctx.logger.warn("dsh-evolution-review: aux review skipped — lease acquire failed");
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
if (!lease.ok) {
|
|
811
|
+
ctx.logger.warn("dsh-evolution-review: aux review already leased (" + lease.reason + ")");
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
leaseToken = lease.token;
|
|
815
|
+
}
|
|
778
816
|
const state = {};
|
|
779
817
|
auxRunning.set(session.id, state);
|
|
780
818
|
const reviewId = "aux-" + randomUUID();
|
|
781
819
|
const startedAt = Date.now();
|
|
782
820
|
const controller = new AbortController();
|
|
821
|
+
inFlightControllers.add(controller);
|
|
783
822
|
let timedOut = false;
|
|
784
823
|
const timer = setTimeout(() => {
|
|
785
824
|
timedOut = true;
|
|
786
825
|
controller.abort();
|
|
787
826
|
}, config.reviewTimeoutMs);
|
|
827
|
+
let leaseRenewTimer;
|
|
828
|
+
if (leaseToken !== void 0 && authority?.lease !== void 0) leaseRenewTimer = setInterval(() => {
|
|
829
|
+
authority.lease.renew(leaseToken).then((record) => {
|
|
830
|
+
if (record === null) controller.abort();
|
|
831
|
+
}).catch(() => {
|
|
832
|
+
controller.abort();
|
|
833
|
+
});
|
|
834
|
+
}, Math.max(5e3, Math.min(3e4, Math.floor(config.reviewTimeoutMs / 2))));
|
|
788
835
|
const AUX_TOOL_ALLOW = new Set([
|
|
789
836
|
"skill_manage",
|
|
790
837
|
"memory",
|
|
@@ -836,13 +883,16 @@ function apply(ctx, rawConfig = {}) {
|
|
|
836
883
|
cacheReadTokens: result.usage.cacheReadTokens ?? 0,
|
|
837
884
|
cacheWriteTokens: 0
|
|
838
885
|
};
|
|
839
|
-
status = "completed";
|
|
886
|
+
status = toolAllow.size === 0 ? "failed" : "completed";
|
|
887
|
+
if (toolAllow.size === 0) error = "aux review has no allowed tools for this parent (PTC-only header); refusing to report completed";
|
|
840
888
|
} catch (caught) {
|
|
841
889
|
error = caught instanceof Error ? caught.message : String(caught);
|
|
890
|
+
if (caught instanceof ReviewPartialFailure && caught.actions.length > 0) actions = caught.actions;
|
|
842
891
|
status = timedOut ? "timeout" : controller.signal.aborted ? "aborted" : "failed";
|
|
843
892
|
ctx.logger.warn("dsh-evolution-review: aux review failed: " + error);
|
|
844
893
|
} finally {
|
|
845
894
|
clearTimeout(timer);
|
|
895
|
+
if (leaseRenewTimer !== void 0) clearInterval(leaseRenewTimer);
|
|
846
896
|
const finishedAt = Date.now();
|
|
847
897
|
try {
|
|
848
898
|
ctx.emit("evolution/review-completed", {
|
|
@@ -878,19 +928,24 @@ function apply(ctx, rawConfig = {}) {
|
|
|
878
928
|
planId: reviewId,
|
|
879
929
|
memoryApplied: actions.filter((action) => action.type === "memory" && ok(action)).length,
|
|
880
930
|
skillApplied: actions.filter((action) => action.type === "skill" && ok(action)).length,
|
|
881
|
-
rejectedOps: actions.filter((action) =>
|
|
931
|
+
rejectedOps: actions.filter((action) => action.status === "error").length,
|
|
932
|
+
stagedOps: actions.filter((action) => action.status === "staged").length,
|
|
882
933
|
...error === void 0 ? {} : { executionError: error }
|
|
883
934
|
});
|
|
884
935
|
} catch (emitError) {
|
|
885
936
|
ctx.logger.warn("dsh-evolution-review: aux plan-applied emit failed: " + (emitError instanceof Error ? emitError.message : String(emitError)));
|
|
886
937
|
}
|
|
887
938
|
auxRunning.delete(session.id);
|
|
939
|
+
inFlightControllers.delete(controller);
|
|
940
|
+
if (leaseToken !== void 0 && authority?.lease !== void 0) await authority.lease.release(leaseToken).catch(() => {});
|
|
888
941
|
if (state.rerun !== void 0) tryAuxReview(session, agent, state.rerun, signal, reason);
|
|
889
942
|
}
|
|
890
943
|
})();
|
|
891
944
|
return true;
|
|
892
945
|
}
|
|
893
946
|
ctx.effect(() => () => {
|
|
947
|
+
for (const controller of inFlightControllers) controller.abort();
|
|
948
|
+
inFlightControllers = /* @__PURE__ */ new Set();
|
|
894
949
|
sessionState.dispose();
|
|
895
950
|
}, "dsh-evolution-review.cleanup");
|
|
896
951
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Context, Volatile } from '@deepseek-ai/cordis';
|
|
6
6
|
import z from '@deepseek-ai/schemastery';
|
|
7
|
-
import type { ContextFormed } from '@
|
|
7
|
+
import type { ContextFormed } from '@lmzhen/dsh-evolution-core/platform';
|
|
8
8
|
declare module '@deepseek-ai/dsh-llm' {
|
|
9
9
|
interface MessageSourceMap {
|
|
10
10
|
'evolution-review': {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ContentBlock, ContextFormed, GenerateOptions, Message, StreamChunk, ToolCallBlock, ToolCallId, ToolHistory } from '@
|
|
2
|
-
import type { EpochHeader, SessionId } from '@
|
|
1
|
+
import type { ContentBlock, ContextFormed, GenerateOptions, Message, StreamChunk, ToolCallBlock, ToolCallId, ToolHistory } from '@lmzhen/dsh-evolution-core/platform';
|
|
2
|
+
import type { EpochHeader, SessionId } from '@lmzhen/dsh-evolution-core/platform';
|
|
3
3
|
declare module '@deepseek-ai/dsh-llm' {
|
|
4
4
|
interface MessageSourceMap {
|
|
5
5
|
'evolution-review': {
|
|
@@ -41,11 +41,19 @@ export interface ReviewToolPort {
|
|
|
41
41
|
export interface ReviewLlmPort {
|
|
42
42
|
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
43
43
|
}
|
|
44
|
+
export declare class ReviewModelError extends Error {
|
|
45
|
+
readonly code: 'timeout' | 'cancelled' | 'transport';
|
|
46
|
+
constructor(message: string, code: 'timeout' | 'cancelled' | 'transport');
|
|
47
|
+
}
|
|
48
|
+
export declare class ReviewPartialFailure extends Error {
|
|
49
|
+
readonly actions: readonly ReviewAction[];
|
|
50
|
+
constructor(message: string, actions?: readonly ReviewAction[]);
|
|
51
|
+
}
|
|
44
52
|
export interface ReviewAction {
|
|
45
53
|
readonly type: 'tool' | 'skill' | 'memory';
|
|
46
54
|
readonly action: string;
|
|
47
55
|
readonly target: string;
|
|
48
|
-
readonly status: 'ok' | 'error';
|
|
56
|
+
readonly status: 'ok' | 'staged' | 'error';
|
|
49
57
|
}
|
|
50
58
|
export interface ReviewUsage {
|
|
51
59
|
readonly inputTokens?: number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-review",
|
|
3
3
|
"description": "Background review orchestration (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.40.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,22 +27,22 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@deepseek-ai/schemastery": "^3.18.5",
|
|
30
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
30
|
+
"@lmzhen/dsh-evolution-core": "^0.40.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
34
34
|
"@deepseek-ai/dsh-agent": "^0.2.2-rc.0",
|
|
35
35
|
"@deepseek-ai/dsh-llm": "^0.2.2-rc.0",
|
|
36
36
|
"@deepseek-ai/dsh-session": "^0.2.2-rc.0",
|
|
37
|
-
"@lmzhen/dsh-evolution-policy": "^0.
|
|
38
|
-
"@lmzhen/dsh-evolution-state": "^0.
|
|
37
|
+
"@lmzhen/dsh-evolution-policy": "^0.40.0",
|
|
38
|
+
"@lmzhen/dsh-evolution-state": "^0.40.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@deepseek-ai/dsh-agent": "^0.2.2-rc.0",
|
|
42
42
|
"@deepseek-ai/dsh-llm": "^0.2.2-rc.0",
|
|
43
43
|
"@deepseek-ai/dsh-session": "^0.2.2-rc.0",
|
|
44
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
45
|
-
"@lmzhen/dsh-evolution-state": "^0.
|
|
44
|
+
"@lmzhen/dsh-evolution-core": "^0.40.0",
|
|
45
|
+
"@lmzhen/dsh-evolution-state": "^0.40.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"dsh": ">=0.2.2-rc.0 <0.2.3-0"
|