@lmzhen/dsh-evolution-review 0.59.6 → 0.60.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 CHANGED
@@ -1,9 +1,9 @@
1
- import { llmPort, settingsPort, toolsPort } from "@lmzhen/dsh-evolution-adapter/ports";
1
+ import { llmPort, settingsPort, toolsPort } from "@lmzhen/dsh-evolution-platform/ports";
2
2
  import z from "@deepseek-ai/schemastery";
3
3
  import { randomUUID } from "node:crypto";
4
- import { BlockAssembler, SessionId, createToolResultMessage, createUserMessage, defineTool } from "@lmzhen/dsh-evolution-adapter/values";
4
+ import { BlockAssembler, SessionId, createToolResultMessage, createUserMessage, defineTool } from "@lmzhen/dsh-evolution-platform/values";
5
5
  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, clampOnce, classifySessionEvent, clearReviewChannel, currentReviewContext, liveBool, markReviewChannel, paramRowId, pickWithPolicy, readDispatchSignal, recordReviewRead, reviewPrompt, sessionAudited, sessionTurnSignals, sweepReviewChannelSessions, unwrapLive, userSetKeys, verifyPromptBundle, withReviewContext } from "@lmzhen/dsh-evolution-core";
6
- import { createReviewChildAgent } from "@lmzhen/dsh-evolution-adapter/review-child";
6
+ import { createReviewChildAgent } from "@lmzhen/dsh-evolution-platform/review-child";
7
7
  import { assertSkillsRootAliasRetired, filterUnreadSkillOps } from "@lmzhen/dsh-evolution-core/skills";
8
8
  //#region lib/types/review-executor.js
