MCPcopy Index your code
hub / github.com/FIND-Lab/AgentWard / register

Function register

index.ts:90–447  ·  view source on GitHub ↗
(api: OpenClawPluginApi)

Source from the content-addressed store, hash-verified

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 = [];

Callers

nothing calls this directly

Calls 15

shutdownMethod · 0.95
isRunningMethod · 0.95
initLoggerFunction · 0.90
initFileLogFunction · 0.90
setWorkerFunction · 0.90
getWorkerFunction · 0.90
handleAgentWardCommandFunction · 0.90
detectFoundationScanFunction · 0.90
getLoggerFunction · 0.90
formatUserPrependWarningFunction · 0.90

Tested by

no test coverage detected