dsh-lean-router 2.2.2 → 2.2.3

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.
@@ -12,6 +12,12 @@
12
12
  - `npm pack --dry-run` / `npm publish` 把 notice 写到 stderr,PowerShell 会把它当错误并使退出码变成 1。用 `cmd /c "npm ... 2>&1"` 或只看 stdout 判断。
13
13
  - `npm publish` 返回成功后 registry 仍要约 90 秒才可见,立刻 `npm view` 会 404。不要把 404 当发布失败。
14
14
  - `npm.ps1` 在本机可能因 `npmNodeDir` 为空失败,一律用 `npm.cmd`。
15
+ - 发版后升级本机 profile,一律用 `node scripts/install-profile.mjs <version>`。它会拉包、替换 `node_modules`、用 Node 写回清单版本并自检(无 BOM、可解析、版本一致)。**不要手工用 PowerShell 改 profile 清单**。
16
+ - profile 的 `package.json` 一旦带 UTF-8 BOM,内核 `JSON.parse` 直接抛 `Unexpected token '', "{ "depe"... is not valid JSON`,desktop 配置档加载失败,所有会话起不来(对话界面表现为热重载后每个进行中的对话都报这句)。PowerShell 5.1 的 `Set-Content -Encoding utf8` / `Out-File -Encoding utf8` 会写 BOM;必须写时的安全写法:
17
+ - PowerShell:`[IO.File]::WriteAllText($p, $text, (New-Object System.Text.UTF8Encoding($false)))`
18
+ - Node:`writeFileSync(p, JSON.stringify(manifest, null, 2) + '\n')`
19
+ 写完后必须复核:文件头 3 字节不得是 `EF BB BF`,且 `JSON.parse` 通过。
20
+ - 不要在 DSH 运行中替换 profile 的 `node_modules`:文件监听会触发客户端插件热重载,正在进行的对话会重读缓存并报错。正确顺序是**先完全退出 DSH → 再装 → 再启动**。
15
21
 
16
22
  ## 版本号判断
17
23
 
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
 
3
- > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 2.2.1).
3
+ > English version of [changelog.md](./changelog.md). Versions follow package.json (currently 2.2.3).
4
+
5
+ ## 2.2.3 (2026-11-29)
6
+
7
+ ### Changed
8
+
9
+ - **Removed the forced opener**: the `spec` band no longer asks reasoning and the first reply to start with "We need …", and `react` no longer asks for "I'm doing …". Real-world use showed no benefit to routing or output quality — only extra fixed tokens and stylistic noise. `guideText` now keeps just the task tone plus the fixed convergence and anti-drift anchors (`GUIDE_TAIL`). `personaText`, `ROUTER_PROMPT` and the preset shards are untouched.
10
+ - **Tests inverted**: `test/router-bands.test.mjs` now asserts that every band's `guideText` contains neither "We need", "I'm doing", nor any first-reply constraint, so the opener cannot creep back in.
4
11
 
5
12
  ## 2.2.2 (2026-11-29)
6
13
 
package/docs/changelog.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # 变更记录(changelog)
2
2
 
3
- > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 2.2.1)。
3
+ > 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 2.2.3)。
4
+
5
+ ## 2.2.3 (2026-11-29)
6
+
7
+ ### 变更
8
+
9
+ - **移除强制开头句式**:`spec` 带不再要求推理与回复首句以 "We need …" 开头,`react` 带不再要求 "I'm doing …"。实机使用后判定该句式对路由与产出无收益,只额外增加固定 token 与表达噪音;`guideText` 现只保留任务基调与固定的收敛/反跑题锚(`GUIDE_TAIL`)。`personaText`、`ROUTER_PROMPT` 与分片均未改动。
10
+ - **测试改为反向断言**:`test/router-bands.test.mjs` 现在断言三条带的 `guideText` 都不含 "We need"、"I'm doing" 或对首句的约束,防止句式被重新加回。
4
11
 
5
12
  ## 2.2.2 (2026-11-29)
6
13
 
package/lib/bands.js CHANGED
@@ -35,8 +35,7 @@ export const BANDS = {
35
35
  GUIDE_TAIL,
36
36
  guideText:
37
37
  "Near-field guide (inspect-and-plan): you are working a fix/inspection task. Read and locate before changing; state the plan when your information is complete, then apply the smallest safe change and verify it. " +
38
- GUIDE_TAIL +
39
- ' Start reasoning and your first reply with "We need …", naming the gap before acting.',
38
+ GUIDE_TAIL,
40
39
  },
