@fractalsynapse/dsh-chapters 0.2.60 → 0.2.62

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * #545: proxy-safe service binding.
3
+ *
4
+ * The host calls cordis SERVICES through interface proxies — measured stack on the maintainer's
5
+ * machine and reproduced in the rig: `command-compact → cordis Object.apply → Proxy.compactNow`,
6
+ * where the engine's ES private access (`this.#observeRoute`) throws
7
+ * `TypeError: Receiver must be an instance of class ChaptersCompactionEngine` even though
8
+ * `instanceof` answers true. ES private brands demand the ACTUAL instance; a proxy receiver,
9
+ * however faithful, is not it. The host's own compaction engine survives the same call because
10
+ * it uses zero ES privates (grep-verified: no brands, no WeakSet lowering) — the architecture's
11
+ * rule is therefore: anything serving a host interface must keep private access on the real
12
+ * receiver. Binding every public prototype method to the instance at construction does exactly
13
+ * that: the proxy's get finds an OWN bound function, and `this` inside is the instance the
14
+ * brands were minted for.
15
+ *
16
+ * One helper, one decision (#59): any plugin class that serves a host interface calls this in
17
+ * its constructor. Today that is ChaptersCompactionEngine; tomorrow's service class has the
18
+ * same trap already solved.
19
+ */
20
+ import { Service } from '@deepseek-ai/cordis';
21
+ export function bindPublicMethods(instance) {
22
+ let proto = Object.getPrototypeOf(instance);
23
+ while (proto !== null && proto !== Service.prototype && proto !== Object.prototype) {
24
+ for (const key of Object.getOwnPropertyNames(proto)) {
25
+ if (key === 'constructor')
26
+ continue;
27
+ const desc = Object.getOwnPropertyDescriptor(proto, key);
28
+ if (desc === undefined)
29
+ continue;
30
+ // FIRST-WRITER WINS: the walk starts at the most-derived prototype, and a later base
31
+ // class must NOT overwrite the wrapper already installed for an override (measured:
32
+ // re-installing from BasicCompactionEngine.prototype shadowed our compactIfNeeded
33
+ // override and the base's pressure check threw with the very headroom default #140
34
+ // exists to zero). Own already means bound — skip.
35
+ if (Object.prototype.hasOwnProperty.call(instance, key))
36
+ continue;
37
+ if (typeof desc.value === 'function') {
38
+ // LATE-DISPATCH wrapper, not a captured bind: the call resolves the CURRENT prototype
39
+ // method at call time and applies it to the real instance. A captured bind would shadow
40
+ // prototype stubs installed after construction (measured: 22 engine-test doubles went
41
+ // silently inert) — late dispatch keeps both the brands and the test seams alive.
42
+ const owner = proto;
43
+ instance[key] = function (...args) {
44
+ // resolve on the PROTOTYPE owner at call time — never via the instance, whose own
45
+ // wrapper would self-recurse.
46
+ const current = Object.getOwnPropertyDescriptor(owner, key)?.value;
47
+ if (typeof current === 'function')
48
+ return Reflect.apply(current, instance, args);
49
+ return undefined;
50
+ };
51
+ }
52
+ else if (desc.get !== undefined || desc.set !== undefined) {
53
+ // Accessors run with the RECEIVER as `this` — a getter that touches a private brand
54
+ // would throw the same way. Re-define them own, bound to the real instance.
55
+ const bound = {
56
+ enumerable: desc.enumerable === true,
57
+ configurable: true,
58
+ };
59
+ if (desc.get !== undefined)
60
+ bound.get = desc.get.bind(instance);
61
+ if (desc.set !== undefined)
62
+ bound.set = desc.set.bind(instance);
63
+ Object.defineProperty(instance, key, bound);
64
+ }
65
+ }
66
+ proto = Object.getPrototypeOf(proto);
67
+ }
68
+ }
69
+ //# sourceMappingURL=proxy-safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-safe.js","sourceRoot":"","sources":["../src/proxy-safe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,IAAI,KAAK,GAAkB,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;IAC1D,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,OAAO,CAAC,SAAS,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACnF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;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BAC/D,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS;oBAAE,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBAC/D,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YAC7C,CAAC;QACH,CAAC;QACD,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;AACH,CAAC"}
package/lib/version.d.ts CHANGED
@@ -6,4 +6,4 @@
6
6
  * reader cannot recover later, so it belongs in the bytes. A row in tests asserts this literal equals
7
7
  * `package.json`'s version — the one place a hand-mirrored constant must never be allowed to drift.
8
8
  */
9
- export declare const PLUGIN_VERSION = "0.2.60";
9
+ export declare const PLUGIN_VERSION = "0.2.62";
package/lib/version.js CHANGED
@@ -6,5 +6,5 @@
6
6
  * reader cannot recover later, so it belongs in the bytes. A row in tests asserts this literal equals
7
7
  * `package.json`'s version — the one place a hand-mirrored constant must never be allowed to drift.
8
8
  */
9
- export const PLUGIN_VERSION = '0.2.60';
9
+ export const PLUGIN_VERSION = '0.2.62';
10
10
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fractalsynapse/dsh-chapters",
3
- "version": "0.2.60",
3
+ "version": "0.2.62",
4
4
  "description": "dsh plugin: verbatim chapter archive + zero-token index for small-context models",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",