<p align="center"><strong>dsh-flash-presets</strong></p>

<p align="center"><a href="README.md">中文</a> | <strong>English</strong></p>

<p align="center">
  <a href="https://github.com/LarryE135/dsh-flash-presets/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/LarryE135/dsh-flash-presets?style=flat-square&color=eab308"></a>
  <a href="https://www.npmjs.com/package/dsh-flash-presets"><img alt="npm" src="https://img.shields.io/npm/v/dsh-flash-presets?style=flat-square&color=cb3837"></a>
  <a href="https://www.npmjs.com/package/dsh-flash-presets"><img alt="npm downloads" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FLarryE135%2Fdsh-flash-presets%2Fbadges%2Fbadges%2Fdownloads.json&style=flat-square"></a>
</p>

# dsh-flash-presets

Agent presets for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH), tuned for DeepSeek V4.1 Flash.

The idea is simple: compact the context earlier, keep only the head and tail of oversized tool output, leave unused tools out of the system prompt, and fold scattered tool calls into a single `run_code` program. None of this makes the model smarter. It changes how much a session reads, how much it wanders, and when it stops.

Everything ships as a DSH bundle (`dsh.bundle`). It inserts preset rows into a profile and doesn't touch the host source. **Three things do apply to the whole profile at runtime**: the resident PTC runtime (the `ptc-runtime` override in the patch, which affects **every** preset in that profile — the only way to switch it off is to remove this plugin card), the `glob` / `grep` concurrency marks (`DSH_FLASH_PRESETS_CONCURRENCY=0` disables them), and legacy preset-id resolution (`DSH_FLASH_PRESETS_ALIAS=0` disables that).

