@magic6/dsh-compaction-policy-engine 0.5.8 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,115 @@ All notable changes to this project are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.5.10] - 2026-11-26
8
+
9
+ ### Fixed — installing the plugin now actually takes over compaction
10
+
11
+ The bundle shipped its engine row `disabled: true`, on the theory that "superseding the
12
+ stock engine is a deployment decision". That reasoning silently assumed the stock engine
13
+ was *running*. On a preset-based host it is not: `dsh-web-app` — which backs both the
14
+ `web` and `desktop` profiles — disables the host-plane `compaction-basic` itself. So with
15
+ this plugin installed there were **two disabled engines and no owner of `ctx.compaction`**:
16
+
17
+ - the settings card rendered and returned the configured threshold;
18
+ - `engine up` printed nothing, because the engine never mounted;
19
+ - nothing compacted, ever.
20
+
21
+ Observed on a Win11 `desktop` profile: a session grew to 158,118 tokens and then could
22
+ not compact at all. Four forced compactions ran (two in turn 27, one in turn 28, one
23
+ manual `/compact`) and every one came back `context_length_exceeded` from the gateway,
24
+ because the summary request has to carry the same oversized history that triggered it.
25
+ The session was unrecoverable — retrying sent the same request, and compaction could not
26
+ shrink it.
27
+
28
+ The fix is for the bundle to do both halves of the swap in one place:
29
+
30
+ ```yaml
31
+ - id: compaction-basic
32
+ disabled: true
33
+
34
+ - insert:
35
+ - id: compaction-control
36
+ name: '@magic6/dsh-compaction-policy-engine/engine'
37
+ ```
38
+
39
+ Uninstalling removes both, so the stock engine comes back automatically. The plugin can no
40
+ longer leave a profile with no compaction at all.
41
+
42
+ `ctx.compaction` is a **single-slot service**, not an agreement between engines: a second
43
+ engine in the same context throws `service "compaction" has been registered at
44
+ <BasicCompactionEngine>` during construction and never mounts (the host only prints
45
+ `dsh: warning: 1 entry did not activate`). That is why "leave the stock engine enabled as
46
+ a late backstop" is not an option — verified by hand on the same Win11 host.
47
+
48
+ ### Fixed — a test fixture that hid the bug
49
+
50
+ `e2e/run.sh` wrote `- id: compaction-control / disabled: false` into the fixture profile.
51
+ That was intended to mean "the engine has to be on for the test to run", but it also meant
52
+ the suite could never observe the bundle's own default. Every scenario stayed green while
53
+ the shipped bundle was unusable.
54
+
55
+ The fixture now overrides only `config:`, leaving `disabled` at whatever the bundle ships.
56
+ `fired` additionally asserts that the engine printed its own `[compaction] engine up:` line
57
+ before it judges anything about thresholds — the precondition that the old suite silently
58
+ assumed.
59
+
60
+ Regression check with the corrected fixture (same suite, same fake provider):
61
+
62
+ | version | result |
63
+ |:--|:--|
64
+ | `0.5.9` (buggy) | **0 passed, 1 failed** — "our engine never started", plus "no compaction fired" |
65
+ | this release | 2 passed, 0 failed |
66
+
67
+ ### Changed — README
68
+
69
+ The mounting section now states that installing the plugin *is* the takeover, that the
70
+ stock row must be disabled because the seam is single-slot, and that uninstalling restores
71
+ it. The two silent-bad-combination warnings keep their original text but now name which
72
+ one this release fixed.
73
+
74
+ ## [0.5.9] - 2026-11-25
75
+
76
+ ### Fixed — three bugs that only a real host could expose
77
+
78
+ An end-to-end layer (`e2e/`, `npm run test:e2e`) now starts a real `dsh` against a fake
79
+ provider and drives the pressure gate across its threshold. It found three defects that
80
+ the unit suite could not, because each one lived in an assumption the code made about the
81
+ host rather than in the logic it tested.
82
+
83
+ 1. **`source=` named the wrong layer.** When `settings.yaml` does not exist, the watcher
84
+ reports the composition as its fallback section and says so (`origin: 'composition'`),
85
+ but `reloadPolicy` only tested `_fileSection !== undefined` and wrote
86
+ `origin = 'settings.yaml'`. The one diagnostic meant to expose "your config never
87
+ reached the engine" therefore asserted the opposite. Now it reads `_fileOrigin`.
88
+
89
+ 2. **The patch layer was read from the wrong profile.** `patchFilePaths` trusted
90
+ `process.env.DSH_PROFILE`, which the host injects into every *shell tool* execution
91
+ — so a `dsh --profile headless …` launched from inside an agent inherited the parent's
92
+ profile name and watched `profiles/web/cordis.patch.yml` instead of its own. A patch
93
+ layer that was present and correct read as absent, silently, once a second. The engine
94
+ now passes `ctx.get('profileContext').name`, which is the host's own answer; the env
95
+ var remains only as a fallback hint.
96
+
97
+ 3. **`NO THRESHOLD` could never print.** The guard tested
98
+ `policy.thresholdRatio !== undefined`, but `resolvePolicy` always fills that field from
99
+ `DEFAULT_THRESHOLD_RATIO`, so the function returned unconditionally. The warning
100
+ existed for exactly the case it could not report. It now tests
101
+ `policy.source.threshold.layer`, and an unknown layer counts as unstated.
102
+
103
+ The unit test that was supposed to cover (3) passed because it fed a hand-written policy
104
+ shape the resolver never produces. It now uses the resolved shape, and a new case asserts
105
+ that an engine-default threshold *is* reported.
106
+
107
+ ### Added
108
+
109
+ - `e2e/run.sh` with `fired` (threshold crossed → `FIRED`, `source=cordis.patch.yml`, and
110
+ `measured` falling back below the threshold afterwards) and `unstated` (`NO THRESHOLD`
111
+ must be printed when no layer states one).
112
+ - Two regression tests for (2) and (3); both fail against 0.5.8 and pass against 0.5.9.
113
+
114
+ Unit suite: 201 passing.
115
+
7
116
  ## [0.5.8] - 2026-11-25
