@magic6/dsh-compaction-policy-engine 0.5.16 → 0.5.17

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,21 @@ 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.17] - 2026-11-30
8
+
9
+ ### Fixed — the engine is read the companion service with `ctx.get`, not `ctx.inject`
10
+
11
+ 0.5.16 fetched the companion's live policy with `ctx.inject([…])`. In cordis an
12
+ inject whose dependency never arrives leaves the fiber pending, and the host
13
+ then stops calling the engine at all — no gate check, no diagnostic. It only
14
+ shows on a profile whose companion row is absent (the bundle inserts one by
15
+ default), which is exactly what the e2e "unstated threshold" scenario strips
16
+ down, and that scenario went red in CI. The service is now read on demand with
17
+ `ctx.get`, so an engine without a companion row stays usable and keeps
18
+ reporting; the signature check in `policyFor` still picks the service up as
19
+ soon as the row mounts. The e2e scenario now asserts the engine states the
20
+ threshold and layer it applies.
21
+
7
22
  ## [0.5.16] - 2026-11-30
8
23
 
9
24
  ### Fixed — the policy reaches the engine through the loader, not a file poll
package/lib/index.js CHANGED
@@ -504,11 +504,19 @@ export class CompactionControlEngine extends BasicCompactionEngine {
504
504
  reportedWarnings = new Set();
505
505
 
506
506
  /**
507
- * The companion row's live document, or undefined until that row mounts.
507
+ * The companion row's live document, or undefined until that row is active.
508
508
  *
509
- * @type {{ current: () => object | undefined, runtimeRef?: object } | undefined}
509
+ * Read with `ctx.get` on demand rather than `ctx.inject`: an inject whose
510
+ * dependency never arrives (a profile without the companion row) keeps this
511
+ * fiber pending, and the host then never calls the engine at all — measured
512
+ * 2026-11-30 on the e2e "unstated threshold" scenario. `get` costs nothing
513
+ * and answers as soon as the row is up.
514
+ *
515
+ * @returns {{ current: () => object | undefined, runtimeRef?: object } | undefined}
510
516
  */
511
- _livePolicy;
517
+ livePolicy() {
518
+ return this.ctx.get?.(POLICY_SERVICE);
519
+ }
512
520
 
513
521
  /** `JSON.stringify` of the live document last resolved, so a card save between two steps is noticed. */
514
522
  _liveSignature;
@@ -532,18 +540,15 @@ export class CompactionControlEngine extends BasicCompactionEngine {
532
540
  this.controlConfig = controlConfig;
533
541
  this.baseConfig = controlConfig;
534
542
 
535
- // The companion row (`compaction-control-settings`) owns the user's document
536
- // and this row mounts first, so its service is injected rather than read: the
537
- // callback runs as soon as that row is up, and again if it ever remounts. Its
538
- // cells are updated in place by the loader on every card save, so this one
539
- // hand-off is a live view — no file, no poll, no path to derive.
543
+ // The companion row (`compaction-control-settings`) owns the user's document.
544
+ // Its cells are updated in place by the loader on every card save, so reading
545
+ // the service (`livePolicy()`) is a live view — no file, no poll, no path to
546
+ // derive. It is picked up on the next policy lookup, and again if the row
547
+ // remounts; see `livePolicy()` for why this is not an `inject`.
540
548
  //
541
549
  // The file readers below stay as the fallback for a profile that mounts no
542
550
  // companion row, and for an edit made straight to the patch file.
543
- ctx.inject([POLICY_SERVICE], (policyCtx) => {
544
- this._livePolicy = policyCtx[POLICY_SERVICE];
545
- this.reloadPolicy();
546
- });
551
+ if (this.livePolicy() !== undefined) this.reloadPolicy();
547
552
 
548
553
  // The running host's own facts, provided before any profile row mounts
549
554
  // (`boot()` runs `prepare(hostCtx)` — which provides `profileContext` —
@@ -639,7 +644,7 @@ export class CompactionControlEngine extends BasicCompactionEngine {
639
644
  * quietly grows past the threshold the operator believes is in force.
640
645
  */
641
646
  publishRuntime() {
642
- const ref = this._livePolicy?.runtimeRef;
647
+ const ref = this.livePolicy()?.runtimeRef;
643
648
  if (ref === undefined || typeof ref[VOLATILE_WRITE] !== 'function') return;
644
649
  const declared = this.controlConfig.default;
645
650
  ref[VOLATILE_WRITE](
@@ -677,7 +682,8 @@ export class CompactionControlEngine extends BasicCompactionEngine {
677
682
  let origin = 'composition';
678
683
  // Recorded before validation: a live document that is refused must not be
679
684
  // re-examined on every step until it changes again.
680
- this._liveSignature = this._livePolicy === undefined ? undefined : JSON.stringify(this._livePolicy.current());
685
+ const livePolicy = this.livePolicy();
686
+ this._liveSignature = livePolicy === undefined ? undefined : JSON.stringify(livePolicy.current());
681
687
  // `_fileOrigin` says where `_fileSection` came from, and it is the only
682
688
  // honest answer: when `settings.yaml` is absent the watcher still reports
683
689
  // the composition as a fallback section, so testing `_fileSection` alone
@@ -687,11 +693,11 @@ export class CompactionControlEngine extends BasicCompactionEngine {
687
693
  if (this._fileSection !== undefined && this._fileOrigin === 'settings.yaml') {
688
694
  document = overlayDocument(document, this._fileSection);
689
695
  origin = 'settings.yaml';
690
- } else if (this._livePolicy !== undefined) {
696
+ } else if (livePolicy !== undefined) {
691
697
  // The companion row's own config, as the loader resolved it: the bundle's
692
698
  // composition under the user's override. Overlaid for the same reason as
693
699
  // the file layers — a partial save must not drop the rest.
694
- const live = this._livePolicy.current();
700
+ const live = livePolicy.current();
695
701
  if (live !== undefined) {
696
702
  document = overlayDocument(document, live);
697
703
  origin = 'companion';
@@ -735,8 +741,9 @@ export class CompactionControlEngine extends BasicCompactionEngine {
735
741
  // hear (`loader/volatile-update` is scoped to the companion's own fiber),
736
742
  // so the live document is compared by value here — a few small objects per
737
743
  // step — and any difference is resolved before the cache is consulted.
738
- if (this._livePolicy !== undefined) {
739
- const signature = JSON.stringify(this._livePolicy.current());
744
+ const livePolicy = this.livePolicy();
745
+ if (livePolicy !== undefined) {
746
+ const signature = JSON.stringify(livePolicy.current());
740
747
  if (signature !== this._liveSignature) this.reloadPolicy();
741
748
  }
742
749
  const key = `${target.provider}\u0000${target.model}\u0000${contextWindow ?? ''}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic6/dsh-compaction-policy-engine",
3
- "version": "0.5.16",
3
+ "version": "0.5.17",
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",