dsh-live-compact 1.1.13 → 1.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-live-compact",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "In-place newest-turn compaction for DeepSeek Harness. Compress while the task runs and keep the prefix.",
5
5
  "license": "MIT",
6
6
  "author": "MerkyorLynn <268568828+MerkyorLynn@users.noreply.github.com>",
@@ -44,18 +44,20 @@
44
44
  "compaction"
45
45
  ],
46
46
  "scripts": {
47
- "test:gate": "node test/p0-gate.mjs && node test/p0-blockers.mjs && node test/excerpt.mjs && node test/shadow-worker.mjs && node test/shadow-worker-pool.mjs && node test/shadow-worker-fuse.mjs && node test/v107.mjs && node --test test/turn-end-bridge.mjs && node --test test/failed-diagnostics.test.mjs test/public-exports.test.mjs test/cooldown.test.mjs test/gate-config.test.mjs test/stand-down.test.mjs test/drain-stopline.mjs test/scan-once.mjs test/issue-19.mjs test/issue-20.mjs test/issue-34.mjs test/issue-49.mjs test/issue-62.mjs test/review-derived.test.mjs test/windows-acl.test.mjs test/issue-27.mjs test/issue-29.mjs test/issue-29-notice.mjs test/client-settings.test.mjs test/settings-integration.test.mjs test/runtime-lifecycle.mjs test/shadow-lifecycle.mjs test/finalize-over-32000.mjs test/p1-fable-review.mjs",
48
- "test:compat41": "node test/compat-cordis41.mjs",
47
+ "test:gate": "node test/p0-gate.mjs && node test/p0-blockers.mjs && node test/excerpt.mjs && node test/shadow-worker.mjs && node test/shadow-worker-pool.mjs && node test/shadow-worker-fuse.mjs && node test/v107.mjs && node --test test/turn-end-bridge.mjs && node --test test/failed-diagnostics.test.mjs test/public-exports.test.mjs test/cooldown.test.mjs test/gate-config.test.mjs test/stand-down.test.mjs test/drain-stopline.mjs test/scan-once.mjs test/issue-19.mjs test/issue-20.mjs test/issue-34.mjs test/issue-49.mjs test/issue-62.mjs test/review-derived.test.mjs test/windows-acl.test.mjs test/issue-27.mjs test/issue-29.mjs test/issue-29-notice.mjs test/client-settings.test.mjs test/settings-integration.test.mjs test/runtime-lifecycle.mjs test/shadow-lifecycle.mjs test/finalize-over-32000.mjs test/p1-fable-review.mjs test/adapter.test.mjs test/cli-status.test.mjs test/cli-search.test.mjs test/min-gain.test.mjs test/diagnostics.test.mjs && node test/decision-log-budget.mjs",
48
+ "test:compat41": "node test/compat/run.mjs 41",
49
+ "test:compat42": "node test/compat/run.mjs 42",
50
+ "test:compat-rc12": "node test/compat/run.mjs rc12",
49
51
  "test:live-gate": "python3 -B -m unittest discover -s test/live-fill -p test_*.py"
50
52
  },
51
53
  "engines": {
52
54
  "node": "^22.19 || >=24",
53
- "dsh": ">=0.2.0-rc.2 <0.3.0"
55
+ "dsh": ">=0.2.0-rc.2 <0.3.0-0 || 0.2.1-rc.3 || >=0.2.2-rc.1 <0.3.0-0 || >=0.2.3-alpha.2 <0.3.0-0"
54
56
  },
55
57
  "peerDependencies": {
56
- "@deepseek-ai/dsh-compaction": ">=0.2.0-rc.2 <0.3.0",
57
- "@deepseek-ai/dsh-compaction-basic": ">=0.2.0-rc.2 <0.3.0",
58
- "@deepseek-ai/dsh-llm": ">=0.2.0-rc.2 <0.3.0",
58
+ "@deepseek-ai/dsh-compaction": ">=0.2.0-rc.2 <0.3.0-0 || 0.2.1-rc.3 || >=0.2.2-rc.1 <0.3.0-0 || >=0.2.3-alpha.2 <0.3.0-0",
59
+ "@deepseek-ai/dsh-compaction-basic": ">=0.2.0-rc.2 <0.3.0-0 || 0.2.1-rc.3 || >=0.2.2-rc.1 <0.3.0-0 || >=0.2.3-alpha.2 <0.3.0-0",
60
+ "@deepseek-ai/dsh-llm": ">=0.2.0-rc.2 <0.3.0-0 || 0.2.1-rc.3 || >=0.2.2-rc.1 <0.3.0-0 || >=0.2.3-alpha.2 <0.3.0-0",
59
61
  "@deepseek-ai/schemastery": ">=3.18.0 <4",
60
62
  "react": ">=18"
61
63
  },
