Personal Telegram developer console for GitHub

fix(hardening): keep kill switch enforcement read-only compatible

davoodmehraban89 committed Oct 5, 2026 at 13:22 UTC f00bc28112d26c1bbeb701930a24f334be6410d7
1 file changed +7 -39
src/core/kill-switch.js
+7 -39
@@ -1,44 +1,12 @@
1 export class KillSwitch {
2 constructor({ store } = {}) {
3 - if (!store || typeof store.get !== 'function' || typeof store.set !== 'function') throw new Error('Kill switch store is required');
3 + if (!store || typeof store.get !== 'function') throw new Error('Kill switch store is required');
4 this.store = store;
5 }
6 -
7 - async status() {
8 - const state = await this.store.get();
9 - if (!state || !['NORMAL', 'LOCKED'].includes(state.mode)) throw new Error('Kill switch state is unavailable');
10 - return state;
11 - }
12 -
13 - async blocks(risk) {
14 - if (!['WRITE', 'DESTRUCTIVE'].includes(String(risk || ''))) return false;
15 - try {
16 - return (await this.status()).mode !== 'NORMAL';
17 - } catch {
18 - return true;
19 - }
20 - }
21 -
22 - async automationBlocked() {
23 - try {
24 - return (await this.status()).mode !== 'NORMAL';
25 - } catch {
26 - return true;
27 - }
28 - }
29 -
30 - async lock(context = {}) {
31 - this.#assertControl(context);
32 - return this.store.set({ mode: 'LOCKED', changedAt: Date.now() });
33 - }
34 -
35 - async unlock(context = {}) {
36 - this.#assertControl(context);
37 - return this.store.set({ mode: 'NORMAL', changedAt: Date.now() });
38 - }
39 -
40 - #assertControl(context) {
41 - if (context.isOwner !== true) throw new Error('Kill switch control requires owner');
42 - if (context.approved !== true) throw new Error('Kill switch control requires approval');
43 - }
6 + async status(){const state=await this.store.get();if(!state||!['NORMAL','LOCKED'].includes(state.mode))throw new Error('Kill switch state is unavailable');return state;}
7 + async blocks(risk){if(!['WRITE','DESTRUCTIVE'].includes(String(risk||'')))return false;try{return(await this.status()).mode!=='NORMAL';}catch{return true;}}
8 + async automationBlocked(){try{return(await this.status()).mode!=='NORMAL';}catch{return true;}}
9 + async lock(context={}){this.#assertControl(context);if(typeof this.store.set!=='function')throw new Error('Kill switch store is not writable');return this.store.set({mode:'LOCKED',changedAt:Date.now()});}
10 + async unlock(context={}){this.#assertControl(context);if(typeof this.store.set!=='function')throw new Error('Kill switch store is not writable');return this.store.set({mode:'NORMAL',changedAt:Date.now()});}
11 + #assertControl(context){if(context.isOwner!==true)throw new Error('Kill switch control requires owner');if(context.approved!==true)throw new Error('Kill switch control requires approval');}
12 }