-
Notifications
You must be signed in to change notification settings - Fork 19
fix: OpenClaw integration #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 UninstallHooks with RestoreBackup leaves manifest file behind When Was this helpful? React with 👍 or 👎 to provide feedback. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "id": "gryph", | ||
| "configSchema": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "properties": {} | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "name": "@gryph/openclaw-plugin", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "description": "Gryph audit trail plugin for OpenClaw", | ||
| "type": "module", | ||
| "openclaw": { | ||
| "extensions": [ | ||
| "./index.ts" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,83 @@ | ||
| import { execFileSync } from "child_process"; | ||
| import { join } from "path"; | ||
| import { homedir } from "os"; | ||
| import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry"; | ||
|
|
||
| export default function gryphPlugin(api) { | ||
| function invokeGryph(hookType, payload) { | ||
| try { | ||
| execFileSync("__GRYPH_COMMAND__", ["_hook", "openclaw", hookType], { | ||
| input: JSON.stringify(payload), | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| timeout: 5000, | ||
| }); | ||
| } catch (e) { | ||
| if (e.status === 2) { | ||
| throw new Error(e.stderr?.toString()?.trim() || "Blocked by gryph"); | ||
| } | ||
| } | ||
| } | ||
| const PLUGIN_ID = "gryph"; | ||
| const transcriptPath = join(homedir(), ".openclaw", "logs", "commands.log"); | ||
|
|
||
| function resolveSessionId(event, ctx) { | ||
| return event.sessionId || ctx.sessionKey || ""; | ||
| } | ||
|
|
||
| api.on("before_tool_call", (event, ctx) => { | ||
| invokeGryph("before_tool_call", { | ||
| hook_type: "before_tool_call", | ||
| tool: event.toolName, | ||
| args: event.params, | ||
| session_id: ctx.sessionKey, | ||
| agent_id: ctx.agentId, | ||
| function invokeGryph(hookType, payload) { | ||
| try { | ||
| execFileSync("__GRYPH_COMMAND__", ["_hook", "openclaw", hookType], { | ||
| input: JSON.stringify(payload), | ||
| stdio: ["pipe", "pipe", "pipe"], | ||
| timeout: 5000, | ||
| }); | ||
| }); | ||
| } catch (e) { | ||
| if (e.status === 2) { | ||
| throw new Error(e.stderr?.toString()?.trim() || "Blocked by gryph"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| api.on("after_tool_call", (event, ctx) => { | ||
| try { | ||
| invokeGryph("after_tool_call", { | ||
| hook_type: "after_tool_call", | ||
| export default definePluginEntry({ | ||
| id: PLUGIN_ID, | ||
| name: "Gryph", | ||
| description: "Audit trail plugin for OpenClaw agent actions", | ||
| register(api) { | ||
| api.on("before_tool_call", (event, ctx) => { | ||
| invokeGryph("before_tool_call", { | ||
| hook_type: "before_tool_call", | ||
| tool: event.toolName, | ||
| args: event.params, | ||
| result: event.result, | ||
| error: event.error, | ||
| duration_ms: event.durationMs, | ||
| session_id: ctx.sessionKey, | ||
| session_id: resolveSessionId(event, ctx), | ||
| agent_id: ctx.agentId, | ||
| transcript_path: transcriptPath, | ||
| }); | ||
| } catch (_) {} | ||
| }); | ||
| }); | ||
|
|
||
| api.on("session_start", (event, ctx) => { | ||
| try { | ||
| invokeGryph("session_start", { | ||
| hook_type: "session_start", | ||
| session_id: event.sessionId, | ||
| agent_id: ctx.agentId, | ||
| }); | ||
| } catch (_) {} | ||
| }); | ||
| api.on("after_tool_call", (event, ctx) => { | ||
| try { | ||
| invokeGryph("after_tool_call", { | ||
| hook_type: "after_tool_call", | ||
| tool: event.toolName, | ||
| args: event.params, | ||
| result: event.result, | ||
| error: event.error, | ||
| duration_ms: event.durationMs, | ||
| session_id: resolveSessionId(event, ctx), | ||
| agent_id: ctx.agentId, | ||
| transcript_path: transcriptPath, | ||
| }); | ||
| } catch (_) {} | ||
| }); | ||
|
|
||
| api.on("session_end", (event, ctx) => { | ||
| try { | ||
| invokeGryph("session_end", { | ||
| hook_type: "session_end", | ||
| session_id: event.sessionId, | ||
| message_count: event.messageCount, | ||
| duration_ms: event.durationMs, | ||
| agent_id: ctx.agentId, | ||
| }); | ||
| } catch (_) {} | ||
| }); | ||
| } | ||
| api.on("session_start", (event, ctx) => { | ||
| try { | ||
| invokeGryph("session_start", { | ||
| hook_type: "session_start", | ||
| session_id: resolveSessionId(event, ctx), | ||
| agent_id: ctx.agentId, | ||
| transcript_path: transcriptPath, | ||
| }); | ||
| } catch (_) {} | ||
| }); | ||
|
|
||
| api.on("session_end", (event, ctx) => { | ||
| try { | ||
| invokeGryph("session_end", { | ||
| hook_type: "session_end", | ||
| session_id: resolveSessionId(event, ctx), | ||
| message_count: event.messageCount, | ||
| duration_ms: event.durationMs, | ||
| agent_id: ctx.agentId, | ||
| transcript_path: transcriptPath, | ||
| }); | ||
| } catch (_) {} | ||
| }); | ||
| }, | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 "Already installed" check returns early without writing new required manifest and package.json files
When
InstallHooksdetects that the plugin file (index.ts) already exists and contains"invokeGryph", it returns early at line 80 with a success warning, skipping the manifest and package.json writes at lines 127-137. This means that users upgrading from a previous gryph version (which didn't deploy these files) will get a misleading "already installed" success, whileGetHookStatus(agent/openclaw/hooks.go:234-244) will report the installation as invalid due to the missingopenclaw.plugin.jsonandpackage.json. The only workaround isgryph install --force, but users won't know this unless they rungryph status.Suggested fix approach
The "already installed" check should also verify that the manifest and package.json exist. If they are missing, the install should proceed to write them (or at least the missing files) rather than returning early.
Was this helpful? React with 👍 or 👎 to provide feedback.