package/plan.js CHANGED
@@ -8,6 +8,8 @@
8
8
  * Open background jobs do not delay the cut; the card records that they were still running.
9
9
  */
10
10
 
11
+ import { readEngineSetting } from "./settings.js";
12
+
11
13
  const MARK = "Spine extract.";
12
14
  const KEEP_BUDGET = 8000;
13
15
  const TEXTUAL = new Set(["text", "input_text", "output_text"]);
@@ -786,9 +788,9 @@ export function resolveProviderBaseURL({
786
788
  return catalogProviderURL(provider, catalog, model);
787
789
  }
788
790
 
789
- export function resolveEngine({ provider = "", baseURL = "", env = process.env } = {}) {
790
- const override = String(env.SPINE_ENGINE || "").trim().toLowerCase();
791
- if (override === "local" || override === "cloud") return { engine: override, source: "env" };
791
+ export function resolveEngine({ provider = "", baseURL = "", env = process.env, config } = {}) {
792
+ const override = readEngineSetting(config, env);
793
+ if (override.engine === "local" || override.engine === "cloud") return override;
792
794
  if (/strata/i.test(String(provider || ""))) return { engine: "local", source: "provider" };
793
795
  if (provider === "deepseek-account" && baseURL) {
794
796
  try {
package/settings.js CHANGED
@@ -10,6 +10,9 @@ export const DEFAULTS = Object.freeze({
10
10
  chunkMax: 32000, // 一刀上限,等于卡片轨道
11
11
  bigGate: 650000, // 绝对停切线
12
12
  cooldownMs: 0, // 0 = 只用 seq 一次性跳过
13
+ minGainRatio: 0, // 0 = 关闭首刀收益门
14
+ engine: "auto",
15
+ shadowMaxMb: 256,
13
16
  });
14
17
 
15
18
  /** 旧的环境变量仍然有效,但只作为 config 缺席时的兜底。 */
@@ -21,6 +24,9 @@ export const ENV = Object.freeze({
21
24
  chunkMin: "SPINE_CHUNK_MIN",
22
25
  chunkMax: "SPINE_CHUNK_MAX",
23
26
  cooldownMs: "SPINE_COOLDOWN_MS",
27
+ minGainRatio: "SPINE_MIN_GAIN_RATIO",
28
+ engine: "SPINE_ENGINE",
29
+ shadowMaxMb: "SPINE_SHADOW_MAX_MB",
24
30
  });
25
31
 
26
32
  // volatile 字段的现值是 cosmokit 的取值对象,读之前先摊平。
@@ -72,17 +78,41 @@ const finite = (value) => {
72
78
  return Number.isFinite(number) ? number : undefined;
73
79
  };
74
80
 
81
+ const ENGINES = ["auto", "local", "cloud"];
82
+
83
+ export function readEngineSetting(config, env = process.env) {
84
+ const configured = plain(config?.engine);
85
+ if (ENGINES.includes(configured)) return { engine: configured, source: "config" };
86
+ const fallback = String(env?.[ENV.engine] || "").trim().toLowerCase();
87
+ if (fallback === "local" || fallback === "cloud") return { engine: fallback, source: "env" };
88
+ return { engine: DEFAULTS.engine };
89
+ }
90
+
91
+ export function configuredShadowMaxMb(config) {
92
+ const mb = finite(config?.shadowMaxMb);
93
+ return mb > 0 && Number.isSafeInteger(Math.floor(mb * 1024 * 1024)) && mb * 1024 * 1024 >= 1 ? mb : undefined;
94
+ }
95
+
75
96
  export function readSettings(config = {}, env = process.env) {
76
97
  const next = {};
77
98
  for (const [key, fallback] of Object.entries(DEFAULTS)) {
99
+ if (key === "engine" || key === "shadowMaxMb") continue;
78
100
  const envName = ENV[key];
79
101
  const numeric = (value) => {
80
102
  const number = finite(value);
81
- return key === "keepRounds" && (!Number.isInteger(number) || number < 1) ? undefined : number;
103
+ if (key === "keepRounds" && (!Number.isInteger(number) || number < 1)) return undefined;
104
+ if (key === "minGainRatio" && number < 0) return undefined;
105
+ return number;
82
106
  };
83
107
  next[key] =
84
108
  numeric(config?.[key]) ?? numeric(envName ? env?.[envName] : undefined) ?? fallback;
85
109
  }
110
+ next.engine = readEngineSetting(config, env).engine;
111
+ const bytes = Number(env?.SPINE_SHADOW_MAX_BYTES);
112
+ const mb = Number(env?.[ENV.shadowMaxMb]);
113
+ next.shadowMaxMb = configuredShadowMaxMb(config) ??
114
+ (Number.isFinite(bytes) && bytes > 0 ? bytes / (1024 * 1024)
115
+ : Number.isFinite(mb) && mb > 0 ? mb : DEFAULTS.shadowMaxMb);
86
116
  if (!next.pointerTokens) next.pointerTokens = next.chunkMax;
87
117
  return Object.freeze(next);
88
118
  }
@@ -132,5 +162,14 @@ export function configSchema(z, stockSchema) {
132
162
  cooldownMs: count(0)
133
163
  .description("官方压缩之后跳过小切的时间窗;0 = 只按事件序号跳过一次。")
134
164
  .volatile(),
165
+ minGainRatio: z.number().min(0)
166
+ .description("首刀最小节省/重写比例;0 = 关闭,紧急线以上照常切。")
167
+ .volatile(),
168
+ engine: z.union(ENGINES.map((value) => z.const(value)))
169
+ .description("小切模式:auto 按地址判定,local 单刀,cloud 可连续收尾。")
170
+ .volatile(),
171
+ shadowMaxMb: z.number().min(1 / (1024 * 1024))
172
+ .description("shadow 容量上限(MiB);留空沿用环境变量或 256 MiB。")
173
+ .volatile(),
135
174
  });
136
175
  }
@@ -26,10 +26,12 @@ async function handle(id, payload) {
26
26
  const result = saveShadowTransaction(normalizeShadowBody(payload));
27
27
  parentPort.postMessage({ id, ok: true, result });
28
28
  } catch (error) {
29
+ const step = error?.step || error?.cause?.step;
29
30
  parentPort.postMessage({ id, ok: false, error: {
30
31
  name: error?.name || "Error",
31
32
  message: error?.message || String(error),
32
33
  code: error?.code,
34
+ step: typeof step === "string" && step.length <= 64 ? step : undefined,
33
35
  } });
34
36
  }
35
37
  }
package/shadow-search.js CHANGED
@@ -14,7 +14,7 @@
14
14
  // 由插件自己维护(本模块不另立一套过滤规则)
15
15
  // · 返回值是纯数据,不含句柄、不读环境变量、不碰全局状态
16
16
 
17
- import { readFileSync } from "node:fs";
17
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from "node:fs";
18
18
  import { resolve } from "node:path";
19
19
  import { listPluginShadows, sessionDir } from "./shadow.js";
20
20
 
@@ -68,17 +68,36 @@ export function searchShadow(options = {}) {
68
68
 
69
69
  // 只列这一层:listPluginShadows 内部就是一次 readdir + 只收符合命名的普通文件,
70
70
  // 因此天然不会递归进别的会话目录。
71
- for (const file of listPluginShadows(directory)) {
72
- if (file.size > maxFileBytes) {
73
- skipped += 1;
74
- continue;
75
- }
71
+ let directoryStat;
72
+ let files = [];
73
+ try {
74
+ directoryStat = lstatSync(directory);
75
+ if (directoryStat.isDirectory()) files = listPluginShadows(directory, { stat: lstatSync });
76
+ } catch {}
77
+ for (const file of files) {
78
+ let fd;
76
79
  let text;
77
80
  try {
78
- text = readFileSync(file.path, "utf8");
81
+ fd = openSync(file.path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
82
+ const opened = fstatSync(fd);
83
+ const named = lstatSync(file.path);
84
+ const parent = lstatSync(directory);
85
+ if (!opened.isFile() || !named.isFile() || opened.dev !== named.dev || opened.ino !== named.ino ||
86
+ opened.size > maxFileBytes || !parent.isDirectory() || parent.dev !== directoryStat.dev ||
87
+ parent.ino !== directoryStat.ino) throw new Error("unsupported search file");
88
+ const data = Buffer.alloc(opened.size);
89
+ let end = 0;
90
+ while (end < data.length) {
91
+ const bytes = readSync(fd, data, end, data.length - end, end);
92
+ if (!bytes) break;
93
+ end += bytes;
94
+ }
95
+ text = data.toString("utf8", 0, end);
79
96
  } catch {
80
97
  skipped += 1;
81
98
  continue;
99
+ } finally {
100
+ if (fd !== undefined) closeSync(fd);
82
101
  }
83
102
  scanned += 1;
84
103
  let hitThisFile = false;