41
40
  react: {
42
41
  id: "react",
@@ -47,8 +46,7 @@ export const BANDS = {
47
46
  GUIDE_TAIL,
48
47
  guideText:
49
48
  "Near-field guide (hands-on production): you are working a build task. Produce the next working increment now; verify by running it before claiming progress. " +
50
- GUIDE_TAIL +
51
- ' Start reasoning and your first reply with "I\'m doing …", naming the action you take.',
49
+ GUIDE_TAIL,
52
50
  },
53
51
  weak: {
54
52
  id: "weak",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lean-router",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "lean 省 token × 思考链路由 × code_run 工具遮蔽的 DSH cordis 插件(单 bundle:预设)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -0,0 +1,113 @@
1
+ // dsh-lean-router - 把指定版本装进 desktop profile 的 node_modules,并同步 profile 清单版本号。
2
+ //
3
+ // 为什么必须用这个脚本而不是手工替换:
4
+ // profile 的 package.json 一旦带 UTF-8 BOM,内核 JSON.parse 会抛
5
+ // `Unexpected token '', "{ "depe"... is not valid JSON`,桌面配置档加载失败,
6
+ // 所有会话起不来。PowerShell 5.1 的 Set-Content/Out-File -Encoding utf8 会写 BOM。
7
+ // 本脚本一律用 writeFileSync 写 UTF-8(无 BOM),并在写完后自检。
8
+ //
9
+ // 用法:node scripts/install-profile.mjs <version> [--profile <dir>] [--registry <url>]
10
+ import { execFileSync, execSync } from "node:child_process";
11
+ import { cpSync, existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
12
+ import { tmpdir } from "node:os";
13
+ import { join } from "node:path";
14
+
15
+ const PKG = "dsh-lean-router";
16
+ const DEFAULT_PROFILE = "C:\\Users\\charl\\.dsh\\profiles\\desktop";
17
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
18
+
19
+ function parseArgs(argv) {
20
+ const options = { version: undefined, profile: DEFAULT_PROFILE, registry: DEFAULT_REGISTRY };
21
+ for (let i = 0; i < argv.length; i += 1) {
22
+ const arg = argv[i];
23
+ if (arg === "--profile") options.profile = argv[++i];
24
+ else if (arg === "--registry") options.registry = argv[++i];
25
+ else if (!arg.startsWith("--") && options.version === undefined) options.version = arg;
26
+ }
27
+ return options;
28
+ }
29
+
30
+ function fail(message) {
31
+ console.error("[install-profile] 失败:" + message);
32
+ process.exit(1);
33
+ }
34
+
35
+ function tarCommand() {
36
+ // Windows 上 GNU tar 会解析到 MSYS 版并对 C:\ 路径报错,必须用系统自带 bsdtar。
37
+ if (process.platform === "win32") {
38
+ const bsdtar = "C:\\Windows\\System32\\tar.exe";
39
+ if (existsSync(bsdtar)) return bsdtar;
40
+ }
41
+ return "tar";
42
+ }
43
+
44
+ function assertNoBom(file, label) {
45
+ const buf = readFileSync(file);
46
+ if (buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) {
47
+ fail(label + " 含 UTF-8 BOM(会被内核 JSON.parse 拒绝):" + file);
48
+ }
49
+ return buf;
50
+ }
51
+
52
+ function readJson(file, label) {
53
+ const buf = assertNoBom(file, label);
54
+ try {
55
+ return JSON.parse(buf.toString("utf8"));
56
+ } catch (error) {
57
+ fail(label + " 不是合法 JSON:" + file + " :: " + error.message);
58
+ }
59
+ }
60
+
61
+ const options = parseArgs(process.argv.slice(2));
62
+ if (options.version === undefined) fail("缺少版本号。用法:node scripts/install-profile.mjs <version>");
63
+
64
+ const { version, profile, registry } = options;
65
+ if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(version)) fail("版本号不合法:" + version);
66
+ if (!existsSync(join(profile, "package.json"))) fail("profile 不存在:" + profile);
67
+
68
+ // 1) 拉包到临时目录并解压
69
+ const stage = mkdtempSync(join(tmpdir(), "dsh-lean-router-install-"));
70
+ try {
71
+ // npm 在 Windows 上是 .cmd,Node 无法直接 spawn(EINVAL);用拼接字符串的 execSync 绕开,
72
+ // 同时避免 execFileSync + shell:true + 数组参数触发的 DEP0190 警告。
73
+ execSync(["npm", "pack", PKG + "@" + version, "--registry", registry, "--silent"].join(" "), {
74
+ cwd: stage,
75
+ stdio: ["ignore", "pipe", "inherit"],
76
+ });
77
+ const tarball = readdirSync(stage).find((name) => name.endsWith(".tgz"));
78
+ if (tarball === undefined) fail("npm pack 没有产出 tarball");
79
+ execFileSync(tarCommand(), ["-xzf", join(stage, tarball), "-C", stage], { stdio: "inherit" });
80
+
81
+ const source = join(stage, "package");
82
+ if (!existsSync(join(source, "package.json"))) fail("tarball 解压后缺少 package/package.json");
83
+ const packed = readJson(join(source, "package.json"), "打包内的 package.json");
84
+ if (packed.name !== PKG || packed.version !== version) {
85
+ fail("tarball 内容不符:" + packed.name + "@" + packed.version);
86
+ }
87
+
88
+ // 2) 替换 node_modules 里的包目录
89
+ const target = join(profile, "node_modules", PKG);
90
+ rmSync(target, { recursive: true, force: true });
91
+ cpSync(source, target, { recursive: true });
92
+
93
+ // 3) 同步 profile 清单版本号(Node 写 UTF-8,永不产生 BOM)
94
+ const manifestPath = join(profile, "package.json");
95
+ const manifest = readJson(manifestPath, "profile 的 package.json");
96
+ manifest.dependencies = { ...(manifest.dependencies ?? {}), [PKG]: version };
97
+ writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
98
+
99
+ // 4) 自检:无 BOM、可解析、版本一致、插件文件存在
100
+ const written = readFileSync(manifestPath);
101
+ if (written[0] === 0xef && written[1] === 0xbb && written[2] === 0xbf) fail("写回后仍含 BOM");
102
+ const reloaded = JSON.parse(written.toString("utf8"));
103
+ if (reloaded.dependencies?.[PKG] !== version) fail("写回后清单版本不一致");
104
+ const installed = readJson(join(target, "package.json"), "已安装的 package.json");
105
+ if (installed.version !== version) fail("node_modules 内版本不一致:" + installed.version);
106
+ if (!existsSync(join(target, "lib", "lean", "usage-ledger.js"))) fail("安装结果缺少 lib/lean/usage-ledger.js");
107
+
108
+ console.log("[install-profile] 完成:" + PKG + "@" + version + " -> " + target);
109
+ console.log("[install-profile] 清单 " + manifestPath + " 无 BOM、可解析、版本一致");
110
+ console.log("[install-profile] 下一步:完全退出并重启 DSH,然后在宿主运行时不要替换这些文件(热重载会重读缓存)。");
111
+ } finally {
112
+ rmSync(stage, { recursive: true, force: true });
113
+ }
@@ -33,24 +33,19 @@ test("BANDS 三带形状:id/label/personaText/guideText 齐备且工具面宽
33
33
  assert.equal(BANDS.weak.toolsWide, false);
34
34
  });
35
35
 
36
- test("思考句式:spec/react 引导带固定开头句式,weak 不强制,persona 保持原样", () => {
37
- // spec:先陈述缺口(We need …)再行动。
38
- assert.ok(BANDS.spec.guideText.includes("We need"), "spec 引导含 We need 句式");
39
- assert.ok(BANDS.spec.guideText.includes("reasoning"), "spec 引导覆盖内部推理");
40
- assert.ok(BANDS.spec.guideText.includes("first reply"), "spec 引导覆盖回复第一句");
41
- assert.ok(!BANDS.spec.guideText.includes("I'm doing"), "spec 不混入 react 句式");
42
- // react:直接说明正在做的动作(I'm doing …)。
43
- assert.ok(BANDS.react.guideText.includes("I'm doing"), "react 引导含 I'm doing 句式");
44
- assert.ok(BANDS.react.guideText.includes("reasoning"), "react 引导覆盖内部推理");
45
- assert.ok(BANDS.react.guideText.includes("first reply"), "react 引导覆盖回复第一句");
46
- assert.ok(!BANDS.react.guideText.includes("We need"), "react 不混入 spec 句式");
47
- // weak:交给模型自判,不加任何强制句式。
48
- assert.ok(!BANDS.weak.guideText.includes("We need"), "weak 不强制 spec 句式");
49
- assert.ok(!BANDS.weak.guideText.includes("I'm doing"), "weak 不强制 react 句式");
36
+ test("引导文本:不再强制任何开头句式,只保留固定前缀与固定基调", () => {
37
+ // 曾经要求 spec 以 "We need …"、react 以 "I'm doing …" 开头;实机使用后判定无收益,已移除。
38
+ // 这里反向断言,防止句式被重新加回来。
39
+ for (const id of BAND_IDS) {
40
+ assert.ok(!BANDS[id].guideText.includes("We need"), id + " 引导不含 We need 句式");
41
+ assert.ok(!BANDS[id].guideText.includes("I'm doing"), id + " 引导不含 I'm doing 句式");
42
+ assert.ok(!BANDS[id].guideText.includes("first reply"), id + " 引导不约束回复首句");
43
+ }
50
44
  // 固定前缀与固定基调不变(GUIDE_TAIL 仍保留)。
51
45
  for (const id of BAND_IDS) {
52
46
  assert.ok(BANDS[id].guideText.startsWith("Near-field guide"), id + " 引导固定前缀");
53
47
  assert.ok(BANDS[id].guideText.includes("Recall what you have already done"), id + " 保留 GUIDE_TAIL");
48
+ assert.ok(BANDS[id].guideText.includes("Converge"), id + " 保留收敛锚");
54
49
  }
55
50
  // personaText 当前无运行时消费者:保持原样,不新增句式。
56
51
  for (const id of BAND_IDS) {