8
117
 
9
118
  ### Documentation
package/README.en.md CHANGED
@@ -358,6 +358,28 @@ then a `TMPDIR` fallback), which is exactly why the job is there.
358
358
  > mean "unsupported" — it means nobody has verified it yet. If you ran the suite
359
359
  > somewhere else, a PR adding the row is welcome.
360
360
 
361
+ ## End-to-end self-check
362
+
363
+ The unit suite exercises the policy resolver with a fake engine and a fake meter; it
364
+ cannot tell you whether a real host ever receives the policy. A second layer does:
365
+
366
+ ```bash
367
+ npm run test:e2e # same as e2e/run.sh
368
+ ```
369
+
370
+ It starts an isolated `DSH_HOME`, builds a temporary profile, installs this package, and
371
+ points a fake provider at `127.0.0.1` with a deliberately huge `contextWindow` and an
372
+ **absolute** token threshold — so a handful of short turns crosses the gate without
373
+ spending 12k real tokens. It then waits for `gate=wait` to become `gate=FIRE`.
374
+
375
+ Assertions do not stop at "compaction fired": they also check **which layer `source=`
376
+ names**, whether `thresholdTokens` equals the configured value, and whether `measured`
377
+ actually falls back below the threshold afterwards. See [e2e/README.md](e2e/README.md).
378
+
379
+ > This layer found three bugs in 0.5.9 that the unit suite could not — two of them were
380
+ > diagnostics lying about their own provenance. The acceptance rule for a new scenario is
381
+ > in that README: **it must go red on the old version.**
382
+
361
383
  ## Compatibility and migration
362
384
 
363
385
  - DSH `0.2.1-rc.x` / `0.2.2-rc.x` (`engines.dsh`: `>=0.2.1-0 <0.3.0-0`), Node.js 20+.
package/README.md CHANGED
@@ -86,38 +86,55 @@ cd dsh-compaction-policy-engine
86
86
  dsh plugin --profile web add "$PWD"
