@linxin666/dsh-liangshen 0.3.22 → 0.3.24

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 (37) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +45 -38
  3. package/README.zh.md +44 -37
  4. package/lib/client.js +1058 -11
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +105 -22
  7. package/lib/types/client/LiangShenSettingsCard.d.ts +61 -0
  8. package/lib/types/client/PluginSettingsCard.d.ts +133 -0
  9. package/lib/types/client/index.d.ts +34 -0
  10. package/lib/types/client/locales.d.ts +27 -1
  11. package/lib/types/client/plugin-card-seat.d.ts +96 -0
  12. package/lib/types/client/settings-form.d.ts +197 -0
  13. package/lib/types/core/lever.d.ts +6 -3
  14. package/lib/types/index.d.ts +23 -11
  15. package/lib/types/sync.d.ts +29 -2
  16. package/package.json +6 -2
  17. package/presets/liangshen/NOTICE +4 -4
  18. package/presets/liangshen/agent.cordis.yml +130 -119
  19. package/presets/liangshen/minimal-prompt.mjs +71 -36
  20. package/presets/liangshen/paging.mjs +232 -0
  21. package/presets/liangshen/tool-activate.mjs +176 -0
  22. package/presets/liangshen/tool-catalog.mjs +610 -218
  23. package/presets/liangshen/working-context.mjs +214 -0
  24. package/src/client/LiangShenLever.tsx +4 -1
  25. package/src/client/LiangShenSettingsCard.tsx +149 -0
  26. package/src/client/PluginSettingsCard.tsx +550 -0
  27. package/src/client/index.ts +60 -1
  28. package/src/client/locales.ts +53 -1
  29. package/src/client/plugin-card-seat.ts +185 -0
  30. package/src/client/settings-card.module.css +418 -0
  31. package/src/client/settings-form.ts +439 -0
  32. package/src/core/lever.ts +7 -4
  33. package/src/index.ts +35 -14
  34. package/src/sync.test.ts +86 -7
  35. package/src/sync.ts +108 -6
  36. package/tools/benchmark-live-run.mjs +24 -33
  37. package/presets/liangshen/custom-bash.mjs +0 -213
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: fce0b0bac57f894854372a0ad570092e6b74793d
6
- README.zh.md: 82ed025985564508569bef37c08a07a9b5cdc452
5
+ README.md: 17e0004b1af01dabd3237cd1ac1b0887fbd94139
6
+ README.zh.md: a39fd5cc5198e34bf516d1fe88038cfa6d4e5b89
package/README.md CHANGED
@@ -1,34 +1,33 @@
1
- # dsh-liangshen — LiangShen Mode (minimal persona + PTC tool surface)
1
+ # dsh-liangshen — LiangShen Mode (minimal persona + programmatic tool transport)
2
2
 
3
3
  English | [中文](README.zh.md)
4
4
 
5
- Ships the LiangShen preset as a one-command plugin of the dsh-web family: on host startup it syncs the bundled preset into `~/.dsh/.agent-presets`, so new sessions can pick "梁神模式" from the preset picker, and its browser half adds a slot-machine lever beside the model selector on the new-session screen for switching that mode on and off. The preset keeps a minimal persona with standing working discipline, session workspace directory, and AGENTS.md-style workspace instructions in the system prompt, and delivers its tool surface as a durable user message after the user's message from the first turn on — the way the harness injects the skill catalog, naming exactly the tools that request opens — while the wire is staged: the session's entire first user turn natively presents a foundational tool surface (default `[bash, str_replace_editor, exit_plan_mode, skill]`, with bash-only preserved as a configuration experiment), and from the second turn the session presents its tools in PTC mode upon successful activation, where the wire carries the single `run_code` transport and other tools are reached via the generated SDK. Deterministic turn boundary transition occurs when PTC is actually activated, preserving full input and output key parameter semantics with no reasoning gating and no output-token cap. Built entirely on the official NPM SDK — no dsh source changes.
5
+ Ships the LiangShen preset as a one-command plugin of the dsh-web family: on host startup it syncs the bundled preset into `~/.dsh/.agent-presets`, so new sessions can pick "梁神模式" from the preset picker, and its browser half adds a slot-machine lever beside the model selector on the new-session screen for switching that mode on and off. The preset keeps a minimal persona with standing working discipline and the session workspace directory in the system prompt, lets the harness deliver AGENTS.md-style workspace instructions as its own user-role messages, and delivers its tool surface as a durable user message after the user's message — the way the harness injects the skill catalog, naming exactly the tools that request opens. The wire keeps one presentation for the whole session (`presentation: 'ptc'` by default): it collapses to the single `run_code` transport and every other tool is reached inside the program through the generated SDK, which leaves the native roster's schema payload out of every request. A deployment without a mounted code runtime degrades to the native surface with a one-time warning instead of presenting a transport the request cannot carry. Tools held back by paging (default pattern `mcp__*`) are unreachable until activated: they appear in the catalog as namespace summaries, and under `ptc` they stay out of the generated SDK as well, because the page is a registry restriction rather than only a wire filter. `tool_activate` loads one namespace back onto the whole surface. Built entirely on the official NPM SDK — no dsh source changes.
6
6
 
7
7
  ## Why
8
8
 
9
- DeepSeek V4 models condition strongly on the initial prompt and the first-turn model-visible tool surface when choosing their execution trajectory. Exposing an unbounded tool surface prematurely can scatter execution trajectories, while completely omitting editing or planning tools restricts the completion of complex tasks.
9
+ DeepSeek V4.1 Flash is post-trained against its native DSML tool-call surface, and the official scaffold comparison for code-agent benchmarks places a native minimal surface ahead of a programmatic (PTC) one (DeepSWE v1.1: 72.6% native minimal vs 67.6% PTC; Terminal-Bench 2.1: 90.6% vs 85.8%). Real engineering sessions, meanwhile, depend on MCP servers and plugins that a closed four-tool surface cannot reach, while a flat roster carrying every external schema buries the conversation under tool definitions.
10
10
 
11
- LiangShen mode adopts a staged tool and compact prompt architecture: the anchoring portion (the system prompt) keeps a minimal persona with standing working discipline and workspace instructions; the capability portion (the tool surface) is announced from the first user message via a skill-catalog-style injection, while the entire first user turn natively presents a foundational anchor tool set (`[bash, str_replace_editor, exit_plan_mode, skill]`) covering discovery, editing, exiting plan mode, and skill lookups; from the second turn onward, upon meeting code runtime requirements and successful declaration, it smoothly transitions to PTC (program-as-tool) mode. Under PTC presentation, the injected message carries generated SDK bindings, complete input and output key parameter semantics, the program contract ("one program per intent"), and the rule that only `run_code` may be called directly. This mode makes no overcommitments regarding "exact identity with official Minimal", "community benchmark scores proving this version is universally superior", or "prompt cache prefix hits equating to behavioral identity", but rather ensures execution stability through a well-defined tiered contract.
11
+ LiangShen mode therefore keeps the whole session on one presentation, chosen by the `presentation` key. The shipped default is `ptc`: the wire collapses to the single `run_code` transport and every other tool is reached from inside the program through the generated SDK, which is the cheapest static context of the three modes because the native roster's schema payload leaves every request. That default is a static-context choice, not a measured win — the same official comparison ranks this presentation below the natively presented surface on both code-agent benchmarks (DeepSWE v1.1: 67.6 against 72.6; Terminal-Bench 2.1: 85.8 against 90.6), and this repository has not run the bundled matrix that would settle the trade. Set `presentation: 'native'` (or `'both'`) to opt into the surface the official numbers favour. The anchoring part (the system prompt) stays a compact persona with an action-triggered working discipline; the capability part is announced from the first user message on as a durable skill-catalog-style injection that names exactly the tools the request opens. External tools matched by the paging patterns (default `mcp__*`) are announced as namespace summaries and stay off the wire — and, under `ptc`, out of the generated SDK, because the page is applied to the registry a program dispatches against — until `tool_activate`, so the static schema surface stays small. The mode makes no overcommitment of benchmark superiority; it guarantees that the declared surface and the request's own wire never disagree.
12
12
 
13
13
  ## How it works
14
14
 
