Personal Telegram developer console for GitHub
feat(hardening): pause automation when kill switch is locked
davoodmehraban89 committed
Oct 5, 2026 at 13:22 UTC
3ef3ead2cae5456f31b1e708791648fe9c15801b
1 file changed
+9
-1
src/core/automation-runner.js
+9
-1
@@ -1 +1,9 @@
1
-import {transitionAutomation} from './automation.js';export class AutomationRunner{constructor({router,store}){this.router=router;this.store=store;}async advance(state){const step=state.steps[state.cursor];if(!step)return state;const routed=await this.router.dispatchCallback(step.callback,{isOwner:true,ownerId:state.ownerId});if(!routed)throw new Error('Automation action unavailable');if(routed.requiresApproval){const next=transitionAutomation(state,{type:'pause',intent:{pluginId:routed.pluginId,actionId:routed.actionId,risk:routed.risk,input:routed.approval?.input,callback:step.callback,key:step.key}});await this.store.put(next);return next;}const checkpoint=await this.store.put(state);const result=routed.execute?await routed.execute():routed;const next=transitionAutomation(checkpoint,{type:'complete_step',key:step.key});await this.store.put(next);return {...next,lastResult:result};}async resume(state,{approval,key}){if(!approval||state.approvalIntent?.key!==key)throw new Error('Matching approval required');const resumed=transitionAutomation(state,{type:'resume',key});await this.store.put(resumed);return resumed;}}
1
+import {transitionAutomation} from './automation.js';
2
+export class AutomationRunner{
3
+ constructor({router,store,killSwitch=null}){this.router=router;this.store=store;this.killSwitch=killSwitch;}
4
+ async advance(state){
5
+ if(this.killSwitch&&await this.killSwitch.automationBlocked()){const next={...structuredClone(state),status:'paused_kill_switch',updatedAt:Date.now()};await this.store.put(next);return next;}
6
+ const step=state.steps[state.cursor];if(!step)return state;const routed=await this.router.dispatchCallback(step.callback,{isOwner:true,ownerId:state.ownerId});if(!routed)throw new Error('Automation action unavailable');if(routed.killSwitchLocked){const next={...structuredClone(state),status:'paused_kill_switch',updatedAt:Date.now()};await this.store.put(next);return next;}if(routed.requiresApproval){const next=transitionAutomation(state,{type:'pause',intent:{pluginId:routed.pluginId,actionId:routed.actionId,risk:routed.risk,input:routed.approval?.input,callback:step.callback,key:step.key}});await this.store.put(next);return next;}const checkpoint=await this.store.put(state);const result=routed.execute?await routed.execute():routed;const next=transitionAutomation(checkpoint,{type:'complete_step',key:step.key});await this.store.put(next);return {...next,lastResult:result};
7
+ }
8
+ async resume(state,{approval,key}){if(this.killSwitch&&await this.killSwitch.automationBlocked())throw new Error('Automation blocked by emergency kill switch');if(!approval||state.approvalIntent?.key!==key)throw new Error('Matching approval required');const resumed=transitionAutomation(state,{type:'resume',key});await this.store.put(resumed);return resumed;}
9
+}