87
87
  ```
88
88
 
89
- 包本身是 bundle,会挂两行:
89
+ 包本身是 bundle,**装上即接管压缩**:
90
90
 
91
- - **引擎行**(`compaction-control`),**默认 disabled**;
92
- - **companion 行**(`compaction-control-settings`),始终启用,负责设置卡片与上下文提示词;
91
+ - 把官方 `compaction-basic` 行设为 `disabled: true`;
92
+ - **启用**引擎行(`compaction-control`);
93
+ - companion 行(`compaction-control-settings`)始终启用,负责设置卡片与上下文提示词;
93
94
  它**不**认领 `ctx.compaction`。
94
95
 
96
+ 卸载插件时这三件事一起消失:`compaction-basic` 的覆盖随 bundle 走,官方引擎自动恢复。
97
+ **不会出现「卸掉插件后什么都不压缩」的状态**,这一点有 e2e 守着(见 `e2e/` 的 `fired` 场景)。
98
+
99
+ ### 为什么必须自己关官方引擎
100
+
101
+ `ctx.compaction` 是**单槽服务**,不是两个引擎之间的约定:
102
+
103
+ ```js
104
+ super(ctx, "compaction") // 第二个 -> 'service "compaction" has been registered at …'
105
+ ```
106
+
107
+ 同一 context 里放第二个引擎**不会**退化成「低阈值赢」,而是在构造时抛错、那一行根本不挂载。
108
+ 所以「留着官方引擎当兜底」不成立——要么关掉它,要么本插件无法启动。
109
+
110
+ > **上一版(≤0.5.9)出厂把引擎设成 `disabled: true`**,理由是「替换官方引擎属于部署决策」。
111
+ > 那条推理默认官方引擎**正在运行**;而 `dsh-web-app`(`web` / `desktop` profile)本来就把宿主
112
+ > 平面的 `compaction-basic` 停了。两边都没开 → 设置卡片正常渲染、阈值读得回来、压缩一次都不触发。
113
+ > Win11 上一个会话就是这样涨到 158k token,随后四次压缩全被上游拒绝。见 CHANGELOG 0.5.10。
114
+
95
115
  ### 先确定挂载平面
96
116
 
97
- `ctx.compaction` 是**按 realm 解析的单槽接缝**。必须挂在 agent 实际解析到的作用域;挂在别处
98
- 不是「覆盖」而是「并存」——两个引擎都订阅冒泡的 `agent/pre-step`,触发点变成两者中较低的那个,
99
- 表现为「装完插件后压缩异常地早」。
117
+ `ctx.compaction` 是**按 realm 解析的单槽服务**。`isolate: compaction: true` 让每个 preset realm
118
+ 各有一份,所以 preset 宿主里会同时存在「宿主平面一个 + preset 内一个」——两个 context,不冲突。
119
+ 宿主平面的引擎服务 `headless` 与解析到宿主平面的 agent;想让策略进到某个 preset 内部,
120
+ 替换它自己的 `compaction` 组(见下)。
100
121
 
101
- | profile | agent 的压缩引擎属于谁 | 怎么挂 |
122
+ | profile | agent 的压缩引擎属于谁 | 需要做什么 |
102
123
  |:--|:--|:--|
103
- | `headless` | 宿主平面(没有 preset) | profile 的 `cordis.patch.yml`,覆盖 bundle 已插入的引擎行 |
104
- | `web` | **agent preset**(`dsh-web-app` 停用了宿主平面的 `compaction-basic`) | 覆盖 preset 声明;本仓库带一个示例 bundle |
124
+ | `headless` | 宿主平面(没有 preset) | 无。bundle 已接管 |
125
+ | `web` / `desktop` | **agent preset**(宿主平面的 `compaction-basic` 由 `dsh-web-app` 停用) | 宿主平面已接管;要让 preset 内部也用策略,需覆盖 preset 声明 |
105
126
 
106
127
  #### headless(宿主平面)
107
128
 
108
- bundle 已经插入 `compaction-control`(disabled)。**覆盖这一行**,不要再 `insert` 一份:
129
+ 无。装上就生效,bundle 已经写好了那两行。要改门槛就改 `config:`:
109
130
 
110
131
  ```yaml
111
132
  # $DSH_HOME/profiles/<profile>/cordis.patch.yml
112
- - id: compaction-basic
113
- disabled: true
114
-
115
133
  - id: compaction-control
116
- disabled: false
117
134
  config:
118
135
  default:
119
- threshold: 0.8
120
- retain: 0.16
136
+ threshold: 0.42
137
+ retain: 0.08
121
138
  ```
122
139
 
123
140
  loader 认的键是 **`disabled`**,不是 `disable`;写错不会报错,会被静态配置静默丢掉
@@ -145,8 +162,10 @@ dsh plugin --profile web add "$PWD/examples/standard-with-policy"
145
162
 
146
163
  两种静默坏组合:
147
164
 
148
- - 宿主平面挂了引擎,preset 里原版 `compaction-basic` 还在 → 两个引擎,阈值低的赢;
165
+ - 宿主平面挂了引擎,同一 realm 里原版 `compaction-basic` 还在 → 第二个引擎注册失败,
166
+ 只有一行 warning(`dsh: warning: 1 entry did not activate`),策略静默失效;
149
167
  - 原版停用了却没有挂任何替代引擎 → 接缝无人认领,会话静默停止压缩,一路涨到被上游拒绝。
168
+ **这正是 0.5.9 及更早版本在 `web` / `desktop` 上的默认行为**,已由 bundle 自身修掉。
150
169
 
151
170
  「停用旧的」和「启用新的」必须写在同一个组合里,一起 review。
152
171
 
@@ -312,6 +331,25 @@ Windows 一行是 2026-11-25 才加上的:在那之前 CI 只跑 `ubuntu-lates
312
331
  > 只列跑过测试的平台。没在这里出现 ≠ 不支持,只是还没人验证过 ——
