@linxin666/dsh-liangshen 0.1.20 → 0.2.1

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/README.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: c92073da251703316c10f0268e8befe94d89d1d5
6
- README.zh.md: b93cfb8d13c52e9e941219a2664e8439ab9da5c6
5
+ README.md: 5699b2aee7b9cfdec6184e042a48ab359a76b5d7
6
+ README.zh.md: 44295097d6561d0d5db7388b438f4bef8509ff4e
package/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  English | [中文](README.zh.md)
4
4
 
5
- Ships the "Anchored Standard" preset as a one-command plugin of the dsh-web-ui family: on host startup it syncs the bundled preset into `~/.dsh/.agent-presets`, so new sessions can pick "梁神模式" from the preset picker. The first model request sees only the builtin Minimal preset's exact two tools — persistent `bash` plus `str_replace_editor` — only the one-line persona prompt section, no runtime contexts, and no injected instructions; after the anchor is established the wire switches to Code Mode (PTC) and the ordinary injections open. Built entirely on the official NPM SDK — no dsh source changes.
5
+ Ships the "Anchored Standard" preset as a one-command plugin of the dsh-web-ui family: on host startup it syncs the bundled preset into `~/.dsh/.agent-presets`, so new sessions can pick "梁神模式" from the preset picker. The first model request sees only the builtin Minimal preset's exact two tools — persistent `bash` plus `str_replace_editor` — only the one-line persona prompt section, no runtime contexts, and no injected instructions; after the anchor is established the wire switches to PTC Mode and the ordinary injections open. Built entirely on the official NPM SDK — no dsh source changes.
6
6
 
7
7
  ## Why
8
8
 
