The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): host.pluginDecisions hands out frozen copies, not the live store object
teknium14cec3f85e7c5
diff --git a/apps/desktop/src/sdk/bridge.test.ts b/apps/desktop/src/sdk/bridge.test.tsindex e84ba599d04..36d4457a5ec 100644--- a/apps/desktop/src/sdk/bridge.test.ts+++ b/apps/desktop/src/sdk/bridge.test.ts@@ -38,7 +38,9 @@ describe('host capabilities bridge', () => {// Declined by design: a plugin must not flip another plugin's enable state,// and the singleton host cannot attribute the caller to restrict `set` to its// own id. The view is a live, subscribable mirror of the app's store with NO- // writer at runtime (a type-only `ReadableAtom` cast would still carry `.set`).+ // writer at runtime (a type-only `ReadableAtom` cast would still carry `.set`),+ // and the values it hands out are frozen copies — mutating one must not reach+ // the object `pluginActive()` reads and `saveDecisions()` persists.it('pluginDecisions is a live read-only view of the decisions store', () => {const seen: Record<string, boolean>[] = []const unsubscribe = host.pluginDecisions.subscribe(value => seen.push(value))@@ -49,6 +51,14 @@ describe('host capabilities bridge', () => {expect(seen.at(-1)).toEqual({ 'demo-plugin': false })expect(typeof (host.pluginDecisions as unknown as { set?: unknown }).set).toBe('undefined')+ for (const view of [host.pluginDecisions.get(), host.pluginDecisions.value!, seen.at(-1)!]) {+ expect(() => {+ view['other-plugin'] = false+ }).toThrow(TypeError)+ }++ expect($pluginDecisions.get()).toEqual({ 'demo-plugin': false })+unsubscribe()})})diff --git a/apps/desktop/src/sdk/bridge.ts b/apps/desktop/src/sdk/bridge.tsindex 33e20aa5dad..dec031f2c33 100644--- a/apps/desktop/src/sdk/bridge.ts+++ b/apps/desktop/src/sdk/bridge.ts@@ -49,20 +49,25 @@ export const profiles = {* the user never chose, so the plugin's own `defaultEnabled` applies).* A hand-built view rather than a `computed`/type cast: both of those still* carry `.set` at runtime, and the point is that a plugin cannot cast its way- * into another plugin's toggle. */+ * into another plugin's toggle. Every value handed out is a frozen copy: the+ * store's own object is what `pluginActive()` reads and `saveDecisions()`+ * spreads, so returning it live would make `get()['other'] = false` a `set()`+ * by another door. */+const frozen = (v: Record<string, boolean>): Record<string, boolean> => Object.freeze({ ...v })+export const pluginDecisions: ReadableAtom<Record<string, boolean>> = {- get: () => $pluginDecisions.get(),+ get: () => frozen($pluginDecisions.get()),get init() {return $pluginDecisions.init},get lc() {return $pluginDecisions.lc},- listen: listener => $pluginDecisions.listen(listener),+ listen: listener => $pluginDecisions.listen((value, oldValue) => listener(frozen(value), oldValue)),notify: oldValue => $pluginDecisions.notify(oldValue),off: () => $pluginDecisions.off(),- subscribe: listener => $pluginDecisions.subscribe(listener),+ subscribe: listener => $pluginDecisions.subscribe((value, oldValue) => listener(frozen(value), oldValue)),get value() {- return $pluginDecisions.value+ return frozen($pluginDecisions.value)}}diff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.mdindex 64258320093..261766a7865 100644--- a/website/docs/developer-guide/desktop-plugin-sdk.md+++ b/website/docs/developer-guide/desktop-plugin-sdk.md@@ -839,8 +839,8 @@ host.skills.list(profile?) // every skill for the scope (Capabilhost.skills.setEnabled(name, on, profile?) // enable/disable a skill — the Capabilities togglehost.toolsets.list(profile?) // toolsets + enabled statehost.toolsets.setEnabled(name, on, profile?)// enable/disable a toolset-host.profiles.list(scope?) // the profile list the profile rail reads-host.pluginDecisions // READ-ONLY atom: this window's plugin on/off decisions+host.profiles.list(scope?: ProfileScope) // the profile list the profile rail reads+host.pluginDecisions // READ-ONLY atom: this window's plugin on/off decisions (frozen copies)````host.request` is the same JSON-RPC the app itself uses (sessions, config, skills,@@ -1064,7 +1064,10 @@ calling `window.hermesDesktop.api` raw.plugin flip another plugin's enable state — exactly "plugins messing with eachother's functionality" — and `host` is a module singleton that cannot tell whichplugin is calling to restrict a writer to the caller's own id. The object has no-`set` at runtime, not just in the types. Enabling/disabling plugins stays in the+`set` at runtime, not just in the types, and every value it hands out (`get()`,+`.value`, the argument to `subscribe`/`listen` callbacks) is a **frozen copy** —+assigning into it throws instead of leaking into the map the app reads and+persists. Enabling/disabling plugins stays in theapp's Plugins tab; link to it with `host.navigate('/capabilities?tab=plugins')`.Teardown: the verbs are discrete user-triggered actions that write the same