9
9
  /**
@@ -456,7 +456,7 @@ function nativeReviewToolChannel(parent, toolAllow, tools, executionAgent = pare
456
456
  *
457
457
  * PTC runs tools through `run_code`; its nested dispatch appends to
458
458
  * `exec.agent.session`. The review executor therefore passes a detached child
459
- * agent created by `@lmzhen/dsh-evolution-adapter/review-child`.
459
+ * agent created by `@lmzhen/dsh-evolution-platform/review-child`.
460
460
  *
461
461
  * The review completion tools (`review_done`, `review_wait`) are registered
462
462
  * ONCE per plugin instance by {@link PtcReviewToolHost}. Their `when` guard only
@@ -997,6 +997,21 @@ function injectKind(debt) {
997
997
  if (debt.memory && debt.skill) return "combined";
998
998
  return debt.memory ? "memory" : debt.skill ? "skill" : null;
999
999
  }
1000
+ /** Split one debt by which kinds actually scheduled; failed kinds are retried next boundary. */
1001
+ function splitScheduledDebt(debt, result) {
1002
+ const scheduled = {
1003
+ memory: debt.memory && result.memory,
1004
+ skill: debt.skill && result.skill
1005
+ };
1006
+ const failed = {
1007
+ memory: debt.memory && !result.memory,
1008
+ skill: debt.skill && !result.skill
1009
+ };
1010
+ return {
1011
+ ...scheduled.memory || scheduled.skill ? { scheduled } : {},
1012
+ ...failed.memory || failed.skill ? { failed } : {}
1013
+ };
1014
+ }
1000
1015
  function mergeDebt(a, b) {
1001
1016
  if (a === null || a === void 0) return b ?? void 0;
1002
1017
  if (b === null || b === void 0) return a;
@@ -1131,7 +1146,27 @@ function apply(ctx, rawConfig = {}) {
1131
1146
  if (params().reviewMode === "inject") ctx.logger.warn("dsh-evolution-review: reviewMode \"inject\" (debug-only) runs the review in the parent session and emits NO evolution/plan-applied ledger entry — evolution-activity and evolution-replay stay empty in this mode (see the evolution-review README, \"Known Limitations and Deferred Work\"). Set reviewMode: \"branch\" on the evolution-policy row to keep the audited plan path; branch review is a temporary platform-gap path (see the README known limitations).");
1132
1147
  const reviewStateLocks = sessionState.add("reviewStateLocks", /* @__PURE__ */ new Map());
1133
1148
  async function withReviewStateLock(id, task) {
1134
- const next = (reviewStateLocks.get(id) ?? Promise.resolve()).catch(() => {}).then(task);
1149
+ const next = (reviewStateLocks.get(id) ?? Promise.resolve()).catch(() => {}).then(async () => {
1150
+ const authority = ctx.get("evolutionMutationAuthority");
1151
+ let token;
1152
+ if (authority !== void 0) {
1153
+ for (let attempt = 0; attempt < 50; attempt += 1) {
1154
+ const acquired = await authority.lease.acquire("foreground", "review-state:" + id);
1155
+ if (acquired.ok) {
1156
+ token = acquired.token;
1157
+ break;
1158
+ }
1159
+ await new Promise((resolve) => setTimeout(resolve, 10));
1160
+ }
1161
+ if (token === void 0) ctx.logger.warn("dsh-evolution-review: review-state lease busy for " + id + "; counters may be refreshed under contention");
1162
+ }
1163
+ try {
1164
+ await ctx.get("evolutionState")?.reload?.();
1165
+ return await task();
1166
+ } finally {
1167
+ if (token !== void 0 && authority !== void 0) await authority.lease.release(token);
1168
+ }
1169
+ });
1135
1170
  reviewStateLocks.set(id, next);
1136
1171
  try {
1137
1172
  return await next;
@@ -1282,8 +1317,9 @@ function apply(ctx, rawConfig = {}) {
1282
1317
  if (pendingDebt !== void 0) {
1283
1318
  pendingCadenceReviews.delete(session.id);
1284
1319
  if (params().reviewMode === "aux") {
1285
- await consumeReviewDebt(session.id, pendingDebt);
1286
- await scheduleAuxDebt(session, agent, pendingDebt, signal, "cadence");
1320
+ const scheduled = await scheduleAuxDebt(session, agent, pendingDebt, signal, "cadence");
1321
+ if (scheduled.scheduled !== void 0) await consumeReviewDebt(session.id, scheduled.scheduled);
1322
+ if (scheduled.failed !== void 0) pendingCadenceReviews.set(session.id, scheduled.failed);
1287
1323
  return;
1288
1324
  }
1289
1325
  const pendingKind = injectKind(pendingDebt);
@@ -1488,10 +1524,10 @@ function apply(ctx, rawConfig = {}) {
1488
1524
  } });
1489
1525
  }
1490
1526
  async function scheduleAuxDebt(session, agent, debt, signal, reason) {
1491
- const tasks = [];
1492
- if (debt.memory) tasks.push(tryAuxReview(session, agent, "memory", signal, reason));
1493
- if (debt.skill) tasks.push(tryAuxReview(session, agent, "skill", signal, reason));
1494
- await Promise.all(tasks);
1527
+ return splitScheduledDebt(debt, {
1528
+ memory: debt.memory ? await tryAuxReview(session, agent, "memory", signal, reason) : false,
1529
+ skill: debt.skill ? await tryAuxReview(session, agent, "skill", signal, reason) : false
1530
+ });
1495
1531
  }
1496
1532
  async function consumeReviewDebt(sessionId, debt) {
1497
1533
  await withReviewStateLock(sessionId, async () => {
@@ -1865,4 +1901,4 @@ function resultCallIdOf(event) {
1865
1901
  return null;
1866
1902
  }
1867
1903
  //#endregion
1868
- export { Config, apply, clampReviewConfig, filterUnreadSkillOps, inject, name, noticeAllowed, resolveReviewRowSettings, shouldCompletionReview, sweepDeadSessionEntries };
1904
+ export { Config, apply, clampReviewConfig, filterUnreadSkillOps, inject, name, noticeAllowed, resolveReviewRowSettings, shouldCompletionReview, splitScheduledDebt, sweepDeadSessionEntries };
@@ -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 '@lmzhen/dsh-evolution-platform-contract';
7
+ import type { ContextFormed } from '@lmzhen/dsh-evolution-platform/contract';
8
8
  declare module '@deepseek-ai/dsh-llm' {
9
9
  interface MessageSourceMap {
10
10
  'evolution-review': {
@@ -12,6 +12,7 @@ declare module '@deepseek-ai/dsh-llm' {
12
12
  } & ContextFormed;
13
13
  }
14
14
  }
15
+ import { type ReviewDebt } from '@lmzhen/dsh-evolution-core';
15
16
  export { filterUnreadSkillOps } from '@lmzhen/dsh-evolution-core/skills';
16
17
  /** S2-6 (FLOW1-1): the settle-grace margin a subagent handle gets beyond its
17
18
  * own deadline before the review abandons it. As the dispose watchdog's WHOLE
@@ -116,6 +117,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
116
117
  root: z<string, string, "defined">;
117
118
  skillsRoot: z<string, string, "defined">;
118
119
  }>>, "plain">;
120
+ /** Split one debt by which kinds actually scheduled; failed kinds are retried next boundary. */
121
+ export declare function splitScheduledDebt(debt: ReviewDebt, result: {
122
+ readonly memory: boolean;
123
+ readonly skill: boolean;
124
+ }): {
125
+ scheduled?: ReviewDebt;
126
+ failed?: ReviewDebt;
127
+ };
119
128
  /** F5 (P2-16, v11): the clamp sets exactly these four numeric fields — the
120
129
  * old `as Required<Config>` lied about `reviewToolAllow` etc. being populated
121
130
  * (`[...undefined]` TypeErrors under a direct `apply(ctx, {})`).
@@ -1,5 +1,5 @@
1
- import type { ContentBlock, ContextFormed, GenerateOptions, Message, StreamChunk, ToolCallBlock, ToolCallId, ToolHistory } from '@lmzhen/dsh-evolution-platform-contract';
2
- import type { EpochHeader, SessionId } from '@lmzhen/dsh-evolution-platform-contract';
1
+ import type { ContentBlock, ContextFormed, GenerateOptions, Message, StreamChunk, ToolCallBlock, ToolCallId, ToolHistory } from '@lmzhen/dsh-evolution-platform/contract';
2
+ import type { EpochHeader, SessionId } from '@lmzhen/dsh-evolution-platform/contract';
3
3
  import type { ReviewToolChannel } from './review-tool-channel.ts';
4
4
  import type { ReviewWriteLocks } from './review-write-locks.ts';
5
5
  declare module '@deepseek-ai/dsh-llm' {
@@ -1,4 +1,4 @@
1
- import type { ToolDefinition } from '@lmzhen/dsh-evolution-adapter/values';
1
+ import type { ToolDefinition } from '@lmzhen/dsh-evolution-platform/values';
2
2
  import type { ReviewReport } from './review-executor.ts';
3
3
  import type { ReviewToolChannel } from './review-tool-channel.ts';
4
4
  import type { ReviewWriteLocks } from './review-write-locks.ts';
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @module @lmzhen/dsh-evolution-review/review-tool-channel
11
11
  */
12
- import type { ToolSchema } from '@lmzhen/dsh-evolution-platform-contract';
12
+ import type { ToolSchema } from '@lmzhen/dsh-evolution-platform/contract';
13
13
  import type { ReviewParent, ReviewReport, ReviewToolOutcome, ReviewToolPort } from './review-executor.ts';
14
14
  /** One executable tool transport for a review task. */
15
15
  export interface ReviewToolChannel {
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.59.6",
4
+ "version": "0.60.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -29,23 +29,20 @@
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
31
  "@deepseek-ai/schemastery": "^3.18.5",
32
- "@lmzhen/dsh-evolution-core": "0.59.6",
33
- "@lmzhen/dsh-evolution-platform-contract": "0.59.6",
34
- "@lmzhen/dsh-evolution-adapter": "0.59.6"
32
+ "@lmzhen/dsh-evolution-core": "0.60.0",
33
+ "@lmzhen/dsh-evolution-platform": "0.60.0"
35
34
  },
36
35
  "peerDependencies": {
37
36
  "@deepseek-ai/cordis": "^4.0.5",
38
37
  "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
39
38
  "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
40
- "@deepseek-ai/dsh-session": "0.2.2-rc.5",
41
- "@lmzhen/dsh-evolution-state": "^0.59.6"
39
+ "@deepseek-ai/dsh-session": "0.2.2-rc.5"
42
40
  },
43
41
  "devDependencies": {
44
42
  "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
45
43
  "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
46
44
  "@deepseek-ai/dsh-session": "0.2.2-rc.5",
47
- "@lmzhen/dsh-evolution-core": "^0.59.6",
48
- "@lmzhen/dsh-evolution-state": "^0.59.6"
45
+ "@lmzhen/dsh-evolution-core": "^0.60.0"
49
46
  },
50
47
  "engines": {
51
48
  "dsh": "0.2.2-rc.5"