9
9
  DeepSeek V4 Pro conditions strongly on the API tool catalog visible in the FIRST request when choosing its execution trajectory. In the community eval ([xiaobright/modeltest](https://github.com/xiaobright/modeltest)), Standard / PTC scored 91/92 while Minimal reached 99/96 — but Minimal keeps only two tools. This two-phase approach separates the first-trajectory choice from full later capability:
10
10
 
11
11
  1. The first model request exposes only the builtin Minimal preset's exact two tools (persistent `bash` plus `str_replace_editor`), keeps only the `deployment:persona` prompt section, empties runtime contexts, and passes only the user's own messages;
12
- 2. After the session's first durable `tool/call`, promotion waits until the first reasoning block is minimal-like (contains `we` and no `let me`), with a four-step fallback; the wire then switches to Code Mode (PTC) — a single `run_code` tool backed by the full tool registry SDK — and every assembled prompt section plus the ordinary workspace-instruction, skill-catalog, and runtime-context injections return;
12
+ 2. After the session's first durable `tool/call`, promotion waits until the first reasoning block is minimal-like (contains `we` and no `let me`), with a four-step fallback; the wire then switches to PTC Mode — a single `run_code` tool backed by the full tool registry SDK — and every assembled prompt section plus the ordinary workspace-instruction, skill-catalog, and runtime-context injections return;
13
13
  3. The phase derives from persisted session events, so resume / reload never lose state.
14
14
 
15
15
  Measured on native Windows (DeepSeek V4 Pro, max, V4.1b task): 98 / 99, mean 98.5, zero `let me` traces in the second run — reproducible, not a lucky draw, and no tool capability sacrificed. Original experiment: [xiaobright/dsh-anchored-standard](https://github.com/xiaobright/dsh-anchored-standard).
@@ -23,8 +23,9 @@ The preset ships with extra safeguards on top of the reference mechanism, all co
23
23
  - `anchorGate` — after the first `tool/call`, the catalog stays two-tool until the first reasoning block classifies minimal-like, so a `Let me` first block does not immediately earn the full catalog;
24
24
  - `maxBootstrapSteps` — fallback promotion after N steps when no anchored block appeared;
25
25
  - `promoteAfterFirstResponse` — a tool-less first response promotes once it has responded; an anchor-gated session also releases when its first turn ends (`turn/end`), so the next user turn already sees the promoted catalog;
26
- - `promotedPresentation: code` — after promotion the wire is Code Mode (PTC): one `run_code` tool with the full registry available through the generated SDK, switched at the step boundary so the current step's native calls are never interrupted;
26
+ - `promotedPresentation: code` — after promotion the wire is PTC Mode: one `run_code` tool with the full registry available through the generated SDK, switched at the step boundary so the current step's native calls are never interrupted;
27
27
  - `deferredSources` + `deferredGraceSteps` — workspace instructions and the skill catalog wait one extra step after promotion, so the tool-catalog switch and the injection shock do not land in the same step;
28
+ - `instructionHint` (on by default, issue #388) — the post-promotion full-text AGENTS.md injection is replaced by a single non-imperative hint naming the reference files and suggesting on-demand reads, so the injection never flips the anchored trajectory; the model still reaches the knowledge through read / skill_load. Set `false` to restore the legacy full-text injection;
28
29
  - `bootstrapMaxTokens` — caps the phase-1 request output budget (community measurements put `max_tokens=1024` in the high-hit "We need" window, versus 0/5 at the 256k DSH default), and the cap is stripped again after promotion so `requestProposal` never solders 1024 into every later request;
29
30
  - `phase1FirstCallInstruction` — an opt-in extra line appended to the phase-1 persona, off by default: test builds use it to ask the model to ground its first answer with one Minimal-native tool call before responding, so first-turn capability questions are answered from the promoted registry instead of the cropped two-tool view. It deviates from the byte-exact Minimal surface, which is why it ships unset.
30
31
 
@@ -34,10 +35,10 @@ Plan mode is supported: phase 1 filters the assembled prompt sections down to th
34
35
 
35
36
  ```sh
36
37
  # Option 1: family bundle (recommended)
37
- dsh plugin --profile web add @linxin666/dsh-web-ui-all
38
+ dsh plugin --profile web add @linxin666/dsh-web-ui-all@latest
38
39
 
39
40
  # Option 2: standalone
40
- dsh plugin --profile web add @linxin666/dsh-liangshen
41
+ dsh plugin --profile web add @linxin666/dsh-liangshen@latest
41
42
 
42
43
  # Pick ONE of the two: the bundle and the standalone @linxin666/dsh-liangshen
43
44
  # both mount this preset. If you switch between them, remove the other first:
package/README.zh.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  [English](README.md) | 中文
4
4
 
5
- 把「Anchored Standard」preset 做成 DSH 全家桶里的一键安装插件:Host 启动时把内置 preset 同步到 `~/.dsh/.agent-presets`,新建会话即可在预设选择器中选择「梁神模式」。首轮模型请求只看到官方 Minimal 精确双工具——持久 `bash` 与 `str_replace_editor`——与一行 persona,没有运行时上下文和指令注入;锚定建立后 wire 切换为 Code Mode(PTC),并开放全部 prompt section 与常规注入。全部通过官方 NPM SDK 实现,不修改 DSH 源码。
5
+ 把「Anchored Standard」preset 做成 DSH 全家桶里的一键安装插件:Host 启动时把内置 preset 同步到 `~/.dsh/.agent-presets`,新建会话即可在预设选择器中选择「梁神模式」。首轮模型请求只看到官方 Minimal 精确双工具——持久 `bash` 与 `str_replace_editor`——与一行 persona,没有运行时上下文和指令注入;锚定建立后 wire 切换为 PTC Mode,并开放全部 prompt section 与常规注入。全部通过官方 NPM SDK 实现,不修改 DSH 源码。
6
6
 
7
7
  ## 原理
8
8
 
9
9
  DeepSeek V4 Pro 会强烈依赖 API 中可见的**首轮工具目录**选择执行轨迹。社区评测([xiaobright/modeltest](https://github.com/xiaobright/modeltest))中,Standard / PTC 只有 91/92 分,Minimal 达到 99/96,但 Minimal 只有两个工具。两阶段方案把「首次轨迹选择」与「后续完整工具能力」拆开:
10
10
 
11
11
  1. 首轮模型请求只暴露官方 Minimal 精确双工具(持久 `bash` 与 `str_replace_editor`),只保留 `deployment:persona` 一个 prompt section,清空运行时上下文,并且只放行用户自己的消息;
12
- 2. 会话出现首次持久 `tool/call` 后,晋升会等到首个 reasoning 块呈 minimal-like(包含 `we` 且无 `let me`)才发生,四步兜底;随后 wire 切换为 Code Mode(PTC)——只暴露一个 `run_code`,完整工具注册表通过生成的 SDK 调用——并恢复全部 prompt section(含 plan mode 的 `plan:policy`)以及 workspace 指令、skill 目录与运行时快照等常规注入;
12
+ 2. 会话出现首次持久 `tool/call` 后,晋升会等到首个 reasoning 块呈 minimal-like(包含 `we` 且无 `let me`)才发生,四步兜底;随后 wire 切换为 PTC Mode——只暴露一个 `run_code`,完整工具注册表通过生成的 SDK 调用——并恢复全部 prompt section(含 plan mode 的 `plan:policy`)以及 workspace 指令、skill 目录与运行时快照等常规注入;
13
13
  3. 阶段从持久化 session events 推导,resume / reload 不丢失状态。
14
14
 
15
15
  Windows 原生环境实测(DeepSeek V4 Pro、max、V4.1b 题面):98 / 99,均值 98.5,第二轮全程无 `let me` 痕迹,证明不是抽卡,也不需要牺牲完整工具能力。原始实验 preset:[xiaobright/dsh-anchored-standard](https://github.com/xiaobright/dsh-anchored-standard)。
@@ -23,8 +23,9 @@ preset 在参考机制之上内置了额外保护,全部在 `agent.cordis.yml`
23
23
  - `anchorGate`:首次 `tool/call` 后,目录继续保持双工具,直到首个 reasoning 块被判定为 minimal-like,避免 `Let me` 开局立刻拿到完整目录;
24
24
  - `maxBootstrapSteps`:N 步后仍无锚定块时强制晋升;
25
25
  - `promoteAfterFirstResponse`:首轮无工具调用的回答在响应后自动晋升;锚定门控中的会话也会在首轮结束时(`turn/end`)释放,因此新用户轮次一开始就拿到晋升后的目录;
26
- - `promotedPresentation: code`:晋升后 wire 为 Code Mode(PTC)——一个 `run_code` 工具、完整注册表通过生成 SDK 调用;切换发生在 step 边界,不会打断当前步的原生工具调用;
26
+ - `promotedPresentation: code`:晋升后 wire 为 PTC Mode——一个 `run_code` 工具、完整注册表通过生成 SDK 调用;切换发生在 step 边界,不会打断当前步的原生工具调用;
27
27
  - `deferredSources` + `deferredGraceSteps`:workspace 指令与 skill 目录在晋升后再等一步注入,工具目录切换和注入冲击不同时落地;
28
+ - `instructionHint`(默认开启,issue #388):晋升后的 AGENTS.md 全文注入替换为一条非命令式 hint(列出参考文件路径、建议按需读取),模型经 read / skill_load 按需获取,避免全量注入翻转锚定轨迹;置 `false` 恢复旧的全文注入;
28
29
  - `bootstrapMaxTokens`:phase 1 请求的输出预算封顶(社区实测 `max_tokens=1024` 是 "We need" 轨迹的高命中窗口,DSH 默认 256k 命中率为 0),晋升后自动剥离该封顶,避免 `requestProposal` 把 1024 焊进后续每个请求;
29
30
  - `phase1FirstCallInstruction`:追加到 phase-1 persona 的可选一行指令,默认关闭:测试版本用它要求模型在正式作答前先做一次 Minimal 原生工具调用,让首轮能力类提问在晋升后的完整目录下作答,而不是基于被裁剪的双工具视图回答。因为它偏离了逐字节一致的 Minimal 表面,所以默认不开启。
30
31
 
@@ -34,10 +35,10 @@ preset 在参考机制之上内置了额外保护,全部在 `agent.cordis.yml`
34
35
 
35
36
  ```sh
36
37
  # 方式一:全家桶(推荐)
37
- dsh plugin --profile web add @linxin666/dsh-web-ui-all
38
+ dsh plugin --profile web add @linxin666/dsh-web-ui-all@latest
38
39
 
39
40
  # 方式二:单独安装
40
- dsh plugin --profile web add @linxin666/dsh-liangshen
41
+ dsh plugin --profile web add @linxin666/dsh-liangshen@latest
41
42
 
42
43
  # 两种方式二选一:聚合包与独立 @linxin666/dsh-liangshen 都会挂载本 preset。
43
44
  # 需要在两者之间切换时,先 dsh plugin remove 移除另一个再安装:
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
1
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, utimesSync } from "node:fs";
2
2
  import { basename, dirname, isAbsolute, join, relative } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import z from "schemastery";
@@ -205,6 +205,31 @@ function validatePresetAgentFile(presetDir) {
205
205
  if (!existsSync(agent)) return ["agent.cordis.yml is missing from the preset tree"];
206
206
  return validateAgentCordis(readFileSync(agent, "utf8"));
207
207
  }
208
+ /**
209
+ * Copy the whole tree under `sourceDir` into `targetDir`, creating the target
210
+ * directory as needed. Intentionally not `fs.cpSync` (recursive): on Node 22
211
+ * for Windows, `fs.cpSync` with `recursive: true` crashes the process with a
212
+ * fatal error (STATUS_STACK_BUFFER_OVERRUN / 0xC0000409, no JS exception is
213
+ * thrown) whenever the source path contains non-ASCII characters such as a
214
+ * CJK home directory (nodejs/node#54476, regression from nodejs/node#53614).
215
+ * Since `engines` supports Node ^22.19.0, this must work on Node 22, so the
216
+ * copy is done with the same per-entry primitives the rest of the module
217
+ * already uses. Source mtimes are preserved to keep the `preserveTimestamps`
218
+ * contract of the previous `cpSync` call.
219
+ */
220
+ function copyTreeSync(sourceDir, targetDir) {
221
+ mkdirSync(targetDir, { recursive: true });
222
+ for (const entry of readdirSync(sourceDir)) {
223
+ const source = join(sourceDir, entry);
224
+ const target = join(targetDir, entry);
225
+ const stat = statSync(source);
226
+ if (stat.isDirectory()) copyTreeSync(source, target);
227
+ else {
228
+ copyFileSync(source, target);
229
+ utimesSync(target, stat.atime, stat.mtime);
230
+ }
231
+ }
232
+ }
208
233
  /** Copy `sourceRoot/<id>` into `targetRoot/<id>`, idempotently. */
209
234
  function syncOnePreset(sourceDir, targetDir) {
210
235
  const sourceFiles = filesUnder(sourceDir);
@@ -214,10 +239,7 @@ function syncOnePreset(sourceDir, targetDir) {
214
239
  force: true
215
240
  });
216
241
  if (!existsSync(targetDir)) {
217
- cpSync(sourceDir, targetDir, {
218
- recursive: true,
219
- preserveTimestamps: true
220
- });
242
+ copyTreeSync(sourceDir, targetDir);
221
243
  pruneExtras(targetDir, sourceSet);
222
244
  return "synced";
223
245
  }
@@ -237,10 +259,7 @@ function syncOnePreset(sourceDir, targetDir) {
237
259
  }
238
260
  if (!dirty) return "current";
239
261
  pruneExtras(targetDir, sourceSet);
240
- cpSync(sourceDir, targetDir, {
241
- recursive: true,
242
- preserveTimestamps: true
243
- });
262
+ copyTreeSync(sourceDir, targetDir);
244
263
  pruneExtras(targetDir, sourceSet);
245
264
  return "synced";
246
265
  }
@@ -364,7 +383,7 @@ function mountOnce(packageName, fn) {
364
383
  * The preset is the "anchored-standard" idea shipped as a named mode: the
365
384
  * first model request sees only the builtin Minimal preset's exact two tools
366
385
  * (persistent `bash` plus `str_replace_editor`), and after the anchor the
367
- * wire switches to Code Mode (PTC). Derived from
386
+ * wire switches to PTC Mode. Derived from
368
387
  * https://github.com/xiaobright/dsh-anchored-standard (MIT).
369
388
  */
370
389
  /** Stable cordis plugin name. */
@@ -380,7 +399,7 @@ const DEFAULT_ANNOUNCE = true;
380
399
  /** Order of the announcement section within the tool-guidance band. */
381
400
  const SECTION_ORDER = 150;
382
401
  /** Model-facing announcement: plugin presence, principle, and limits. */
383
- const LIANGSHEN_GUIDANCE = "本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:两阶段锚定——首轮模型请求仅暴露官方 Minimal 精确双工具(持久 bash 与 str_replace_editor,文件工具继承宿主沙箱),只保留一行 persona,清空运行时上下文并只放行用户的直接消息,锚定 Minimal 推理轨迹;晋升受首块锚定门控(首块包含 we 且无 let me,四步兜底),无工具首轮会在响应后自动晋升,晋升后 wire 切换为 Code Mode(PTC,单一 run_code)并在 persona 追加所选工作区路径,workspace 指令与 skill 目录在晋升后再延迟一步注入。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。";
402
+ const LIANGSHEN_GUIDANCE = "本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:两阶段锚定——首轮模型请求仅暴露官方 Minimal 精确双工具(持久 bash 与 str_replace_editor,文件工具继承宿主沙箱),只保留一行 persona,清空运行时上下文并只放行用户的直接消息,锚定 Minimal 推理轨迹;晋升受首块锚定门控(首块包含 we 且无 let me,四步兜底),无工具首轮会在响应后自动晋升,晋升后 wire 切换为 PTC Mode(单一 run_code)并在 persona 追加所选工作区路径,workspace 指令与 skill 目录在晋升后再延迟一步注入。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。";
384
403
  /** Absolute path of the bundled preset tree inside this package. */
385
404
  function bundledPresetsRoot() {
386
405
  return fileURLToPath(new URL("../presets/", import.meta.url));
@@ -10,7 +10,7 @@
10
10
  * The preset is the "anchored-standard" idea shipped as a named mode: the
11
11
  * first model request sees only the builtin Minimal preset's exact two tools
12
12
  * (persistent `bash` plus `str_replace_editor`), and after the anchor the
13
- * wire switches to Code Mode (PTC). Derived from
13
+ * wire switches to PTC Mode. Derived from
14
14
  * https://github.com/xiaobright/dsh-anchored-standard (MIT).
15
15
  */
16
16
  import type { Context } from '@deepseek-ai/cordis';
@@ -28,7 +28,7 @@ export interface Config {
28
28
  }
29
29
  export declare const Config: z<Config>;
30
30
  /** Model-facing announcement: plugin presence, principle, and limits. */
31
- export declare const LIANGSHEN_GUIDANCE = "\u672C\u673A\u5DF2\u5B89\u88C5 dsh-liangshen \u63D2\u4EF6\uFF08\u6881\u795E\u6A21\u5F0F agent preset\uFF09\uFF1A\u65B0\u5EFA\u4F1A\u8BDD\u7684\u9884\u8BBE\u9009\u62E9\u5668\u4E2D\u53EF\u9009\u300C\u6881\u795E\u6A21\u5F0F\u300D\u3002\u539F\u7406\uFF1A\u4E24\u9636\u6BB5\u951A\u5B9A\u2014\u2014\u9996\u8F6E\u6A21\u578B\u8BF7\u6C42\u4EC5\u66B4\u9732\u5B98\u65B9 Minimal \u7CBE\u786E\u53CC\u5DE5\u5177\uFF08\u6301\u4E45 bash \u4E0E str_replace_editor\uFF0C\u6587\u4EF6\u5DE5\u5177\u7EE7\u627F\u5BBF\u4E3B\u6C99\u7BB1\uFF09\uFF0C\u53EA\u4FDD\u7559\u4E00\u884C persona\uFF0C\u6E05\u7A7A\u8FD0\u884C\u65F6\u4E0A\u4E0B\u6587\u5E76\u53EA\u653E\u884C\u7528\u6237\u7684\u76F4\u63A5\u6D88\u606F\uFF0C\u951A\u5B9A Minimal \u63A8\u7406\u8F68\u8FF9\uFF1B\u664B\u5347\u53D7\u9996\u5757\u951A\u5B9A\u95E8\u63A7\uFF08\u9996\u5757\u5305\u542B we \u4E14\u65E0 let me\uFF0C\u56DB\u6B65\u515C\u5E95\uFF09\uFF0C\u65E0\u5DE5\u5177\u9996\u8F6E\u4F1A\u5728\u54CD\u5E94\u540E\u81EA\u52A8\u664B\u5347\uFF0C\u664B\u5347\u540E wire \u5207\u6362\u4E3A Code Mode\uFF08PTC\uFF0C\u5355\u4E00 run_code\uFF09\u5E76\u5728 persona \u8FFD\u52A0\u6240\u9009\u5DE5\u4F5C\u533A\u8DEF\u5F84\uFF0Cworkspace \u6307\u4EE4\u4E0E skill \u76EE\u5F55\u5728\u664B\u5347\u540E\u518D\u5EF6\u8FDF\u4E00\u6B65\u6CE8\u5165\u3002preset \u6587\u4EF6\u7531\u63D2\u4EF6\u7EF4\u62A4\u4E8E ~/.dsh/.agent-presets\uFF0C\u5347\u7EA7\u63D2\u4EF6\u65F6\u81EA\u52A8\u66F4\u65B0\uFF1B\u9ED8\u8BA4\u9884\u8BBE\u7531\u7528\u6237\u81EA\u884C\u9009\u62E9\u3002\u7528\u6237\u63D0\u5230\u300C\u6881\u795E\u6A21\u5F0F / \u951A\u5B9A\u6A21\u5F0F / anchored standard\u300D\u65F6\u5373\u6307\u672C\u63D2\u4EF6\uFF0C\u8BF7\u636E\u6B64\u534F\u4F5C\u3002";
31
+ export declare const LIANGSHEN_GUIDANCE = "\u672C\u673A\u5DF2\u5B89\u88C5 dsh-liangshen \u63D2\u4EF6\uFF08\u6881\u795E\u6A21\u5F0F agent preset\uFF09\uFF1A\u65B0\u5EFA\u4F1A\u8BDD\u7684\u9884\u8BBE\u9009\u62E9\u5668\u4E2D\u53EF\u9009\u300C\u6881\u795E\u6A21\u5F0F\u300D\u3002\u539F\u7406\uFF1A\u4E24\u9636\u6BB5\u951A\u5B9A\u2014\u2014\u9996\u8F6E\u6A21\u578B\u8BF7\u6C42\u4EC5\u66B4\u9732\u5B98\u65B9 Minimal \u7CBE\u786E\u53CC\u5DE5\u5177\uFF08\u6301\u4E45 bash \u4E0E str_replace_editor\uFF0C\u6587\u4EF6\u5DE5\u5177\u7EE7\u627F\u5BBF\u4E3B\u6C99\u7BB1\uFF09\uFF0C\u53EA\u4FDD\u7559\u4E00\u884C persona\uFF0C\u6E05\u7A7A\u8FD0\u884C\u65F6\u4E0A\u4E0B\u6587\u5E76\u53EA\u653E\u884C\u7528\u6237\u7684\u76F4\u63A5\u6D88\u606F\uFF0C\u951A\u5B9A Minimal \u63A8\u7406\u8F68\u8FF9\uFF1B\u664B\u5347\u53D7\u9996\u5757\u951A\u5B9A\u95E8\u63A7\uFF08\u9996\u5757\u5305\u542B we \u4E14\u65E0 let me\uFF0C\u56DB\u6B65\u515C\u5E95\uFF09\uFF0C\u65E0\u5DE5\u5177\u9996\u8F6E\u4F1A\u5728\u54CD\u5E94\u540E\u81EA\u52A8\u664B\u5347\uFF0C\u664B\u5347\u540E wire \u5207\u6362\u4E3A PTC Mode\uFF08\u5355\u4E00 run_code\uFF09\u5E76\u5728 persona \u8FFD\u52A0\u6240\u9009\u5DE5\u4F5C\u533A\u8DEF\u5F84\uFF0Cworkspace \u6307\u4EE4\u4E0E skill \u76EE\u5F55\u5728\u664B\u5347\u540E\u518D\u5EF6\u8FDF\u4E00\u6B65\u6CE8\u5165\u3002preset \u6587\u4EF6\u7531\u63D2\u4EF6\u7EF4\u62A4\u4E8E ~/.dsh/.agent-presets\uFF0C\u5347\u7EA7\u63D2\u4EF6\u65F6\u81EA\u52A8\u66F4\u65B0\uFF1B\u9ED8\u8BA4\u9884\u8BBE\u7531\u7528\u6237\u81EA\u884C\u9009\u62E9\u3002\u7528\u6237\u63D0\u5230\u300C\u6881\u795E\u6A21\u5F0F / \u951A\u5B9A\u6A21\u5F0F / anchored standard\u300D\u65F6\u5373\u6307\u672C\u63D2\u4EF6\uFF0C\u8BF7\u636E\u6B64\u534F\u4F5C\u3002";
32
32
  export { dshHome } from './dsh-home.ts';
33
33
  /** Absolute path of the bundled preset tree inside this package. */
34
34
  export declare function bundledPresetsRoot(): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-liangshen",
3
- "description": "LiangShen (梁神) agent preset for the dsh web GUI: a two-phase anchored-standard preset — the first model request exposes only the builtin Minimal exact two-tool surface (persistent bash plus str_replace_editor) with no runtime contexts or injected instructions (Minimal-aligned trajectory anchor), promotion is gated on the first minimal-like reasoning block with a fallback, and the wire then switches to Code Mode (PTC, a single run_code tool over the full registry) with the ordinary injections returning afterwards. The preset files are synced into ~/.dsh/.agent-presets on host startup. Hot-pluggable — mounted via cordis.patch.yml + a profile node_modules symlink, no dsh source changes.",
4
- "version": "0.1.20",
3
+ "description": "LiangShen (梁神) agent preset for the dsh web GUI: a two-phase anchored-standard preset — the first model request exposes only the builtin Minimal exact two-tool surface (persistent bash plus str_replace_editor) with no runtime contexts or injected instructions (Minimal-aligned trajectory anchor), promotion is gated on the first minimal-like reasoning block with a fallback, and the wire then switches to PTC Mode (a single run_code tool over the full registry) with the ordinary injections returning afterwards. The preset files are synced into ~/.dsh/.agent-presets on host startup. Hot-pluggable — mounted via cordis.patch.yml + a profile node_modules symlink, no dsh source changes.",
4
+ "version": "0.2.1",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": "^22.19.0 || >=24.0.0"
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@deepseek-ai/cordis": "^4.0.1",
29
- "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6",
29
+ "@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.7",
30
30
  "@types/node": "^22.20.0",
31
31
  "tsdown": "0.22.2",
32
32
  "typescript": "~5.7.2",
@@ -2,7 +2,7 @@
2
2
  # preset's exact two tools (persistent `bash` plus `str_replace_editor`) and
3
3
  # the same one-line persona, with no runtime contexts and no injected pre-step
4
4
  # messages, anchoring the Minimal trajectory; after a stabilized anchor the
5
- # wire switches to Code Mode (PTC) and the ordinary injections open. The
5
+ # wire switches to PTC Mode and the ordinary injections open. The
6
6
  # phase-1 surface matches the official "exact RL prompt and schemas" snapshot
7
7
  # byte-for-byte on the model-visible wire shape, at the cost of keeping the
8
8
  # persistent shell for the whole session. Unlike the builtin Minimal preset,
@@ -50,14 +50,14 @@
50
50
  # `promoteAfterFirstResponse` avoids a permanent two-tool session after a
51
51
  # tool-less first response, and releases an anchor-gated session once its
52
52
  # first turn ends (`turn/end`). After promotion the catalog is presented as
53
- # Code Mode (PTC): a single `run_code` tool on the wire, switched at the step
53
+ # PTC Mode: a single `run_code` tool on the wire, switched at the step
54
54
  # boundary; workspace instructions and the skill catalog are deferred one
55
55
  # step after promotion. `bootstrapMaxTokens` caps the phase-1 request output
56
56
  # budget (community-observed "We need" trigger window, 1024) and is stripped
57
57
  # again after promotion so the cap never solders into later requests.
58
58
  # After a compaction the session falls back to the controlled phase — the
59
59
  # bootstrap pair plus `compactionTools` (a core work set) — until a NEW
60
- # promotion signal exists past the boundary, and Code Mode is released until
60
+ # promotion signal exists past the boundary, and PTC Mode is released until
61
61
  # the session re-promotes.
62
62
  # `phase1FirstCallInstruction` is an opt-in extra line appended to the
63
63
  # phase-1 persona for test builds (issue #274): the model is asked to ground
@@ -79,6 +79,13 @@
79
79
  deferredSources: [agent-instructions, skill-catalog]
80
80
  deferredGraceSteps: 1
81
81
  promotedPresentation: code
82
+ # Issue #388: after promotion, inject one non-imperative hint (reference
83
+ # files exist at these paths; read them on demand) instead of the full
84
+ # AGENTS.md dump — the full-text injection measurably flips the anchored
85
+ # trajectory (upstream dsh-anchored-standard #49, E1/E1.5/E2). Knowledge
86
+ # stays reachable through read / skill_load. Set false to restore the
87
+ # legacy full-text injection.
88
+ instructionHint: true
82
89
  # phase1FirstCallInstruction: After your first reasoning block, before answering, make one tool call (for example run `pwd` through the shell or view a workspace file) and base your answer on its result.
83
90
 
84
91
  # Workspace instructions are quarantined by `tool-bootstrap` during phase 1
@@ -16,7 +16,7 @@
16
16
  * `promoteAfterFirstResponse` promotes a tool-less first response once it has
17
17
  * responded, and also releases an anchor-gated session when its first turn
18
18
  * ends (`turn/end`). With `promotedPresentation: code` the promoted catalog
19
- * is presented as Code Mode (PTC): the wire shows a single `run_code` tool
19
+ * is presented as PTC Mode: the wire shows a single `run_code` tool
20
20
  * backed by the generated SDK, switched at the step boundary so the current
21
21
  * step's native calls are never interrupted. `deferredSources` and
22
22
  * `deferredGraceSteps` delay selected injected message kinds (workspace
@@ -25,7 +25,7 @@
25
25
  * COMPACTION (local addition, ported from the upstream compaction-epoch
26
26
  * semantics): a compaction rewrites the whole model-visible surface, so the
27
27
  * first post-compaction request is a "second first request". A
28
- * `compaction/end` event releases Code Mode (the presentation disposer) and
28
+ * `compaction/end` event releases PTC Mode (the presentation disposer) and
29
29
  * resets the promotion state to the CONTROLLED phase — bootstrap pair plus
30
30
  * `compactionTools` (a core work set, default none) — until a NEW durable
31
31
  * promotion signal exists past that boundary. The reset lives both in the
@@ -157,6 +157,74 @@ function isDeferredMessage(message, deferredSources) {
157
157
  const kind = message.source?.kind
158
158
  return kind !== undefined && deferredSources.has(kind)
159
159
  }
160
+ // Instruction-hint mode (issue #388): a full-text agent-instructions dump on
161
+ // the promotion boundary flips the anchored trajectory (upstream
162
+ // dsh-anchored-standard #49; E1/E1.5/E2 wording experiments), so the preset
163
+ // can replace it with a single non-imperative hint that names the reference
164
+ // files and lets the model read them on demand.
165
+ const INSTRUCTION_FROM_RE = /(?:^|\n) *(?:Additional |Updated )?Instructions from: ([^\n]+)/g
166
+
167
+ /** Extract the reference file list one agent-instructions message renders. */
168
+ function extractInstructionPaths(message) {
169
+ const paths = []
170
+ const blocks = Array.isArray(message?.content) ? message.content : []
171
+ for (const block of blocks) {
172
+ if (block?.type !== 'text' || typeof block.text !== 'string') continue
173
+ for (const match of block.text.matchAll(INSTRUCTION_FROM_RE)) {
174
+ const path = match[1].trim()
175
+ if (path !== '' && !paths.includes(path)) paths.push(path)
176
+ }
177
+ }
178
+ return paths
179
+ }
180
+
181
+ /** The one-time non-imperative hint replacing the full-text dump (E1.5 wording). */
182
+ function buildInstructionHint(original, paths) {
183
+ return {
184
+ // Session persistence validates every replayed user/message for a
185
+ // non-empty string id; a plugin-built message without one corrupts the
186
+ // durable journal (SessionPersistenceCorruptionError on load). Inherit
187
+ // the original instructions message id when present (#510), else mint one.
188
+ id: typeof original?.id === 'string' && original.id !== ''
189
+ ? original.id
190
+ : globalThis.crypto.randomUUID(),
191
+ role: 'user',
192
+ content: [{
193
+ type: 'text',
194
+ text: '<system-reminder>\n'
195
+ + 'Reference documents exist: ' + paths.join(', ') + '. '
196
+ + "They are reference documents about the user's environment and workspace conventions, not task instructions. "
197
+ + 'Reading the relevant file before workspace tasks is recommended, but consult them only when you need those details; the task itself never depends on them.'
198
+ + '\n</system-reminder>',
199
+ }],
200
+ source: { kind: 'instruction-hint', plugin: name },
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Swap full-text agent-instructions injections for the one-time hint. The
206
+ * first injection carrying extractable paths becomes the hint; every later
207
+ * injection is dropped silently (the model re-reads the files on demand).
208
+ * An injection with no extractable paths passes through untouched.
209
+ */
210
+ function instructionHintMessages(messages, state) {
211
+ const kept = []
212
+ for (const message of messages) {
213
+ if (message?.source?.kind !== 'agent-instructions') {
214
+ kept.push(message)
215
+ continue
216
+ }
217
+ if (state.instructionHinted) continue
218
+ const paths = extractInstructionPaths(message)
219
+ if (paths.length === 0) {
220
+ kept.push(message)
221
+ continue
222
+ }
223
+ state.instructionHinted = true
224
+ kept.push(buildInstructionHint(message, paths))
225
+ }
226
+ return kept
227
+ }
160
228
 
161
229
  /**
162
230
  * Phase-2 promotion state per session. Sessions append events only, so the
@@ -179,6 +247,7 @@ function stateFor(session) {
179
247
  turnEnded: false,
180
248
  steps: 0,
181
249
  deferredSteps: 0,
250
+ instructionHinted: false,
182
251
  presentationApplied: false,
183
252
  hasCompacted: false,
184
253
  presentationDisposer: undefined,
@@ -195,7 +264,7 @@ function stateFor(session) {
195
264
  * first-token conditions the bootstrap exists to control — so the session
196
265
  * re-anchors: promotion state is cleared (the durable `next` scan pointer is
197
266
  * kept, so events recorded BEFORE the boundary never re-promote), and the
198
- * Code Mode presentation is disposed so the next assembly sees the native
267
+ * PTC Mode presentation is disposed so the next assembly sees the native
199
268
  * catalog and the phase-1 filter can narrow it again.
200
269
  */
201
270
  function resetToControlled(state) {
@@ -204,7 +273,7 @@ function resetToControlled(state) {
204
273
  state.presentationDisposer()
205
274
  } catch {
206
275
  // A failed presentation reset must never break the session; the
207
- // next promotion re-declares Code Mode anyway.
276
+ // next promotion re-declares PTC Mode anyway.
208
277
  }
209
278
  state.presentationDisposer = undefined
210
279
  }
@@ -215,12 +284,13 @@ function resetToControlled(state) {
215
284
  state.turnEnded = false
216
285
  state.steps = 0
217
286
  state.deferredSteps = 0
287
+ state.instructionHinted = false
218
288
  state.presentationApplied = false
219
289
  state.hasCompacted = true
220
290
  }
221
291
 
222
292
  /**
223
- * Switch one agent's wire presentation to Code Mode (PTC: a single `run_code`
293
+ * Switch one agent's wire presentation to PTC Mode (PTC: a single `run_code`
224
294
  * tool backed by the generated SDK) after promotion. `agent.ctx.tools` is the
225
295
  * per-agent view of the host registry, so the switch affects this session only.
226
296
  */
@@ -228,10 +298,10 @@ function applyPresentation(agent, state, policy) {
228
298
  if (state.presentationApplied || policy.promotedPresentation !== 'code') return
229
299
  const tools = agent.ctx.tools
230
300
  // Latch only after the switch really happened: without a tools view there
231
- // is nothing to present, and latching early would skip Code Mode forever.
301
+ // is nothing to present, and latching early would skip PTC Mode forever.
232
302
  if (tools === undefined) return
233
303
  // The disposer restores the deployment-default (native) presentation; it is
234
- // kept on the state so a post-compaction reset can release Code Mode and
304
+ // kept on the state so a post-compaction reset can release PTC Mode and
235
305
  // let the phase-1 catalog filter see the native tool list again.
236
306
  state.presentationDisposer = tools.presentAs('code')
237
307
  state.presentationApplied = true
@@ -356,6 +426,10 @@ export function apply(ctx, config) {
356
426
  maxBootstrapSteps: integerAtLeast(config.maxBootstrapSteps ?? 4, 'maxBootstrapSteps', 1),
357
427
  deferredGraceSteps: integerAtLeast(config.deferredGraceSteps ?? 0, 'deferredGraceSteps', 0),
358
428
  promotedPresentation: presentation,
429
+ // Opt-in (issue #388): replace the post-promotion full-text
430
+ // agent-instructions dump with a one-time non-imperative hint naming the
431
+ // reference files, so the injection never flips the anchored trajectory.
432
+ instructionHint: config.instructionHint === true,
359
433
  bootstrapMaxTokens,
360
434
  compactionTools,
361
435
  phase1FirstCallInstruction,
@@ -365,8 +439,8 @@ export function apply(ctx, config) {
365
439
  // executing tools: switching the presentation mid-step would collapse the
366
440
  // native calls that step already planned. By `step/end` the tool-call and
367
441
  // reasoning events are durable, so the NEXT prompt assembly already sees
368
- // Code Mode with its generated SDK section. A `compaction/end` event
369
- // releases Code Mode and resets the promotion state (see
442
+ // PTC Mode with its generated SDK section. A `compaction/end` event
443
+ // releases PTC Mode and resets the promotion state (see
370
444
  // resetToControlled); the reset also runs inside scanEvents, so a cold
371
445
  // start reconstructs the same controlled phase from the durable log.
372
446
  ctx.on('session/event', (session, event) => {
@@ -451,14 +525,18 @@ export function apply(ctx, config) {
451
525
  messages: decision.messages.filter(message => isAllowedMessage(message, messageSources)),
452
526
  }
453
527
  }
528
+ let result = decision
454
529
  if (state.deferredSteps < policy.deferredGraceSteps) {
455
530
  state.deferredSteps += 1
456
- return {
457
- ...decision,
458
- messages: decision.messages.filter(message => !isDeferredMessage(message, deferredSources)),
531
+ result = {
532
+ ...result,
533
+ messages: result.messages.filter(message => !isDeferredMessage(message, deferredSources)),
459
534
  }
460
535
  }
461
- return decision
536
+ if (policy.instructionHint) {
537
+ result = { ...result, messages: instructionHintMessages(result.messages, state) }
538
+ }
539
+ return result
462
540
  }, { prepend: true })
463
541
 
464
542
  // Phase 1 caps the next request output budget to bootstrapMaxTokens, the
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * The preset is the "anchored-standard" idea shipped as a named mode: the
11
11
  * first model request sees only the builtin Minimal preset's exact two tools
12
12
  * (persistent `bash` plus `str_replace_editor`), and after the anchor the
13
- * wire switches to Code Mode (PTC). Derived from
13
+ * wire switches to PTC Mode. Derived from
14
14
  * https://github.com/xiaobright/dsh-anchored-standard (MIT).
15
15
  */
16
16
 
@@ -50,7 +50,7 @@ const DEFAULT_ANNOUNCE = true
50
50
  const SECTION_ORDER = 150
51
51
 
52
52
  /** Model-facing announcement: plugin presence, principle, and limits. */
53
- export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:两阶段锚定——首轮模型请求仅暴露官方 Minimal 精确双工具(持久 bash 与 str_replace_editor,文件工具继承宿主沙箱),只保留一行 persona,清空运行时上下文并只放行用户的直接消息,锚定 Minimal 推理轨迹;晋升受首块锚定门控(首块包含 we 且无 let me,四步兜底),无工具首轮会在响应后自动晋升,晋升后 wire 切换为 Code Mode(PTC,单一 run_code)并在 persona 追加所选工作区路径,workspace 指令与 skill 目录在晋升后再延迟一步注入。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
53
+ export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:两阶段锚定——首轮模型请求仅暴露官方 Minimal 精确双工具(持久 bash 与 str_replace_editor,文件工具继承宿主沙箱),只保留一行 persona,清空运行时上下文并只放行用户的直接消息,锚定 Minimal 推理轨迹;晋升受首块锚定门控(首块包含 we 且无 let me,四步兜底),无工具首轮会在响应后自动晋升,晋升后 wire 切换为 PTC Mode(单一 run_code)并在 persona 追加所选工作区路径,workspace 指令与 skill 目录在晋升后再延迟一步注入。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
54
54
  // The harness-home resolution (DSH_HOME override with the platform-home
55
55
  // fallback and ~ expansion) lives in the family-shared copy ./dsh-home.ts.
56
56
  // Re-export it so the plugin surface stays stable while the implementation is
package/src/sync.test.ts CHANGED
@@ -52,6 +52,23 @@ describe('syncPresetTrees', () => {
52
52
  } finally { f.dispose() }
53
53
  })
54
54
 
55
+ it('copies a preset whose source path contains non-ASCII characters', () => {
56
+ const f = fixture()
57
+ try {
58
+ // Regression test for nodejs/node#54476: on Node 22 for Windows,
59
+ // fs.cpSync({ recursive: true }) aborts the process (0xC0000409) when
60
+ // the source path contains CJK characters, e.g. a CJK home directory.
61
+ // sync.ts must not use fs.cpSync; a CJK user profile must still boot.
62
+ const chinese = join(f.source, '梁神')
63
+ mkdirSync(chinese, { recursive: true })
64
+ writeFileSync(join(chinese, 'agent.cordis.yml'), VALID_AGENT_YAML)
65
+ writeFileSync(join(chinese, 'preset.yml'), 'name: 梁神模式\n')
66
+ const result = syncPresetTrees(f.source, f.target)
67
+ expect(result.synced).toContain('梁神')
68
+ expect(readFileSync(join(f.target, '梁神', 'agent.cordis.yml'), 'utf8')).toBe(VALID_AGENT_YAML)
69
+ } finally { f.dispose() }
70
+ })
71
+
55
72
  it('retires a previously bundled preset directory removed from the source', () => {
56
73
  const f = fixture()
57
74
  try {
package/src/sync.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * can observe (and surface) a broken preset rather than silently shipping it.
16
16
  */
17
17
 
18
- import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync } from 'node:fs'
18
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, utimesSync } from 'node:fs'
19
19
  import { basename, dirname, join, relative } from 'node:path'
20
20
  import { validateAgentCordis } from './schema.ts'
21
21
 
@@ -99,6 +99,33 @@ function validatePresetAgentFile(presetDir: string): string[] {
99
99
  return validateAgentCordis(readFileSync(agent, 'utf8'))
100
100
  }
101
101
 
102
+ /**
103
+ * Copy the whole tree under `sourceDir` into `targetDir`, creating the target
104
+ * directory as needed. Intentionally not `fs.cpSync` (recursive): on Node 22
105
+ * for Windows, `fs.cpSync` with `recursive: true` crashes the process with a
106
+ * fatal error (STATUS_STACK_BUFFER_OVERRUN / 0xC0000409, no JS exception is
107
+ * thrown) whenever the source path contains non-ASCII characters such as a
108
+ * CJK home directory (nodejs/node#54476, regression from nodejs/node#53614).
109
+ * Since `engines` supports Node ^22.19.0, this must work on Node 22, so the
110
+ * copy is done with the same per-entry primitives the rest of the module
111
+ * already uses. Source mtimes are preserved to keep the `preserveTimestamps`
112
+ * contract of the previous `cpSync` call.
113
+ */
114
+ function copyTreeSync(sourceDir: string, targetDir: string): void {
115
+ mkdirSync(targetDir, { recursive: true })
116
+ for (const entry of readdirSync(sourceDir)) {
117
+ const source = join(sourceDir, entry)
118
+ const target = join(targetDir, entry)
119
+ const stat = statSync(source)
120
+ if (stat.isDirectory()) {
121
+ copyTreeSync(source, target)
122
+ } else {
123
+ copyFileSync(source, target)
124
+ utimesSync(target, stat.atime, stat.mtime)
125
+ }
126
+ }
127
+ }
128
+
102
129
  /** Copy `sourceRoot/<id>` into `targetRoot/<id>`, idempotently. */
103
130
  export function syncOnePreset(sourceDir: string, targetDir: string): 'synced' | 'current' {
104
131
  const sourceFiles = filesUnder(sourceDir)
@@ -108,7 +135,7 @@ export function syncOnePreset(sourceDir: string, targetDir: string): 'synced' |
108
135
  rmSync(targetDir, { recursive: true, force: true })
109
136
  }
110
137
  if (!existsSync(targetDir)) {
111
- cpSync(sourceDir, targetDir, { recursive: true, preserveTimestamps: true })
138
+ copyTreeSync(sourceDir, targetDir)
112
139
  pruneExtras(targetDir, sourceSet)
113
140
  return 'synced'
114
141
  }
@@ -131,10 +158,10 @@ export function syncOnePreset(sourceDir: string, targetDir: string): 'synced' |
131
158
  }
132
159
  if (!dirty) return 'current'
133
160
 
134
- // Drop target-only entries first so file/dir type clashes never reach cpSync,
135
- // then copy and prune again per the post-copy contract.
161
+ // Drop target-only entries first so file/dir type clashes never reach the
162
+ // copy, then copy and prune again per the post-copy contract.
136
163
  pruneExtras(targetDir, sourceSet)
137
- cpSync(sourceDir, targetDir, { recursive: true, preserveTimestamps: true })
164
+ copyTreeSync(sourceDir, targetDir)
138
165
  pruneExtras(targetDir, sourceSet)
139
166
  return 'synced'
140
167
  }