313
332
  > 如果你在别的平台跑通了,欢迎提 PR 把这一行补上。
314
333
 
334
+ ## 端到端自测
335
+
336
+ 单元测试里引擎和 meter 都是假的,只能证明策略解析对了。仓库里另有一层端到端验证:
337
+
338
+ ```bash
339
+ npm run test:e2e # 等价于 e2e/run.sh
340
+ ```
341
+
342
+ 它起一个**独立 `DSH_HOME`**、建临时 profile、从 npm(或工作树)装这个包,让一个假
343
+ provider 声明很大的 `contextWindow`、用**绝对 token 数**把门槛压到几轮对话就能跨过,
344
+ 然后真的等 `gate=wait` 翻成 `gate=FIRE`。
345
+
346
+ 断言不只看「压缩触发了没有」,还看 **`source=` 是哪一层**、`thresholdTokens` 是否等于
347
+ 配置值、压缩后 `measured` 有没有真的落回门槛之下。细节见
348
+ [e2e/README.md](e2e/README.md)。
349
+
350
+ > 这一层在 0.5.9 抓到了三个单元测试测不出的 bug,其中两个是「诊断本身在撒谎」。
351
+ > 加场景的验收标准同样写在那份 README 里:**它必须在旧版本上会红**。
352
+
315
353
  ## 兼容与迁移
316
354
 
317
355
  - DSH `0.2.1-rc.x` / `0.2.2-rc.x`(`engines.dsh`:`>=0.2.1-0 <0.3.0-0`)、Node.js 20+。
package/cordis.patch.yml CHANGED
@@ -1,45 +1,56 @@
1
- # Plugin bundle for dsh-compaction-policy-engine: mounts the policy engine (inert by
2
- # default) and the always-enabled host-plane companion.
1
+ # Plugin bundle for dsh-compaction-policy-engine: mounts the policy engine and the
2
+ # host-plane companion.
3
3
  #
4
4
  # The engine subclasses `BasicCompactionEngine`, so region selection, tool-pairing
5
5
  # balance, summary framing, and the durable compaction transaction stay the
6
6
  # official implementation — only the policy (three-layer threshold + summarization
7
7
  # model) becomes configurable here.
8
8
  #
9
- # `ctx.compaction` is a single-slot seam: enabling this row means the stock
10
- # `compaction-basic` row must be disabled in the same profile. This bundle
11
- # deliberately does not do that for you, and ships the engine `disabled`:
12
- # superseding the stock engine is a deployment decision, and a bundle that turned
13
- # itself on without also re-enabling `compaction-basic` would leave the profile
14
- # with no compaction at all. Enable both in the same patch:
15
- #
16
- # - id: compaction-basic
17
- # disabled: true
18
- #
19
- # - id: compaction-control
20
- # disabled: false
21
- # config:
22
- # default:
23
- # threshold: 0.8 # ratio of the adapter-declared window
24
- # summarizationModel: auto # `auto` = the conversation's own model
25
- # providers:
26
- # gateway-b:
27
- # threshold: 0.5
28
- # models:
29
- # - provider: local
30
- # model: model-g
31
- # threshold: 0.9
9
+ # ── Mounting this plugin swaps the engine (2026-11-26) ────────────────────────
10
+ #
11
+ # `ctx.compaction` is a SINGLE-SLOT service, not an agreement between engines:
12
+ #
13
+ # super(ctx, "compaction") // -> 'service "compaction" has been registered
14
+ # // at <BasicCompactionEngine>'
15
+ #
16
+ # A second engine in the same context does not lose a threshold race — it throws
17
+ # during construction and never mounts at all. So "leave the stock engine on as a
18
+ # late backstop" is not available: the bundle must disable it, or the policy engine
19
+ # cannot start. This file therefore does both halves in one place:
20
+ #
21
+ # - disables the stock `compaction-basic` row, and
22
+ # - enables the policy engine.
23
+ #
24
+ # Doing only one half is the failure this file used to ship. It shipped the engine
25
+ # `disabled` on the theory that "superseding the stock engine is a deployment
26
+ # decision" — but that theory silently assumed the stock engine was *running*.
27
+ # On a preset-based host (`dsh-web-app`: `web` and `desktop` profiles) the host
28
+ # plane's `compaction-basic` is disabled by the app itself, so a bundle that also
29
+ # left its own engine disabled yielded **no compaction at all**: the settings card
30
+ # rendered, the threshold read back, and nothing ever fired. That is how a Win11
31
+ # session grew past 158k tokens and then could not compact — four forced
32
+ # compactions in a row, every one rejected upstream, and every local test green.
33
+ #
34
+ # Unmounting the plugin reverses both halves automatically: these rows and the
35
+ # `compaction-basic` override disappear together, restoring the stock engine.
36
+ #
37
+ # ── Which realm the engine lands in ──────────────────────────────────────────
38
+ #
39
+ # `isolate: compaction: true` in the agent presets gives each preset realm its own
40
+ # `compaction` slot, so a preset host keeps a stock `compaction-basic` inside the
41
+ # realm alongside this host-plane engine — two engines, two contexts, no conflict.
42
+ # The host-plane one (this row) serves `headless` and any agent that resolves the
43
+ # host plane; a preset that wants the policy inside its realm replaces its own
44
+ # `compaction` group, see `examples/standard-with-policy/`.
32
45
  #