> Current version: 0.3.2 (declared the official release on 2026-11-17 — npm's `latest` dist-tag points at it; for npm, always trust `npm view dsh-flash-presets version`) · mis-published version 0.3.3 (the number currently in `package.json`: still installable from npm, `deprecated`, **not an official release**) · presets v3 / v3 balance · plan mode plan-mode v1 (1.0.0) · requires DSH `>=0.2.1-rc.5 <0.2.3-0` (an `engines` gate: installs are refused outside it, and at load time an out-of-range DSH skips this plugin — `dsh plugin allow-version` can override at your own risk; the script install doesn't go through this gate), tested on 0.2.1-rc.5 and 0.2.2-rc.1
>
> Official release: tag `v0.3.2` + npm 0.3.2 + GitHub Release, all on the same day (check with `npm view dsh-flash-presets version`; if a mirror still shows 0.3.1, `#v0.3.2` installs the same code). 0.3.1 was the previous official release. **0.3.3 was published by mistake**: the plan was to release 0.3.2, but `package.json` was written as 0.3.3 and `npm publish` went out with it — so 0.3.2 is now treated as the official release and 0.3.3 is `deprecate`d on npm (still installable, not official). Pin the version: a `^0.3` range can still resolve to 0.3.3. 0.3.2 closes out two external audits, the round-three self-audit and round four: host event shape, auto-approve being dropped on tier change, the review guard, delivery-gate hangs and Windows support, the panel Host allowlist, the publish-script interlocks, and installer adoption boundaries — and the `run_code` optimisation takes effect on install. **Do not install 0.2.5** — it cannot create sessions on DSH 0.2.2-rc.1 (#19).

## Who it's for, and who it isn't

**A good fit for**

- Tasks with a clear goal and a way to check the result: changing code, running scripts, cleaning data, producing a file in a fixed format.
- Long sessions. DSH compacts at 80% of the context window by default, which most sessions never reach. These presets compact at 25%, so long sessions stay within bounds.
- Anyone who watches their token bill and would rather not repeat the same instructions in every message.

**Not a good fit for**

- Problems clearly beyond the model, such as competition-level tasks where the goal is partial credit. Standard mode holds up better there; see [measured evidence](docs/实测证据.md).
- Workflows that rely on the current date, installing plugins from inside a conversation, or scheduled tasks. Those capabilities are trimmed out (see [Differences from the official PTC preset](#differences-from-the-official-ptc-preset)).
- Models other than DeepSeek V4.1 Flash. The rules may still help, but nobody has checked.
- DSH below 0.2.1-rc.5 (including 0.2.1-rc.2 through rc.4). Use the matching older release instead (see [versions and compatibility](docs/版本与兼容性.md), in Chinese). The directory-style presets for DSH before 0.1.7 are no longer shipped as of 0.2.6.

## What it does

Four mechanisms, each acting at a different point in a session:

| Mechanism | When it acts | Setting | Effect |
|---|---|---|---|
| Turn compaction | When the stored context grows too large | `thresholdRatio: 0.25`, `retainTokens: 20000` (DSH default: 0.8) | History is replaced by a summary; only long sessions trigger it |
| Tool-output trimming | When a tool result enters the context | first 4096 / last 1024 characters | Oversized output keeps only its two ends |
| Disabled plugins | When the system prompt is assembled | 6 plugins set to `disabled: true` | Their tool schemas never reach the prompt — a fixed saving |
| Behavioral rules | At every step the model takes | persona rules (13 in lean-v3, 3 in balance) | Nudges the model to read less, batch calls, and edit incrementally |

Two more things come with the bundle:

- Tools are presented through PTC (`tool-presentation: ptc`), and the PTC runtime stays resident for the whole session (`ptc-runtime: persistent-in-memory`). Measured: the fixed startup cost per program dropped from 108 ms to about 0 (per the cost model), and nested tool calls from 44 ms to 15 ms ([benchmark notes](https://github.com/LarryE135/dsh-flash-presets/blob/main/docs/压测-run_code开销.md), in Chinese). The gain grows linearly with the number of calls inside a program; a short task that runs a single command will barely notice.
- The plugin marks `glob` and `grep` as safe to run concurrently, so several searches in the same turn can execute in parallel. A one-line self-check is printed at startup -- that is the line to read first when troubleshooting:

  ```
  [tool-concurrency] v0.3.2 生效｜targets=glob,grep｜sweep=500ms｜witness=glob=true grep=true｜scopes=1
  ```

  - **Two states to keep apart**: npm 0.3.0 rode on the plan-mode row -- on a host without `webServer` (headless, some desktop setups) that row stayed `pending`, so the optimization never ran and never complained. Since 0.3.1 it is its own row, `flash-presets-core`, which takes effect as soon as the package is installed (0.3.1, 0.3.2 and the mis-published 0.3.3 all carry it, so nothing has to wait for a future release).
  - **Turning it off** (highest priority first): env `DSH_FLASH_PRESETS_CONCURRENCY=0` > that row's `config.toolConcurrency.enabled=false` > on by default.
  - **Scope**: `glob` and `grep` only. For other read-only tools, list them in that row's `toolConcurrency.tools`.
  - **Deprecated path**: the old `scripts/tune-runtime.mjs` edited fs-search inside `node_modules`; that file has not existed since DSH 0.2.2-rc.1. Patching registered definitions in memory at runtime is the only supported route.

For the reasoning behind each setting, with source line references, see the [four mechanisms write-up](docs/技术文档-省token四机制.md) (Chinese).

## Presets: lean-v3 + balance (the package ships exactly these two)

| Preset | id | Rules | Compaction | Use it when |
|---|---|---:|---|---|
| 精简·PTC v3 (lean-v3) | `flash-lean-ptc-v3` | 13 | 0.25 / 20k | **Default.** The most token-efficient option, right for most everyday work |
| 精简·PTC v3 balance | `flash-lean-ptc-v3-balance` | 3 | 0.25 / 20k | Weaker constraints; for work where the model should have more room |

Both share the same compaction/trimming framework and plugin set; only the persona rule text differs.

**ids that are not shipped** (add a row to your own profile patch if you need one):

- `flash-lean-ptc-v1` (14 rules / 0.3·50k) and `flash-lean-ptc-v2` (12 rules / 0.25·20k): the 0.2.5 rules.
  They still **resolve** to `flash-lean-ptc-v3` through the alias layer (opening old sessions wins over rule
  fidelity); they carry `rulesDiffer: true` and print a warning on first hit. Add a row to your own profile patch
  if you want the original rules. Source files: tag `v0.2.5`.
- `flash-lean-ptc-v3-lite` (0.2.6–0.2.8) and the older `flash-lean` / `flash-lean-ptc`: identical (or superseded)
  rules, resolved to `flash-lean-ptc-v3` by the runtime alias layer — no card needed.

Lite's 13 rules fall into five groups: budget (count turns, not steps; aim for 20 or fewer, and stop to re-plan past roughly 60), sequencing (think briefly, run one cheap probe, and for submission tasks ship the smallest working artifact first), verification (one consolidated acceptance pass, then deliver — no extra random or stress rounds), tools and output (read files with read/glob/grep, batch calls, edit incrementally), and scope (answer in the user's language, stay in scope, keep secrets out of the session, switch approach after two failures).

Balance keeps only the three rules the harness can't enforce on its own: respect the user's language and scope, never put secrets into the session, and after two failed attempts change approach and report the exact command and output.

Does the number of rules matter? Across three task sets we tested up to four arms — 0, 3, 7 and 13 rules (all four on the algorithm bed; 0/3/13 and 3/13 on the other two), n = 5–15 — and found no measurable difference in either quality or tokens ([measured evidence](docs/实测证据.md), "三床 × 四臂"). At that sample size, differences smaller than about 2× are undetectable, so the honest reading is "no difference observed", not "no difference". The savings come mainly from the first three mechanisms above and from PTC, not from the wording of the rules.

> A naming note for the evidence files: in the 2026-11-04 experiments, "v3" means the 13-rule preset (today's `flash-lean-ptc-v3`, shown as 精简·PTC v3（lean-v3）) and "lite" means the 3-rule preset (today's `flash-lean-ptc-v3-balance`). Display names changed in 0.2.6 and again in 0.2.9; **ids never changed**.

## Measurements

Every number below comes with its conditions and sample size. The experiments use different setups, so don't compare across tables.

### Office benchmark

Two synthetic suites of everyday office data-processing tasks: [Office benchmark v1](https://github.com/LarryE135/dsh-flash-presets/tree/main/benchmarks/office/base-v1) (8 tasks) and [Office addendum v1](https://github.com/LarryE135/dsh-flash-presets/tree/main/benchmarks/office/addendum-v1) (5 tasks). The table shows the mean tokens per configuration, including cache reads, in millions. OPS refers to [dsh-ops](https://github.com/T-Auto/dsh-ops).

<!-- bench-table:begin（本块由 scripts/render-bench-table.mjs 生成，勿手改）-->
| Setup | Office benchmark v1 | vs standard | Office addendum v1 | vs standard |
|---|---:|---:|---:|---:|
| Standard mode | 5.380 M(n=5) | — | 2.827 M(n=5) | — |
| PTC mode | 3.553 M(n=5) | −34.0% | 1.560 M(n=5) | −44.8% |
| lean-v3 | 1.437 M(n=5) | −73.3% | 0.481 M(n=5) | −83.0% |
<!-- bench-table:end -->

![Average token consumption on the office benchmark and addendum suites (including cache reads)](https://raw.githubusercontent.com/LarryE135/dsh-flash-presets/main/docs/images/bench-office-token.png)

How to read it:

- `lean-v3` is the 13-rule preset as it stood in 0.2.5; its rules match `flash-lean-ptc-v3` up to 0.3.1. From 0.3.2 on, rule 7 of v3 is worded slightly differently (a call that is single-use still goes through a one-line `run_code` program); the other 12 rules are unchanged.
- "vs standard" also includes the gain from switching to PTC tools. To isolate the preset, compare against PTC mode instead: roughly −59.6% and −69.2% on the two suites (computed from the table).
- Tokens only. Per-task accuracy is not kept in this repository (`docs/实测证据.md` has a separate office-bench batch scoring 68.9167/100, a different run set), so it isn't broken out. Tasks were written and graded by the same model (`GPT-6.1-Sol`), but the answering stage had no access to the ground truth or the grader.
- `OPS + PTC` has only 4 valid runs on Office benchmark v1. The two suites contain different tasks and are not pooled into one ranking.
- Scoring rules are public in [`benchmarks/office/grading/`](https://github.com/LarryE135/dsh-flash-presets/tree/main/benchmarks/office/grading); ground truth and graders live in a private repository.

## Install

### With the plugin manager (recommended)

The plugin manager installs the whole plugin card: both presets, the plan-mode component, the resident PTC runtime, and the legacy-id compatibility layer.

```console
# from npm, pinned to a version (never leave a `^0.3` range)
dsh plugin --profile web add dsh-flash-presets@0.3.2
# or the same release as a tag, if you'd rather not use npm
dsh plugin --profile web add github:LarryE135/dsh-flash-presets#v0.3.2
```

`--profile` is normally `web` or `desktop` (presets don't activate under `headless`, and `acp` is untested — see [Known limitations](#known-limitations)). Entering the package name or GitHub address under Plugins → Add plugin in the GUI does the same thing.

Presets directly shape agent behavior, so pin a version when you need reproducible results. With a bare npm name the manager records a caret range, and any later pnpm operation may move you to the newest 0.3.x; a `github:` install records a git ref (`#v<version>`) instead and won't drift.

> Which number to fill in: **the official release is 0.3.2** (`…@0.3.2` or `github:…#v0.3.2`). The 0.3.3 in the example above is installable but was published by mistake (`deprecated`); swap it for 0.3.2. Either way, avoid `^0.3` ranges — they can still resolve to 0.3.3.

### Offline, or with the install script

Download and unpack the archive from [Releases](https://github.com/LarryE135/dsh-flash-presets/releases), or clone the tag:

```bash
git clone --depth 1 -b v0.3.2 https://github.com/LarryE135/dsh-flash-presets.git
cd dsh-flash-presets
bash scripts/install.sh --profile web                  # Windows: scripts\install.ps1 -Profile web
```

The script writes a single managed block containing the two preset rows into the profile patch. It backs up the file first, and re-running it never creates a second block. The plan-mode component, the legacy-id layer, the composition self-check and the `glob`/`grep` concurrency marks are all part of the plugin, so only a plugin-manager install brings them. With `--with-runtime` (formerly `--with-plan-mode`; `-WithRuntime` in PowerShell) the script also writes a profile-level `ptc-runtime: persistent-in-memory` — that one applies to **every** preset in the profile, and `--uninstall` removes it too.

The two paths are either/or: if the script already wrote the preset rows and you want the plugin card instead, run `--uninstall` first. Having both does not error out (`--dump-config` still exits 0), but every preset shows up twice in the picker (8 preset rows measured in the patch). `agent-preset/invalid` is the error code for a **preset definition that fails to parse**, not for duplicates.

### Restart after installing

Presets and runtime settings are read once, at process start.

- `web` profile: reload the page.
- `desktop`: quit the host completely and start it again. The classic symptom of skipping this is "the plugin is installed, but the `run_code` speedup isn't there".
- `headless` / `acp`: presets don't activate there anyway (`headless` measured, `acp` untested), so there is nothing to restart.

### Check the installation

```bash
dsh --profile web --dump-config | grep -c 'id: preset-'             # 6 (4 built-in + 2 from this package, with no other preset packages)
dsh --profile web --dump-config | grep -c 'persistent-in-memory'    # 1
dsh --profile web --dump-config | grep -c 'plan-mode-ui'            # 1
node scripts/doctor.mjs --profile web                                # version, duplicate rows, !!js, YAML parsing in one pass
```

Those `node scripts/...` paths assume you're in the repository (or the unpacked release archive). With a plugin-manager install the scripts live inside the profile: `node ~/.dsh/profiles/web/node_modules/dsh-flash-presets/scripts/doctor.mjs --profile web`.

### Update and uninstall

To update, run the same `add` again, or `remove` and then `add`.

To uninstall:

```console
dsh plugin --profile web remove dsh-flash-presets     # if installed with the plugin manager
bash scripts/install.sh --uninstall --profile web     # if installed with the script (Windows: scripts\install.ps1 -Uninstall)
```

pnpm leaves one line for this package in the profile's `pnpm-workspace.yaml`, and `remove` doesn't clear it. It has no effect on the composed configuration.

### Upgrading from an older release

- **Preset ids no longer change.** The 13-rule preset is `flash-lean-ptc-v3`; the 3-rule preset is `flash-lean-ptc-v3-balance`. 0.2.7–0.2.8 renamed the first one to `flash-lean-ptc-v3-lite`; 0.2.9 reverts that and will not rename ids again — DSH persists the preset id inside the session log, so renaming it is what makes old sessions fail to open. Rule text may evolve; identifiers stay put.
- Old sessions still open, and none of them get rewritten: `flash-lean-ptc-v3-lite` (0.2.6–0.2.8) has identical rules and is aliased to `flash-lean-ptc-v3`; older `flash-lean` / `flash-lean-ptc` are aliased too, and `flash-lean-ptc-v1` / `-v2` are aliased as well (0.2.8 already aliased them and 0.2.9 keeps that promise); their rules differ from v3, so the first hit logs a warning — add a row to your profile patch if you want the old rules, which is what this machine does for `v2`. Ids used only in local experiments can be added through `DSH_FLASH_PRESETS_ALIAS_EXTRA`. The layer steps in only when resolution fails and never rewrites a session file. The mapping is in [`presets/legacy-preset-map.json`](presets/legacy-preset-map.json); the design is described in [preset id contract and upgrades](docs/预设-id-契约与升级.md) (Chinese).
- **The install never touches sessions**: `install.sh` / `install.ps1` and plugin startup do not scan or rewrite `sessions/`. As of 0.2.9 **no code in this package writes a session file at all** (the start-up self-heal `lib/compat-heal.js` is gone: it rewrote the header without invalidating DSH's projection cache, so it barely worked and left a stale lock behind). CI asserts that a session directory is byte-identical after an install and an uninstall.
- **Desktop app / plugin card**: whether old sessions open depends on the bundle carrying a `flash-presets-alias` row (a standalone plugin that injects only `agentPresets`). Cards older than 0.2.9 lack it — reinstall with `dsh plugin --profile desktop add github:LarryE135/dsh-flash-presets#v0.3.2`. `node scripts/doctor.mjs --profile desktop` tells you whether the row is there.
- **Script install (`install.sh` / `install.ps1`)**: this path has no alias layer. If the patch mentioned `flash-lean-ptc-v3-lite` before the upgrade, `merge-presets` keeps one extra compatibility row (`order: 99`, labelled "do not pick"), otherwise those sessions would be not-found. A profile that already carries the plugin card is refused (`exit 4`) — pass `--force` to stack them anyway.
- If you installed the standalone `dsh-plan-mode-ui` package, run `dsh plugin remove dsh-plan-mode-ui` first, or plan mode will be injected twice.
- If the profile's `selectedDefault` points at `flash-lean-ptc-v3-lite`, set it to `flash-lean-ptc-v3` (the old value still resolves through the compatibility layer).

## Plan mode (optional component)

The same plugin card carries a plan-mode component, plan-mode v1 (1.0.0). Within a single turn, the agent writes a plan, waits for your approval, then executes it, and writes the measured acceptance results back to the card at the end. The two halves divide the work cleanly: the presets govern how each turn spends its budget; plan mode makes the turn think before it acts.

- The control sits to the left of the input box, with off / light / full levels independent of the preset.
- Light is the recommended default. In a comparison with n = 3 and 7 acceptance checks, both levels passed 3/3; full used about 17% more tokens (median 40.2k vs 34.3k) and about 33% more time (196 s vs 147 s) ([changelog](docs/CHANGELOG.md), Chinese).
- If you don't want it, switch the component off on the card. The presets behave exactly the same without it.
- **The panel only talks to loopback**: `/api/plan-mode/*` accepts requests whose `Host` is `127.0.0.1` / `localhost` / `[::1]` (DNS-rebinding guard). If you reach the Web GUI through a LAN IP or a custom hostname, the panel answers 403 and the UI tells you to set `DSH_FLASH_PRESETS_TRUST_HOST=1` and restart.

## Delivery gate (optional component, off by default)

The same card also ships a delivery gate, `delivery-gate`. It needs no rule text: at the end of a turn it runs your acceptance script for you. If the workspace contains `verify.sh` it runs once, and the turn only finishes when it passes; a failure is fed back to the model, which keeps working.

- Why: in the P15654 runs all three implementations *honestly* wrote "17-19 timed out / not covered" in their closing message and shipped anyway. What was missing was not self-reporting but a "you may not finish while it fails" mechanism.
- Turning it on: set `enabled: true` on that row (the `delivery-gate` row near the end of `cordis.patch.yml`), or set `DSH_DELIVERY_GATE=1` for one run. Turn it off with `enabled: false` or `DSH_DELIVERY_GATE=0`.
- Script contract: it looks for `verify.sh` in the workspace root by default (change it via the `scripts` config); a timeout counts as a failure; it reads only the exit code and the tail of the output and never edits your files.
- Note: the shipped row sets `enabled: false`, and the schema default is also `false` (0.3.1 shipped `true`, which chased ordinary chats with an acceptance gate; 0.3.2 flipped it back). 0.3.1 only honoured `DSH_DELIVERY_GATE=0`; `=1` starts working in 0.3.2.
- **Version note:** the delivery gate is not in 0.3.0 but **ships with npm from 0.3.1 onwards** (the tarball contains `lib/delivery-gate.js`, and `cordis.patch.yml` carries the row — `enabled: false` / `maxRounds: 2`, with the acceptance script picked per platform: `verify.ps1` first on Windows, `verify.sh` elsewhere). On 0.3.0 the only route is git: `dsh plugin --profile web add github:LarryE135/dsh-flash-presets#main`. npm 0.3.1, 0.3.2 (official) and the mis-published 0.3.3 all carry it, so there is **no need to wait for a future release**.

## Getting the most out of it

- **State the goal and how success is checked.** The sharper the criteria, the better the result; when the boundaries are fuzzy, pair it with plan or goal mode. The P15654 comparison is in [measured evidence](docs/实测证据.md).
- **Raise the output limit.** 120K or more is recommended, 384K if you can, so long reasoning isn't cut off.
- **On Windows**, install PowerShell 7 (the MSI build) or Git Bash first.
- **Give long-thinking models one problem per session.** Handed several at once, a model may lay out every plan in a single response and get cut off upstream before it ever acts ([measured evidence](docs/实测证据.md), "跨模型").

## Troubleshooting

Run the checkup before guessing:

```bash
node scripts/doctor.mjs --profile web          # add --dump to also run dsh --dump-config
node scripts/diag-preset-load.mjs --profile desktop   # when a preset card in the GUI shows "failed to load"
```

| Symptom | Cause | Fix |
|---|---|---|
| A preset card shows "failed to load" | A plugin the preset references can't be resolved. Most often a hand-edited preset still lists `.../dsh-tool-subagent-control/list-agents`, a subpath DSH 0.2.2-rc.1 removed | Locate it with `diag-preset-load.mjs` and delete that row |
| The compact / plan / goal slash commands disappear, and the next message fails with `tool executor is unavailable` | A plugin hot reload released the preset composition of an open session and didn't remount it | Restart DSH. The plugin checks every 2 minutes and logs the remedy; set `DSH_FLASH_PRESETS_SELFCHECK_HEAL=1` to remount automatically |
| Two or three presets with the same name | Bare rows from an old install sit next to the new managed block | Re-run the install script; it adopts and merges the old rows |
| `js-yaml` reports `unknown tag` | The file still contains `!!js` tags | `node scripts/doctor.mjs --fix` (back up first) |
| The presets don't appear at all | DSH is older than 0.2.1-rc.5, or the wrong profile was targeted | Upgrade DSH, or point `--profile` at the right one |
| The presets vanish after a DSH upgrade | DSH went past the `engines` ceiling `<0.2.3-0`, so the plugin is skipped at load time | Upgrade this package; `dsh plugin allow-version` can force it at your own risk |

The preset patch only defines the agent-side plugin set. It doesn't touch GUI pieces such as the workspace picker, the directory picker, or the terminal. If something unrelated to presets breaks after installing, please open an [issue](https://github.com/LarryE135/dsh-flash-presets/issues) with the doctor output and the browser console errors.

## Differences from the official PTC preset

| In the official preset, not here | What it means |
|---|---|
| `time-context` | The prompt carries no current date or time; state it yourself when a task needs it |
| `tool-schedule` | No tool for scheduled or recurring tasks |
| `tool-plugin-market` | No installing plugins from inside a conversation; use `dsh plugin` |

The presets also declare `tool-subagent-codex`, `tool-subagent-claude-code`, `workflow-ptc`, `tool-workflow`, `tool-ralph`, and the plugin-manager tools, all disabled. If you need any of these, the official preset is the easier choice.

## Known limitations

- Under the headless profile on DSH 0.2.2-rc.1, both presets and plan mode stay pending and never take effect (each run reports `3 entries did not activate`). Use the web or desktop profile. `acp` is completely unverified.
- macOS hasn't been verified on real hardware. The install script is written for bash 3.2 and runs in CI on all three platforms.
- The patch contains `!!js` tags that the DSH loader resolves; third-party YAML parsers report an unknown tag. The install script resolves them to plain values before writing to the profile.
- The `glob` / `grep` concurrency marks only exist in a plugin-manager install (`DSH_FLASH_PRESETS_CONCURRENCY=0` disables them); the script install never has them. Legacy-id resolution comes from the plugin too (`DSH_FLASH_PRESETS_ALIAS=0`).
- The plan-mode component also reads two environment variables: `DSH_PLAN_TODO_SYNC=off|remind|strict` (default `remind`) controls whether todo writes are reminded or required, and `DSH_PLAN_LAG_TURNS=<n>` (default 2) is how many turns behind the run may fall before a nudge; they mirror the `todoSync` / `lagTurns` plugin config keys.
- The plan-mode tier is visible to other plugins that watch `planMode`. If you also run a plugin that injects reminders while plan mode is on (e.g. `chatgpt-subscription`), a pure Q&A turn — one that only talks and calls no tools — may be judged unfinished and **answered twice**. Mitigation: set the plan-mode tier to `off` in such sessions.
- Development and testing centered on the public Luogu problem set and the office benchmark above. Other kinds of work have little data behind them.

## Development and checks

```console
npm run verify          # composition, YAML, preset structure, text lint, version consistency, benchmark leak guard, and more
npm run bench:office    # structure and integrity checks for the office benchmark (repo only; the npm package excludes benchmarks/)
bash scripts/selftest.sh
node scripts/verify-session-compat.mjs   # whether old sessions still open after an upgrade (10 synthetic sessions, two negative controls)
```

`cordis.patch.yml` is composed from `presets/*.patch.yml`; don't edit it by hand — CI asserts the two match. The measurement table in this README is generated from `docs/bench-office-results.json`. See [CONTRIBUTING](https://github.com/LarryE135/dsh-flash-presets/blob/main/CONTRIBUTING.md) for how to contribute.

## Version history

### v0.3.2 (2026-11-17, current official release)

Released: npm 0.3.2 (`…@0.3.2` — verify with `npm view dsh-flash-presets version`, whose `latest` tag points at it), GitHub Release `v0.3.2`, tag `v0.3.2` (= `8f4d349`). 0.3.1 was the previous official release.

Round-three self-audit fixes (P0 1 / P1 3 / P2 10 / P3 12), itemised in [the audit note](https://github.com/LarryE135/dsh-flash-presets/blob/main/docs/审计-第三轮-自查-20261117.md):

- **The installer no longer deletes preset rows you edited**: `merge-presets` used to match by shape only (wrapper row + `config.id`) and would drop an out-of-block row with the same id while printing "identical to what the installer writes". It now compares line by line: an edited row is kept verbatim, and we don't write a second copy of that id.
- **Full-tier "approve → execute" never arrived on rc.3**: `agent.steer()` was called synchronously inside a `session/event` listener, tripping the host's append re-entrancy guard; the throw was swallowed into a single log line. Delivery now goes through a macrotask, and so does the mid-turn "you started writing during planning" nudge.
- **PTC mode missed "wrote before planning"**: nested calls never emit `tool/call`, only `tool/ptc-dispatch(-start)`; the plugin handles both now, with regression tests.
- **Two service lookups silently failed**: reading `ctx.webServer` / `ctx.sessionProjections` without `inject` throws, so the fallback never ran. Both go through `ctx.get` now (core status route, built-in `/plan` yield gate).
- **Release scripts fail closed**: `publish.sh`'s CI gate no longer skips when it can't verify (missing gh, not logged in, runs unfinished, empty list → refuse; `ALLOW_UNKNOWN_CI=1` opts out); `DRY_RUN` moved after the remote-tag guard; `verify-versions` is no longer blocked by stale zips in `dist/`.
- **Delivery gate picks its script by platform**: the bundled patch no longer pins `verify.sh`; Windows defaults to `verify.ps1`.
- **Docs corrected**: retired the stale "300k+" reading and "0.25 compresses every session", fixed 54 self-tests / 30 plugin test files / plugin 1.0.0, the `align-presets.sh` pointer, v1/v2 aliases, and the missing troubleshooting log block in the Chinese README; the review guard no longer false-positives on a bare reference, a comment, or a string.

**Round four (this round)**:

- **Sync `agent.steer()` from a `session/event` listener** trips the host's append re-entrancy guard; delivery now goes through a macrotask.
- **Under the PTC presets, tool calls inside `run_code` never emit `tool/call`**: the plugin listens on `tool/ptc-dispatch-start` and `tool/ptc-dispatch` instead, with the same semantics for the mid-turn nudge and for "already running" accounting.
- **The review guard (`tools.guard`)** no longer treats a tool name written in a comment or a string as a call, and now catches real call shapes such as `tools["<name>"]?.()`, template keys and `.call(`.
- **`scripts/merge-presets.mjs` claims legacy leftovers by indentation**: item boundaries are no longer taken at the first blank line (a 199-line item used to read as 13 lines, get judged installer-written, and be rewritten into broken YAML with its head dropped); `- insert:` arrays are claimed one entry at a time (other people's entries and in-array comments survive); the uninstall path gained a "top level must be a block array" structural gate; a block the user edited entirely is no longer replaced with an empty managed block.
- **New `scripts/test-merge-presets.mjs`** (24 assertions), wired into `scripts/selftest.sh` (now 54 checks).

**0.3.2's own fixes** (this batch):

- **Auto-approve button rebuilt to glyph v1.1**: two ring arrows plus a center check, all three states (`off / on / fire`) working — every real auto-approval flings the ring half a turn and pops the check, 20 px. Fixes the old `.pmo-aa svg` rule that forced 15 px and rotated every svg in the button, which made the check spin with the ring and kept the icon tiny.
- **Lean defaults in the bundle**: `tool-skill.catalogDescriptionMaxLength: 60`, `session-log-deepseek` / `plugin-package-inventory-deepseek` disabled (~40 KB less per request, none of it in context).
- **Delivery gate defaults back to off**: `delivery-gate.enabled` `true` → `false`.
- **Plan mode**: a no-op planning phase no longer counts as approval; default scope `always` -> `auto`.

### v0.3.3 (2026-11-17, published by mistake: still on npm, now deprecated)

> **This version exists because the version number was wrong**: the plan was to release 0.3.2, but `package.json` was written as 0.3.3 and `npm publish` went out with it. The decision: **0.3.2 is the official release** (npm `latest` points at it), and 0.3.3 is marked as a mis-publish and `deprecate`d on npm (still installable, not official).
> The content is the same fix batch as 0.3.2 (round-three self-audit plus round four) — only the number differs; see the section above.
> The banner published at the time read "Current version: 0.3.3 (tag `v0.3.3` pushed 2026-11-17; npm 0.3.3 + GitHub Release go out the same day)" and has been rewritten to the 0.3.2 wording.
> **Pin the version**: 0.3.3 is deprecated, but a `^0.3` range can still resolve to it.

### v0.3.1 (2026-11-12, previous official release)

- **The `run_code` optimization now applies on install**: the `glob`/`grep` concurrency-safety patch is its own row
  (`flash-presets-core`, injecting only `tools`/`agents`) instead of riding on `plan-mode-ui`, which silently dropped it in
  headless or partial installs. Opt out with `DSH_FLASH_PRESETS_CONCURRENCY=0`.
- **Fixed subagent model selection / discovery being off on DSH 0.2.2** (#21).
- **New delivery gate** `delivery-gate` (disabled by default) and `doctor`'s 9th check.
- Old-session compat guard (A5), empty-environment false alarms (A3), alias and preset rows must not be `disabled` (A8).
- Preset ids, rule text and tuning values are unchanged.

### v0.3.0 (2026-11-07)

- **Display names and descriptions only — no id, rule or behavior change**: `flash-lean-ptc-v3` now reads "the most token-efficient option, right for most everyday work"; `flash-lean-ptc-v3-balance` is shown as 精简·PTC v3 balance with the internal note dropped. DSH resolves presets by `config.id`; `config.name` is just picker text, so old sessions and old ids keep resolving.
- Also fixes two 0.2.9 bookkeeping errors (stale `publishedVersion`, shipped docs saying npm was unpublished).

### v0.2.9 (2026-11-07)

- **Preset ids are back to stable values.** The lite preset's id returns from `flash-lean-ptc-v3-lite` to `flash-lean-ptc-v3` (the identity it shipped with through 0.2.5) and will not be renamed again. The 0.2.7 rename is what broke old desktop sessions after upgrading: their logs record `flash-lean-ptc-v3`, and a compatibility layer can only patch the resolution step, not every other check. The fix is to stop moving the identifier and let only the rule text and descriptions evolve.
- The compatibility layer stays, pointing the other way: `flash-lean-ptc-v3-lite` (produced by 0.2.7–0.2.8) plus the older `flash-lean`, `flash-lean-ptc`, `-v1`, `-v2` all resolve to `flash-lean-ptc-v3`.
- No migration needed for anyone who did not install `--with-runtime`: install the new version and every old session opens.

### v0.2.8 (2026-11-06)

- Third-round audit fixes: the regression where `--with-runtime` followed by `--uninstall` left an empty patch file and the profile would not boot (uninstall now reverts the runtime block first, and the revert restores `[]`); Windows `-Uninstall` now removes the runtime override too.
- `tune-runtime` no longer silently ignores unknown arguments (`-Profile` used to apply the override to every profile); `doctor` checks only the two current presets in section 3, no longer suggests installing the bare package name in section 6, and exits 1 when it finds problems; `install.sh --help` no longer truncates its last line.
- `publish.sh` / `publish.ps1` drop the move-the-tag escape hatch (they refuse to run when the remote tag can't be queried, and archive by tag); `verify-versions` now checks the versions hard-coded in the installers, the marketplace entry, and both READMEs.
- npm skips 0.2.7 and goes straight to 0.2.8: 0.2.7 exists only as the GitHub tag `v0.2.7`.

### v0.2.7 (2026-11-06)

- Second-round audit fixes: installer wording and the `--with-runtime` rename, `--uninstall` now removes the runtime override, `doctor --sessions` no longer crashes, the alias table no longer carries `$comment`, the peer range covers 0.2.2-rc.1, and `NOTICE` carries the upstream MIT text.
- Docs now match the implementation: the top of this README states the two things that apply to the whole profile and how to switch them off; "12 historical ids" became 5; broken anchors and a dangling reference are gone; plan mode's "26% more expensive" is corrected to 17% (medians).
- CI gained a 0.2.2-rc.1 install matrix entry and a pack → unpack → run-user-scripts job, and `bundle-install` now compares exact ids instead of substrings.
### v0.2.6 (2026-11-06)

- Two presets remain: lite (13 rules, default) and balance (3 rules). v1, v2, and the experimental variants are no longer shipped.
- Plan mode moved back into the main package (plan-mode v1), on the same plugin card as the two presets.
- New runtime compatibility layer: the 5 ids this package ever published resolve to lite without rewriting session files.
- New composition self-check, a four-layer alignment audit (`npm run audit:align`), and read-only concurrency marks for `glob` / `grep`.
- Fixed: preset cards showed "failed to load" after DSH 0.2.2-rc.1 removed the `list-agents` subpath.

Earlier releases: 0.2.5 installed only v3 by default; 0.2.2 made the package installable from npm; 0.2.1 made v3 the main preset; 0.2.0 introduced the bundle format; 0.1.0 was the first release. Details are in the [changelog](docs/CHANGELOG.md) (Chinese) and on the [Releases](https://github.com/LarryE135/dsh-flash-presets/releases) page.

## Documentation (Chinese)

- [Measured evidence](docs/实测证据.md): every experiment, including the conclusions that didn't hold
- [Versions and compatibility](docs/版本与兼容性.md): version mapping and install regression
- [Preset id contract and upgrades](docs/预设-id-契约与升级.md)
- [The four token-saving mechanisms](docs/技术文档-省token四机制.md), [How the presets are implemented](docs/技术文档-精简预设实现.md)
- [Changelog](docs/CHANGELOG.md)

## License

[MIT](LICENSE)

## Maintainer

<table>
  <tbody>
    <tr>
      <td align="center" width="150"><a href="https://github.com/LarryE135"><img src="https://github.com/LarryE135.png?size=160" width="96" height="96" alt="LarryE135"></a><br><a href="https://github.com/LarryE135"><b>LarryE135</b></a></td>
    </tr>
  </tbody>
</table>