(api: OpenClawPluginApi)
| 88 | // Example-only: allow-always cache for exact operation matches during this process lifetime. |
| 89 | allowAlwaysOps: new Set<string>(), |
| 90 | register(api: OpenClawPluginApi) { |
| 91 | initLogger(api); |
| 92 | if (!plugin.config) { |
| 93 | // First-time initialization only — register() may be called again |
| 94 | // if the plugin registry is reloaded (e.g., cache eviction). |
| 95 | const config = PluginConfig.fromPluginConfig(api.pluginConfig); |
| 96 | plugin.config = config; |
| 97 | plugin.startupConfig = structuredClone(config); |
| 98 | } |
| 99 | if (plugin.config!.logging.enableFileLog) { |
| 100 | initFileLog(); |
| 101 | } |
| 102 | |
| 103 | api.registerService({ |
| 104 | id: "agent-ward-worker", |
| 105 | start: async (ctx) => { |
| 106 | const worker = new PersistentWorker({ |
| 107 | tmpDir: resolvePreferredOpenClawTmpDir(), |
| 108 | config: { |
| 109 | timeout: plugin.config!.worker.timeout ?? 60000, |
| 110 | debug: plugin.config!.worker.debug ?? false, |
| 111 | logLevel: plugin.config!.worker.logLevel ?? 'info', |
| 112 | }, |
| 113 | }); |
| 114 | |
| 115 | setWorker(worker); |
| 116 | }, |
| 117 | stop: async (ctx) => { |
| 118 | const worker = getWorker(); |
| 119 | if (worker) { |
| 120 | worker.shutdown(); |
| 121 | setWorker(null); |
| 122 | } |
| 123 | }, |
| 124 | }); |
| 125 | |
| 126 | api.registerCommand({ |
| 127 | name: "agentward", |
| 128 | description: "View and modify AgentWard security configuration", |
| 129 | acceptsArgs: true, |
| 130 | requireAuth: true, |
| 131 | handler: (ctx) => { |
| 132 | const cfg = plugin.config!; |
| 133 | return handleAgentWardCommand(ctx, cfg, plugin.startupConfig!, (newCfg) => { plugin.config = newCfg; }); |
| 134 | }, |
| 135 | }); |
| 136 | |
| 137 | api.on("before_prompt_build", async (event, ctx) => { |
| 138 | let state = plugin.status.get(ctx.sessionKey!); |
| 139 | if (!state) { |
| 140 | state = new SessionState(api, event, ctx); |
| 141 | await state.setLLMContext(api); |
| 142 | plugin.status.set(ctx.sessionKey!, state); |
| 143 | } else { |
| 144 | await state.setLLMContext(api); |
| 145 | state.clear_tags(); |
| 146 | state.historyMessages = event?.messages; |
| 147 | state.currentMessages = []; |
nothing calls this directly
no test coverage detected