33
46
  # Thresholds are ratios, never absolute token counts: a model's advertised window
34
47
  # is not stable, and a model that declares no window cannot honor a token budget.
35
48
  #
36
- # The companion row below is a **separate, enabled, host-plane** row because the
37
- # browser bundle is discovered from enabled loader entries (`dsh-client-modules`
38
- # walks `ctx.loader.entries()` and skips disabled or fiberless ones) — the engine
39
- # row is disabled by default and normally mounted inside an agent preset, where
40
- # that scan cannot see it. It deliberately does NOT claim `ctx.compaction`: the
41
- # seam resolves per realm, so a host-plane engine would run *beside* the preset
42
- # one on the same bubbling `agent/pre-step` and the lower threshold would win.
49
+ # The companion row is a **separate, enabled, host-plane** row because the browser
50
+ # bundle is discovered from enabled loader entries (`dsh-client-modules` walks
51
+ # `ctx.loader.entries()` and skips disabled or fiberless ones) — the engine can
52
+ # live inside an agent preset, where that scan cannot see it. It deliberately does
53
+ # NOT claim `ctx.compaction`.
43
54
  #
44
55
  # `name` is the **bare package name**, which resolves to `lib/companion.js`. That
45
56
  # split is load-bearing: the loader mounts a row's `exports.default` and reads no
@@ -47,10 +58,13 @@
47
58
  # `export:` key, which was silently dropped — putting a second engine on the host
48
59
  # plane at the shipped default and capping every raised threshold. Two
49
60
  # `[compact-debug]` lines per step with the same `measured` were the signature.)
61
+
62
+ - id: compaction-basic
63
+ disabled: true
64
+
50
65
  - insert:
51
66
  - id: compaction-control
52
67
  name: '@magic6/dsh-compaction-policy-engine/engine'
53
- disabled: true
54
68
 
55
69
  - insert:
56
70
  - id: compaction-control-settings