15
- 1. `minimal-prompt` narrows every assembled prompt to the persona section — the one-line persona, the mode's standing working discipline (exit thinking loops immediately, design-first reasoning over pre-rehearsed code, YAGNI and PDCA, no redundant code comments), and one appended orientation line, `Your working directory is <cwd>.` read from the session header — so the harness identity, web-surface, tool-guidance, file-reference, and structured-output sections do not reach the model by default; plan mode's `plan:policy` is kept, because that section is the only thing that enforces plan mode (its exit tool stays registered in every mode);
16
- 2. the AGENTS.md-style workspace instructions join the system prompt itself: at assembly time `minimal-prompt` reads the harness's baseline chain (`$DSH_HOME/AGENTS.md`, then `AGENTS.md` / `CLAUDE.md` and their `.local` overlays from the project root down to the session cwd) and appends the content as one `workspace-instructions` section after the stable prefix, under a byte budget that omits broadest files first and truncates the most specific last; the read happens on every assembly, so file edits propagate without durable messages, and the harness's own agent-instructions injections are dropped instead of duplicating the prompt. Subdirectory dynamic rules will subsequently support registered file tools (including `str_replace_editor`) and sub-calls inside PTC reaching target directories; arbitrary bash/program code is not parsed, and automatic discovery of file accesses performed directly within shell commands is not guaranteed;
17
- 3. the anchor turn (the session's entire first user turn, rather than merely a single first step) keeps the wire on the foundational anchor tool set: default `[bash, str_replace_editor, exit_plan_mode, skill]`, presented natively (`anchorTools`); the `[bash]` single-shell experimental configuration is also preserved and supported (without requiring extra preset registration or registry changes). From the second turn, when a code runtime exists and presentation declaration succeeds, `tool-catalog` activates PTC presentation for that session (`agent.ctx.tools.presentAs('ptc')`, declared on anchor turn end), collapsing the wire to `run_code` where other tools are invoked via the generated SDK; if code runtime is absent or activation fails, it gracefully degrades to the native tool surface with a one-time warning;
18
- 4. `tool-catalog` appends the tool list as a durable user message after the user's message from the first turn on, preserving complete input and output key parameter semantics rather than an oversimplified 200-character-only contract (`descriptionMaxLength: 200` only caps single-line summaries, without stripping key parameter structures). It names exactly the tools the current request opens: the anchor set during the native anchor turn, and, under PTC, the SDK-reachable roster plus the program contract — one program per intent instead of one call per step, `run_code`'s `code`/`description` shape, independent read-only calls overlapping under `Promise.all`, `ToolCallError` handling, curated program output, and the rule that `run_code` is the only directly callable tool once on the wire. It republishes only when that surface changed or the published copy left the visible surface (a compaction, a resume), so the promotion boundary carries one contract update without insisting on absolute context immutability;
19
- 5. runtime contexts (the sandbox and approval snapshots) and the skill catalog flow as in Standard mode.
15
+ 1. `minimal-prompt` narrows every assembled prompt to the persona section — the one-line persona, the mode's standing working discipline (close a repeated hypothesis after two reasoning passes and call an inspection tool instead of speculating; think only about the next concrete operation rather than pre-rehearsing code; emit multiple tool calls concurrently in a single turn for independent inspections; treat shell processes as ephemeral with no directory persistence across calls and use compound commands or explicit workdir for subdirectories; verify against actual tool output during execution; YAGNI and PDCA; no redundant comments), and one appended orientation line, `Your working directory is <cwd>.` read from the session header — so the harness identity, web-surface, tool-guidance, file-reference, and structured-output sections do not reach the model by default; plan mode's `plan:policy` is kept, because that section is the only thing that enforces plan mode (its exit tool stays registered in every mode);
16
+ 2. AGENTS.md-style workspace instructions reach the model through `instructionSource`: by default (`host`) the preset appends no section of its own and leaves the harness's own delivery of those instructions untouched, so they arrive as its user-role messages — one persistent baseline plus incremental additions, replacements, and removals as directories are touched; under `system-prompt` they join the system prompt itself: at assembly time `minimal-prompt` reads the harness's baseline chain (`$DSH_HOME/AGENTS.md`, then `AGENTS.md` / `CLAUDE.md` and their `.local` overlays from the project root down to the session cwd) and appends the content as one `workspace-instructions` section after the stable prefix, under a byte budget that omits broadest files first and truncates the most specific last; the read happens on every assembly, so file edits propagate without durable messages, and the harness's own agent-instructions injections are dropped instead of duplicating the prompt. Subdirectory dynamic rules will subsequently support registered file tools (including `str_replace_editor`) and `run_code` sub-calls reaching target directories; arbitrary bash or program code is not parsed, and automatic discovery of file accesses performed directly within shell commands is not guaranteed;
17
+ 3. the wire keeps one presentation for the entire session, selected by `presentation`: `both` (the default) keeps the native roster and the `run_code` transport co-resident, balancing native accuracy and programmatic execution; `ptc` collapses the wire to `run_code`; `native` carries the assembled native roster; `ptc` and `both` need a mounted code runtime; without one the plugin declares no presentation at all and the session simply runs the native surface. The legacy `ptcPresentation` key maps onto `ptc`/`native` with a deprecation warning, and the retired `anchorTools` first-turn narrowing no longer engages — setting it warns;
18
+ 4. `tool-catalog` appends the tool list as a durable user message after the user's message, preserving complete input and output key parameter semantics (`descriptionMaxLength: 200` caps only the one-line summaries). It names exactly the tools the current request opens — the native roster, plus `run_code` when it is co-resident — and, under tool paging, adds one-line summaries for the namespaces whose tools are held back. Under `ptc` the summaries name namespaces that are genuinely unreachable — neither listed in the request's `tools:sdk` section nor callable from inside a `run_code` program — until `tool_activate`; It republishes only when that surface changes or the published copy left the visible surface (a compaction, a resume);
19
+ 5. tools stay resident on the wire out of the box; when configured with `pagedToolPatterns`, gentle tool paging holds matching tools off the wire until activated: calling `tool_activate` restores the namespace from the next request on, keeping at most three active namespaces at once (activating a fourth evicts the least recently used back to summary). Activation state is rebuilt from the durable event stream across compactions and resumes;
20
+ 6. a minimal working-context line — plan-mode state, active paged namespaces, and in-progress todos — is injected at the tail of the latest message only when its sources are readable, keeping current state inside the model's local attention window; runtime contexts (the sandbox and approval snapshots) and the skill catalog flow as in Standard mode;
21
+ 7. the catalog groups the tools of an activated paged family under a `namespace `<name>` (activated):` heading instead of scattering one server's tools through the alphabetical list, while every non-paged tool keeps its flat entry;
22
+ 8. `maxResidentTokens` (default 6000) estimates the always-on-wire surface and warns once when it is crossed, naming the heaviest tools and `pagedToolPatterns` as the remedy. The guard never truncates: silently dropping a tool the session needs would trade a measurable context cost for an unmeasurable capability loss.
20
23
 
21
24
  ## Security model
22
25
 
23
26
  This mode operates strictly within the official host security architecture and complies with sandbox policies:
24
27
 
25
- - **Host sandbox constraints**: All file tools (whether `str_replace_editor` and Standard file tools natively presented in the first turn, or file operations invoked via PTC `run_code` later) are subject to host file sandbox policies, inheriting the current session's sandbox level (e.g., `danger-full-access` or workspace-restricted/read-only). Bare local filesystem access does not exist (no `dsh-fs-local` mount); all reads and writes across workspaces are guarded by host policy.
26
- - **Windows platform limitations and Git Bash**: DSH's PTY backend is Linux/Darwin-only. On Windows (win32), the persistent-shell group is disabled, and `bash` is provided by `presets/liangshen/custom-bash.mjs` through system Git Bash subprocess invocation:
27
- - Windows Git Bash runs through an ordinary subprocess seam; subject to Windows platform constraints, it lacks namespace/cgroups-based OS sandbox isolation;
28
- - The shell process does not persist across invocations, so command state (environment variables, current directory, etc.) does not carry over;
29
- - Non-zero exits are returned as results rather than thrown;
30
- - Users and developers must not modify `custom-bash.mjs` to bypass security policies; privileged actions must follow host prompts and environment security guidelines.
31
- - **PTC code sandbox**: In PTC mode, `run_code` scripts execute within an isolated worker thread context, with access to system resources strictly bounded by the SDK's exposed tools.
28
+ - **Host sandbox constraints**: All file tools — the natively presented Standard file tools and any file operation a `run_code` program dispatches through the SDK — are subject to host file sandbox policies, inheriting the current session's sandbox level (e.g., `danger-full-access` or workspace-restricted/read-only). Bare local filesystem access does not exist (no `dsh-fs-local` mount); all reads and writes across workspaces are guarded by host policy.
29
+ - **Standard shell on both platforms**: the preset mounts the upstream standard Stdio shell stack on every host, mirroring the builtin Standard preset. POSIX mounts `bash` (`@deepseek-ai/dsh-tool-bash`); win32 mounts `pwsh` (`@deepseek-ai/dsh-tool-pwsh`). Each platform exposes exactly one shell tool (`bash` on POSIX, `pwsh` on win32), featuring active-voice description title cards and deterministic exit codes. The preset ships no shell implementation of its own.
30
+ - **Code runtime sandbox**: `run_code` programs execute within an isolated worker thread context, with access to system resources strictly bounded by the SDK's exposed tools.
32
31
 
33
32
  ## The lever
34
33
 
@@ -43,16 +42,19 @@ The lever drives the session's preset through the agent-preset Remote namespace
43
42
 
44
43
  ## Preset configuration
45
44
 
46
- Both preset-local plugins are configured in `agent.cordis.yml`:
45
+ The preset-local plugins are configured in `agent.cordis.yml`:
47
46
 
48
47
  | Key | Default | Behavior |
49
48
  | --- | --- | --- |
50
49
  | `keepPlanPolicy` | `true` | Keep plan mode's `plan:policy` section in the otherwise one-line system prompt. Set `false` for the strict one-line surface, which leaves plan mode with no policy text behind it. |
51
- | `instructionSource` | `system-prompt` | Where workspace instructions reach the model. `system-prompt` reads the AGENTS.md-style chain at assembly time and appends it to the system prompt (the harness's own injections are dropped); `hint` restores the pointer behavior: the first injection becomes a one-time non-imperative reference-file hint and later injections are dropped. |
52
- | `instructionMaxBytes` | `65536` | Byte budget for the rendered workspace-instructions section (system-prompt mode): broadest files are omitted first, the most specific file is truncated last. |
53
- | `descriptionMaxLength` | `200` | Cap for one tool's one-line summary in the injected catalog. Complete key parameter semantics and contracts remain fully preserved by the SDK itself. |
54
- | `anchorTools` | `[bash, str_replace_editor, exit_plan_mode, skill]` | Tool set natively presented on the wire throughout the entire first user turn; promoted surface engages from the second turn. Shipped default includes the core four tools; can also be configured as `[bash]` for single-shell experiments (without modifying registry). Empty disables staging. |
55
- | `ptcPresentation` | `true` | Attempt to declare PTC presentation from the second turn onward; upon successful activation, wire collapses to `run_code` preserving complete input/output key parameter semantics. Requires a mounted code runtime and a readable tool projection; without either it keeps native presentation with a single warning. The injected catalog always describes the transport the request's own wire carries, and never announces PTC for an assembly the declaration could not reach. Set `false` to keep assembled native roster from second turn. |
50
+ | `instructionSource` | `host` | Where workspace instructions reach the model. `host` (the default) appends no section of its own and leaves the harness's agent-instructions injection untouched, so the instructions arrive as the harness's own user-role messages: one persistent baseline plus incremental additions, replacements, and removals as directories are touched; `system-prompt` reads the AGENTS.md-style chain at assembly time and appends it to the system prompt (the harness's own injections are dropped); `hint` replaces the first injection with a one-time non-imperative reference-file hint and drops later ones. |
51
+ | `instructionMaxBytes` | `65536` | Byte budget for the rendered workspace-instructions section, used only in `system-prompt` mode: broadest files are omitted first, the most specific file is truncated last. |
52
+ | `descriptionMaxLength` | `200` | Cap for one tool's one-line summary in the injected catalog. Complete key parameter semantics remain fully preserved. |
53
+ | `presentation` | `both` | Wire presentation for the whole session. `both` (the shipped default) keeps the full native roster and adds `run_code` co-resident, balancing native accuracy and programmatic capability; `ptc` collapses the wire to `run_code`; `native` keeps the assembled native roster. `ptc` and `both` need a mounted code runtime and degrade to `native` with a one-time warning when missing. |
54
+ | `pagedToolPatterns` | `[]` | Preset default is empty (all tools resident and available out of the box); when configured with glob patterns, matching tools are held back from the wire until activated through `tool_activate({ namespace })`. Held-back namespaces appear in the catalog as one-line summaries. At most three paged namespaces stay active at once, rebuilt from the event stream. |
55
+ | `maxResidentTokens` | `6000` | Estimated-token ceiling for the always-on-wire surface (the serialized schemas at roughly four characters per token), calibrated above the shipped roster so it flags real growth rather than the factory configuration. Crossing it warns once, names the heaviest tools, and points at `pagedToolPatterns`; it never truncates the roster. |
56
+ | `ptcPresentation` | (retired) | Legacy alias: `true` maps to `presentation: 'ptc'` and `false` to `'native'`, both with a deprecation warning. |
57
+ | `anchorTools` | (retired) | First-turn anchor narrowing is removed; setting this key warns and no longer narrows the wire. |
56
58
 
57
59
  ## Install
58
60
 
@@ -74,11 +76,12 @@ Fully restart `dsh web`, open a NEW empty session, and pick "梁神模式" as th
74
76
 
75
77
  Export the session JSONL and inspect `request/header`:
76
78
 
77
- - the first header's `system` should be exactly the persona block (the minimal persona, the working-discipline list, and the workspace line `Your working directory is <cwd>.`), plus plan mode's policy while plan mode is on, plus the `workspace-instructions` section carrying the AGENTS.md chain;
78
- - the entire first user turn's header tools should be exactly the anchor surface — default `[bash, str_replace_editor, exit_plan_mode, skill]`, presented natively — never the promoted roster and never an unactivated `run_code`;
79
- - the anchor turn's admitted messages should hold one `plugin`-sourced message from `liangshen-tool-catalog` after the user message, naming exactly the anchor tools by argument signature; from the promoted turn on, that message names the SDK-reachable roster and states the `run_code` program contract, including that `run_code` is the only directly callable tool;
80
- - from the second turn on, provided PTC successfully activates, headers carry exactly one tool, `run_code` (PTC presentation); without code runtime it gracefully degrades to native roster with a single warning;
81
- - after a compaction the catalog is republished once as a replacement list and the session stays in its current presentation mode;
79
+ - with `instructionSource: host` the first header's `system` should be exactly the persona block (the minimal persona, the working-discipline list, and the workspace line `Your working directory is <cwd>.`) plus plan mode's policy while plan mode is on — while the AGENTS.md chain arrives as the harness's own user-role message; under `instructionSource: system-prompt` the `system` carries one extra `workspace-instructions` section instead;
80
+ - every header keeps the same presentation for the whole session: under the default `presentation: 'ptc'` the wire carries `run_code` alone, and no turn boundary ever collapses the wire further;
81
+ - the admitted messages hold one `plugin`-sourced message from `liangshen-tool-catalog` after the user message, naming exactly the tools the request opens by argument signature; tools held back by paging appear as one-line namespace summaries instead;
82
+ - under `ptc` an unactivated namespace is absent from the request's `tools:sdk` section and cannot be called from inside a `run_code` program — from the FIRST request on, not one request later;
83
+ - after `tool_activate({ namespace })` succeeds, that namespace's tools join the wire from the next request, and no more than three paged namespaces are active at once;
84
+ - after a compaction the catalog is republished once as a replacement list, paged activations are rebuilt from the durable event stream, and the presentation mode is unchanged;
82
85
  - file writes obey the host file sandbox policy — there is no bare local-filesystem bypass.
83
86
 
84
87
  ### Real session validation conditions and benchmark evaluation
@@ -87,9 +90,9 @@ When validating mode behavior and evaluating performance, verification tiers mus
87
90
 
88
91
  1. **Real inference probe ≠ Mode integration pass ≠ Statistical improvement**:
89
92
  - **Real inference probe**: Verifies only transport connectivity and minimal model response capability to specific formats (e.g. using a headless probe to verify output parsing); a single successful probe demonstrates absence of blockers, but never that mode integration has succeeded.
90
- - **Mode integration pass**: Requires full session verification of complete headers, tiered tool transitions, actual PTC activation, SDK parameter semantics parsing, and sandbox policy enforcement.
93
+ - **Mode integration pass**: Requires full session verification of complete headers, the configured presentation behavior, paged activation and eviction, SDK parameter semantics under `run_code`, and sandbox policy enforcement.
91
94
  - **Statistical improvement**: Must be evaluated across multiple comparative benchmark rounds in an isolated environment with recorded fixed routes and source hashes, evaluating task completion rate, tool failure rate, rule violation rate, human intervention frequency, and time/token costs. Single or few smoke runs do not constitute evidence of performance improvement.
92
- 2. **Benchmark tooling**: the isolated runner is `packages/dsh-liangshen/tools/benchmark-live-run.mjs`. It writes the evaluated preset into a temporary root selected through the roster's own `roots` config, redirects session persistence into the run directory, and records a baseline (repository commit, shipped preset hash, DSH version, fixed route, task revision) with every run. The candidate matrix is `B` (shipped persona and two-stage strategy), `P` (candidate persona), `T` (candidate persona, PTC from the first turn), `N` (candidate persona, full native roster throughout), and `M` (the bundle's official Minimal preset, an external reference rather than a single-factor arm). Run one smoke case with `node tools/benchmark-live-run.mjs --variant B`, or the bounded matrix over the seed corpus with `node tools/benchmark-live-run.mjs --tasks tools/tasks/liangshen-v41-flash.json --groups B,P,T,N,M --repeat 3 --max-sessions 60 --budget-usd 5`; aggregate the run records in a results directory with `node tools/benchmark-report.mjs .benchmark-results`, which reports per-group success rates with Wilson intervals, paired per-task deltas with confidence intervals, token and cost totals, infrastructure failures separately, and the recorded baseline. Smoke runs validate the protocol and the cost estimate; they are not evidence of a general coding gain.
95
+ 2. **Benchmark tooling**: the isolated runner is `packages/dsh-liangshen/tools/benchmark-live-run.mjs`. It writes the evaluated preset into a temporary root selected through the roster's own `roots` config, redirects session persistence into the run directory, and records a baseline (repository commit, shipped preset hash, DSH version, fixed route, task revision) with every run. The candidate matrix isolates the persona and the presentation strategy: `B` (shipped defaults), `P` (candidate persona), the presentation arms `T` (candidate persona, PTC from the first turn) and `N` (candidate persona, full native roster throughout), and `M` (the bundle's official Minimal preset, an external reference rather than a single-factor arm). Run one smoke case with `node tools/benchmark-live-run.mjs --variant B`, or the bounded matrix over the seed corpus with `node tools/benchmark-live-run.mjs --tasks tools/tasks/liangshen-v41-flash.json --groups B,P,T,N,M --repeat 3 --max-sessions 60 --budget-usd 5`; aggregate the run records in a results directory with `node tools/benchmark-report.mjs .benchmark-results`, which reports per-group success rates with Wilson intervals, paired per-task deltas with confidence intervals, token and cost totals, infrastructure failures separately, and the recorded baseline. Smoke runs validate the protocol and the cost estimate; they are not evidence of a general coding gain.
93
96
 
94
97
  ## Configuration
95
98
 
@@ -97,21 +100,25 @@ When validating mode behavior and evaluating performance, verification tiers mus
97
100
  | --- | --- | --- |
98
101
  | `enabled` | `true` | Master switch: when false, neither preset sync nor announcement runs. |
99
102
  | `announceToAgent` | `false` | Opt-in: when true, a system-prompt section announces the plugin. Off by default so agent system prompts stay clean. |
103
+ | `presentation` | `both` | Wire presentation written into the synced preset's `tool-catalog` row: `both` (default) keeps the roster and transport co-resident; `ptc` collapses the wire to `run_code`; `native` keeps the assembled roster. A change takes effect on the next DSH start, when the preset is re-synced. |
100
104
 
101
- Both fields are editable in the web settings surface (plugin config, live) or through the profile patch (`dsh plugin` / `cordis.patch.yml`).
105
+ All fields are editable in the web settings surface (plugin config) or through the profile patch (`dsh plugin` / `cordis.patch.yml`). The preset-shaping presentation field reaches a session through the preset sync: the plugin writes it into the synced `agent.cordis.yml` as it copies the bundle, so the settings surface — not the bundled file — is what the operator's sessions actually run. A key the composition does not carry is never invented: the overlay only narrows the shipped configuration. Restart DSH for a change to take effect.
102
106
 
103
107
  ## Behavior and limits
104
108
 
105
- - The system prompt is stable for the whole session: the persona block (persona, working discipline, workspace directory), plus plan mode's policy while plan mode is on, plus the workspace-instructions section. Nothing is appended after a tool call, and no output-token cap is applied;
106
- - The workspace-instructions section is re-read at every assembly, so instruction-file edits propagate on the next request without a durable message; the section renders last, after the stable prefix, so the anchor's cache prefix stays intact. Subdirectory dynamic rules will subsequently support registered file tools (including `str_replace_editor`) and sub-calls inside PTC reaching target directories; arbitrary bash/program code is not parsed, and automatic discovery of file accesses performed directly within shell commands is not guaranteed;
107
- - The wire's schema set stays on the foundational anchor tool set during the entire first user turn (default `[bash, str_replace_editor, exit_plan_mode, skill]`, supporting `[bash]` experiments); from the second turn onward, upon successful PTC activation, it collapses to `run_code`; the catalog message is written once per session plus one replacement when the exposed surface changes — the promotion boundary included — or a compaction shadows it;
108
- - The injected catalog is durable: it is written once per session, plus one replacement when the tool surface changes or a compaction shadows the published copy, and it stays in the history for later requests;
109
+ - The system prompt is stable for the whole session: the persona block (persona, working discipline, workspace directory), plus plan mode's policy while plan mode is on, plus the workspace-instructions section in `system-prompt` mode. Nothing is appended after a tool call, and no output-token cap is applied;
110
+ - In `system-prompt` mode the workspace-instructions section is re-read at every assembly, so instruction-file edits propagate on the next request without a durable message; the section renders last, after the stable prefix, so the cache prefix stays intact. Subdirectory dynamic rules will subsequently support registered file tools (including `str_replace_editor`) and `run_code` sub-calls reaching target directories; arbitrary bash or program code is not parsed, and automatic discovery of file accesses performed directly within shell commands is not guaranteed;
111
+ - The wire keeps the same presentation for the entire session — there is no turn-boundary transition: `native` carries the assembled native roster, `both` adds a co-resident `run_code`, and `ptc` (the default) collapses the wire to `run_code` alone with every other tool reached through the generated SDK;
112
+ - The injected catalog is durable: it is written once per session, plus one replacement when the tool surface changes (a paged activation, a presentation change) or a compaction shadows the published copy, and it stays in the history for later requests;
109
113
  - A step whose prompt assembly was not observed injects nothing — the catalog is never guessed from a stale view;
110
114
  - A composition exposing none of the accepted persona section names (`deployment:persona-prefix`, `deployment:persona`, `persona`) keeps the assembled prompt and warns once instead of sending an empty system prompt;
111
115
  - Plan mode is supported through its `plan:policy` section; with `keepPlanPolicy: false` the mode keeps its tool but loses the policy text that enforces it;
112
- - PTC presentation is declared per session and needs a mounted code runtime (the shipped web and headless compositions mount `dsh-code-runtime-worker-thread`); without one or upon activation failure, the mode stays native with a one-time warning;
113
- - The roster is the builtin PTC preset's model-authored surface: the `workflow` tool is not published beside `run_code`, while the workflow engine stays mounted for `ralph`;
114
- - The persistent `bash` replaces the Standard ephemeral shell for the whole session (both tools register the name `bash`), so shell state survives across calls; on win32 `custom-bash` provides the same-named tool through Git Bash, with no OS sandbox confinement and non-persistent state;
116
+ - Paged tools (default pattern `mcp__*`) stay off the wire until the model activates their namespace through `tool_activate`; at most three paged namespaces are active at once, activating a fourth evicts the least recently used one back to its summary, and activation state is rebuilt from the durable event stream after compactions and resumes;
117
+ - The working-context line is injected only when its sources (plan-mode state, active paged namespaces, in-progress todos) are readable, and omitted otherwise;
118
+ - Tool results are pruned once they exceed 4096 characters, keeping a 1500-character head and a 500-character tail, so oversized outputs do not crowd the context;
119
+ - `run_code` needs a mounted code runtime (the shipped web and headless compositions mount `dsh-code-runtime-worker-thread`); without one, `ptc` and `both` declare nothing and the session runs the native surface;
120
+ - The roster does not publish the `workflow` tool, while the workflow engine stays mounted for `ralph`;
121
+ - The shell mounts the upstream standard Stdio stack, registering `bash` on POSIX and `pwsh` on win32 — each host mounts exactly one shell tool, featuring concise description title cards and deterministic exit codes;
115
122
  - The file tools inherit the host file sandbox (no bare `dsh-fs-local` filesystem);
116
123
  - The preset carries the same trust level as shell access — review `presets/liangshen/` before installing;
117
124
  - The plugin makes no network requests and adds no telemetry;
@@ -120,4 +127,4 @@ Both fields are editable in the web settings surface (plugin config, live) or th
120
127
 
121
128
  ## License
122
129
 
123
- Plugin body Apache-2.0 (zhu1090093659). `presets/liangshen/agent.cordis.yml` derives from the DeepSeek Harness builtin Minimal, Standard, and PTC presets (MIT), and `custom-bash.mjs` comes from xiaobright/dsh-anchored-standard (MIT) — copyright and license notices are kept in the preset's `NOTICE`.
130
+ Plugin body Apache-2.0 (zhu1090093659). `presets/liangshen/agent.cordis.yml` derives from the DeepSeek Harness builtin Minimal, Standard, and PTC presets (MIT) — copyright and license notices are kept in the preset's `NOTICE`.
package/README.zh.md CHANGED
@@ -1,34 +1,33 @@
1
- # dsh-liangshen — 梁神模式(极简 persona + PTC 工具面)
1
+ # dsh-liangshen — 梁神模式(极简 persona + 程序化工具传输)
2
2
 
3
3
  [English](README.md) | 中文
4
4
 
5
- 把梁神模式做成 DSH 全家桶里的一键安装插件:Host 启动时把内置 preset 同步到 `~/.dsh/.agent-presets`,新建会话即可在预设选择器中选择「梁神模式」,浏览器半区还在新建会话页的模型选择器旁提供一台老虎机拨杆来开关该模式。该 preset 让系统提示词保持极简 persona——外加本模式的固定工作纪律、会话工作区目录与 AGENTS.md 类工作区指令——并从第一条用户消息起就把工具面作为持久 user 消息注入在用户消息之后——形状与 harness 注入 skill 目录一致,且只宣告该次请求实际开放的工具——而 wire 按回合分层:首轮整个 user turn 原生呈现基础锚定工具集(默认 `[bash, str_replace_editor, exit_plan_mode, skill]`,并保留 bash-only 配置实验),从第二个回合起在 PTC 成功激活后以 PTC 模式呈现工具,wire 上只有 `run_code` 这一条传输工具,其余工具都在程序里经生成的 SDK 调用。PTC 实际激活时发生确定性的回合边界跃迁,保留完整输入输出关键参数语义,没有推理内容门控、没有输出预算上限。全部通过官方 NPM SDK 实现,不修改 DSH 源码。
5
+ 把梁神模式做成 DSH 全家桶里的一键安装插件:Host 启动时把内置 preset 同步到 `~/.dsh/.agent-presets`,新建会话即可在预设选择器中选择「梁神模式」,浏览器半区还在新建会话页的模型选择器旁提供一台老虎机拨杆来开关该模式。该 preset 让系统提示词保持极简 persona——外加本模式的固定工作纪律与会话工作区目录——AGENTS.md 类工作区指令交由 harness 以自己的 user 角色消息送达;工具面则从第一条用户消息起作为持久 user 消息注入在用户消息之后——形状与 harness 注入 skill 目录一致,且只宣告该次请求实际开放的工具。wire 在整个会话中保持由 `presentation` 选定的同一种呈现(默认 `presentation: 'ptc'`):wire 收拢为唯一的 `run_code` 传输工具,其余工具都在程序内经生成的 SDK 触达,原生清单的 schema 负载因此离开每一个请求;未挂载 code runtime 的部署回退为原生呈现并一次性告警,而不是宣告一个该请求无法承载的传输工具。被分页扣留的匹配工具(默认 `mcp__*`)在激活前不可达:它们以命名空间摘要出现在目录里,`ptc` 下同时不出现在生成的 SDK 中——分页是注册表级限制,不只是 wire 过滤。`tool_activate` 把一个命名空间挂回整个可达面。全部通过官方 NPM SDK 实现,不修改 DSH 源码。
6
6
 
7
7
  ## 原理
8
8
 
9
- DeepSeek V4 模型在选择执行轨迹时,会受到初始提示词与首轮可见工具面的显著影响。过多过早暴露未受约束的工具可能分散执行轨迹,而完全缺乏编辑或规划手段又限制了复杂任务的完成。
9
+ DeepSeek V4.1 Flash 的后训练直接对齐其原生 DSML 工具调用面,官方脚手架横评中代码 Agent 基准上原生极简面领先于程序化(PTC)面(DeepSWE v1.1:72.6% 对 67.6%;Terminal-Bench 2.1:90.6% 对 85.8%)。而真实工程会话依赖 MCP 服务与插件生态——封闭的 4 工具极简面在物理上够不到它们,无边界平铺的全量清单又会把会话内容埋在工具定义之下。
10
10
 
11
- 梁神模式采用分层工具与紧凑提示词架构:负责锚定的部分(系统提示词)保持极简 persona 与明确的工作纪律,并注入工作区指令;负责能力的部分(工具面)从第一条用户消息起以 skill-catalog 式的上下文注入宣告,并在首轮整个 user turn 原生呈现基础锚定工具集(`[bash, str_replace_editor, exit_plan_mode, skill]`),提供探索、编辑、退出规划与技能查询的基础能力;从第二个回合起在满足 code runtime 条件并成功声明后,平滑过渡至 PTC(程序即代码)模式。在 PTC 呈现下,注入消息承载生成 SDK 的绑定清单、完整输入输出关键参数语义、「一段程序编排多步调用」的程序契约、以及「只有 `run_code` 可直接调用」的规则。本模式不做出「与官方 Minimal 完全一致」、「社区评测分数证明本版必定更优」或「提示词缓存命中等同于行为一致」的过度承诺,而是以清晰的分层契约保障执行稳定性。
11
+ 梁神模式因此在整个会话中保持由 `presentation` 选定的同一种呈现。出厂默认为 `ptc`:wire 收拢为唯一的 `run_code` 传输工具,其余工具都在程序内经生成的 SDK 触达;这是三种模式里静态上下文最省的一种,因为原生清单的 schema 负载离开了每一个请求。该默认值取的是静态上下文成本,而不是经过测量的收益——同一份官方横评在两个代码 Agent 基准上把这个呈现排在原生呈现之后(DeepSWE v1.1:67.6% 对 72.6%;Terminal-Bench 2.1:85.8% 对 90.6%),而本仓库尚未运行可用于裁决该取舍的评测矩阵。要切到官方数据更看好的面,把 `presentation` 设为 `'native'`(或 `'both'`)。被分页模式匹配的外部工具(默认 `mcp__*`)先以命名空间摘要宣告,`tool_activate` 激活前既不在 wire 上、`ptc` 下也不在生成的 SDK 中(分页施加在程序分派所依据的注册表上),静态 Schema 面因此保持小巧。本模式不承诺基准领先,只保证「目录宣告的面」与「请求 wire 实际携带的面」永不矛盾。
12
12
 
13
13
  ## 工作机制
14
14
 
15
- 1. `minimal-prompt` 把每次组装出的提示词收窄到 persona 一段——一行 persona、本模式的固定工作纪律(思维循环即断、先理解需求与方案再实现验证、YAGNI/PDCA、代码不加冗余注释)、以及一行从会话头读取的方位信息 `Your working directory is <cwd>.`——因此 harness identity、web surface、工具用法、文件引用与结构化输出等 section 默认不会到达模型;plan mode 的 `plan:policy` 保留,因为该 section 是 plan mode 唯一的执行依据(它的退出工具在任何模式下都保持注册);
16
- 2. AGENTS.md 类工作区指令直接进入系统提示词本身:组装时 `minimal-prompt` 读取 harness 的基线链(`$DSH_HOME/AGENTS.md`,再从项目根到会话 cwd 沿途的 `AGENTS.md` / `CLAUDE.md` 及其 `.local` 覆盖层),把内容作为一段 `workspace-instructions` 追加在稳定前缀之后,受字节预算约束——放不下时先省略最宽的文件、最后才截断最具体的文件;读取在每次组装时都发生,文件改动无需持久消息即可在下次请求生效,harness 自己的 agent-instructions 注入则被丢弃以免与提示词重复。工作区子目录动态规则后续将支持注册文件工具(含 `str_replace_editor`)及 PTC 内子调用触达的目录;不解析任意 bash/program 代码,不保证 shell 自行文件访问的自动发现;
17
- 3. 锚定回合(会话的首轮整个 user turn,而非仅第一步单次请求)把 wire 保持在基础锚定工具集上:默认 `[bash, str_replace_editor, exit_plan_mode, skill]`,原生呈现(`anchorTools`);同时保留 `[bash]` 的单 shell 实验配置(无需额外注册预设,无需更改注册表)。从第二个回合起,在 code runtime 存在且声明成功时,`tool-catalog` 为该会话激活 PTC 呈现(`agent.ctx.tools.presentAs('ptc')`,在锚定回合结束时声明),wire 收拢为 `run_code` 这一条传输工具,其余工具都在程序里经生成的 SDK 调用;若缺少 code runtime 或激活失败,则优雅回退至原生工具面并发出一次性告警;
18
- 4. `tool-catalog` 把工具清单从第一条用户消息起作为持久 user 消息追加在用户消息之后,保留完整输入输出关键参数语义而非 200 字唯一契约(`descriptionMaxLength: 200` 仅作为一行摘要长度上限,不裁剪关键参数结构)。目录只宣告该次请求实际开放的工具:原生锚定回合是锚定工具集,PTC 下则是经 SDK 可达的完整工具面,并附带程序契约:一段程序完成一个意图而不是一步一次调用、`run_code` 的 `code`/`description` 形状、独立只读调用用 `Promise.all` 并发、`ToolCallError` 的处理、程序输出需要自己挑选,以及 `run_code` 一旦在 wire 上就是唯一可直接调用的工具。只在工具面变化、或已发布副本离开可见面(压缩、恢复)时重发,因此晋升边界会进行一次契约更新,不再坚持上下文绝对不变;
19
- 5. 运行时上下文(sandbox 与 approval 快照)与 skill 目录按 Standard 模式正常注入。
15
+ 1. `minimal-prompt` 把每次组装出的提示词收窄到 persona 一段——一行 persona、本模式的固定工作纪律(同一假设的思考推演不超过两轮,缺少事实时立即闭合思考并调用检查工具而非空想;思考只决定下一步具体操作,不预演完整代码实现;多处独立检查或搜索在单轮内并发发射多个工具调用;Shell 为无状态进程,跨调用目录不保留,子目录操作使用复合命令或显式 workdir;正确性一律在执行阶段以工具实际输出验证;YAGNI 与 PDCA;不写冗余注释)、以及一行从会话头读取的方位信息 `Your working directory is <cwd>.`——因此 harness identity、web surface、工具用法、文件引用与结构化输出等 section 默认不会到达模型;plan mode 的 `plan:policy` 保留,因为该 section 是 plan mode 唯一的执行依据(它的退出工具在任何模式下都保持注册);
16
+ 2. AGENTS.md 类工作区指令经 `instructionSource` 送达模型:默认(`host`)下 preset 不追加任何自有段,也不改动宿主自己的送达,工作区指令以宿主的 user 角色消息抵达——一条持久基线,加上触碰目录后的增量、替换与移除;`system-prompt` 下它们直接进入系统提示词本身:组装时 `minimal-prompt` 读取 harness 的基线链(`$DSH_HOME/AGENTS.md`,再从项目根到会话 cwd 沿途的 `AGENTS.md` / `CLAUDE.md` 及其 `.local` 覆盖层),把内容作为一段 `workspace-instructions` 追加在稳定前缀之后,受字节预算约束——放不下时先省略最宽的文件、最后才截断最具体的文件;读取在每次组装时都发生,文件改动无需持久消息即可在下次请求生效,harness 自己的 agent-instructions 注入则被丢弃以免与提示词重复。工作区子目录动态规则后续将支持注册文件工具(含 `str_replace_editor`)及 `run_code` 内子调用触达的目录;不解析任意 bash/program 代码,不保证 shell 自行文件访问的自动发现;
17
+ 3. wire 在整个会话中保持由 `presentation` 选定的同一种呈现:`both`(默认)让原生清单与传输工具同驻,兼顾原生最高胜率与特化计算;`ptc` 把 wire 收拢为 `run_code`、其余工具经生成的 SDK 调用;`native` 携带组装出的原生清单;`ptc` 与 `both` 需要挂载的 code runtime;没有时插件不做声明,会话直接运行原生工具面。旧键 `ptcPresentation` 映射到 `ptc`/`native` 并发出弃用告警,已退役的 `anchorTools` 首回合收窄不再生效——设置它会收到告警;
18
+ 4. `tool-catalog` 把工具清单作为持久 user 消息追加在用户消息之后,保留完整输入输出关键参数语义(`descriptionMaxLength: 200` 仅限制一行摘要长度)。目录只宣告该次请求实际开放的工具——原生清单加上同驻时的 `run_code`——并在分页开启时为被扣留的命名空间附上一行摘要;`ptc` 下这些摘要代表真正不可达的命名空间——既不在该请求的 `tools:sdk` 段中,也不能在 `run_code` 程序内调用——直到 `tool_activate`;只在工具面变化、或已发布副本离开可见面(压缩、恢复)时重发;
19
+ 5. 工具默认常驻 wire 开箱可用;若配置 `pagedToolPatterns` 则启用温和分页,把匹配工具扣留在 wire 之外直到模型经 `tool_activate` 激活:激活的命名空间从下一个请求起重新可达,最多保持三个已激活的分页命名空间(激活第四个时将最久未用的逐回摘要状态)。激活状态从持久事件流重建,压缩与恢复均可还原;
20
+ 6. 最小版 working-context 行——plan-mode 状态、已激活的分页命名空间、进行中的 todo——只在其来源可读时注入到最新消息尾部,让当前状态落在模型的局部注意力窗口内;运行时上下文(sandbox 与 approval 快照)与 skill 目录按 Standard 模式正常注入;
21
+ 7. 目录把已激活分页家族的工具归在 `namespace `<名称>` (activated):` 标题之下,而不是把一个服务端的工具散落在字母序清单里;未被分页的工具仍保持扁平条目;
22
+ 8. `maxResidentTokens`(默认 6000)估算常驻 wire 面并在超过时告警一次,列出最重的工具并把 `pagedToolPatterns` 指为处置手段。该守卫从不截断:静默丢掉会话需要的工具,等于用可度量的上下文成本换取不可度量的能力损失。
20
23
 
21
24
  ## 安全模型
22
25
 
23
26
  本模式坚持在官方宿主安全架构内运行,严格遵守沙箱策略:
24
27
 
25
- - **宿主沙箱约束**:所有文件工具(无论是首轮原生呈现的 `str_replace_editor`、Standard 文件工具,还是后续在 PTC `run_code` 中调用的文件操作)均受宿主文件沙箱策略约束,继承当前会话的沙箱级别(如 `danger-full-access` 或只读/工作区受限)。不存在裸本地文件系统访问(不挂载 `dsh-fs-local`),所有跨越工作区的读写均受宿主策略拦截。
26
- - **Windows 平台现有限制与 Git Bash**:DSH 的 PTY 后端仅支持 Linux/Darwin。在 Windows (win32) 下,持久 shell 组被禁用,`bash` 由 `presets/liangshen/custom-bash.mjs` 调用系统 Git Bash 子进程提供:
27
- - Windows Git Bash 运行于普通子进程通道,受 Windows 平台限制,不具备 Linux 下基于 namespace/cgroups 的 OS 沙箱隔离;
28
- - shell 进程不跨调用常驻,命令状态(环境变量、当前目录等)不跨调用保留;
29
- - 非零退出码以结果返回而非抛错;
30
- - 用户与开发者切勿修改 `custom-bash.mjs` 去尝试规避安全策略;高权限操作需遵从宿主提示和环境安全规范。
31
- - **PTC 代码沙箱**:PTC 模式下执行的 `run_code` 代码运行于独立的 worker thread 隔离上下文,其对系统资源的访问完全受限于 SDK 暴露的 tools 边界。
28
+ - **宿主沙箱约束**:所有文件工具——原生呈现的 Standard 文件工具,以及 `run_code` 程序经 SDK 分发的任何文件操作——均受宿主文件沙箱策略约束,继承当前会话的沙箱级别(如 `danger-full-access` 或只读/工作区受限)。不存在裸本地文件系统访问(不挂载 `dsh-fs-local`),所有跨越工作区的读写均受宿主策略拦截。
29
+ - **两个平台都挂标准 shell**:本 preset 在每个宿主上挂载上游的标准 Stdio shell 栈,与内置 Standard 一致。POSIX 挂 `bash`(`@deepseek-ai/dsh-tool-bash`);win32 挂 `pwsh`(`@deepseek-ai/dsh-tool-pwsh`)。每个平台恰好暴露一个 shell 工具(POSIX 为 `bash`,win32 为 `pwsh`),带有主动语态简短描述标题卡片与确定性退出码。本 preset 不自带任何 shell 实现。
30
+ - **代码运行时沙箱**:`run_code` 程序运行于独立的 worker thread 隔离上下文,其对系统资源的访问完全受限于 SDK 暴露的 tools 边界。
32
31
 
33
32
  ## 拨杆
34
33
 
@@ -48,11 +47,14 @@ DeepSeek V4 模型在选择执行轨迹时,会受到初始提示词与首轮
48
47
  | 键 | 默认值 | 行为 |
49
48
  | --- | --- | --- |
50
49
  | `keepPlanPolicy` | `true` | 在只有一行 persona 的系统提示词中保留 plan mode 的 `plan:policy` 段。置 `false` 得到严格的一行表面,此时 plan mode 背后没有任何策略文本。 |
51
- | `instructionSource` | `system-prompt` | 工作区指令送达模型的方式。`system-prompt` 在组装时读取 AGENTS.md 链并追加进系统提示词(harness 自己的注入被丢弃);`hint` 恢复指针行为:首次注入替换为一次性的、非命令式的参考文件提示,后续注入丢弃。 |
52
- | `instructionMaxBytes` | `65536` | 渲染后的 workspace-instructions 段的字节预算(system-prompt 模式):最宽的文件先被省略,最具体的文件最后被截断。 |
53
- | `descriptionMaxLength` | `200` | 注入目录中单个工具一行摘要的长度上限。完整关键参数语义与契约仍由 SDK 自身完整保留。 |
54
- | `anchorTools` | `[bash, str_replace_editor, exit_plan_mode, skill]` | 首轮整个 user turn wire 上原生呈现的工具集;晋升面从第二个回合起生效。出厂默认包含基础四工具,亦可按需配置为 `[bash]` 进行单 shell 实验(无需额外注册预设,无需修改注册表)。留空则关闭分层。 |
55
- | `ptcPresentation` | `true` | 从第二个回合起尝试为该会话声明 PTC 呈现,成功激活后 wire 收拢为 `run_code`,保留完整输入输出关键参数语义。需要挂载 code runtime 与可读取的工具投影;缺失任一项时保持原生呈现并只告警一次。注入目录始终描述该次请求 wire 实际携带的传输方式,声明无法在本回合生效时不会宣告 PTC。置 `false` 则从第二个回合起 wire 上仍是组装出的原生清单。 |
50
+ | `instructionSource` | `host` | 工作区指令送达模型的方式。`host`(默认)不追加任何自有段,也不改动宿主的 agent-instructions 注入,工作区指令以宿主自己的 user 角色消息送达:一条持久基线,加上触碰目录后的增量、替换与移除;`system-prompt` 在组装时读取 AGENTS.md 链并追加进系统提示词(harness 自己的注入被丢弃);`hint` 把首次注入替换为一次性的、非命令式的参考文件提示,后续注入丢弃。 |
51
+ | `instructionMaxBytes` | `65536` | 渲染后的 workspace-instructions 段的字节预算,仅在 `system-prompt` 模式下生效:最宽的文件先被省略,最具体的文件最后被截断。 |
52
+ | `descriptionMaxLength` | `200` | 注入目录中单个工具一行摘要的长度上限。完整关键参数语义保持完整。 |
53
+ | `presentation` | `both` | 整个会话的 wire 呈现方式。`both`(出厂默认)保持完整原生清单并同驻一个 `run_code`,兼顾原生高胜率与特化计算;`ptc` 把 wire 收拢为 `run_code`,其余工具经生成的 SDK 调用;`native` 保持组装出的原生清单。`ptc` 与 `both` 需要挂载的 code runtime;没有时插件根本不做声明,会话直接运行原生工具面。 |
54
+ | `pagedToolPatterns` | `[]` | 预设默认置空(全量常驻开箱可用);若配置 glob 模式,命中工具被扣留在 wire 之外,直到模型通过 `tool_activate({ namespace })` 激活其命名空间。被扣留的命名空间在目录中以一行摘要出现。最多同时保持三个已激活的分页命名空间,激活状态从持久事件流重建。 |
55
+ | `maxResidentTokens` | `6000` | 常驻 wire 面的估算 token 上限(按序列化 schema 约四字符一 token),校准在出厂清单之上,用于发现真实增长而非出厂配置本身。超过时告警一次、列出最重的工具并指向 `pagedToolPatterns`;不会截断工具清单。 |
56
+ | `ptcPresentation` | (已退役) | 旧别名:`true` 映射为 `presentation: 'ptc'`,`false` 映射为 `'native'`,两者都伴随弃用告警。 |
57
+ | `anchorTools` | (已退役) | 首回合锚定收窄已移除;设置该键会收到告警,且不再收窄 wire。 |
56
58
 
57
59
  ## 安装
58
60
 
@@ -74,11 +76,12 @@ dsh plugin --profile web remove @linxin666/dsh-liangshen
74
76
 
75
77
  导出 session JSONL,检查 `request/header`:
76
78
 
77
- - 第一份 header 的 `system` 应恰好是 persona 块(极简 persona、工作纪律清单、工作区目录行 `Your working directory is <cwd>.`),plan mode 开启时另加其策略段,再另加承载 AGENTS.md 链的 `workspace-instructions` 段;
78
- - 首轮整个 user turn 的 header tools 应恰好是锚定面——默认 `[bash, str_replace_editor, exit_plan_mode, skill]`,原生呈现——既不是全量晋升清单,也不会是未激活的 `run_code`;
79
- - 锚定回合放行的消息里应有一条来自 `liangshen-tool-catalog` 的 `plugin` 消息,位于用户消息之后,按参数签名恰好列出锚定工具;从晋升回合起,该消息改为列出经 SDK 可达的完整工具面并写明 `run_code` 程序契约,其中 `run_code` 是唯一可直接调用的工具;
80
- - 从第二个回合起,在 PTC 成功激活的前提下,header 上恰好只有一条工具 `run_code`(PTC 呈现);若无 code runtime 则优雅回退到原生清单并伴随一次性告警;
81
- - 压缩之后目录会重发一次,形式为替换清单,且会话保持当前呈现模式;
79
+ - `instructionSource: host` 下第一份 header 的 `system` 应恰好是 persona 块(极简 persona、工作纪律清单、工作区目录行 `Your working directory is <cwd>.`)加上 plan mode 开启时的策略段——AGENTS.md 链则以宿主自己的 user 角色消息抵达;`instructionSource: system-prompt` 下 `system` 改为多出一段 `workspace-instructions`;
80
+ - 每份 header 在整个会话中保持同一种呈现:默认 `presentation: 'ptc'` 下 wire 只携带 `run_code`,任何回合边界都不会再收窄 wire;
81
+ - 放行的消息里应有一条来自 `liangshen-tool-catalog` 的 `plugin` 消息,位于用户消息之后,按参数签名恰好列出该次请求开放的工具;被分页扣留的工具以一行命名空间摘要出现;
82
+ - `ptc` 下未激活的命名空间既不出现在该请求的 `tools:sdk` 段中,也不能在 `run_code` 程序内调用——**从第一个请求起**成立,而不是晚一个请求;
83
+ - `tool_activate({ namespace })` 成功后,该命名空间的工具从下一个请求起进入 wire,且同时激活的分页命名空间不超过三个;
84
+ - 压缩之后目录会重发一次,形式为替换清单,分页激活状态从持久事件流重建,呈现模式保持不变;
82
85
  - 文件写入受宿主文件沙箱策略约束,不存在裸本地文件系统绕过。
83
86
 
84
87
  ### 真实会话验证条件与评测说明
@@ -87,9 +90,9 @@ dsh plugin --profile web remove @linxin666/dsh-liangshen
87
90
 
88
91
  1. **真实推理探针 ≠ 模式集成通过 ≠ 统计提升**:
89
92
  - **真实推理探针**:仅验证链路连通性与模型对特定格式的最小响应能力(例如使用 headless 探针验证模型是否能正常解析输出);单次探针成功仅代表功能未阻断,绝不证明模式集成已达标。
90
- - **模式集成通过**:要求在真实完整会话中,验证完整 header、工具分层流转、PTC 真实激活、SDK 参数语义解析与沙箱策略执行无误。
93
+ - **模式集成通过**:要求在真实完整会话中,验证完整 header、所配置呈现行为、分页激活与驱逐、`run_code` 下的 SDK 参数语义解析与沙箱策略执行无误。
91
94
  - **统计显著性提升**:必须在固定 route 与源码 hash 记录的隔离环境中进行多轮对比评测,综合评估任务完成率、工具失败率、规则违反率、人工介入次数与耗时/token 开销。单次或少数 smoke 运行不构成效果提升的证据。
92
- 2. **评测工具**:隔离 runner 位于 `packages/dsh-liangshen/tools/benchmark-live-run.mjs`:它把被评测 preset 写入临时目录并通过 roster 自己的 `roots` 配置选中,把会话持久化改写到本次运行目录,并为每次运行记录基线(仓库提交、出厂 preset hash、DSH 版本、固定 route、任务版本)。候选矩阵为 `B`(出厂 persona 与两阶段策略)、`P`(候选 persona)、`T`(候选 persona,首轮即用 PTC)、`N`(候选 persona,全程原生工具)与 `M`(内置包官方 Minimal preset,仅作外部参照而非单因素对照)。单次 smoke 用 `node tools/benchmark-live-run.mjs --variant B`,按种子任务集跑有界矩阵用 `node tools/benchmark-live-run.mjs --tasks tools/tasks/liangshen-v41-flash.json --groups B,P,T,N,M --repeat 3 --max-sessions 60 --budget-usd 5`,再用 `node tools/benchmark-report.mjs .benchmark-results` 汇总结果目录:按组给出成功率与 Wilson 区间、按任务配对差值与置信区间、token 与费用合计、单独列出的基础设施失败以及记录的基线。smoke 只验证协议与费用估算,不构成通用编码能力提升的证据。
95
+ 2. **评测工具**:隔离 runner 位于 `packages/dsh-liangshen/tools/benchmark-live-run.mjs`:它把被评测 preset 写入临时目录并通过 roster 自己的 `roots` 配置选中,把会话持久化改写到本次运行目录,并为每次运行记录基线(仓库提交、出厂 preset hash、DSH 版本、固定 route、任务版本)。候选矩阵隔离 persona 与呈现策略两个因素:`B`(出厂默认)、`P`(候选 persona)、呈现臂 `T`(候选 persona,首轮即 PTC)与 `N`(候选 persona,全程原生清单)、以及 `M`(内置包官方 Minimal preset,仅作外部参照而非单因素对照)。单次 smoke 用 `node tools/benchmark-live-run.mjs --variant B`,按种子任务集跑有界矩阵用 `node tools/benchmark-live-run.mjs --tasks tools/tasks/liangshen-v41-flash.json --groups B,P,T,N,M --repeat 3 --max-sessions 60 --budget-usd 5`,再用 `node tools/benchmark-report.mjs .benchmark-results` 汇总结果目录:按组给出成功率与 Wilson 区间、按任务配对差值与置信区间、token 与费用合计、单独列出的基础设施失败以及记录的基线。smoke 只验证协议与费用估算,不构成通用编码能力提升的证据。
93
96
 
94
97
  ## 配置
95
98
 
@@ -97,21 +100,25 @@ dsh plugin --profile web remove @linxin666/dsh-liangshen
97
100
  | --- | --- | --- |
98
101
  | `enabled` | `true` | 总开关:关闭后预设同步与公告都不执行。 |
99
102
  | `announceToAgent` | `false` | 按需开启:开启后向 agent 系统提示注入本插件公告。默认关闭,保持系统提示词干净。 |
103
+ | `presentation` | `both` | 写入同步后 preset 之 `tool-catalog` 行的 wire 呈现:`both`(默认)让清单与传输工具同驻;`ptc` 把 wire 收拢为 `run_code`;`native` 保持组装出的原生清单。改动在下次 DSH 启动重新同步 preset 时生效。 |
100
104
 
101
- 两个字段都可在 Web 设置界面(插件配置,即时生效)或 profile patch(`dsh plugin` / `cordis.patch.yml`)中编辑。
105
+ 各字段都可在 Web 设置界面(插件配置)或 profile patch(`dsh plugin` / `cordis.patch.yml`)中编辑。其中塑造 preset 的 presentation 字段经预设同步抵达会话:插件在拷贝 bundle 的同时把它写入同步产出的 `agent.cordis.yml`,因此真正被会话运行的是设置界面的取值,而不是包内文件。组合里没有的键绝不会被凭空写入——覆写只会收窄出厂配置。改动需重启 DSH 生效。
102
106
 
103
107
  ## 行为与限制
104
108
 
105
- - 系统提示词在整个会话中保持稳定:persona 块(persona、工作纪律、工作区目录),plan mode 开启时另加其策略段,另加 workspace-instructions 段。工具调用后不会再追加内容,也不施加任何输出预算上限;
106
- - workspace-instructions 段在每次组装时重新读取,指令文件的改动无需持久消息即可在下一次请求生效;该段渲染在稳定前缀之后的最后位置,锚定的缓存前缀不受影响。工作区子目录动态规则后续将扩展支持注册文件工具(含 `str_replace_editor`)及 PTC 内子调用触达的目录;不解析任意 bash/program 代码,不保证 shell 自行文件访问的自动发现;
107
- - wire 的 schema 集在首轮整个 user turn 保持在基础锚定工具集(默认 `[bash, str_replace_editor, exit_plan_mode, skill]`,且支持 `[bash]` 实验);在第二个回合起且仅在 PTC 成功激活时收拢为 `run_code`;目录消息每会话写一次,另在工具面变化(含晋升边界)或压缩遮蔽时替换一次;
108
- - 注入的目录是持久消息:每个会话写入一次,另在工具面变化或压缩遮蔽已发布副本时替换一次,并留在历史中供后续请求使用;
109
+ - 系统提示词在整个会话中保持稳定:persona 块(persona、工作纪律、工作区目录),plan mode 开启时另加其策略段,`system-prompt` 模式下另加 workspace-instructions 段。工具调用后不会再追加内容,也不施加任何输出预算上限;
110
+ - `system-prompt` 模式下 workspace-instructions 段在每次组装时重新读取,指令文件的改动无需持久消息即可在下一次请求生效;该段渲染在稳定前缀之后的最后位置,缓存前缀不受影响。工作区子目录动态规则后续将扩展支持注册文件工具(含 `str_replace_editor`)及 `run_code` 内子调用触达的目录;不解析任意 bash/program 代码,不保证 shell 自行文件访问的自动发现;
111
+ - wire 在整个会话中保持同一种呈现——不存在回合边界跃迁:`native` 携带组装出的原生清单,`both` 同驻一个 `run_code`,`ptc`(默认)把 wire 收拢为 `run_code` 一条,其余工具经生成的 SDK 调用;
112
+ - 注入的目录是持久消息:每个会话写入一次,另在工具面变化(分页激活、呈现变更)或压缩遮蔽已发布副本时替换一次,并留在历史中供后续请求使用;
109
113
  - 未观测到 prompt 组装的步不注入任何内容——目录绝不会由过期视图推测;
110
114
  - 若组合中不存在任何被接受的 persona section 名(`deployment:persona-prefix`、`deployment:persona`、`persona`),过滤器会保留组装结果并只告警一次,而不是发出空系统提示词;
111
115
  - plan mode 通过其 `plan:policy` 段支持;置 `keepPlanPolicy: false` 后该模式仍有工具,但失去约束它的策略文本;
112
- - PTC 呈现按会话声明,需要挂载的 code runtime(随包发布的 web 与 headless 组合都挂载 `dsh-code-runtime-worker-thread`);没有 runtime 或激活失败时该模式保持原生呈现并只告警一次;
113
- - 清单就是官方 PTC preset 的模型自著面:不在 `run_code` 之外再发布 `workflow` 工具,而 workflow 引擎仍为 `ralph` 保留挂载;
114
- - 持久 `bash` 会替代 Standard 的一次性 shell 直到会话结束(两个工具都注册 `bash` 名字),因此 shell 状态跨调用保留;win32 上由 `custom-bash` 经 Git Bash 提供同名工具,无 OS 沙箱约束且状态不跨调用保留;
116
+ - 被分页扣留的工具(默认模式 `mcp__*`)在模型经 `tool_activate` 激活其命名空间之前不进 wire;同时最多三个分页命名空间保持激活,激活第四个会把最近最少使用的逐回摘要状态,激活状态在压缩与恢复后从持久事件流重建;
117
+ - working-context 行只在其来源(plan-mode 状态、已激活的分页命名空间、进行中的 todo)可读时注入,否则省略;
118
+ - 工具结果超过 4096 字符即被修剪,保留 1500 字符头部与 500 字符尾部,避免超大输出挤占上下文;
119
+ - `run_code` 需要挂载的 code runtime(随包发布的 web 与 headless 组合都挂载 `dsh-code-runtime-worker-thread`);没有时 `ptc` 与 `both` 不做声明,会话运行原生工具面;
120
+ - 清单不发布 `workflow` 工具,而 workflow 引擎仍为 `ralph` 保留挂载;
121
+ - shell 挂载上游标准 Stdio 栈,POSIX 注册 `bash`,win32 注册 `pwsh`——每个宿主恰好挂一个 shell 工具,带简短功能描述标题卡片与确定性退出码;
115
122
  - 文件工具继承宿主文件沙箱(不挂载裸 `dsh-fs-local`);
116
123
  - preset 与 shell 访问具有相同信任等级,安装前可自行审阅 `presets/liangshen/`;
117
124
  - 插件不发起网络请求,也不增加遥测;
@@ -120,4 +127,4 @@ dsh plugin --profile web remove @linxin666/dsh-liangshen
120
127
 
121
128
  ## 许可
122
129
 
123
- 插件本体 Apache-2.0(zhu1090093659)。`presets/liangshen/agent.cordis.yml` 基于 DeepSeek Harness 内置 Minimal、Standard 与 PTC preset 修改(MIT),`custom-bash.mjs` 来自 xiaobright/dsh-anchored-standard(MIT),版权与许可声明见 preset 的 `NOTICE`。
130
+ 插件本体 Apache-2.0(zhu1090093659)。`presets/liangshen/agent.cordis.yml` 基于 DeepSeek Harness 内置 Minimal、Standard 与 PTC preset 修改(MIT),版权与许可声明见 preset 的 `NOTICE`。