@lmzhen/dsh-evolution-review 0.3.37 → 0.3.39

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.
Files changed (2) hide show
  1. package/lib/index.js +55 -20
  2. package/package.json +10 -10
package/lib/index.js CHANGED
@@ -62,16 +62,20 @@ function apply(ctx, rawConfig) {
62
62
  const turnStarts = /* @__PURE__ */ new Map();
63
63
  const cumulativeToolCalls = /* @__PURE__ */ new Map();
64
64
  const completionInjected = /* @__PURE__ */ new Set();
65
+ const pendingCadenceReviews = /* @__PURE__ */ new Map();
66
+ const pendingCadenceWarned = /* @__PURE__ */ new Set();
65
67
  let reviewInFlight = false;
66
68
  const policy = () => ctx.get("evolutionPolicy")?.get();
67
69
  ctx.on("session/event", (session, event) => {
68
70
  if (event.type === "turn/start") turnStarts.set(session.id, session.seq - 1);
69
71
  if (event.type !== "turn/end") return;
70
- if (turnStarts.size >= COUNTER_SWEEP_THRESHOLD || cumulativeToolCalls.size >= COUNTER_SWEEP_THRESHOLD || completionInjected.size >= COUNTER_SWEEP_THRESHOLD) {
72
+ if (turnStarts.size >= COUNTER_SWEEP_THRESHOLD || cumulativeToolCalls.size >= COUNTER_SWEEP_THRESHOLD || completionInjected.size >= COUNTER_SWEEP_THRESHOLD || pendingCadenceReviews.size >= COUNTER_SWEEP_THRESHOLD) {
71
73
  const isAlive = (id) => ctx.agents.get(id) !== void 0;
72
74
  sweepDeadSessionEntries(turnStarts, isAlive);
73
75
  sweepDeadSessionEntries(cumulativeToolCalls, isAlive);
74
76
  sweepDeadSessionEntries(completionInjected, isAlive);
77
+ sweepDeadSessionEntries(pendingCadenceReviews, isAlive);
78
+ sweepDeadSessionEntries(pendingCadenceWarned, isAlive);
75
79
  }
76
80
  onTurnEnd(session, event);
77
81
  });
@@ -115,26 +119,57 @@ function apply(ctx, rawConfig) {
115
119
  await stateService?.saveReviewState(session.id, state);
116
120
  const cumulative = (cumulativeToolCalls.get(session.id) ?? 0) + signal.toolCalls;
117
121
  cumulativeToolCalls.set(session.id, cumulative);
118
- if (kind) {
119
- if (await trySubagentReview(session, agent, kind, signal)) ctx.emit("evolution/review-scheduled", {
120
- sessionId: session.id,
121
- kind,
122
- toolCalls: signal.toolCalls,
123
- userChars: signal.userChars,
124
- assistantChars: signal.assistantChars
125
- });
126
- else agent.inject(createUserMessage({
127
- content: [{
128
- type: "text",
129
- text: reviewPrompt(kind)
130
- }],
131
- source: {
132
- kind: "plugin",
133
- plugin: "dsh-evolution-review",
134
- form: "notice",
135
- summary: "auto-review"
122
+ if (event.data.reason.kind === "completed") {
123
+ const pendingKind = pendingCadenceReviews.get(session.id);
124
+ if (pendingKind !== void 0) {
125
+ pendingCadenceReviews.delete(session.id);
126
+ if ((policy()?.reviewMode ?? config.reviewMode) === "inject") try {
127
+ agent.inject(createUserMessage({
128
+ content: [{
129
+ type: "text",
130
+ text: reviewPrompt(pendingKind)
131
+ }],
132
+ source: {
133
+ kind: "plugin",
134
+ plugin: "dsh-evolution-review",
135
+ form: "notice",
136
+ summary: "auto-review"
137
+ }
138
+ }));
139
+ } catch (injectError) {
140
+ ctx.logger.warn(`dsh-evolution-review: deferred review inject failed: ${injectError instanceof Error ? injectError.message : String(injectError)}`);
136
141
  }
137
- }));
142
+ else if (await trySubagentReview(session, agent, pendingKind, signal)) ctx.emit("evolution/review-scheduled", {
143
+ sessionId: session.id,
144
+ kind: pendingKind,
145
+ toolCalls: signal.toolCalls,
146
+ userChars: signal.userChars,
147
+ assistantChars: signal.assistantChars
148
+ });
149
+ else try {
150
+ agent.inject(createUserMessage({
151
+ content: [{
152
+ type: "text",
153
+ text: reviewPrompt(pendingKind)
154
+ }],
155
+ source: {
156
+ kind: "plugin",
157
+ plugin: "dsh-evolution-review",
158
+ form: "notice",
159
+ summary: "auto-review"
160
+ }
161
+ }));
162
+ } catch (injectError) {
163
+ ctx.logger.warn(`dsh-evolution-review: deferred review inject failed: ${injectError instanceof Error ? injectError.message : String(injectError)}`);
164
+ }
165
+ }
166
+ }
167
+ if (kind) {
168
+ pendingCadenceReviews.set(session.id, kind);
169
+ if (!pendingCadenceWarned.has(session.id)) {
170
+ pendingCadenceWarned.add(session.id);
171
+ ctx.logger.warn(`dsh-evolution-review: ${kind} review threshold reached; the review runs at the end of the conversation (no mid-task execution)`);
172
+ }
138
173
  return;
139
174
  }
140
175
  const trigger = config.skillReviewTrigger;
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.3.37",
4
+ "version": "0.3.39",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -31,9 +31,9 @@
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
33
  "@deepseek-ai/schemastery": "^3.18.1",
34
- "@lmzhen/dsh-evolution-approval": "^0.3.37",
35
- "@lmzhen/dsh-evolution-core": "^0.3.37",
36
- "@lmzhen/dsh-evolution-plan-validator": "^0.3.37"
34
+ "@lmzhen/dsh-evolution-approval": "^0.3.39",
35
+ "@lmzhen/dsh-evolution-core": "^0.3.39",
36
+ "@lmzhen/dsh-evolution-plan-validator": "^0.3.39"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@deepseek-ai/cordis": "^4.0.1",
@@ -42,8 +42,8 @@
42
42
  "@deepseek-ai/dsh-llm": "^0.1.1-rc.2",
43
43
  "@deepseek-ai/dsh-session": "^0.1.1-rc.2",
44
44
  "@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
45
- "@lmzhen/dsh-evolution-state": "^0.3.37",
46
- "@lmzhen/dsh-evolution-policy": "^0.3.37"
45
+ "@lmzhen/dsh-evolution-state": "^0.3.39",
46
+ "@lmzhen/dsh-evolution-policy": "^0.3.39"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@deepseek-ai/dsh-agent": "^0.1.1-rc.2",
@@ -54,9 +54,9 @@
54
54
  "@deepseek-ai/dsh-session-persistence": "^0.1.1-rc.2",
55
55
  "@deepseek-ai/dsh-session-persistence-jsonl": "^0.1.1-rc.2",
56
56
  "@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
57
- "@lmzhen/dsh-evolution-approval": "^0.3.37",
58
- "@lmzhen/dsh-evolution-core": "^0.3.37",
59
- "@lmzhen/dsh-evolution-plan-validator": "^0.3.37",
60
- "@lmzhen/dsh-evolution-state": "^0.3.37"
57
+ "@lmzhen/dsh-evolution-approval": "^0.3.39",
58
+ "@lmzhen/dsh-evolution-core": "^0.3.39",
59
+ "@lmzhen/dsh-evolution-plan-validator": "^0.3.39",
60
+ "@lmzhen/dsh-evolution-state": "^0.3.39"
61
61
  }
62
62
  }