package/lib/index.js CHANGED
@@ -308,7 +308,17 @@ function summarizationInput(input, agent) {
308
308
  * @param policy - the resolved policy, or `undefined` when no target was routed.
309
309
  */
310
310
  function reportUnstatedThreshold(engine, target, policy) {
311
- if (policy !== undefined && (policy.thresholdRatio !== undefined || policy.thresholdTokens !== undefined)) return;
311
+ // "Stated" is `source.threshold.layer !== 'engine'`, **not** "the resolved
312
+ // fields are defined": `resolvePolicy` always fills `thresholdRatio` from
313
+ // `DEFAULT_THRESHOLD_RATIO`, so the old test made this function return
314
+ // unconditionally and the warning it exists for could never appear. A unit
315
+ // test kept it green by passing a policy shape (`{ retainRatio: 0.1 }`) that
316
+ // the resolver never produces. Measured 2026-11-25.
317
+ //
318
+ // An unknown layer is reported too: "I cannot tell whether a threshold was
319
+ // stated" must not read as "one was".
320
+ const layer = policy?.source?.threshold?.layer;
321
+ if (layer !== undefined && layer !== 'engine') return;
312
322
  const key = target === undefined ? 'no-routed-target' : `${target.provider}/${target.model}`;
313
323
  engine._reportedUnstatedThreshold ??= new Set();
314
324
  if (engine._reportedUnstatedThreshold.has(key)) return;
@@ -525,8 +535,13 @@ export class CompactionControlEngine extends BasicCompactionEngine {
525
535
  //
526
536
  // The patch layer outranks `settings.yaml` because it is the layer dsh
527
537
  // applies last, so it is allowed to override the section read above.
538
+ // The running profile, not an inherited env var: `DSH_PROFILE` names the
539
+ // *parent* process's profile when this dsh was launched from an agent's
540
+ // shell tool. `profileContext` is the host's own answer (see
541
+ // `patchFilePaths` for the measured failure).
542
+ const runningProfile = ctx.get?.('profileContext')?.name;
528
543
  this._patchFileWatcher = watchPatchFile({
529
- files: patchFilePaths(),
544
+ files: patchFilePaths(process.env, runningProfile),
530
545
  onConfig: (config) => {
531
546
  // `reloadPolicy` derives `source=` from which layers are present, so
532
547
  // this callback only records the value.
@@ -571,7 +586,13 @@ export class CompactionControlEngine extends BasicCompactionEngine {
571
586
  // re-reads it is exactly how an edit went unnoticed until restart.
572
587
  let document = this.baseConfig;
573
588
  let origin = 'composition';
574
- if (this._fileSection !== undefined) {
589
+ // `_fileOrigin` says where `_fileSection` came from, and it is the only
590
+ // honest answer: when `settings.yaml` is absent the watcher still reports
591
+ // the composition as a fallback section, so testing `_fileSection` alone
592
+ // labelled a built-in default as `settings.yaml`. That turned the one
593
+ // diagnostic meant to expose "the config never reached the engine" into a
594
+ // line asserting the opposite. Measured 2026-11-25.
595
+ if (this._fileSection !== undefined && this._fileOrigin === 'settings.yaml') {
575
596
  document = overlayDocument(document, this._fileSection);
576
597
  origin = 'settings.yaml';
577
598
  } else if (this.settingsState !== undefined) {
@@ -44,10 +44,21 @@ export function settingsFilePath(home = process.env.DSH_HOME ?? join(process.env
44
44
  * @param env - the environment to read.
45
45
  * @returns absolute path candidates, most specific first.
46
46
  */
47
- export function patchFilePaths(env = process.env) {
47
+ export function patchFilePaths(env = process.env, profileName = undefined) {
48
48
  const home = env.DSH_HOME ?? join(env.HOME ?? '', '.dsh');
49
49
  const profiles = [];
50
- if (env.DSH_PROFILE !== undefined && env.DSH_PROFILE !== '') profiles.push(env.DSH_PROFILE);
50
+ // `profileName` is the authoritative answer: the host exposes the *running*
51
+ // profile as `ctx.profileContext.name`, and this plugin passes it in.
52
+ //
53
+ // `DSH_PROFILE` is only a hint, and a dangerous one. The host injects it into
54
+ // every shell tool execution so a subprocess can see *its parent's* profile;
55
+ // a `dsh --profile other …` launched from inside an agent therefore inherits
56
+ // `DSH_PROFILE` naming the parent. Relying on it made this plugin watch
57
+ // `profiles/web/cordis.patch.yml` while running under `--profile headless`,
58
+ // so a patch layer that was present and correct read as "no patch layer" —
59
+ // silently, once a second, forever. Measured 2026-11-25.
60
+ if (typeof profileName === 'string' && profileName !== '') profiles.push(profileName);
61
+ else if (env.DSH_PROFILE !== undefined && env.DSH_PROFILE !== '') profiles.push(env.DSH_PROFILE);
51
62
  if (!profiles.includes('web')) profiles.push('web');
52
63
  return profiles.map((profile) => join(home, 'profiles', profile, 'cordis.patch.yml'));
53
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic6/dsh-compaction-policy-engine",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Layered, live-reloading context compaction policy for DeepSeek Harness: provider-level rules, field-by-field inheritance, ratio/token units and a settings panel on top of the official engine.",
5
5
  "type": "module",
6
6
  "main": "lib/companion.js",
@@ -23,6 +23,7 @@
23
23
  ],
24
24
  "scripts": {
25
25
  "test": "node --test test/*.test.js",
26
+ "test:e2e": "e2e/run.sh",
26
27
  "prepublishOnly": "npm test"
27
28
  },
28
29
  "keywords": [